ARIMA Forecasting
Classical Model statsmodels

ARIMA Models

Learn the basics of ARIMA (AutoRegressive Integrated Moving Average) models for time series forecasting.

What is ARIMA?

ARIMA combines three ideas:

  • AR(p): AutoRegressive part (depends on past values).
  • I(d): Integrated (differencing to remove trend).
  • MA(q): Moving Average (depends on past errors).

ARIMA(p, d, q) uses:

  • p: number of AR lags.
  • d: number of differences to make series stationary.
  • q: number of MA lags.

Example: Simple ARIMA Forecast

ARIMA(1,1,1) with statsmodels
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.arima.model import ARIMA

# Create synthetic time series with trend
np.random.seed(42)
dates = pd.date_range(start="2020-01-01", periods=100, freq="D")
values = 50 + np.arange(100) * 0.5 + np.random.normal(scale=2, size=100)
ts = pd.Series(values, index=dates)

ts.plot(title="Synthetic Time Series", figsize=(10, 4))
plt.show()

# Fit ARIMA model
model = ARIMA(ts, order=(1, 1, 1))  # ARIMA(p,d,q)
model_fit = model.fit()

print(model_fit.summary())

# Forecast next 10 days
forecast = model_fit.forecast(steps=10)

plt.figure(figsize=(10, 4))
plt.plot(ts, label="History")
plt.plot(forecast.index, forecast.values, label="Forecast", color="red")
plt.title("ARIMA Forecast")
plt.legend()
plt.show()