"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(backtest): declare target_positions.csv so the runner actually exposes it
Haozhe Wufd7b8d4a090d
diff --git a/agent/src/core/runner.py b/agent/src/core/runner.pyindex 80a7bce5b..caed5461c 100644--- a/agent/src/core/runner.py+++ b/agent/src/core/runner.py@@ -334,6 +334,13 @@ _ARTIFACTS_SPEC = {"metrics": {"schema": "metrics_csv", "path": "artifacts/metrics.csv"},"trades": {"schema": "trade_log", "path": "artifacts/trades.csv"},"positions": {"schema": "positions_csv", "path": "artifacts/positions.csv"},+ # Optimiser requests, kept separate from the executed book above. Without+ # this entry the file is written but never appears in the runner's+ # artifact map, so nothing downstream can compare intent against fills.+ "target_positions": {+ "schema": "positions_csv",+ "path": "artifacts/target_positions.csv",+ },"run_card_json": {"schema": "json", "path": "run_card.json"},"run_card_md": {"schema": "markdown", "path": "run_card.md"},},diff --git a/agent/tests/test_base_engine.py b/agent/tests/test_base_engine.pyindex 3c6a8e4ea..91cb29627 100644--- a/agent/tests/test_base_engine.py+++ b/agent/tests/test_base_engine.py@@ -486,6 +486,52 @@ def test_positions_artifact_reports_fills_not_blocked_targets(tmp_path) -> None:assert target_csv.iloc[1]["AAPL.US"] == pytest.approx(0.8)+def test_every_written_artifact_is_declared_to_the_runner(tmp_path) -> None:+ """An artifact the engine writes but the spec omits is invisible downstream.++ ``Runner`` builds its returned artifact map by walking+ ``_ARTIFACTS_SPEC``, so a file that is written and not declared exists on+ disk while no caller can find it. Asserting the direction that matters+ (written ⊆ declared) makes adding an artifact without registering it fail+ here rather than silently.+ """+ from src.core.runner import _ARTIFACTS_SPEC++ dates, bars, close_df, targets = _fractional_fixture([0.2, 0.8, 0.8])+ engine = _FractionalEngine(block_adds_after_first=True)+ engine._execute_bars(dates, {"AAPL.US": bars}, close_df, targets, ["AAPL.US"])+ equity = pd.Series(+ [snapshot.equity for snapshot in engine.equity_snapshots], index=dates+ )+ engine._write_artifacts(+ tmp_path,+ {"AAPL.US": bars},+ dates,+ equity,+ pd.Series(1_000.0, index=dates),+ pd.Series(0.0, index=dates),+ targets,+ {},+ ["AAPL.US"],+ )++ declared = {+ entry["path"].split("artifacts/", 1)[1]+ for entry in _ARTIFACTS_SPEC["artifacts"].values()+ if str(entry.get("path", "")).startswith("artifacts/")+ }+ # Per-symbol OHLCV copies are deliberately undeclared: their names depend on+ # the universe, and they mirror the loader's input rather than a result.+ written = {+ path.name+ for path in (tmp_path / "artifacts").glob("*.csv")+ if not path.name.startswith("ohlcv_")+ }++ undeclared = sorted(written - declared)+ assert not undeclared, f"written but not declared in _ARTIFACTS_SPEC: {undeclared}"++def _run_lifecycle(engine: _LifecycleEngine) -> None:dates = pd.DatetimeIndex([pd.Timestamp("2026-01-02")])frame = pd.DataFrame({"open": [100.0], "close": [100.0]}, index=dates)