Detect look-ahead bias in a backtest
Look-ahead bias occurs when a historical decision consumes information that would arrive later. Frequent sources include the same bar’s future high, centered windows, a future-shifted column and fundamentals joined by period end instead of publication time.
Run the same decision with less data
Pick a decision time and produce the signal from the full input. Cut every input to what was available at that time, rerun and compare the signal at the same clock. Repeat at ordinary bars, around session boundaries and on release dates.
for decision_time in checkpoints:
available = data[data.available_at <= decision_time]
assert signal_at(full_run, decision_time) == signal_at(run(available), decision_time)
For example, a 30-minute bar labelled 12:00 may not close until 12:30. A 12:10 decision cannot depend on that bar’s final range. A release can carry a period date in March and a published timestamp in May. Use the latter to join it to a historical decision.
Separate labels and decisions
Future returns can be target labels for training. Keep them out of live features and cut samples whose target horizon crosses a training boundary. Fit transformations on each training window and apply the frozen versions forward. When a check fails, trace the earliest diverging input, then record its event and availability times.
LEAN on time and bar periods · Chronological walk-forward splits