The orchestrator exposes POST/GET /backtest so agents (or any client) can run a backtest using qtos-core and use the results to gate decisions—e.g. "only alert if this signal would have been profitable in a backtest."
- Backtest API:
POST /backtestandGET /backtestwith symbol, data source (CSV or data-ingestion-service), initial_cash, quantity, strategy_type (currentlybuy_and_hold), and optional period for data_service. - Runner:
orchestrator.backtest_runnerloads OHLCV from a CSV path or from the data-ingestion-service (DATA_SERVICE_URL), runs qtos-core’sBacktestEnginewithBuyAndHoldStrategy, and returns metrics (PnL, CAGR, Sharpe, max drawdown, etc.) and num_trades. - Requirements: qtos-core must be present as a sibling of the orchestrator (same workspace root). Optional: data-ingestion-service for live data.
- Agent produces a signal (e.g. sentiment shift, insider activity).
- Agent (or orchestrator) calls
POST /backtestwith the relevant symbol and parameters (e.g. quantity, period). - Client checks metrics in the response:
sharpe_ratio,max_drawdown_pct,total_return_pct, etc. - Gate the alert: Only notify or act if metrics pass thresholds (e.g.
sharpe_ratio > 0.5andmax_drawdown_pct < 20).
Example (pseudo-code in an agent or wrapper):
response = requests.post(
"http://localhost:8000/backtest",
json={"symbol": "AAPL", "data_source": "data_service", "period": "1y", "quantity": 10},
)
data = response.json()
metrics = data.get("metrics", {})
if metrics.get("sharpe_ratio", 0) > 0.5 and metrics.get("max_drawdown_pct", 100) < 20:
send_alert("Signal passed backtest", data)
else:
log("Signal did not pass backtest; no alert")- csv — Use
csv_path(or default qtos-core sample atqtos-core/examples/data/sample_ohlcv.csv). Good for demos and CI. - data_service — Use data-ingestion-service. Set
DATA_SERVICE_URL(e.g.http://localhost:8001). Requires the data service to have ingested prices for the symbol.
- More strategies: Extend
backtest_runner.run_backtest()to accept otherstrategy_typevalues and instantiate the corresponding qtos-core strategy (or wrap VectorBT/Backtrader later). - Advisors/validators/observers: The qtos-core
BacktestEnginealready supports advisors, validators, and observers. The runner can be extended to accept optional agent hooks (e.g. regime filter, guardian validator) and pass them into the engine. - Richer metrics: The API already returns standard metrics; add custom metrics in the runner or in the client.
- qtos-core backtesting: qtos-core README and
backtesting/module. - Orchestrator API: Swagger at
http://localhost:8000/docswhen the API is running.