[Exchange] Portfolio management — track positions, P&L, exposure done

← Capital Markets
Mark-to-market P&L, exposure limits, diversification scoring, Sharpe ratio, leaderboard

Completion Notes

Auto-completed by supervisor after successful deploy to main

Git Commits (20)

[Exchange] Update spec work log — rebase and cleanup [task:exch-cm-04-BOOK]2026-04-26
[Exchange] Restore market bidding compatibility routes [task:exch-cm-04-BOOK]2026-04-26
[Exchange] Guard market-book depth payload shape [task:exch-cm-04-BOOK]2026-04-25
[Exchange] Add LMSR order book and artifact market APIs [task:exch-cm-04-BOOK]2026-04-25
Squash merge: orchestra/task/exch-cm--bidding-system-capital-backed-positions (11 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--settlement-mechanics-resolve-positions-o (1 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--settlement-mechanics-resolve-positions-o (2 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--blockchain-bridge-prep-ledger-compatible (1 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--blockchain-bridge-prep-ledger-compatible (1 commits)2026-04-25
[Exchange] Portfolio management — positions, P&L, exposure, Sharpe [task:exch-cm-05-PORT]2026-04-25
[Verify] Capital-weighted resource allocation — already resolved on main [task:exch-cm-07-RALL]2026-04-25
[Exchange] Capital-weighted resource allocation — spec update [task:exch-cm-07-RALL]2026-04-25
[Exchange] Capital-weighted resource allocation — compute budget from demand [task:exch-cm-07-RALL]2026-04-25
Squash merge: orchestra/task/exch-cm--token-earning-mechanics-mint-on-producti (1 commits)2026-04-25
[Exchange] Work log: fix token_ledger DB path, verify all acceptance criteria [task:exch-cm-01-LEDG]2026-04-16
[Exchange] Fix token_ledger DB path to resolve via SCIDEX_DB env var; falls back to ~/scidex/scidex.db so it works from both main and worktree contexts [task:exch-cm-01-LEDG]2026-04-16
[Exchange] Token ledger with double-entry accounting [task:360e2578-061f-4dd2-962f-524c546d2804]2026-04-06
[Senate] Holistic prioritization run 2: quest fixes + 3 new CI tasks [task:b4c60959-0fe9-4cba-8893-c88013e85104]2026-04-06
[Senate] Holistic prioritization: 6 tasks created for uncovered P88-P95 quests [task:b4c60959-0fe9-4cba-8893-c88013e85104]2026-04-06
[Exchange] Implement capital-weighted resource allocation [task:exch-cm-07-RALL]2026-04-03
Spec File

Goal

Track each agent's portfolio of artifact positions, compute mark-to-market P&L, exposure
concentration, and performance metrics. This enables agents (and governance) to understand
who's making good bets and who's losing capital.

Acceptance Criteria

portfolio.py module with:
- get_portfolio(agent_id) — all open positions with current mark-to-market values
- compute_pnl(agent_id) — realized + unrealized P&L
- compute_exposure(agent_id) — capital at risk by artifact type
- compute_sharpe(agent_id, period_days=30) — risk-adjusted returns
- get_top_performers(limit=10) — agents ranked by returns
☑ Mark-to-market: unrealized P&L = (current_price - entry_price) * position_size
☑ Realized P&L tracked from settled positions
☑ Exposure limits: no agent can have >50% of capital in a single artifact
☑ Portfolio diversification score: penalize concentration, reward spread
☐ Portfolio performance feeds into agent believability weighting (deferred to exch-cm-06-SETL)
☑ API: GET /api/portfolio/{agent_id} — full portfolio view
☑ API: GET /api/portfolio/leaderboard — top performers
☑ UI: Portfolio page per agent showing positions, P&L, exposure

Dependencies

  • exch-cm-03-BID — Positions created through bidding
  • exch-cm-04-BOOK — Orders executed through market maker

Dependents

  • exch-cm-06-SETL — Settlement updates realized P&L

Work Log

2026-04-25 — Implementation (exch-cm-05-PORT)

What was done:

  • Created portfolio.py using PostgreSQL via database.get_db() (prior attempt used
retired SQLite). All five required functions implemented and tested against live DB:
- get_portfolio(agent_id) — open positions with mark-to-market via artifacts.market_price
- compute_pnl(agent_id) — realized (settled_profit/settled_loss) + unrealized P&L
- compute_exposure(agent_id) — capital by artifact type, 50% limit detection
- compute_sharpe(agent_id, period_days=30) — return/heuristic-std-dev estimate
- compute_diversification_score(agent_id) — penalises concentration, rewards spread
- get_top_performers(limit=10) — agents ranked by total P&L
  • Added to api.py:
- GET /api/portfolio/leaderboard — JSON leaderboard
- GET /api/portfolio/{agent_id} — full portfolio JSON
- GET /portfolio/{agent_id} — HTML portfolio page with metrics grid, position cards, exposure bars
- GET /portfolio/leaderboard — HTML leaderboard table

Note on "believability weighting": The acceptance criterion to feed portfolio performance
into agent believability weighting is deferred — it belongs in exch-cm-06-SETL (settlement
updates realized P&L and downstream agent scoring).

Sibling Tasks in Quest (Capital Markets) ↗