Expand description
The event-driven backtest loop.
Look-ahead bias is structurally prevented by default: signal-driven orders
are decided on a bar’s close and fill on the next bar’s open. An
opt-in fill_timing: "close" instead fills market orders on the signalling
bar’s own close (close-to-close, deliberately optimistic). Stop-loss and
take-profit are price levels checked intrabar against each bar’s OHLC and
fill at the level (conservative: the stop is assumed hit before the target
when a bar’s range brackets both). Equity is marked to market at every close.
Supports long and short positions; market, limit and stop entry orders (a
limit/stop rests at a percent offset from the signal close and fills when a
later bar reaches it, otherwise it keeps working); maker/taker fees (resting
limit fills pay maker, market/stop fills pay taker) and fixed-bps, order-book-spread or
volume-impact slippage; and leverage / position sizing (fixed fraction / cash / quantity,
risk-per-trade and vol-target, capped by max_leverage and
max_position_pct; without max_leverage the cap is 1x equity — no leverage
by default). Execution latency (latency_bars) delays every fill, and
volume-participation partial fills (partial_fills + max_participation)
cap an entry to a fraction of the bar’s volume. Perpetual funding
(costs.funding) is charged each bar to an open position from the
derivatives feed, and a leveraged position is liquidated intrabar at its
bankruptcy price when risk.liquidation is set.
Structs§
- Feeds
- The optional non-OHLCV feeds for one bar: a reference-series close (pairwise),
a derivatives tick (derivatives) and an order-book snapshot (order-book).
Absent feeds are
None; indicators that need a missing feed yield nothing. - Streaming
Backtest - A streaming backtest: feed bars one at a time with
StreamingBacktest::step, thenStreamingBacktest::finish. The historical runner is exactly this fed from a slice, so backtest and live share one code path — pointstepat a live feed and the same engine becomes the live bot.
Constants§
- DEFAULT_
CAPITAL - Default starting capital for the runner.
Functions§
- run
- Run a backtest of
specovercandleswith the default capital. - run_
stream - Run a backtest over a candle stream, invoking
on_barwith the streaming state after each bar — the streaming entry point for a live tail or for emitting the equity curve incrementally. - run_
with_ capital - Run a backtest with explicit starting
capital. - run_
with_ cross_ section - Run a backtest with a per-bar market cross-section for breadth indicators
(advance/decline,
McClellan, TRIN, …).sectionsmust be the same length ascandles. - run_
with_ deriv - Run a backtest with a per-bar derivatives feed for derivatives indicators
(funding, open interest, long/short ratio, …).
derivsmust be the same length ascandles. - run_
with_ orderbook - Run a backtest with a per-bar order-book feed for order-book indicators
(imbalance, microprice, quoted spread, …).
booksmust be the same length ascandles. - run_
with_ ref - Run a backtest with a reference price series for pairwise indicators. The
reference candle at each index supplies the second input (its close) to
pairwise indicators such as correlation, beta or spread.
referencemust be the same length ascandles. - run_
with_ trades - Run a backtest with a per-bar trade feed for trade-flow indicators (CVD,
trade imbalance, VPIN, signed volume, …).
trades[i]is the list of trades that printed within bari; the outer length must matchcandles.