Definition
Many series are published with a delay and revised afterwards: national accounts, company results, sales corrected for returns. A database that keeps only the latest value of each period answers the question what happened. A model needs the answer to another question: what did we know on that day. Croushore and Stark built a real-time data set for that purpose, with one vintage of the data per publication date.
The same bias appears without any revision when a transformation uses the full sample: scaling by the mean and standard deviation of all years, or choosing which series to keep according to how they ended.
Worked example
A monthly indicator is first published with a measurement error and revised later to its final value. Next month's outcome depends on the final value. We fit the same regression twice: on final values, which a history file would contain, and on first releases, which is all that was available in time.
import numpy as np
rng = np.random.default_rng(3)
n = 5000
final = rng.normal(size=n) # the revised, final figure
first = final + rng.normal(scale=1.0, size=n) # what was published at the time
outcome = 0.5 * final + rng.normal(scale=1.0, size=n)
def r2(x, y):
half = n // 2 # fit on the first half, score on the second
b = np.polyfit(x[:half], y[:half], 1)
resid = y[half:] - np.polyval(b, x[half:])
return 1 - resid.var() / y[half:].var()
print(f"backtest on final values (not known in time): R2 = {r2(final, outcome):.3f}")
print(f"backtest on first releases (point in time): R2 = {r2(first, outcome):.3f}")Output, produced by running the code above when this page was built:
backtest on final values (not known in time): R2 = 0.193 backtest on first releases (point in time): R2 = 0.096
Both backtests are out of sample in the usual sense: the model is scored on rows it was not fitted on. The first one still overstates what could have been achieved, because its input did not exist yet on the day of the forecast.
How to find it
- Store two dates for each value: the period it describes and the date it was published or last changed. Join on the second.
- Recompute a sample of past inputs from archived sources and compare with the database.
- Fit every scaling, encoding and selection on the training window only.
- Check the universe: a list of products, clients or securities drawn up today excludes those that disappeared, which is survivorship bias, a close relative.
A related problem is the resolution of the data. A rule tested on daily closing values may assume a price or a stock level that was never available within the day.
In our work
We check three things for every input: its source, the date each value was known, and whether a second source agrees. One such audit found 79,383 values served before their publication date.
Service: data pipelines and CRM Research note: how we treat data
References
- Croushore, D., Stark, T. (2001). A real-time data set for macroeconomists. Journal of Econometrics, 105(1), 111-130. doi:10.1016/S0304-4076(01)00072-0
- Kaufman, S., Rosset, S., Perlich, C., Stitelman, O. (2012). Leakage in data mining: formulation, detection, and avoidance. ACM Transactions on Knowledge Discovery from Data, 6(4), 1-21. doi:10.1145/2382577.2382579
- López de Prado, M. (2018). Advances in financial machine learning. Wiley, Hoboken.