Class Backtester

java.lang.Object
com.quantfinlib.backtest.Backtester

public final class Backtester extends Object
Event-driven, single-instrument, long-only backtesting engine.

Execution model: signals fill at the bar close (adjusted for slippage); stop-loss / take-profit levels are evaluated intrabar against the bar's low/high on bars after entry, with gap-aware fills (a gap through the level fills at the open). Commission is charged on both entry and exit notional.

  • Method Details

    • run

      public static BacktestResult run(TradingStrategy strategy, BarSeries series, BacktestConfig config)
    • run

      public static BacktestResult run(TradingStrategy strategy, BarSeries series, BacktestConfig config, int tradeFrom)
      Variant with a WARM-UP prefix: indicators are initialized over the whole series, but no signal is acted on (and no equity recorded) before tradeFrom. This is how walk-forward analysis avoids the cold-start bias — evaluating a fold on a bare test slice re-computes every indicator from scratch, silently forcing HOLD through the first lookback bars of every fold; feeding the preceding bars as warm-up (they are the past — no look-ahead) lets the strategy enter the test window with warm indicators, the way it would trade live. The returned equity curve covers [tradeFrom, n) only.

      Scope of the warm-up: it warms whatever TradingStrategy.init(com.quantfinlib.core.BarSeries) precomputes over the series (all shipped strategies). onBar is NOT called for warm-up bars, so a strategy that accumulates state inside onBar still starts cold at tradeFrom.