[codex] filter IBKR strategy portfolio equity#156
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae8394f95d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| strategy_market_value = sum( | ||
| float(details.get("quantity") or 0.0) * float(details.get("avg_cost") or 0.0) | ||
| for details in filtered_positions.values() | ||
| ) | ||
| buying_power = float(dict(account_values or {}).get("buying_power") or 0.0) | ||
| filtered_account_values = { | ||
| **dict(account_values or {}), | ||
| "equity": buying_power + strategy_market_value, |
There was a problem hiding this comment.
Base projected equity on market value, not cost basis
For accounts that already hold any strategy symbol whose current price differs from its average cost, this projection changes account_values["equity"] from broker net liquidation to buying power plus cost basis (quantity * avg_cost). execute_rebalance then sizes targets from this equity while valuing current holdings with live quotes, so appreciated positions can be under-targeted and depreciated positions over-targeted even when the account contains only strategy positions. The projection needs to carry/use actual market value from the portfolio snapshot or quote the filtered symbols rather than using average cost.
Useful? React with 👍 / 👎.
Summary
Root Cause
IBKR account snapshots use broker account net liquidation, so non-strategy positions could inflate strategy logs, notifications, and value-target inputs.
Validation
python3 -m py_compile application/rebalance_service.py strategy_runtime.py_strategy_portfolio_viewand projectedPortfolioSnapshotequity.