Backtest Kit exposes the same simulation engine through two complementary execution models: a background (event-driven) model whereDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-docs/llms.txt
Use this file to discover all available pages before exploring further.
Backtest.background() fires without blocking your process and emits results through event listeners, and an async iterator (pull-based) model where you for await over Backtest.run() and process each event inline. Both models share identical engine guarantees — they differ only in how you consume results, making it straightforward to switch between them as your workflow evolves.
Execution Models
Background Execution
Non-blocking. Best for production bots, multi-symbol fan-out, and monitoring dashboards.
listenDoneBacktest triggers report generation when complete.Async Iterator
Pull-based. Best for research scripts, testing pipelines, and LLM agent workflows where you want direct control over the event loop.
Background Execution Model
The background model runs the full historical replay without blocking the calling process. Register your listeners before callingBacktest.background() to ensure no events are missed.
listenDoneBacktest fires once per symbol when all timeframes in the frame have been replayed. Use it to generate and persist the Markdown report.
Async Iterator Model
The async iterator model yields each closed signal event as it is produced. Every yielded event hasaction === 'closed' and includes the full PNL and close-reason data for that signal.
for await supports early termination via break. The iterator is not
reusable — create a new Backtest.run() call for each replay.Registering Components
Before a backtest can run, you need to register three schemas: an exchange (data source), a frame (time window), and a strategy (signal logic). A risk schema is optional but strongly recommended.Add a frame schema
A frame defines the historical window, the tick interval, and the candle resolution the engine replays.The engine iterates over every
interval boundary between startDate and endDate, calling your strategy’s getSignal at the configured strategy interval.Add an exchange schema
An exchange schema wraps any CCXT-compatible data source. The minimal implementation for Binance via CCXT looks like this:The adapter contract requires that the first returned candle’s
timestamp equals the aligned since value, and that exactly limit candles are returned in sequential order.Add a risk schema
Risk validations run before any signal is accepted. They throw to reject a signal and silently pass to allow it.
VWAP Pricing and Realistic Fills
Backtest Kit uses VWAP (Volume Weighted Average Price) computed from the last 5 one-minute candles for all entry and exit decisions, rather than the raw candle close price. This models the realistic slippage of a market order that fills across multiple price levels.OHLC path-aware exit: Backtest Kit does not close positions close-to-close.
When a signal is active, the engine fetches the actual one-minute candle sequence
for
minuteEstimatedTime minutes and replays the OHLC path. A TP or SL is triggered
at the exact candle where the VWAP crosses the level — the same way a live exchange
would behave. This eliminates the look-ahead bias introduced by close-to-close
exit models.Report Generation
When a backtest completes, use theBacktest facade to produce and persist reports.
Performance Metrics
Metrics included in every backtest report
Metrics included in every backtest report
| Metric | Description | ||
|---|---|---|---|
| Total PNL | Cumulative profit/loss across all closed signals | ||
| Win rate | Percentage of trades that closed in profit | ||
| Average PNL | Mean PNL per closed trade | ||
| Sharpe Ratio | Risk-adjusted return: mean(PNL) / stdDev(PNL) | ||
| Annualized Sharpe | Sharpe × √365 | ||
| Sortino Ratio | Downside-risk-adjusted return (penalises only losses) | ||
| Pooled Sharpe | Cross-symbol portfolio Sharpe for multi-symbol runs | ||
| Calmar Ratio | Annualised return divided by maximum drawdown | ||
| Recovery Factor | Total PNL divided by maximum drawdown | ||
| Max Drawdown | Largest peak-to-trough loss in the equity curve | ||
| Expectancy | Expected value per trade in % | ||
| Profit Factor | Gross profit divided by gross loss | ||
| Certainty Ratio | `avgWin / | avgLoss | ` — quality of the win/loss distribution |
| Standard Deviation | Volatility of per-trade PNL |
Listening to Progress
UselistenProgress to track how far through the timeframe the replay has advanced — useful for long multi-day runs.