Lesson 3 of 15
Stationarity & ADF Test
Stationarity & the ADF Test
A time series is stationary if its statistical properties (mean, variance) do not change over time. Most forecasting models assume stationarity.
Variance-Ratio Test
A simple check: split the series in half and compare the variances of both halves. If the ratio is close to 1, the series may be stationary.
is_stationary(xs, threshold=0.5):
half = len(xs) // 2
ratio = variance(xs[:half]) / variance(xs[half:])
return |ratio - 1| < threshold
Augmented Dickey-Fuller (ADF) Statistic
The ADF test regresses the first-difference Δxs[t] on xs[t-1]:
Δxs[t] = intercept + slope * xs[t-1] + ε[t]
The t-statistic of slope is the ADF statistic. A very negative value (e.g., < -3) suggests stationarity.
Task
Implement is_stationary(xs, threshold=0.5) and adf_statistic(xs).
Python runtime loading...
Loading...
Click "Run" to execute your code.