[codex] fix managed portfolio equity#80
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22415491a6
ℹ️ 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".
| position_market_value: float, | ||
| prefer_cash_plus_positions: bool = False, | ||
| ) -> tuple[float, str]: | ||
| resolved_cash = _positive_or_none(cash_balance) |
There was a problem hiding this comment.
Handle zero managed cash before using account totals
When a strategy-managed account is fully invested (cash_balance is reported as $0.00) and also has unmanaged holdings, _positive_or_none(cash_balance) makes resolved_cash None, so the new managed override is skipped and the later balance_total branch still returns the full account value. That reintroduces the exact sizing bug this change is trying to avoid for a common fully-invested portfolio: managed snapshots can include unmanaged holdings in total_equity instead of using the filtered position value (plus zero cash).
Useful? React with 👍 / 👎.
Summary
strategy_symbolsare configured.Root Cause
Firstrade balances can expose full-account value, which was preferred even after positions were filtered to managed symbols.
Validation
python3 -m py_compile application/runtime_broker_adapters.pypandas/requestsimport stubs for managed and unmanaged equity behavior.pandasandrequests.