Backtest API
Run the same costed strategy backtester the Backtest Lab uses on your own rows, from Python, a notebook or curl. Company financial data (GET /api/v1/fundamentals) is documented in the Company Financials API reference.
Authentication
Create a key at /account/api-keys and send it as a bearer token. The backtest endpoint requires a Quant key.
POST /api/v1/backtest
Run a cross-sectional strategy and get a costed result: equity curve, Sharpe/IR, turnover, walk-forward out-of-sample folds β or a parameter sweep with the overfit-corrected Deflated Sharpe. Backtest your rows (panel). Quant key required.
curl -X POST https://www.tradingagentapp.com/api/v1/backtest \
-H "Authorization: Bearer ta_live_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"config": { "direction": "long_short", "quantile": 0.1, "weighting": "equal", "holdDays": 21 },
"panel": [
{ "date": "2024-01-02", "asset": "AAPL", "score": 0.8, "forward_return": 0.012 },
{ "date": "2024-01-02", "asset": "MSFT", "score": -0.3, "forward_return": -0.004 }
],
"sweep": false
}'The two rows only show the shape: a real request needs at least 20 rows across several dates, or the API answers 400 insufficient_data.
| config.direction | long_short | long_only |
| config.quantile | top/bottom fraction per leg (0.01β0.5) |
| config.weighting | equal | score | rank |
| config.holdDays | holding horizon in trading days (1β252) |
| config.costBps | flat round-trip override; omit for per-market real costs |
| config.borrowBps | annual short-borrow cost (bps) |
| panel | [ { date, asset, market?, score, forward_return } ] β backtest your own |
| sweep | true β grid search + Deflated Sharpe of the winner |
{
"object": "backtest_result",
"n_rows": 8421,
"metrics": {
"cagr": 0.123, "sharpe": 1.42, "lo_sharpe": 1.31, "information_ratio": 0.88,
"max_drawdown": 0.19, "avg_turnover": 0.34, "cost_drag_annual": 0.021,
"oos_sharpe_mean": 0.97
},
"equity_curve": [1, 1.01, 0.99, ...],
"folds": [ { "fold": 0, "sharpe": 1.1, "cagr": 0.14, "...": "..." } ]
}Python β tradingagent.py
A single-file client with no dependencies: Download tradingagent.py.
from tradingagent import TradingAgent
ta = TradingAgent() # reads TRADING_AGENT_API_KEY
rows = [ # your own scores: one row per asset per date
{"date": "2024-01-02", "asset": "AAPL", "score": 0.8, "forward_return": 0.012},
{"date": "2024-01-02", "asset": "MSFT", "score": -0.3, "forward_return": -0.004},
]
bt = ta.backtest(
config={"direction": "long_short", "quantile": 0.1, "holdDays": 7},
panel=rows,
)
m = bt["metrics"]
print(f"Sharpe {m['sharpe']:.2f} CAGR {m['cagr']:.1%} maxDD {m['max_drawdown']:.1%}")
# Overfit-corrected sweep
sw = ta.backtest(config={"holdDays": 7}, panel=rows, sweep=True)
print(sw["best"]["label"], sw["deflated_sharpe"]["dsr"], sw["deflated_sharpe"]["survives"])The two rows only show the shape: a real request needs at least 20 rows across several dates, or the API answers 400 insufficient_data.
The API exposes only historical data and factual statistical analysis of it β not forward recommendations and not investment advice. Backtested results are hypothetical, model the modelled spread + each market's statutory costs, and do not predict future returns. Numbers such as forward_return are fractions: 0.025 = +2.5%.