Walk-forward optimization

Walk-forward optimization tests a trading strategy the way you would have traded it. You choose its settings on one stretch of history (in-sample), test those settings on the stretch that follows (out-of-sample), then move both windows forward and repeat. The out-of-sample pieces, joined together, are the honest estimate of how the strategy would have done.

By Keel Research Team · Updated November 11, 2026

How walk-forward optimization works

  1. Split the history into windows. Each step has an in-sample window, where you choose the settings, and an out-of-sample window right after it, where you test them.
  2. On the first in-sample window, try the settings you are considering and pick the one that does best.
  3. Run that setting, unchanged, over the out-of-sample window that follows. Record the result.
  4. Move both windows forward by the length of the out-of-sample window.
  5. Choose again on the new in-sample window and test on the new out-of-sample window.
  6. Repeat until you reach the end of the history.

You end with a run of out-of-sample results, each produced by settings chosen only on the data before it. Joined in date order, they show how the strategy would have done if you had re-tuned it as you went. Read the settings each window chose as well: if the best lookback jumps around from one window to the next, the choice is fitting noise. A strategy whose good settings sit on a wide, flat plateau is more likely to hold up.

Walk-forward analysis, optimization and testing

The three names describe one loop. Walk-forward optimization puts the weight on the tuning step: choosing settings on each in-sample window. Walk-forward analysis puts it on reading the result: how much performance survives out of sample, and how stable the chosen settings are. Walk-forward testing puts it on the out-of-sample runs themselves, and is the name most backtesting tools use for the feature. Keel’s page on walk-forward testing says what Keel supports today.

Anchored or rolling windows

  • Rolling: the in-sample window keeps its length and slides forward, so the oldest data drops off. Use it when you think old market behaviour no longer applies.
  • Anchored: the in-sample window starts at the first bar and grows. Each choice sees more data, so the settings move less from one window to the next. Use it for strategies that should work across regimes.

When in doubt, run both. A strategy that passes one and fails the other is telling you how much it depends on recent conditions.

Walk-forward efficiency and a pass rule

Walk-forward efficiency (WFE) is the out-of-sample Sharpe divided by the in-sample Sharpe for a window. Some loss is expected, because the in-sample number is the one the tuning flattered. The walk-forward analysis tool uses a simple heuristic: a window passes when its out-of-sample Sharpe keeps more than half of a positive in-sample Sharpe, and you read the share of windows that pass. That is a rule of thumb, not a statistical test. To test how likely a chosen setting is to be overfit, see the probability of backtest overfitting and the deflated Sharpe ratio.

A worked example

The walk-forward analysis tool loads a sample daily returns series whose regime changes halfway through. Run it anchored, window 96, step 96, and you get these folds. The in-sample window grows from the first bar; the out-of-sample window is the next 96 bars.

FoldIS barsOOS barsIS SharpeOOS SharpeWFEPass
W11–9697–1924.201.400.33no
W21–192193–2882.843.381.19yes
W31–288289–3843.031.480.49no
W41–384385–4802.421.740.72yes

Mean out-of-sample Sharpe 2.00, mean degradation −31.9%, 2 / 4 folds passing. W1 was tuned on the strong regime and kept a WFE of only 0.33 once the regime turned. The failing folds are W1 (WFE 0.33) and W3 (WFE 0.49). With that pass rate you would not trade this series on the strength of its in-sample Sharpe. The numbers are the tool’s own output for these settings, and a test keeps them equal.

Walk-forward vs a single train/test split

A single split tests your settings once, against one out-of-sample period. If that period happens to suit the strategy, the result looks better than it should; if it does not, a good strategy looks broken. Walk-forward tests against many periods, so you see the spread of out-of-sample results rather than one draw. The cost is more runs, and a shorter out-of-sample window each time. An untouched holdout at the very end is still worth keeping on top of the loop; the out-of-sample testing guide covers how to split the data.

Walk-forward on crypto perps

  • Short histories on newer perps. A recently listed market has only months of data, which leaves room for few windows. Use fewer, longer windows, or start with the older, deeper markets.
  • Fast regime changes. Crypto moves between trend, chop and crash quickly. Many short out-of-sample windows show whether the strategy survives each kind; compare rolling and anchored runs.
  • Funding in every window. Perps pay or charge funding while a position is open, so each window’s backtest has to include it. A strategy that only works before funding looks worse out of sample than in.

How to run it on Keel today

