Data Science

How do we handle "Data Leakage" when training models on time-series financial data?

M Asked by Michael Richardson · 08-11-2023
0 upvotes 10,364 views 0 comments
The question

My team is building a stock price predictor, but our backtesting results look too good to be true. I suspect we are accidentally leaking future information into our training set. Besides basic chronological splitting, what are the best techniques for ensuring our validation set is truly representative of a live trading scenario? 

3 answers

0
PA
Answered on 15-01-2023

Data leakage in time-series is a silent killer. You need to implement "Purged Cross-Validation." This involves not just splitting the data chronologically but also adding a "buffer" or a "gap" between your training and testing sets to account for overlapping information or look-ahead bias. For example, if you are predicting a 5-day return, your test set should start at least 5 days after the last training point. Also, check your feature engineering; ensure that any rolling averages or normalized values are calculated only using the data available before the prediction point, not the entire dataset. 

0
CH
Answered on 20-01-2023

Are there specific Python libraries that automate this "purging" process, or is it better to write custom data loaders for specialized financial sets?

RI 05-02-2023

Christopher, to answer your question, 'Scikit-learn' has a TimeSeriesSplit, but it doesn't handle "purging" out of the box. I highly recommend looking into the 'sktime' library or the 'PyPortfolioOpt' community. Most professional quants I know end up writing custom generators. The key is to strictly enforce an "index-based" mask that ensures your model never sees a timestamp greater than $t$ when training for a prediction at $t+1$. It’s tedious to code, but it’s the only way to trust your results.

0
N
Answered on 10-02-2023

Use walk-forward validation. It mimics real-world trading by expanding the training window one step at a time and testing on the immediate next day. 

Exactly, Nancy. If your model can't survive a walk-forward test, it will definitely fail when you put real money behind it in the live market.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session