fix(backtest): run and settle a ticker or date given twice once (#1415)

- run_backtest drops repeated tickers and dates before building the grid
This commit is contained in:
Yijia-Xiao
2026-09-29 05:57:18 +00:00
parent 13cf1e8138
commit e973dd0e25
2 changed files with 10 additions and 0 deletions
+8
View File
@@ -296,3 +296,11 @@ def test_a_resumed_sweep_reports_only_the_cells_it_runs(tmp_path):
progress=lambda done, total, ticker, date: seen.append((done, total, date)))
assert seen == [(1, 1, "2026-01-12")]
@pytest.mark.unit
def test_a_ticker_or_date_given_twice_runs_and_settles_once(tmp_path):
run_backtest(["NVDA", "NVDA"], ["2026-01-05", "2026-01-05"], _config(tmp_path))
graph = _FakeGraph.instances[-1]
assert graph.calls == [("NVDA", "2026-01-05")]
assert graph.settled == ["NVDA"]
+2
View File
@@ -155,6 +155,8 @@ def run_backtest(
result = BacktestResult(run_id=run_id, log_path=Path(run_config["memory_log_path"]))
done = {(e["ticker"], e["date"]) for e in graph.memory_log.load_entries()}
# A ticker or date given twice is one cell, run and settled once.
tickers, dates = list(dict.fromkeys(tickers)), list(dict.fromkeys(dates))
cells = [(ticker, date) for ticker in tickers for date in dates]
todo = [cell for cell in cells if cell not in done]
result.skipped = len(cells) - len(todo)