Published 2026-10-27

Future function

A future function is a line of code that reads data which did not exist at the moment of the trade — the code-level form of look-ahead bias.


On this page

What it is

A future function is a line of code that reads data which did not exist at the moment the trade was made.

The distortion it produces has a formal name: look-ahead bias. The two are not the same thing. Bias describes what happens to the result; a future function describes what you can actually search for and delete in the code.

That distinction is practical. “Is there look-ahead bias?” is a judgement call. “Does this line read the whole dataframe?” is a yes-or-no question you can answer in a minute.

Why it matters for AI quant

Ask a language model to write a backtest and it will frequently produce a future function without being asked. The default way to normalise, to rank, or to compute a threshold is over the whole array — which silently includes the future.

The model is not making a mistake in the sense of being wrong; it is answering the question as posed. “Write a backtest that shows this works” and “write a backtest that would have worked at the time” are different requests, and only the second one is a test.

Common forms

Form What the code does
Full-sample normalisation Divides by the mean or standard deviation of the entire period
Same-bar close Decides on the closing price and fills at that same close
Restated fundamentals Uses a financial figure as later revised, not as first reported
Today’s constituent list Loops over the index members as they are now, not as they were then
Adjusted price series Uses a forward-adjusted series, so later dividends are baked into past prices
Future-known universe Filters out stocks that were delisted after the test period

How to check

Truncate the data at each decision date and rerun. If the number for a given day changes when you add later data, the code was reading the future.

That single test catches almost every case, and it costs one loop.