Validation

Look-ahead bias: how one shifted index fakes a 100% win rate

The strategy below never lost a single trade on a market that had no edge at all. It was not clever. It was reading the bar it was supposed to predict.

Start with a market that cannot be beaten. Five thousand days of independent returns drawn from a normal distribution with mean zero and 1% daily volatility. No trend, no autocorrelation, no edge of any kind. If a strategy makes money here, something is broken.

Two versions of the same rule run over those 5,000 days. Both take 2,526 trades. They differ by one index.

The one-line difference

The honest rule looks at yesterday’s return. If it was positive, buy and hold for today. That is a momentum rule with a one-day lag, and it is allowed to be wrong.

The look-ahead rule looks at today’s return. If it was positive, buy and book today’s return. Same trade count, same direction, same holding period on paper — except the decision is made after the outcome is known.

In code the two rules are if (r[i-1] > 0) book(r[i]) and if (r[i] > 0) book(r[i]). One index of difference. A 2,000-point difference in outcome.

The result

  • Look-ahead — 2,526 trades, 100.00% hit rate, 2,044% of summed daily returns.
  • Honest — 2,526 trades, 49.41% hit rate, 32% of summed daily returns.

The look-ahead version wins every trade it takes. Not because it found an edge, but because the set of trades it takes is defined as the set of days that went up. The rule is not predicting. It is selecting.

The honest version lands where a zero-drift market says it should: a hit rate just under 50% and a return that is noise around zero. The 32% is not profit; it is what the sum of a few large up-days looks like when nothing else is happening.

Why the curve looks real

A leakage bug rarely looks like a bug. It produces a smooth curve, a plausible trade count, and a Sharpe ratio nobody questions because the number is high but not absurd. A 100% hit rate is easy to spot. A 92% hit rate on a rule that should win 52% is not, and it is the same bug with a different data shape.

The tell is not the win rate. The tell is that the edge does not survive one bar of lag.

Where the shift hides

Almost never in the strategy logic. Almost always in the data assembly:

  • Close-to-close fills. The signal uses the close of bar t and the fill is booked at the close of bar t. In live trading that close is only known after you could have traded it.
  • Revised fundamentals. Using restated earnings instead of the figure published at the time. The restatement contains information nobody had.
  • Index membership. Testing on today’s constituents, which already exclude everything that failed. That is a different bias, and it stacks on this one.
  • Macro releases. Aligning a 10:00 print with a 09:30 decision.
  • Splits without a purge. A test observation whose label window overlaps the training set is a look-ahead dressed as validation. Walk-forward testing is only honest when the folds are purged.
  • Scaled features. Fitting the scaler on the full series, then splitting. The mean and standard deviation of the future leak into the past.

The lag test

One check catches nearly all of it, and it costs a line: shift every input forward by one bar and re-run. If the edge collapses, the original result was leakage.

Two refinements matter. First, lag each input by its own publication delay, not a blanket one bar — a quarterly filing is not available the day the quarter ends. Second, run the lag test before you tune anything. Tuning a leaked feature set produces parameters fitted to a bug.

If the honest version still has an edge, you now have a number you can believe. In the experiment above it does not, which is the correct answer for a market with zero drift.

What this does not prove

A strategy that survives the lag test is not validated. It has cleared one gate: it is not reading the future. It still has to beat its baselines, hold up out of sample, and clear a correction for the number of trials it took to find. A permutation test handles the last part for a single strategy; the deflated Sharpe ratio handles it for a search.

Look-ahead is the first check because it is the cheapest to run and the most common to fail. It is one of the seven ways a backtest misleads, and the only one that can be tested with a single shift of an array.

The rule

If the signal and the fill share a timestamp, one of them is wrong.

Print that sentence and put it above the backtest runner. It has caught more fake edges than any statistical test, because it runs before the statistics and costs nothing to check.

How these numbers were produced

Seeded simulation: Mulberry32(20261107), normal draws by Box-Muller, 5,000 days, 1% daily volatility, zero drift. The two rules differ only in the index used for the decision. Re-running with that generator reproduces these figures exactly; a different generator gives the same picture with slightly different numbers.

Questions

What is look-ahead bias in a backtest?

Using information that was not available when the decision had to be made. The common form is a signal and a fill that share the same bar, so the strategy books an outcome it could not have known.

How much difference does one bar of lag make?

In a 5,000-day random walk with zero drift, deciding on today’s return produced a 100.00% hit rate and 2,044% of summed returns. The same rule with one day of lag produced 49.41% and 32%.

Can look-ahead bias look like a normal win rate?

Yes. A 92% hit rate on a rule that should win 52% is the same bug as a 100% hit rate. The tell is that the edge disappears when every input is lagged by its real publication delay.

How do I test for look-ahead bias?

Shift every input forward by one bar, or by its publication delay, and re-run unchanged. If the edge collapses, the original result came from leakage rather than skill.

Is a strategy safe once it passes the lag test?

No. Passing means it is not reading the future. It still has to beat its baselines, hold up out of sample, and survive a correction for the number of trials.

This article is educational, not financial advice. Past backtest results do not predict future returns.

The number on the page is the number the tool returns.

Enquire about the sale See the eight checks