Overfitting and lookahead bias: how to avoid a backtest that lies

GuidesDeutsch

Overfitting and lookahead bias: how to avoid a backtest that lies

Overfitting is tuning a trading strategy so closely to past data that it fits the noise instead of a repeatable pattern. Lookahead bias is a backtest using information that was not yet available at the moment of the trade. Both make a backtest look far better than live trading, and both can be tested for before money is at risk.

Updated · Orion Quant Technologies

What is overfitting in a trading strategy?

Overfitting in a trading strategy means the rules and parameters describe one stretch of history rather than a lasting edge. Curve fitting is the same thing: adding conditions and tuning numbers until the equity curve looks smooth on the data you tested. The strategy then fails on any data it has not seen.

The cause is the number of tries. Suppose a strategy has no edge at all, and each parameter set has a 5 % chance of looking significant by luck. Test 100 independent sets and you expect 5 of them to look significant, and the chance that at least one does is about 99 % (1 minus 0.95 to the power of 100). The best result of a large search is the one most likely to be luck.

What is lookahead bias in backtesting?

Lookahead bias in backtesting is any use of data that the strategy could not have known at the time it acted. Lookahead bias is usually a bug, not a choice: one line that reads the close of the current bar, or an indicator that is computed on the whole dataset at once. Its result is a backtest that is too good to be true.

Source of lookaheadWhat goes wrongThe fix
Signal and fill on the same barThe rule reads the close, then fills at a price before the closeDecide on the closed bar, fill on the next price
Higher timeframe barsA daily high or an hourly close is used before that bar has endedUse only the last completed higher timeframe bar
Repainting indicatorsThe indicator's past values change once new data arrivesUse values as they were at each moment, never recomputed later
Whole dataset statisticsNormalizing or ranking with the mean or range of all data, future includedCompute statistics on a rolling window up to the current bar
Intrabar orderAssuming the target was hit before the stop inside one barUse tick data, or assume the worse case

How do you know if a backtest is overfitted?

A backtest is likely overfitted when its result collapses on data it was not tuned on, or when small changes to a parameter change the result a lot. Robust strategies degrade gently; overfitted ones fall off a cliff.

  • Out of sample gap: the profit factor or Sharpe ratio drops sharply on the held back period.
  • A lone peak: one parameter value is excellent and its neighbors are poor. A broad plateau of similar results is what a real edge looks like.
  • Too many rules for the trades: many conditions and parameters, few trades. Each free parameter needs a good number of trades behind it.
  • A few trades carry the result: remove the best ten trades and the profit is gone.
  • An equity curve that is too smooth: very low drawdown with a high return on years of data is more often a bug than a gift.

How do you avoid overfitting in backtesting?

You avoid overfitting by keeping the strategy simple and by judging it only on data the optimization never saw. Fewer parameters, wider tests and an honest out of sample period beat any amount of tuning.

  1. Start from an idea, not a search. Write down why the edge should exist before you test it.
  2. Keep parameters few and their ranges coarse. Three parameters with sensible steps are easier to trust than eight with fine ones.
  3. Hold back data. Tune on the first part of the history, test once on the rest, and do not go back and tune again.
  4. Walk forward. Optimize on one window, test on the next, move on and repeat. See walk forward analysis.
  5. Look for plateaus in a heatmap of two parameters instead of picking the single best cell.
  6. Stress the result with a Monte Carlo simulation of the trade order, doubled costs and other markets.

How does the Orion Quant Technologies Engine guard against overfitting?

The Orion Quant Technologies Engine has no lookahead by construction. For overfitting it gives the tests above as tools: hold back part of the range, and every pass of an optimization shows its out of sample result and the gap between the two. Walk forward runs on rolling or anchored windows, and a heatmap shows the result across two parameters, so a lone peak stands out from a plateau.

The audit of a finished run adds a risk tab with Monte Carlo on the trade order, the drawdown at the 95th percentile, the share of profit from the best ten trades and the trades per parameter. A verdict grades the run from A to F over edge, robustness, risk and sample size, and two runs can be compared side by side with every difference in their configuration listed. The engine is in early access through the waitlist.

Frequently asked questions

What is the difference between overfitting and curve fitting?

In trading the two terms mean the same thing: rules and parameters tuned until they match the noise of the tested period. Some traders use curve fitting for the act of tuning and overfitting for the result, a strategy that fails on new data. Either way the test is identical: does the strategy hold up on data it was not tuned on?

How much data should I keep for out of sample testing?

A common split keeps 20 to 30 % of the history out of sample, ideally the most recent part, so the test resembles the future you will trade. The out of sample period should still hold enough trades to judge, a hundred or more if possible. Walk forward testing repeats the split many times and uses the data more fully.

How do I check my strategy for lookahead bias?

Read every line that reads a price and ask whether that value existed at the moment of the decision. Then run a simple test: delay every signal by one bar. A strategy with a real edge usually loses a little; one with lookahead bias often loses most of its profit. Results that are far too smooth are another warning sign.

Is optimization always overfitting?

No. Optimization becomes overfitting when you judge the strategy on the same data you tuned it on, or when you test so many variants that the best one is luck. Optimizing a few parameters over coarse ranges, choosing a plateau over a peak and confirming the choice out of sample and walk forward is sound practice. See strategy optimization.

Research and testing only. A backtest shows how rules behaved in the past, not what they will earn. Nothing here is investment advice.

Orion Quant Technologies