Lesson 92 of 120 · Advanced · 14 min read
Look-ahead bias: the leak that looks like skill
Quick answer
What is look-ahead bias in backtesting?
Look-ahead bias is the use, anywhere in a backtest, of information that was not available when the decision was made, such as filling a trade at a bar's open using that bar's close. It makes results look excellent that cannot be repeated live. Re-running the test with every input delayed by one period is a quick way to catch it.
Try it: Test a rule yourselfFree, no account needed.
What you will be able to do
- Define look-ahead bias in one sentence and apply it to any input a rule reads
- Locate the bar boundary problem in both daily and intraday data
- Recognise same-bar fills in their three common disguises
- Explain why a full-sample statistic used inside the sample is a leak
- Run the shift test and the scramble test as routine detectors rather than as investigations
Read these first
- Anatomy of a candle in Candlesticks, charts and price structure
- What a backtest answers in Backtesting, statistics, costs and validation
Look-ahead bias is the use, anywhere in a backtest, of information that was not available at the moment the decision was made. It is the most destructive defect in the field, not because it is subtle in principle but because it is invisible in output. The code runs, the curve is beautiful, nothing errors, and the result is fiction. This lesson is about the specific places it enters and the specific tests that catch it.
One definition, applied everywhere
Look-ahead bias is the leakage of future information into a past decision. That single sentence covers every variant, and the discipline that follows from it is equally single: for every number your rule reads, ask at what precise moment a person could have known that exact value.
Note the word exact. Knowing that a company reported earnings in the first quarter is not the same as knowing the reported figure on the first day of that quarter. Knowing that a stock is in an index today is not the same as knowing it was in the index five years ago. Knowing a closing price is not the same as knowing it during the session that produced it. Each of those gaps has ended strategies that looked outstanding.
The reason this bias is so damaging is arithmetic rather than philosophical. Even a tiny amount of future information is enormously valuable, because the thing you are trying to predict is mostly noise. A rule that gets a few hours of foresight on a series whose daily movement dwarfs its predictable component will look like genius. The magnitude of the fake edge is not proportional to the size of the leak; it is proportional to how much of the series is unpredictable, which is nearly all of it.
Leakage looks like skill, not like a bug
The bar boundary problem
Most leaks live at the edge of a bar. A daily bar is a summary of a whole session, but it is stored as a single row with a single timestamp, and that row is usually stamped with the session date rather than with the moment its contents became complete.
So a row dated Tuesday contains Tuesday's high, low, close and volume, all of which were unknown at Tuesday's open, and three of which were unknown until Tuesday's close. If your rule reads the Tuesday row and acts on Tuesday, you must be able to say which fields it read and when each became final. Reading the open is fine at any point after the open. Reading the close is fine only after the session ends. Reading the high or the low is fine only after the session ends, and a rule that uses either one intraday is claiming to know the extreme of a range before the range has finished forming.
The same defect on intraday bars
Intraday bars have the identical problem with a shorter fuse, and it is worse in one respect: a partially formed bar is often published as if it were complete. A five-minute bar timestamped at the start of its interval is not usable until five minutes after that stamp. If your loop reads the bar at its own timestamp, every decision is made with the whole interval already known, and the resulting curve is spectacular and meaningless.
The general repair is to stop trusting the timestamp convention and instead attach to every field an explicit available-at time. Then a rule may only read fields whose available-at time is at or before the decision time. This is more work up front and it eliminates an entire class of defect permanently.
Same-bar signals and same-bar fills
The commonest single instance of look-ahead is the same-bar fill: the signal is computed from a bar and the trade is filled at a price inside that same bar. It appears in three flavours and all three are worth naming, because two of them are frequently defended as reasonable.
Fill at the signal bar close
The signal requires the close, and the fill is at the close. This is the archetype. To act on a close you must know the close, and by the time you know it the auction that set it has finished. On the closing auction there is a narrow real version of this, because orders can be entered before the cut-off, but it is only real if the signal is computable before the cut-off too. If the signal needs the closing price itself, the trade cannot exist.
Fill at the signal bar high or low
A rule that says buy on a break of the high and fills at the high is assuming the extreme was known in advance. The honest version fills at a level set before the bar, and only if the bar's range actually reached it, and then at a price that includes the cost of crossing.
Fill at a price better than the bar allows
Simulators that place limit orders inside a bar's range and assume a fill whenever the range touches the level are quietly assuming queue priority you would not have had. The bar touching your price means somebody traded there; it does not mean you did. Lesson four returns to this under cost modelling, because in practice the two issues arrive together.
The safe default, which costs a little realism and buys a great deal of honesty, is a one-bar gap: compute on bar N, act at the open of bar N plus one, and charge full crossing costs. If the result survives that, tighten the assumption afterwards and observe how much of the edge depends on the tightening.
Restated data and revised series
A second family of leaks has nothing to do with bars. It comes from data that was published, then changed, with only the changed version stored.
Company financials are restated. Macroeconomic series are revised, sometimes substantially, sometimes for years afterwards. Index constituents are recalculated. Corporate action adjustments are applied retroactively to the whole history of a price series. In each case the value sitting in your database today is not the value a person had on the historical date, and a rule that reads it is reading a small amount of the future.
The adjustment case deserves particular attention because it is so ordinary. An adjusted price series rewrites every price before a split or a dividend. That is correct for computing returns and wrong for anything that references a price level, because the level in your series was never a level anybody saw. Rules with a price threshold, a round-number condition, or a share-count calculation are all affected, and the effect is not always small.
The tell to look for
Ask of every non-price input: does this dataset have a version history, or only a current state? If it has only a current state, it almost certainly encodes revisions, and you cannot use it for anything time-sensitive without an explicit publication date. Lesson three is entirely about the fix, which is point-in-time data.
Survivorship: look-ahead hidden in the universe
The most expensive leak is often not in a field at all. It is in the list of instruments the rule is allowed to consider.
If you take today's index membership and run a rule back ten years, every name in the test survived ten years and was good enough to be in the index at the end of them. The companies that were removed for poor performance, that were acquired at a discount, that delisted, that went to zero, are simply absent. The rule never had the opportunity to buy them, because your universe filtered them out using information from the end of the sample.
This is look-ahead bias, exactly. The selection criterion uses future information. It is worth separating from other leaks only because the repair is different: you need a historical membership record rather than a timestamp on a field.
How large is it
Large enough to reverse conclusions, and largest precisely where it hurts most. A long-only rule that buys weakness is buying the names most likely to be removed, so the removed names are exactly the ones the rule would have owned. The bias is not a uniform lift applied to all strategies; it is concentrated in the strategies that most resemble buying distress, which is a very large fraction of the mean-reversion literature.
The same reasoning applies beyond survivorship. Any universe built from a screen run today, any list of names you picked because you know them, any dataset that only covers instruments still trading, is carrying the same defect. If the list was assembled with knowledge of the end of the sample, the test is compromised regardless of how careful the rest of the code is.
Normalisation and the whole-sample statistic
The quietest leak of all is a statistic computed over the entire sample and then used inside it. It is quiet because it does not look like data at all; it looks like a modelling step.
- Standardising a feature by subtracting its full-sample mean and dividing by its full-sample standard deviation. Every observation now contains a summary of every other observation, including future ones.
- Ranking across the whole period. A percentile computed against the full history tells the rule where today sits relative to years that had not happened.
- Choosing a threshold from the full sample. Picking a cut-off at the level that separates the data best is fitting to the whole period and then testing on part of it.
- Winsorising or clipping to full-sample percentiles. The clip boundary is a future-dependent number.
- Filling gaps by interpolation. Interpolation between two points uses the later point, so a filled value on a missing day contains the following day's data.
The repair in every case is the same: compute the statistic on a trailing window that ends at or before the decision time, and accept that the early part of the sample will be unusable while the window fills. Losing the first year of a ten-year test is a small price for removing an entire category of fake result.
How to detect it deliberately
Procedures make timing assumptions checkable. These four checks help find problems, but they are diagnostics rather than an exhaustive certification that a backtest is free of leakage.
- The shift test. Delay every input by one additional period and re-run. A sharp loss of performance is a reason to audit timing, but a legitimate short-lived effect can also decay before the delayed decision. Survival does not certify that the inputs were available at the original decision time.
- The scramble test. Replace the signal with a random one of the same frequency and turnover, keeping costs and execution identical. Repeat across many random draws and compare the result with an appropriate exposure-matched baseline. Market drift and chance can produce positive results even without leakage; a long/cash random rule is not a zero-exposure baseline. Investigate unexpected differences rather than treating one profitable random draw as proof of a leak.
- The date audit. Take five trades at random, and for each one, list every input the rule read and the moment each was published. Do it by hand, against a source outside your database. This is tedious and it finds things nothing else finds.
- The impossible-edge check. Compare your per-trade result against what is plausible for the mechanism you claim. An unexpectedly large effect warrants a careful audit of inputs, fills, costs and sample selection. Its size alone does not identify the cause.
Run the shift test before you celebrate
Working it through
A rule ranks a basket of names each day by the past twenty sessions' return, buys the weakest decile and holds for ten sessions. Four versions of the same rule differ only in timing assumptions.
- Version A, as first written. Rank uses today's close, fill at today's close, universe is today's membership, features standardised over the full sample. Reported average per trade +64 basis points.
- Version B, fill moved to the next open. Ranking unchanged. Average falls to +31 basis points. The gap is the overnight move the rule had been given for free.
- Version C, standardisation made trailing. Mean and standard deviation computed over the prior 250 sessions only. Average falls to +18 basis points, and the first year of the sample is discarded.
- Version D, universe made point-in-time. Membership as of each historical date, delisted names retained until their last trading day. Average falls to +4 basis points against a per-trade standard deviation of about 420 basis points.
Then the shift test. Delaying every input one further session moves version D to +3 basis points. Applied to version A, the same test collapses it to near zero. These constructed outcomes demonstrate different sensitivity to delay; they do not by themselves prove which version is free of leakage. The identified same-close fill, full-sample statistics and current membership are the evidence of unavailable information in version A.
The instructive part is the ordering. Ninety-four percent of the reported edge was removed by three changes that touched no logic at all. Nobody wrote a bug. Each version is what a careful person writes when they have not yet been told about the specific trap ahead of them.
Where this goes wrong in practice
- Filling at the close of the bar that produced the signal. The archetype, and still the most common defect in amateur and semi-professional work alike.
- Reading a bar's high or low before the bar has closed. Claims knowledge of an extreme before the range finished forming.
- Standardising or ranking over the full sample. Every observation silently carries a summary of the future.
- Using a current universe for a historical test. The selection itself uses end-of-sample information, and it hits weakness-buying rules hardest.
- Treating restated financials or revised macro series as what was known. The stored value is a later correction, not the published one.
- Interpolating across a data gap. Any fill computed between two points reaches forward to the later one.
- Assuming a limit order fills because the bar touched it. A print at your price is not a fill for you.
- Never running the shift test. The single cheapest detector in the field, skipped because the result already looks good.
What to do with this
- Attach an available-at time to every field and enforce that the rule may only read fields whose time is at or before the decision.
- Adopt the one-bar gap as the default - signal on bar N, act at the open of bar N plus one - and only tighten it with a specific argument.
- Replace every full-sample statistic with a trailing one and accept the loss of the warm-up period.
- Rebuild the universe from historical membership including instruments that later disappeared.
- Run the shift test and the scramble test on every result before you look at any performance statistic.
- Hand-audit five trades against an outside source listing every input and its publication moment.
- Audit an implausibly large effect before relying on it; check the inputs and execution assumptions rather than inferring leakage from the size alone.
Apply the timing audit to a documented test
Start with the daily-rule method in Reality Check, or use the tested-rules library to inspect a written specification. A recorded result is not proof that a method is free of leakage.
Compare the QQQ opening-range breakout study with the SPY overnight study. For each, write down when the signal inputs become available, when the decision is made, and the earliest price at which it could be executed. Check the method, not just the return.
Examples and common mistakes
Worked example
| Version | Timing change | Average per trade | Shift test |
|---|---|---|---|
| A | signal and fill both at today's close | +64 bp | collapses to near zero |
| B | fill moved to the next open | +31 bp | not yet run |
| C | standardisation made trailing over 250 sessions | +18 bp | not yet run |
| D | universe rebuilt point-in-time | +4 bp | moves to +3 bp |
These constructed changes remove about 94% of the reported average return without changing the strategy rule. Version D changes from +4 to +3 bp under an additional delay, while version A collapses. That sensitivity does not prove either version is free of leakage: a legitimate short-lived effect can also disappear after a delay. The same-close fill, full-sample statistics and current membership identify unavailable information in version A; actual publication and execution times must still be audited in every version.
How this goes wrong in practice
- Filling at the close of the same bar that produced the signal
- Reading a bar's high or low before that bar has finished forming
- Standardising or ranking a feature over the whole sample rather than a trailing window
- Running a historical test on today's universe, which hits weakness-buying rules hardest
- Treating restated financials or revised macro series as the values that were published
- Interpolating across a data gap, which reaches forward to the later observation
- Assuming a resting limit order filled because the bar's range touched its price
- Never running the shift test because the result already looks good
Checklist
- An available-at time attached to every field the rule reads
- A one-bar gap between signal and action, unless a specific argument overrides it
- Every full-sample statistic replaced by a trailing one, with the warm-up period discarded
- A universe rebuilt from historical membership, retaining instruments through delisting
- The shift test and the scramble test both run, before any performance figure is read
- Five trades hand-audited against a source outside your own database
Knowledge check
Exercise
Pick one rule you have tested. For every input it reads, write the exact moment a person could have known that value, using a source outside your own database. Then run two tests: delay every input by one further period and record the change, and replace the signal with a random one of the same frequency and turnover and record what the harness reports. Write down what you expected each test to show before you ran it, and note every case where the outcome differed from the expectation.
Glossary, tools and sources
Glossary
- Look-ahead bias
- The use of information in a simulated decision that was not available at the moment that decision was made.
- Same-bar fill
- A trade executed at a price drawn from the same bar that generated the signal, which requires knowing the bar before it has completed.
- Available-at time
- An explicit timestamp recording when a field's exact value became knowable, distinct from the period the value describes.
- Shift test
- Delaying every input by one further period and re-running to measure timing sensitivity. Neither collapse nor survival proves or rules out leakage; short-lived effects can decay.
- Scramble test
- Replacing the signal with repeated random draws of matched frequency and turnover, then comparing with an appropriate exposure-matched baseline. A positive result can reflect market drift or chance and is not proof of leakage.
- Survivorship bias
- Selection of a universe using end-of-sample information, so instruments that were removed, acquired or delisted never enter the test.
Sources
- Auctions - NYSE opening and closing auction timelines(opens in a new tab)
New York Stock Exchange. Retrieved 2026-08-31.
- Stock Split(opens in a new tab)
US Securities and Exchange Commission. Retrieved 2026-08-31.
Risk notice
This lesson is general educational information about research method. It is not investment advice, not a recommendation to buy or sell any security, and not tailored to your circumstances. Every figure shown is a constructed illustration and not a record of any account or system. Removing a bias from a backtest improves the honesty of the estimate; it does not make the result a forecast. Trading involves risk of loss, including loss of the full amount invested.
Press when you have finished reading. Nothing is recorded until you do.