Keel’s Research re-picks a strategy’s settings as it goes, using only the days before each pick, as in Keel’s study below. To drive a windowed loop of your own, with the windows and the choices yours, Keel runs a backtest over any date window:

  1. Build a strategy in the Keel app, or fork one from the strategy library.
  2. Pick your windows: anchored or rolling, the in-sample length and the out-of-sample length.
  3. For each window, change the settings and re-run over the in-sample dates until you have your choice, then run that choice over the out-of-sample dates, in the app or with keel backtest run <strategy> --start-date … --end-date …. Keep the out-of-sample runs and note the settings each window chose.
  4. Export each out-of-sample run’s trades (Export, then Trades (.csv) on the backtest page) and join the return_pct column in date order into one series, one return per closed trade.
  5. Paste that series into the walk-forward analysis tool. It slices it into in-sample and out-of-sample window pairs, computes the Sharpe on each side, and reports the degradation and the windows that pass. It does not tune anything and cannot show how the settings moved; that is the list from step three.
This article is educational. Walk-forward optimization lowers the risk of trading an overfit strategy but does not remove it. A strategy that passes can still lose money live when the market does something its history never showed.
Re-picking the settings
Re-picking the settingsSharpe for 16 cells, lookback days (Days looked back) by every (Days between re-picks); colour from −1.01 to 1.01.0.850.600.690.750.961.010.720.860.880.850.860.500.0540.17−0.130.01660901803657143060Colour · Sharpe · −1.01+1.01lookback days (Days looked back) ↓every (Days between re-picks) →
The numbers
every (Days between re-picks)lookback days (Days looked back)Sharpe
7600.85
14600.60
30600.69
60600.75
7900.96
14901.01
30900.72
60900.86
71800.88
141800.85
301800.86
601800.50
73650.054
143650.17
30365−0.13
603650.016

Keel's study of Momentum Strategy on Hyperliquid · computed Nov 16, 2026 · data Aug 15, 2024 to Sep 29, 2026

Automate it

Trade systematically on Keel

Keel is a strategy builder for Hyperliquid. Describe an idea, backtest it with fees, slippage and funding, and run it live on Hyperliquid’s crypto perps. Stock and index perps are coming soon.

Start free. Connect a Hyperliquid wallet when you’re ready to trade.

What you can do
  • Backtest any strategy with realistic fees, slippage, and funding.
  • Change a parameter and run it again. Every backtest is kept.
  • Run it live on Hyperliquid with stop-losses and leverage caps.
  • Start from a sentence. Describe your idea and Keel builds a strategy you can test.
FAQ

Walk-forward optimization questions

What is walk-forward optimization?

A way to test a strategy's settings on data they were not chosen on, many times over. You pick the settings on one window of history (in-sample), test them unchanged on the window that follows (out-of-sample), then move both windows forward and repeat. The out-of-sample results, joined in date order, estimate how the strategy would have done if you had re-tuned it as you went.

What is walk-forward analysis?

The same loop, with the weight on reading the results: how much of the in-sample performance survives each out-of-sample window, and whether the chosen settings stay stable from one window to the next. Walk-forward analysis, walk-forward optimization and walk-forward testing name one procedure.

Is walk-forward the same as cross-validation?

It is a time-ordered kind of cross-validation. Standard k-fold shuffles the data into folds, so a model can learn from bars that come after the ones it is tested on. Walk-forward only tests on data that comes after the data the settings were chosen on, so no future information leaks in. It is close to blocked, time-aware k-fold run in date order.

How long should the in-sample and out-of-sample windows be?

Long enough that each in-sample window holds enough trades to tell a good setting from a lucky one, and each out-of-sample window holds enough trades to judge it. A common starting point makes the in-sample window a few times longer than the out-of-sample one. A strategy that trades a few times a month needs far more history per window than one that trades every day.

What is a good walk-forward efficiency?

Walk-forward efficiency is a window's out-of-sample result divided by its in-sample result. Some loss is normal, because tuning flatters the in-sample number. The walk-forward analysis tool counts a window as passing when it keeps more than half of a positive in-sample Sharpe; that line is a rule of thumb, not a statistical test. A heavily tuned strategy that keeps nearly all of its in-sample Sharpe on every window is a reason to look for a leak.

Does Keel run walk-forward optimization automatically?

Keel's Research runs a version of it. Its Check a strategy step "Re-picking the settings as you go" re-picks a strategy's setting from a grid every few days, using only the days before each pick, and follows what it picked, so you see how re-picked settings did on the days after (on the plans that include it). It measures; it never changes your strategy's settings. For a windowed loop of your own, run a backtest over any date window, in the app or with keel backtest run <strategy> --start-date … --end-date …, and paste the joined out-of-sample returns into the walk-forward analysis tool.