Backtesting Lab

Backtest Debugging Challenges

Find and fix look-ahead bias, data leakage and unrealistic order fills in three interactive exercises.

Read each example and choose a correction. The explanation shows why the original backtest was misleading.

Look-ahead bias

At the close of bar t, the strategy buys when the next close is higher.

signal = close.shift(-1) > close

Data leakage in preprocessing

A standardizer sees the full time series before the chronological split.

scaled = scaler.fit_transform(features)
train, test = scaled[:cut], scaled[cut:]

Unrealistic stop fill

A sell stop triggers at 1.1000. In this simplified simulation the next executable bid is 1.0992.

fill = stop_price  # 1.1000

Compare trading costs on your own backtest CSV