Leakage-safe lagged features
Question
How would you construct a lagged rolling mean feature for a next-day return model without accidentally using the predicted day's return?
Short answer
Define the decision timestamp first. Use only returns observable by that timestamp, group by asset, and apply any required shift before rolling. Sort within assets and prevent windows crossing entity boundaries. Verify a small example manually around the split cutoff. A rolling function's default alignment may include the current row, which is valid only if that row's value is already observable at prediction time.
Original question and answer written by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solutionLessons behind this question
- Decision Trees: Splitting Criteria and Pruning
- Boosting: AdaBoost and Gradient Boosting
- Sample Spaces, Events, and the Probability Axioms
Start with a free lesson: Probability Fundamentals is part of a free topic. Create a free account, no card needed, to read it in full with worked solutions.
Read it free