Time Series Alignment and Lookahead
There is one bug in quantitative code that does not announce itself by failing. It announces itself by working beautifully. Lookahead bias, using information at a moment that was not available at that moment, produces backtests with impossible Sharpe ratios and signals that stop working the day they go live.
Interviewers at research-adjacent firms probe it directly, because a developer who does not see it will write a data pipeline that quietly poisons everything downstream.
Joining trades to quotes
The canonical version. You have trades and you have quotes, and you want to know the prevailing quote at each trade. A join on exact timestamps matches almost nothing, so the operation you want is an asof join: for each trade, the most recent quote at or before it.
The direction is the whole question. Matching a trade to the nearest quote, or to the next one, uses a quote published after the trade happened. A signal built on that has seen the future, and it will look excellent.
The rest of this lesson is for subscribers
Unlock every lesson in Programming for Quantitative Developers, and every other premium course.
Subscribe to continueTest your knowledge
Keep reading Programming for Quantitative Developers
25 lessons in this course, and every other premium course, on one subscription.
- Every lesson in every course, with the worked examples and interactive simulators
- Graded questions on every lesson, with explanations for the wrong answers as well as the right one
- The trainers, timed assessments and brainteaser library that go with them