From d21110b3d27de2337418f47c6a9fd1165c282ac8 Mon Sep 17 00:00:00 2001 From: Celes Renata Date: Thu, 16 Apr 2026 00:28:59 +0000 Subject: [PATCH] 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. --- services/trading/backtest_replay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/trading/backtest_replay.py b/services/trading/backtest_replay.py index a68b579..89c5b6d 100644 --- a/services/trading/backtest_replay.py +++ b/services/trading/backtest_replay.py @@ -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] = {