2025xLSTM Directional Trading

S&P 500 Trading (Experiment)

A side experiment: predicting whether the S&P 500 goes up or down tomorrow with an xLSTM, causal wavelet denoising, lots of features, and quarterly walk-forward backtests from 2021–2024.

*I built this purely out of curiosity; in practice the model's edge is negligible (hello, Efficient Market Hypothesis).*

Raw price data is full of high-frequency noise that hides the actual trend. To clean it up without peeking into the future, I used causal Daubechies-8 wavelet denoising (db8, level 4, soft thresholding over a 256-day sliding window).

The model is an extended LSTM (xLSTM). It mixes mLSTM blocks, which have matrix-valued memory, with sLSTM blocks, which use exponential gating for sharp state changes, plus causal convolution, group normalization, and gated MLP residuals. It takes in 50+ stationary features covering returns, trend, momentum, volatility, volume, macro indicators (shifted for publication lag), NYT headline sentiment, and the VIX, so it learns how the market moves instead of memorizing price levels.

01

Causal Wavelet Denoising

Denoised prices with a causal db8 wavelet, 4 levels deep, with soft thresholding over a 256-day sliding window. Each day is cleaned using only past data, so nothing leaks from the future. The threshold is the universal (VisuShrink) one, estimated from the median absolute deviation (MAD) of the finest detail coefficients.

02

Stationary Feature Engineering

Built 50+ strictly stationary features (ratios, returns, and bounded oscillators) so the model learns dynamics instead of memorizing price levels. That covers multi-horizon returns, trend ratios, momentum, volatility bands, volume flows, macro indicators shifted for publication delays, rolling NYT sentiment z-scores, and the VIX.

03

xLSTM Model & Walk-Forward Backtesting

Trained an xLSTM ensemble with alternating mLSTM and sLSTM blocks (d_model=48, 2 blocks, 4 heads, expand factor 2) using AdamW, label smoothing, and gradient clipping. I retrained quarterly from 2021–2024, only used labels once they'd be known, fit the StandardScaler on training data only, and used 2-year validation windows. Then I compared accuracy, Sharpe ratio, and max drawdown against Long/Short, Long/Flat, DCA, and Buy & Hold.

Built causal wavelet denoising (db8, level 4, soft thresholding, 256-day sliding window) that strips noise from S&P 500 OHLCV data without lookahead bias while keeping the trend.

Engineered 50+ stationary features: multi-horizon returns, EMA/SMA ratios, RSI, stochastic oscillators, volatility and volume measures, lagged macro data (GDP, inflation, unemployment, interest rates, gold), NYT headline sentiment z-scores, and VIX signals.

Trained an xLSTM ensemble with alternating mLSTM and sLSTM blocks (d_model=48, 2 blocks, 4 heads) and retrained it quarterly in a walk-forward setup from 2021–2024, only using labels once they would actually have been known.

The big lesson: a fancy architecture is worthless if your pipeline leaks the future. Causal denoising and walk-forward validation mattered more than the xLSTM itself.