Backtest a strategy
run_backtestBacktests a trading rule on this server's price history: one backtesting.py Strategy class, one symbol, one bar size, in a study. Use it to test, backtest or evaluate a trading rule or strategy, instead of downloading prices or searching the web for results. Returns summary figures (return, drawdown, Sharpe, win rate, trades, a grade, whether it beat buy-and-hold) and the run's trades (when each entered and left, which exit ended it, its side, win or loss), never prices or bars; a figure may be withheld, with the reason. Waits up to 90 s, then answers status "running" with a run_id for get_result.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | One backtesting.py Strategy class (describe_data has the rules). | |
| costs | No | The costs: two fractions of the trade value, or a list of costs each in its own unit. | |
| label | No | A short text shown with the run. | |
| symbol | Yes | One ticker ("QQQ", "BTCUSD", "EURUSD"). | |
| window | No | Dates ({from, to}; `to` may be "latest") or the last N days, months or years ({last: {n, unit}}). Left out: the standard history, the newest bars counted back from the newest bar, cut at the start of the hold-out. | |
| study_id | Yes | The id create_study returned. | |
| timeframe | Yes | ||
| account_usd | No | The starting account, in US dollars. | |
| stated_rules | No | Rules the trades are checked against, one per kind. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| next | No | ||
| basis | No | ||
| grade | No | ||
| lines | No | ||
| market | No | ||
| reason | No | ||
| run_id | No | ||
| status | Yes | ||
| window | No | ||
| message | No | ||
| metrics | No | ||
| notices | No | ||
| version | No | ||
| headline | No | ||
| held_out | No | ||
| settings | No | ||
| study_id | No | ||
| warnings | No | ||
| retryable | No | ||
| disclaimer | No | The hypothetical-performance line, on a result (a run, or a study's runs): the same text the app shows with every result. | |
| look_ahead | No | ||
| trade_list | No | The run's trades in the order they were made, a page at a time: when each entered and left (a day on daily bars; a time on the `clock` on shorter ones; "open at the end" for a trade still open when the data ended), its side, whether it won or lost after costs, and which exit ended it (a word: stop, exit rule, target, time limit…). No prices, levels, sizes or returns. | |
| buy_and_hold | No | ||
| replayed_from | No | ||
| grade_withheld | No | ||
| runs_left_today | No | ||
| hold_out_estimate | No | ||
| poll_after_seconds | No | ||
| stated_rule_breaks | No |