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:
@@ -176,7 +176,7 @@ class BacktestReplay:
|
|||||||
price = rec.get("current_price", 0.0)
|
price = rec.get("current_price", 0.0)
|
||||||
qty = decision.computed_share_quantity or 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
|
cost = price * qty
|
||||||
if cost <= portfolio_state.active_pool:
|
if cost <= portfolio_state.active_pool:
|
||||||
simulated_positions[ticker] = {
|
simulated_positions[ticker] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user