Skip to content

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 solution

Lessons behind this question

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