FAQ · Getting systematic research right

What is look-ahead bias and how do I find it in my backtest?

Look-ahead bias is a backtest using information that was not available when the decision was made, such as filling at the close of the bar that produced the signal or reading data published later. Find it by checking when each value was known, shifting signals by one bar, and seeing whether results collapse.

Look-ahead bias is a backtest using information that was not available when the decision was made, such as filling at the close of the bar that produced the signal or reading data published later. Find it by checking when each value was known, shifting signals by one bar, and seeing whether results collapse.

Where it usually hides

  • Filling on the signal bar. A signal computed from today's close cannot also buy at today's close: by the time the close is known, it has passed. The honest fill is on the next bar.
  • Vectorised code without a shift. In pandas, signal = close > close.rolling(20).mean() multiplied by returns on the same row trades a return the signal already saw. It needs signal.shift(1).
  • Using the bar's high or low to decide. A rule that reads high to set an entry inside the same bar knows where the bar went before it got there.
  • Indicators fitted on the whole series. A z-score using the full-sample mean, a scaler fitted on all the data, or a hedge ratio estimated over the whole history all carry the future into every bar.
  • Data stamped with the wrong date. Earnings, fundamentals and economic releases are often stamped with the period they describe, not the day they were published. A quarter ending 31 March may not be public until May.
  • Resampled bars. An hourly bar stamped 10:00 holds prices up to 10:59. Treating it as known at 10:00 is an hour of look-ahead.
  • Today's index members. Testing on the stocks in an index now uses knowledge of which companies would survive and grow. That one has its own name: survivorship bias.

How to find it

  1. Shift everything by one bar. Delay every signal by one more bar than you think is needed. A real edge loses a little. A result built on look-ahead loses most of its return.
  2. Check impossible numbers. Win rates above 70% on a simple rule, almost no losing months, or a Sharpe ratio above 3 on daily bars are worth suspecting before celebrating.
  3. Trace one trade by hand. Pick a trade, note the bar that produced the signal and the price it filled at, and check that the fill came after the signal bar ended.
  4. Ask when each input was known. For every column, write down when that value was first public. Anything stamped earlier than that is a leak.
  5. Run it bar by bar. An event-driven loop that only ever sees past bars cannot read the future by accident, and comparing it with a vectorised version exposes a missing shift.

How Reamer Research handles it

Reamer Research runs your strategy one bar at a time. The window passed to on_bar holds only bars that have closed, with index -1 the bar that just closed. An order returned from that bar is eligible from the next bar's ticks and is never matched against the bar it was decided on. So the most common leak, filling on the signal bar, cannot happen.

import reamer_research as rr

def on_bar(d):                       # also runs as a class or a configured object
    if d.close[0] == 0:              # window still filling
        return None
    if d.close[-1] > d.close.mean() and d.position() == 0:
        return rr.buy_market(10)     # fills on the next bar, never this one

Bars on several tickers run on one wall clock. A bar reaches on_bar when it closes, at its ticker's next timestamp, so an hourly bar stamped at the start of its hour is seen when the hour ends. For non-price data, sidecar values become visible at the time they are stamped with. The exogenous data guide covers stamping them with when they were first known.

Limits to know

  • Your timestamps are trusted. The engine controls when each bar and value becomes visible; it cannot know when your data was really published.
  • Anything you compute outside the run is yours to check. A parameter or hedge ratio fitted on the whole history before the run still leaks into every bar.

A $20 month includes the full kit, so you can run your own strategy through it and compare the fills with your current backtest.

Next questions

Why do AI-written backtests give misleading results?AI assistants write backtests that run but often trade on the signal bar, leave out costs, fit values on the whole history, or test today's survivors. The code looks right and the numbers look great. Check the fill timing, the costs and the data the same way you would check a person's code, or run the strategy on an engine that enforces the timing for you.What is survivorship bias and how do I avoid it?Survivorship bias is testing only on assets that still exist today, which leaves out the companies that were delisted, went bankrupt or were acquired. Avoid it by testing on the universe as it was on each date, with delisted names and their final prices included, from a data source that keeps them.My strategy was profitable in the backtest but loses money live. How do I find out why?Rerun the backtest over the exact dates you traded live, then match each live trade to its backtest trade. Missing or extra trades point to the code or the data. Same trades at worse prices point to spread, slippage and costs. If the backtest also lost money over those dates, the market changed or the strategy was never robust. If you have only a few trades, the loss may still be normal variation, so count them before you change anything.How do I backtest a strategy that uses earnings dates or other non-price data?Stamp every record with the moment it became available to you, not the date it describes, then join it to your bars "as of": each bar sees the latest record stamped at or before it, never a later one. Most lookahead in event-driven backtests comes from the timestamps, not the join. Reamer Research attaches a non-price series to each ticker and enforces that rule, so a value appears exactly on the bar carrying its timestamp and never earlier.

Every answer here restates the documents that ship in the kit, which are authoritative. All questions.

Reamer Research

Your first backtest in a minute

Backtesting and live trading in Python and C++. Free to install in Evaluation Mode, with no key or sign-up.

pip install reamer-research

A licence at $20 a month removes every limit. The same code runs unchanged.

Reamer Server

The order-management core for your firm

Your venues, your risk rules on every order, one strategy per CPU core, on your own Linux servers.

$24,000 / year

Or start with a 30-day trial at $2,000.