A leakage-free LSTM that does not beat a random walk
The classic LSTM stock-prediction project, rebuilt to predict next-day returns under purged walk-forward. The honest result: it does not beat a persistence baseline (MASE 1.00, directional accuracy 0.50).
00Overview
Most LSTM stock-prediction tutorials look impressive because they predict price levels, which are autocorrelated, on data that leaks. This is a leakage-free rebuild that predicts next-day returns under purged walk-forward, and reports the result honestly even though the result is a null.
The result
01Method
- A deliberately small LSTM and an LSTM-with-attention variant.
- Target is the next-day log return, not the price level.
- Purged walk-forward with a >= 60-bar embargo; the scaler is fit per fold on training data only.
- Served as an ONNX artifact under 5 MB (TensorFlow is train-only).
02Why this is the answer
Under honest validation the model matches a persistence baseline exactly: return-space RMSE 0.0093, but MASE 1.00, directional accuracy 0.50 and a Diebold-Mariano p-value of 1.00. There is no skill to find here, and the point of the project is the harness that proves it, not a winning model.