Saltar al contenido principal

Recipe: run a backtest from YAML

$resp = curl -X POST http://localhost:8000/backtest/run `
-H "Content-Type: application/json" `
-d '{"config": <parsed YAML as JSON>, "run_name": "my-strategy-run"}'

# Tail progress (canonical {task_id, stage, message, timestamp} frames).
docker exec alphaswarm-api python -c "from alphaswarm.ws.broker import subscribe; \
[print(m) for m in subscribe('<task_id>')]"

The request body is JSON (BacktestRequest): config is the parsed strategy YAML as a dict, not the raw YAML text.

Choose your engine​

The default engine (when the config's backtest: block omits engine:) is the event-driven engine (EventDrivenBacktester). Set engine: in the YAML to one of the registered shortcuts — event / event-driven, vectorbt-pro (alias vbtpro), vectorbt, backtesting (backtesting.py), zvt, aat, or backtrader — to pick a different one. See backtest engines for the capability matrix and fallback cascade.

Walk-forward + WFO​

curl -X POST http://localhost:8000/backtest/walk_forward `
-d '{"config": {...}, "train_window_days":252, "test_window_days":63, "step_days":63}'

The endpoint dispatches the walk-forward run as a single Celery task (run_walk_forward) that writes its own backtest_runs row(s) and streams progress over the usual /chat/stream/{task_id} channel.

Look at results​

  • backtest_runs row in Postgres for the headline metrics.
  • backtest_run_artifacts rows (object-storage pointers, keyed by backtest_run_id / artifact_kind) for the full equity curve, trade log, signal log, and event log — too large for the relational row.
  • The QuantStats tearsheet endpoint at POST /analytics/portfolio/tearsheet for an HTML report.

Deeper reads​