AI & Trading

Time Series Stationarity

A time series is stationary if its statistical properties (mean, variance, autocorrelation) do not change over time. Stock prices are famously non-stationary. They trend up over time (changing mean) and experience volatility clustering (changing variance).

The Danger for ML

If you feed non-stationary data (raw prices) into a machine learning model, the model will learn spurious correlations. It will assume that because the price was $100 yesterday, it will be around $100 today, effectively acting as a naive forecast.

How to test for it:

Use the Augmented Dickey-Fuller (ADF) test. If the p-value is < 0.05, you can reject the null hypothesis that a unit root is present, implying the series is stationary.

Fixing Non-Stationarity

  • Integer Differencing: Using returns instead of prices (e.g. today's close - yesterday's close). This makes the series stationary but destroys memory.
  • Fractional Differencing: A technique popularized by Marcos Lopez de Prado that applies differencing as a real number (e.g., 0.4) to achieve stationarity while preserving the maximum amount of memory (correlation).