#!/usr/bin/env python3 """Check current portfolio status and sector allocations""" import sys sys.path.append('/home/wdjones/.openclaw/workspace/projects/market-watch') import game_engine def main(): gid = game_engine.get_default_game_id() if not gid: print("No game found") return p = game_engine.get_portfolio(gid, 'case') if not p: print("No portfolio found") return print('Current Portfolio Status:') print(f'Total Value: ${p["total_value"]:,.2f}') cash_pct = p["cash"]/p["total_value"]*100 print(f'Cash: ${p["cash"]:,.2f} ({cash_pct:.1f}%)') print(f'Positions: {p["num_positions"]}') print() sectors = game_engine.get_sector_allocation(gid, 'case') if sectors: print('Sector Allocation:') for sector, pct in sorted(sectors.items(), key=lambda x: x[1], reverse=True): violation = ' *** VIOLATION ***' if pct > 30 else '' print(f' {sector}: {pct:.1f}%{violation}') else: print('No sector data available') print() print('Checking for violations...') result = game_engine.rebalance_portfolio(gid, 'case', dry_run=True) if result['violations']: print('Violations found:') for v in result['violations']: print(f' - {v}') print() if result['actions']: print('Recommended actions:') for action in result['actions']: print(f' - {action["action"]} {action["shares"]} {action["ticker"]} @ ${action["price"]:.2f} ({action["reason"]})') else: print('No violations found') # Show individual positions print() print('Individual Positions:') for ticker, pos in p["positions"].items(): sector = pos.get("sector", "Unknown") pct_of_portfolio = (pos["market_value"] / p["total_value"]) * 100 pnl_pct = ((pos["current_price"] - pos["avg_cost"]) / pos["avg_cost"]) * 100 print(f' {ticker:6s} ({sector:20s}): {pos["shares"]:4d} @ ${pos["current_price"]:7.2f} = ${pos["market_value"]:8,.0f} ({pct_of_portfolio:4.1f}% of port, {pnl_pct:+5.1f}% P&L)') if __name__ == "__main__": main()