Walk-forward analysis

by , founder of Stochastly

How does walk-forward analysis turn one backtest into several out-of-sample tests?

It selects parameters on one window, applies them unchanged to the next window, then slides forward and repeats. Joining the out-of-sample windows gives one equity curve in which each result came from parameters chosen before its window was seen.

Window lengths, the parameter grid and the selection rule are still chosen on the same history, and each such choice counts as a trial.

Walk-forward analysis optimizes a strategy on one window of history, tests it on the next window, then moves forward and repeats.

How walk-forward analysis works

The history is cut into consecutive segments. On each step, the parameters are selected on an in-sample window and applied unchanged to the following out-of-sample window. The out-of-sample segments are then joined into one equity curve.

That joined curve is the closest a backtest gets to live trading: each result was produced by parameters chosen without seeing it.

In-sample and out-of-sample equity from a recorded run in Stochastly. The dashed line marks where selection stops and the unseen period starts.Open full size
In-sample and out-of-sample equity from a recorded run in Stochastly. The dashed line marks where selection stops and the unseen period starts.

Rolling and anchored windows

In a rolling scheme the in-sample window keeps a fixed length and slides forward, so old data drops out. In an anchored scheme the window keeps its start date and grows, so each step uses all the history available at that time.

Rolling windows adapt faster to regime changes. Anchored windows use more data per estimate and give more stable parameters.

Walk-forward efficiency

Walk-forward efficiency compares the annualized out-of-sample return with the annualized in-sample return. A ratio near 1 means the optimization carried over to unseen data; a ratio far below 1 points to overfitting.

WFE = annualized out-of-sample return / annualized in-sample return

Limits

Walk-forward analysis still reuses the same history for the final choice of the method, the window lengths and the parameter grid. The deflated Sharpe ratio corrects the selected Sharpe ratio for the number of trials and for non-normal returns. Combinatorially symmetric cross-validation (CSCV) estimates the probability of backtest overfitting (PBO) across a family of candidate configurations. Both depend on a complete count of the variants tried: each choice made after reading the same out-of-sample results turns those results into design data.

“Standard statistical techniques designed to prevent regression overfitting, such as hold-out, tend to be unreliable and inaccurate in the context of investment backtests.”

Frequently asked questions

Is walk-forward analysis better than a single train/test split?

It tests the strategy on several unseen periods and produces a full out-of-sample equity curve, so one lucky period weighs less than in a single split.

What window size should I use?

The in-sample window must hold enough trades to estimate the parameters, and the out-of-sample window must be long enough to include several trades. Test several sets of lengths and report each result.

What is the difference between walk-forward optimization and walk-forward analysis?

Walk-forward optimization is the repeated re-optimization step. Walk-forward analysis is the evaluation of the joined out-of-sample results.

Sources

Bailey, Borwein, López de Prado and Zhu (2017). The Probability of Backtest Overfitting. Journal of Computational Finance 20(4), 39-69.

Arnott, Harvey and Markowitz (2019). A Backtesting Protocol in the Era of Machine Learning. Journal of Financial Data Science 1(1), 64-74.

Bailey and López de Prado (2014). The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting, and Non-Normality. Journal of Portfolio Management 40(5), 94-107.

White (2000). A Reality Check for Data Snooping. Econometrica 68(5), 1097-1126.

Primary source for Walk-forward analysis

In the library

In-Sample vs Out-of-Sample vs Walk-Forward

Related