fix: backtest skips duplicate ticker positions to prevent overwrite

When multiple recommendations for the same ticker produce 'act'
decisions, the second one would overwrite the first in
simulated_positions, losing the first position's value and causing
incorrect portfolio value calculations. Now skips if already holding.
This commit is contained in:
Celes Renata
2026-04-16 00:28:59 +00:00
parent 2eaf6dc025
commit d21110b3d2
+1 -1
View File
@@ -176,7 +176,7 @@ class BacktestReplay:
price = rec.get("current_price", 0.0)
qty = decision.computed_share_quantity or 0
if qty > 0 and price > 0:
if qty > 0 and price > 0 and ticker not in simulated_positions:
cost = price * qty
if cost <= portfolio_state.active_pool:
simulated_positions[ticker] = {