Package com.quantfinlib.backtest
@NullMarked
package com.quantfinlib.backtest
Bar-based backtesting engines, execution models and performance analytics.
Backtester is the single-instrument
engine (fills at the next bar's open by default, see
FillPolicy; intrabar gap-aware stops);
ExecutionAwareBacktester upgrades signals
to parent orders worked through a pluggable
ExecutionModel
(InstantExecution,
SorExecution,
IcebergExecution,
LastLookExecution — FX last-look rejects
on adverse hold-window moves) with multi-bar fills and
one-call TCA per ParentOrder;
ExecutionAlgoBacktester compares
benchmark algorithms by cost, replaying execution.BenchmarkExecutor over a
session's bars and grading it TCA-style (shortfall vs arrival,
slippage vs session VWAP), with its simplifications stated in the
javadoc. BenchmarkComparison reports
alpha, beta, tracking error, information ratio and up/down capture
against a benchmark, and
DrawdownAnalytics reports drawdown
structure: episode depth and duration and time under water.
Sub-packages: strategies (built-ins),
validation (walk-forward, purged K-fold, CSCV overfit
probability, deflated Sharpe), portfolio (multi-asset), and
tick (event-driven tick-level engine).-
ClassDescriptionBacktest execution parameters.Event-driven, single-instrument, long-only backtesting engine.A segment's result and the state it ended in.Book state carried between segments.Result of a backtest run: full equity curve (one point per bar), completed trade history, and derived performance metrics.Benchmark-relative performance — the numbers an allocator actually asks for.Strategy statistics relative to a benchmark.Drawdown structure — because "max drawdown 18%" hides the number that actually fires clients: how long the pain lasted.One peak-to-recovery episode.Drawdown statistics of an equity curve.Backtests the dynamic execution stack over bar data.Execution simulation settings.The TCA-style verdict for one parent worked over one session.Execution-aware backtesting engine: strategy signals create parent orders that are worked through an
ExecutionModel— routed bySorExecution, sliced byIcebergExecution, or filled instantly byInstantExecution.Result of an execution-aware backtest: the standardBacktestResult(equity curve, trades, performance metrics) plus the full parent-order / child-fill history, with one-call TCA per parent order.How parent orders turn into fills in an execution-aware backtest (ExecutionAwareBacktester).When an order decided on bartis filled.Iceberg execution: wraps anotherExecutionModeland caps each bar's execution at theIcebergOrderstate machine's visible tranche (optionally randomized), plus an optional participation cap versus the bar's volume.Baseline execution model: the full quantity fills at the bar close with commission and slippage folded into the all-in price — equivalent to the classicBacktesterfill assumption.Last-look execution model — the missing realism for FX backtests: on ECN and single-dealer FX liquidity, the provider holds your order briefly and may reject it if the price moves against them during the hold.One parent order worked by theExecutionAwareBacktester: the signal that created it, the arrival price (close at signal time — the TCA benchmark), and the child fills with the bar index each filled on.ComputesPerformanceMetricsfrom an equity curve and trade history.Strategy performance analytics.Trading signal emitted by a strategy for a single bar.Smart-order-routed execution over a synthetic fragmented market.One venue's fee, liquidity share and lit or dark status.A completed round-trip trade.Trade-level analytics — the numbers a discretionary reviewer asks for that a Sharpe ratio hides.Trade-level statistics.A pluggable per-trade cost model — the one definition of "what a trade costs" shared by the backtest engines, so an execution-aware number and a survivorship-aware number can come out of the same run:TradeCostModel.flat(double)— a fixed all-in bps (the classic commission assumption, and the exact equivalent of the legacycommissionRateconfigs);TradeCostModel.institutional(double, double, double, int): commission + half-spread + slippage + square-root market impact, with per-symbol ADV/vol estimated from the trailing bars viaMarketImpactModel.estimate(BarSeries, int, int).A bar-driven trading strategy.