Build Futures Backtests Without Look-Ahead Bias
An order cannot trade a 14:05 close before that bar completes. Trace data availability, contract rolls, session clocks, training pipelines, and causality tests through every fill.
Ordered rows can still leak the future
Look-ahead bias occurs whenever a trading rule acts on data that was unavailable at the decision. Tomorrow’s close is the obvious example. Less obvious errors survive clean, sorted rows: a signal and its fill share one bar, the daily volume leader is selected before the day’s volume is complete, or the backtest reads a revision before its publication.
Start with Information time: the earliest moment the strategy could learn the value. Decision time records when its rules run; execution time records the first trade permitted by the fill model. Those clocks need not coincide, though none can run backward. An exchange timestamp says when an event happened, not when downstream code received it.
For these per-contract derived ticks, ts records when the feed was received in UTC. That identifies the event; it does not make its price available for a fill. The trade at 14:00:00.000 can feed a subsequent decision, but a fill on that print requires an order that was already resting there with suitable queue priority.
observation → signal becomes known → order is submitted → earliest eligible fill
The strategy code should reproduce this sequence, including its delays. A live rule that runs once per minute must run once per minute in the backtest. Tick-by-tick evaluation would test a different strategy, even if every tick is available.
A bar close is unavailable while the bar is forming
Depending on the dataset, a five-minute bar stamped 14:00 begins at that time or ends at 14:05. Confirm the convention and encode it in the test. Only the arrival of every trade in the interval establishes the close. A fill at that same close conflates learning the signal with executing it; waiting for the next trade restores the missing order.
Consider a breakout when a five-minute bar closes above 5,000.00.
The fill arrives before its signal
The purchase lands inside an unfinished bar:
14:00–14:05 bar forms; close = 5000.25
14:05 backtest reads close
14:00–14:05 strategy buys at 5000.25 inside the completed bar ← impossible
Waiting for the next trade
After the signal, the next trade can execute the order:
14:05.000 bar becomes complete; signal = long
14:05.000+ order becomes eligible
14:05.013 next trade at 5000.50; modeled buy fill = 5000.50
Using the next bar’s open is also causal when that open is the first eligible trade. Copying a subsequent value into an earlier event is not. Apply the same timing to stops and targets. When one bar contains both, its OHLC cannot reveal which triggered first; use finer data to resolve the path, or commit to a conservative intrabar rule before inspecting the outcome.
The source bars are derived from back-adjusted continuous ticks. UTC epoch alignment determines intraday buckets; daily bars use Chicago’s 17:00 session across daylight-saving changes. Because empty buckets are omitted, the “next bar” is the next observed bar, not the next slot on the wall clock.
The volume leader is unknowable until the day ends
Joining contracts into a continuous price history does not move a selection decision backward in time. If the rule picks the contract with the highest daily volume, the final ranking exists only after that day ends. Trading the winner that morning would borrow information from the future.
Record the inputs, decision time, effective time, and both contract identifiers for every roll. A causal implementation can read completed volume on day t, make the choice after that session, and trade at the next available opportunity on t+1. Open interest is different: these per-contract ticks contain no open-interest measurement, so they cannot support that selection rule.
The exact contract calendar supplies last trade date, first notice date, and delivery terms; weekday formulas recalled from memory are not a substitute. Apply the strategy cutoff to new positions, and distinguish the research series roll from the portfolio roll. A switch in the research data can precede the simulated exit and re-entry fills.
Derived continuous data provides price_raw and back_adjustment, where price = price_raw + back_adjustment. Signals can use adjusted prices, but order prices, tick values, and P&L must follow the dated contract. The guide to continuous futures contracts explains the difference between an adjusted level and an executable historical quote.
A cleaned file still has a publication time
Correctly sorted market timestamps do not stop revised data from leaking the present into history. Replacing yesterday’s file with today’s cleaned version introduces corrections or mappings unavailable to the original rule. A later change to a roll choice has the same effect and clouds comparisons between months.
Attach an immutable snapshot ID to each result and record dataset and calendar versions, adjustment method, code revision, and parameters alongside it. Any mutable value needs both an availability timestamp and the period it describes. A report covering March can arrive after March has ended; preliminary and revised releases remain separate inputs.
Random seeds preserve random draws, not datasets. Choose a short historical window, rebuild it from the named snapshot, and compare signals, roll events, and fills against the original output. Any mismatch means the work is an analysis of the current derived dataset rather than a point-in-time simulation.
A “previous day” is a session, not a date label
UTC timestamps alone cannot define local sessions, settlement windows, or the previous trading day. Chicago and another market can switch to daylight saving on different dates. Keeping one UTC offset throughout the year therefore shifts local rules by an hour during part of the sample.
Build the trading-day key from the exchange session. When a Chicago session opens at 17:00, it can span two UTC dates; the derived daily bar follows that session. Holidays and early closes interrupt evenly spaced rows, and a price carried forward through a closure is still unavailable as a quote while the market is shut.
Exercise the calendar at both daylight-saving transitions, one shortened holiday session, a weekend, and an empty bar. Available intervals are 10s, 1m, 2m, 5m, 30m, 1h, 4h and 1D. Resampling has to retain the source session and its empty-bucket rules; a feature could otherwise include trades after its cutoff while appearing valid.
Leakage can enter during preprocessing
Fitting a scaler to the full dataset exposes it to means and variances from the future. Selecting features on the test period has the same effect. So do choosing a roll setting for its final equity curve and adjusting a threshold after seeing test results, although these choices contaminate the research process rather than the order clock.
Create the splits in time order. Fit each transformation on training rows alone, then leave the fitted object unchanged for validation and test. Trailing features should warm up exclusively on earlier observations; rows without sufficient history must be dropped. Purge or leave a gap around a split when labels overlap, since a training target spanning the next 24 hours cannot reach into the test period.
Walk-forward evaluation fits an earlier window, tests the next window, and advances. Unlike shuffling, this arrangement approximates deployment. Keep the final test untouched until the design is fixed. Repeated looks that alter the design turn even a reserved test set into part of training, so the experiment log should record how often that happened.
Attack the event order with causality tests
A successful run says nothing about whether its chronology is valid. Give the suite specific ways to expose a broken sequence:
- Signal perturbation: change observations beyond a cutoff and verify that every earlier signal and order remains identical.
- Timestamp assertions: enforce
information_time ≤ decision_time < execution_time, except where a same-instant fill has an explicit justification. - Feature provenance: truncate the input, recalculate the feature, and check the result against the full-input value at that timestamp.
- Shift sensitivity: move entries by one trade or bar. Investigate a collapse; by itself, it does not establish leakage.
- Split isolation: values produced by preprocessing fitted on training data must stay fixed when test rows are added.
- Calendar probes: cover cutoffs and session labels through daylight-saving transitions, holidays, expiration, and every roll.
An equal-timestamp exception cannot rest on the inequality alone. Supply evidence of the order that was already resting, its queue position, and how execution preceded any new decision. Otherwise, wait for a strictly later event eligible to fill the order.
Audit one trade by hand:
- Enumerate the inputs used by its signal.
- Record the availability timestamp and snapshot for every input.
- Verify roll state first, then the session label, order eligibility, and fill.
- Repeat the trace for another trade that crosses expiration and a daylight-saving boundary.
Introduce a deliberate one-bar lead. The suite should fail; that failure is the negative control. Then trace several trades from raw observation through adjusted signal, confirming roll state, eligibility, fill, and P&L along the way. Arithmetic assertions can pass while the timeline remains impossible, so put that timeline in writing beside the numeric checks.
Before sign-off, use the broader complete futures backtesting checklist. Print one full trade timeline and include it with the report, giving a reviewer a concrete sequence to falsify.