The Augmented Dickey–Fuller (ADF) test evaluates whether a time series is stationary or contains a unit root associated with nonstationarity. It accommodates autocorrelation by adding lagged difference terms to the regression. section 7.3.7
Interpret the test through its hypotheses and practical limitations:
- Treat nonstationarity as the null hypothesis; reject it when the p-value falls below the typical 5% threshold. section 7.3.7
- Include a constant, optional time trend, lagged levels, lagged differences, and an error term in the estimated regression. section 7.3.7
- Treat lag selection as consequential because it can change results; expect lower power with short or noisy series. section 7.3.7
Testing prices before and after differencing
Applying statsmodels' adfuller to Apple closing prices produces a p-value of 0.5761, so the nonstationarity null is not rejected. After first-order differencing, the p-value becomes 1.25e-16, supporting stationarity. section 7.3.7
>>> from statsmodels.tsa.stattools import adfuller
>>> adf_test = adfuller(train)
>>> print('p-value:', adf_test[1])
p-value: 0.5761116196186049
Run the ADF test with statsmodels and inspect the returned p-value. section 7.3.7
