quantlab.runs.backtest_stats#
Return, relative, win-rate, turnover and trade statistics of a backtest, as public functions.
These are the returns-based rows and the turnover rows of a backtest run’s
metrics.json: the in_sample, out_of_sample and benchmark
return blocks, the relative block, the win rates and the three turnover
rows, the last two counted on the decided rebalances a run records (its
rebalance record), never inferred from its fills; and the round-trip trade rows and Max Gross Exposure [%] of its
whole block, from fill records (round_trips, round_trip_stats,
exposure_stats), with the deepest drawdown the report marks
(drawdown_span). quantlab.runs.run_metrics assembles a run’s metric
blocks from them, for the vectorbt backtester and for a tool that simulates a
run elsewhere (an event-driven replay of a quantlab run) alike, so the
numbers are comparable.
The module imports only numpy, pandas and xarray: no quantlab model or
dataset layer, no vectorbt and no torch, so importing it is cheap and drags
in no simulation engine. return_stats reimplements vectorbt’s
ReturnsAccessor.stats (vectorbt 1.1) to the bit: every sum and product
is accumulated in index order, as vectorbt’s compiled kernels do, rather than
with numpy’s pairwise reductions, which round differently in the last bits.
Every function takes per-bar values on a timestamp axis (an
xarray.DataArray) and plain numbers; ranges are inclusive pairs of bar
labels ("2024-01-02" or "2024-01-02T15:30:00"), compared as exact
timestamps, in time order and never overlapping.
Functions
Return the deepest drawdown of a value curve, from its valley to its recovery. |
|
Return the |
|
Return a boolean mask of the |
|
Return the fill bar of every decided rebalance: the bar after it on |
|
Return a strategy's statistics relative to its benchmark over |
|
Return the return statistics of a per-bar return series, keyed by row name. |
|
Summarize round trips as the trade rows of a run's |
|
Return the position round trips of a run's fills, one per flat-to-flat holding. |
|
Return the turnover of every bar that had rebalance fills, on a |
|
Summarize the rebalance turnover of a slice as the three percent-valued metric rows. |
|
Return the share of holding periods and of months the strategy won, in percent. |
|
Return one year, in vectorbt's convention, for bars of |