Skip to content
Learning path Silver Repeatable method

Data leakage and look-ahead bias

Information unavailable at decision time that contaminates features, rules, validation or order simulation, producing historical results that cannot be replicated causally.

Cite this entry

This reference cites the Cyclepedia entry. The documents it draws on are listed in the entry’s sources.

Who this is for — Anyone turning historical data into signals, optimising parameters, using machine learning or simulating orders. A model can be coded without errors and still “know” the future because causality was violated in a join, feature, split or execution price.

Data leakage is contamination of a research procedure by information that should not have been available at the point where it is used. Look-ahead bias is the temporal case: a decision at time t directly or indirectly incorporates data known only after t. The result is not merely optimistic; it simulates a different strategy equipped with a nonexistent information channel.

In plain terms — Sorting rows by date is not enough. Every step must respect this chain: information available → signal → order → possible fill → position → outcome.

Causal pipeline: event, signal, order and fillEvery arrow must respect availability and the first executable instant. Timing example: no same-bar fill is assumed without a verifiable market rule.Causal pipeline: event, signal, order and fillEvery arrow must respect availability and the first executable instantTiming example: no same-bar fill is assumed without a verifiable market rule.t₀1EventThe market oreconomic factoccurs at eventtime.t₁2AvailabilityThe strategyreceives and canprocess data onlyafter its lag.t₂3SignalCalculationcompletes from theinformationsnapshot thenavailable.t₃4OrderThe instruction isbuilt, sent andaccepted under theprotocol.t₄5FillExecution requiressubsequent priceand liquiditycompatible withthe order.event ≤ availability ≤ signal ≤ order ≤ first feasible fillCyclepedia · conditional teaching diagram, not a forecast or promise
Every arrow must point from past to future. An arrow returning to the left indicates possible information leakage.

Essential distinctions

Problem What happens Example
Look-ahead a future value enters the decision deciding from the auction's final price and backdating the order to that same auction
Target leakage the forecast target leaks into features an aggregation includes the target's future period
Preprocessing leakage estimation or selection uses train and test together normalising with the full sample's mean and standard deviation
Cross-sample leakage training incorporates outcomes not yet observable at its cutoff a five-session label ends inside the test period
Revised information the final value replaces the available vintage a macroeconomic figure corrected months later
Non-causal simulation the order receives an impossible price signal on the close with a guaranteed fill at that close

Survivorship bias is distinct: it arises from observing only entities that survived or were selected after the fact. It can coexist with leakage, but correcting timestamps alone does not recreate failed instruments, closed funds or former index members.


Three clocks: signal, order and fill

A trading rule must state at least three moments:

  1. Signal time: when the signal is ready; distinguish this from the information cutoff used in its calculation.
  2. Order time: creation and submission, followed by arrival and acceptance at the venue.
  3. Fill time: the moment or interval when an admitted order can meet compatible prices and quantities.

If the decision requires the final price close[t], it cannot determine participation in the same auction that forms that price. An on-close order submitted earlier must respect venue cutoffs and use information then available: the cited NYSE sheet separates order entry from the auction process. A later fill might have the same numerical price, but not the same time. A bar's final high and low are unavailable as inputs before the bar is complete; an intrabar replay must expose only events already observed at each decision.

For releases, filings and macroeconomic data, the economic-period date is not the dissemination timestamp. The strategy must also have received and be able to process the data. Point-in-time data retain versions (vintages): a later revision must not replace the version available at the decision. ALFRED reconstructs information known on a historical date; it does not by itself certify intraday timing or a particular vendor's latency.


Where leakage hides

Features and transformations

  • centred averages, bidirectional filters or interpolation using future observations;
  • cross-sectional ranks calculated on a universe reconstructed today;
  • winsorisation, imputation or standardisation estimated on the whole dataset;
  • fundamentals aligned with quarter-end rather than filing time;
  • splits and dividends applied without distinguishing effective date from the date on which they became known.

To standardise a variable: z = (x − mean_train) / standard_deviation_train. Estimate mean and deviation within each fold's training set and reuse them on its test set; handle zero deviation explicitly. The scikit-learn documentation distinguishes fit from transform.

Research and selection

Data snooping reuses a sample for inference or selection: it can produce a chance winner even when every input respects time. It therefore differs from look-ahead.

The test set can be contaminated without any future-looking column. Repeatedly consulting its outcome to select features, thresholds or models gradually turns it into development data. Out-of-sample is not a file label; it is a role in the process. The number of alternatives attempted, rejected decisions and selection criteria must be recorded.

Orders and execution

An OHLC price does not demonstrate that an order would have filled. Stops and limits may be touched without execution; available quantity may be insufficient; queue priority may be unknown; delays and partial fills change the position. Always assigning the most favourable bar price is a form of hindsight, separate from but connected to transaction costs in backtests.


Causal protocol

  1. Write the decision before the code. List inputs, timestamps, time zones, cutoffs, frequency and the action produced.
  2. Version raw data. Preserve snapshots, vintages, the universe and corporate actions without overwriting history.
  3. Compute every feature “as of”. At decision time t, exclude records with available_at > t and select each datum's then-available version; document how available_at is constructed.
  4. Fit on train only. Estimate imputation, scaling and feature selection within each fold's training set; apply the learned transformations to its test set. Select parameters using validation while preserving the final test.
  5. Respect temporal order. Every training label must already be observable at the training cutoff. Where information intervals overlap the test, assess purging and gaps from actual dates, rather than row proximity alone.
  6. Freeze the specification. Record rules, parameters, universe, benchmark and metrics before final evaluation.
  7. Separate signal, order and fill. Apply delays, calendars, order types and genuinely observable data.
  8. Preserve every experiment. An experiment ledger reduces invisible data snooping.
  9. Repeat from a clean snapshot. The result must be reproducible without intermediate files built with future information.

Illustrative example — A rule buys at the open when quarterly earnings exceed expectations. The database associates the figure with quarter-end, but the release arrives six weeks later. The original test therefore buys before publication. The correction preserves availability and vintages for both the release and the expectations consensus, computes the signal and waits for an execution window compatible with the order's arrival. The timing illustrates a causal check, not a recommended strategy.


Diagnostic tests

Test What it may reveal
Shift every feature by one bar hidden dependence on the current bar
Reconstruct the dataset as of a historical date revised values or retrospective membership
Artificially increase latency and gaps fragility in the causal sequence
Fit preprocessing separately in each fold train/test contamination
Remove the bar's “perfect” price impossible fills or favourable selection
Run a placebo with a time-shifted target suspicious pipeline correlations

A collapse after these tests is a warning, not automatic proof of the cause. A stable result does not prove the absence of leakage either: some leaks can survive perturbations.

Future labels and training boundaries

The label is the outcome to predict. For example, the return over the five sessions following row t becomes known only after those sessions. Using it as a target in later training is normal; placing it among the inputs at t, or using it in training completed before it matures, introduces future information. Removing labels beyond the cutoff differs from prohibiting any correlation between observations. The scikit-learn gap counts excluded rows: it does not automatically reconstruct each label's duration and availability.

Limitations

Temporal splits, walk-forward procedures and cross-validation do not repair data already contaminated. Purging and embargoes must follow the structure of the labels rather than being applied as rituals. A causal dataset may still suffer measurement errors, multiple selection, regime change, low power or an incomplete universe. Validation therefore requires both statistical controls and an audit of the information path.


Sources