ARIMA—autoregressive integrated moving average—forecasts a time series from its temporal structure. Unlike methods for unordered observations, it accounts for the possibility that a value depends on earlier values. It is useful when that dependence, including trends, matters to a forecasting decision. section 7.1
The order (p, d, q) specifies three components:
- Autoregression (p) uses a specified number of earlier observations; p = 1 uses one lag. section 7.3.1
- Integration (d) specifies how many times to difference the series to make it stationary. First-order differencing subtracts the preceding observation from each value. section 7.3.4 section 7.3.9
- Moving average (q) specifies how many lagged forecast errors enter the model; q = 0 excludes them. section 7.3.9
Choose d first, using only the training period: inspect the series and its autocorrelation function (ACF), then test stationarity. Examine the ACF and partial autocorrelation function (PACF) of the differenced series when selecting p and q. Fit the model to the original training series—the order tuple specifies the differencing—and reserve later observations for an out-of-sample check. section 7.3.4 section 7.3.7
>>> adf_test_diff = adfuller(train_diff)
>>> print('p-value:', adf_test_diff[1])
p-value: 1.2486140415792743e-16
The augmented Dickey–Fuller test returns a very small p-value after first-order differencing, supporting the choice of d = 1 for this training series. section 7.3.7
Forecast a held-out month of closing prices
For daily Apple closing prices, train covers October 2023 through March 2024; test contains April’s 22 trading days. The selected order uses one autoregressive lag, one difference, and no moving-average terms: from statsmodels.tsa.arima.model import ARIMA model_fit = ARIMA(train, order=(1, 1, 0)).fit() forecast_test = model_fit.forecast(len(test)) Compare forecast_test with the withheld closing prices rather than judging the fitted model alone. The April forecast was approximately $173.51 per day, versus an actual April average near $169.43. The forecast was nearly flat while actual prices varied. section 7.3.7 section 7.3.9 section 7.3.11
Check residual plots and their ACF/PACF for remaining patterns; compare candidate models’ fit and complexity using criteria such as AIC, BIC, and HQIC. A plausible fit does not guarantee an accurate forecast: stock-price volatility and unpredictable influences limit what historical patterns can predict. Exponential smoothing offers a simpler alternative that weights recent observations more heavily, particularly for short-term forecasting; compare forecasts on the same held-out period. section 7.3.10 section 7.0 section 7.4.5

