TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
Backtest singleton orchestrates historical strategy simulations. It wires together the registered exchange, frame, strategy, risk, and action schemas into a single execution pipeline that replays market data chronologically, evaluates signals at each tick, and streams results. The facade offers two consumption models—pull-based run() for research and scripting, and event-driven background() for production pipelines—both backed by the same engine and guarantees.
run()
AsyncIterableIterator that yields one result per closed or cancelled signal. The generator is lazy—no work is done until you start consuming it. Use break or return inside for await to terminate early; the engine cleans up immediately.
IStrategyBacktestResult
The yielded union includes the following discriminated variants:action | Description |
|---|---|
"opened" | A pending position was just activated (scheduled signal filled at priceOpen). |
"scheduled" | A new scheduled signal was created and is waiting for price to reach entry. |
"active" | Candles exhausted while monitoring a signal with minuteEstimatedTime: Infinity. |
"closed" | Signal completed with closeReason: take_profit, stop_loss, time_expired, or closed. |
"cancelled" | A scheduled signal was cancelled (timeout, price_reject, or user). |
background()
getData()
clear() call.
Key fields on BacktestStatisticsModel:
| Field | Description |
|---|---|
signalList | Array of all IStrategyTickResultClosed results. |
totalSignals | Count of closed signals. |
winCount / lossCount | Win and loss counts. |
winRate | Win rate percentage (0–100), null if unsafe. |
avgPnl | Average PNL per signal as percentage, null if unsafe. |
totalPnl | Cumulative PNL across all signals, null if unsafe. |
sharpeRatio | Risk-adjusted return (avgPnl / stdDev), null if unsafe. |
annualizedSharpeRatio | Sharpe × √tradesPerYear, null if unsafe. |
sortinoRatio | Downside deviation Sharpe variant. |
calmarRatio | Annualized return / max drawdown. |
recoveryFactor | Total PNL / max drawdown. |
expectedYearlyReturns | Projected annual return based on average trade duration. |
getReport()
dump()
./dump/backtest/. The filename includes the symbol, strategy name, exchange, frame, and a timestamp for uniqueness.
clear()
getData() and getReport() to reflect only the most recent execution.
stop()
stopStrategy on the underlying strategy instance.
Context Object
All methods accept a context with three required fields:Name of a registered strategy schema.
Name of a registered exchange schema.
Name of a registered frame schema (defines backtest period and tick interval).