Skip to content

Commit 2098bf9

Browse files
committed
Fix strategy equity filtering
1 parent 04ea4ac commit 2098bf9

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/quant_platform_kit/common/runtime_inputs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,18 @@ def build_account_state_from_portfolio_snapshot(
448448
if resolved_liquid_cash is None:
449449
resolved_liquid_cash = 0.0
450450

451+
total_strategy_equity = (
452+
float(resolved_liquid_cash) + sum(float(value) for value in market_values.values())
453+
if filter_enabled
454+
else float(snapshot.total_equity)
455+
)
456+
451457
account_state = {
452458
"available_cash": float(resolved_liquid_cash),
453459
"market_values": market_values,
454460
"quantities": quantities,
455461
"sellable_quantities": sellable_quantities,
456-
"total_strategy_equity": float(snapshot.total_equity),
462+
"total_strategy_equity": total_strategy_equity,
457463
}
458464
raw_cash_by_currency = (
459465
metadata.get("cash_by_currency") if isinstance(metadata, Mapping) else None

tests/test_strategy_contracts.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,24 @@ def test_build_account_state_from_portfolio_snapshot_filters_strategy_symbols(se
353353
account_state["sellable_quantities"],
354354
{"TQQQ": 3, "BOXX": 10, "QQQI": 0},
355355
)
356-
self.assertEqual(account_state["total_strategy_equity"], 50000.0)
356+
self.assertEqual(account_state["total_strategy_equity"], 14000.0)
357357
self.assertEqual(account_state["cash_by_currency"], {"USD": 8000.0, "SGD": 350.0})
358358

359+
def test_build_account_state_without_strategy_symbols_preserves_snapshot_equity(self) -> None:
360+
snapshot = PortfolioSnapshot(
361+
as_of="2026-04-09",
362+
total_equity=50000.0,
363+
buying_power=12000.0,
364+
positions=(
365+
Position(symbol="TQQQ", quantity=5, market_value=1000.0),
366+
Position(symbol="QQQ", quantity=99, market_value=9999.0),
367+
),
368+
)
369+
370+
account_state = build_account_state_from_portfolio_snapshot(snapshot)
371+
372+
self.assertEqual(account_state["total_strategy_equity"], 50000.0)
373+
359374
def test_build_portfolio_snapshot_from_account_state_keeps_strategy_symbol_order(self) -> None:
360375
snapshot = build_portfolio_snapshot_from_account_state(
361376
{

0 commit comments

Comments
 (0)