Machine learning · honest evaluation

Leakage Lab

In 2024 I built a stock price predictor whose errors looked tiny. Re-running its exact setup gives an R² of 0.9997 to 0.9999. It was not predicting anything. This page shows why, and what an honest forecast looks like.

0.9997–0.9999R² of the 2024 setup, on ten stocks
0.997–0.999R² of “today = yesterday”, which forecasts nothing
-0.1%best honest model’s error vs “no change” (lower is better)

The trap

An honest test

Each model predicts tomorrow’s return from what was known at today’s close (recent returns, 20-day volatility and momentum). It is trained on the past, tested on the next month, then refitted (walk-forward validation), over about 1,994 trading days per stock. The table shows each model’s forecast error compared with “no change”.

Error vs “no change” (RMSE of next-day returns). “same” = within 0.05%. Data: Yahoo Finance daily prices, 2015-01-01 to 2025-12-31.
Stock2024 setup R²Historical meanLinear modelGradient boosting
Apple AAPL0.9999-0.1%+0.4%+0.4%
Amazon AMZN0.9998same+0.4%+2.7%
Alphabet GOOGL0.9998-0.1%+0.5%+2.6%
Microsoft MSFT0.9999-0.1%-0.1%+1.8%
Tesla TSLA0.9997same+0.3%+1.4%
Reliance Industries RELIANCE.NS0.9999same+0.5%+1.6%
Tata Consultancy Services TCS.NS0.9998same+0.6%+2.7%
Infosys INFY.NS0.9999same+0.4%+1.2%
State Bank of India SBIN.NS0.9998same+0.6%+3.2%
HDFC Bank HDFCBANK.NS0.9998same+0.4%+3.3%

What this says: no model beats “no change” by a meaningful margin. That is the expected, honest result for daily returns of large, heavily traded stocks. A test in the repository fails on the 2024 setup and passes on the new pipeline, so the leak cannot come back unnoticed.

The interactive app runs with streamlit run streamlit_app.py; a hosted link will appear here. Code, tests and method