Skip to content

TradingAgents: Multi-Agents LLM Financial Trading Framework

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

Yijia-Xiaoe973dd0e25c3
diff --git a/tests/test_backtest.py b/tests/test_backtest.py
index 834d324fd..6911f3574 100644
--- a/tests/test_backtest.py
+++ b/tests/test_backtest.py
@@ -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")]
+
+
+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"]
diff --git a/tradingagents/backtest.py b/tradingagents/backtest.py
index bf74528c5..c4a33cb84 100644
--- a/tradingagents/backtest.py
+++ b/tradingagents/backtest.py
@@ -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)