data-leakage

En esta página

A quién sirve — Anyone doing ML or backtests on time series. Leakage is the silent error that turns a «perfect» model into live losses.

Data leakage occurs when information not available at decision time enters features, targets or preprocessing — look-ahead bias, shuffling time series, normalizing on the full dataset, joins with data revised ex post.

In plain terms — The model «cheats» by seeing exam answers before responding — great on paper, useless live.


Common forms

Type Example
Look-ahead Feature uses current bar close to enter at open
Target leakage Target built with post-event data unknown at t
Global preprocessing StandardScaler fit on train+test together
Survivorship Universe = only stocks still listed today
Revisions Macro «final» instead of first print

In finance time is causal: splits must respect chronology (out-of-sample).


Prevention

  • Features with explicit lags; entries on next bar open
  • Walk-forward and purge between adjacent folds
  • Pipeline audit: «what did I know at t?»
  • Compare to naive baseline — huge jump? suspect leakage

Error típico — Random `train_test_split` on OHLCV — mixes future and past, unrealistic metrics.

Ejemplo — Model predicts gap up: feature includes `high - open` on the same bar you enter at open → leakage, 90%+ accuracy, useless live.

Card

  • Rule: no data from t+1 in decision at t.
  • Test: shift features 1 bar — performance collapses? likely leakage.
  • Related: Overfitting often masks leakage.

Enlaces