diff --git a/src/quant_platform_kit/common/runtime_inputs.py b/src/quant_platform_kit/common/runtime_inputs.py index 852b1cf..90c5724 100644 --- a/src/quant_platform_kit/common/runtime_inputs.py +++ b/src/quant_platform_kit/common/runtime_inputs.py @@ -448,12 +448,18 @@ def build_account_state_from_portfolio_snapshot( if resolved_liquid_cash is None: resolved_liquid_cash = 0.0 + total_strategy_equity = ( + float(resolved_liquid_cash) + sum(float(value) for value in market_values.values()) + if filter_enabled + else float(snapshot.total_equity) + ) + account_state = { "available_cash": float(resolved_liquid_cash), "market_values": market_values, "quantities": quantities, "sellable_quantities": sellable_quantities, - "total_strategy_equity": float(snapshot.total_equity), + "total_strategy_equity": total_strategy_equity, } raw_cash_by_currency = ( metadata.get("cash_by_currency") if isinstance(metadata, Mapping) else None diff --git a/tests/test_strategy_contracts.py b/tests/test_strategy_contracts.py index 5f37f66..423322e 100644 --- a/tests/test_strategy_contracts.py +++ b/tests/test_strategy_contracts.py @@ -353,9 +353,24 @@ def test_build_account_state_from_portfolio_snapshot_filters_strategy_symbols(se account_state["sellable_quantities"], {"TQQQ": 3, "BOXX": 10, "QQQI": 0}, ) - self.assertEqual(account_state["total_strategy_equity"], 50000.0) + self.assertEqual(account_state["total_strategy_equity"], 14000.0) self.assertEqual(account_state["cash_by_currency"], {"USD": 8000.0, "SGD": 350.0}) + def test_build_account_state_without_strategy_symbols_preserves_snapshot_equity(self) -> None: + snapshot = PortfolioSnapshot( + as_of="2026-04-09", + total_equity=50000.0, + buying_power=12000.0, + positions=( + Position(symbol="TQQQ", quantity=5, market_value=1000.0), + Position(symbol="QQQ", quantity=99, market_value=9999.0), + ), + ) + + account_state = build_account_state_from_portfolio_snapshot(snapshot) + + self.assertEqual(account_state["total_strategy_equity"], 50000.0) + def test_build_portfolio_snapshot_from_account_state_keeps_strategy_symbol_order(self) -> None: snapshot = build_portfolio_snapshot_from_account_state( {