Class WalkForwardAnalyzer

java.lang.Object
com.quantfinlib.backtest.validation.WalkForwardAnalyzer

public final class WalkForwardAnalyzer extends Object
Walk-forward analysis — the standard defense against overfit backtests. The series is split into rolling train/test windows; on each fold the parameter grid is optimized only on the train window and the winner is evaluated on the unseen test window. Out-of-sample test segments are stitched into one continuous equity curve (capital carries across folds), giving honest out-of-sample metrics and the walk-forward efficiency ratio (OOS / IS objective — near 1 is robust, near 0 is curve-fitting).

Each test window is evaluated WARM: the backtest sees the preceding train bars for indicator warm-up but only trades from the test boundary (Backtester.run(com.quantfinlib.backtest.TradingStrategy, BarSeries, BacktestConfig, int)). Evaluating a bare test slice would re-compute every indicator cold and force HOLD through each fold's first lookback bars — systematically understating out-of-sample activity.

The efficiency ratio is only meaningful when the in-sample objective sum is positive; when it is zero or negative (the optimizer could not find anything that even backtests well in-sample) efficiency is NaN — a ratio of two losses saying "0.5" would read as robust when both sides are failing.