Skip to content

ARIMA

durbyn provides manual ARIMA/SARIMA specification and automatic model selection via AutoARIMA.


ARIMA — Manual Specification

from durbyn import ARIMA

# Non-seasonal ARIMA(1,1,1)
model = ARIMA(order=(1, 1, 1)).fit(y, m=1)
fc = model.forecast(h=12, level=[80, 95])

# Seasonal ARIMA(2,1,1)(0,1,0)
model = ARIMA(
    order=(2, 1, 1),
    seasonal_order=(0, 1, 0),
).fit(y, m=12)
fc = model.forecast(h=12)

Parameters

Parameter Type Default Description
order tuple[int, int, int] (0, 0, 0) Non-seasonal (p, d, q) orders
seasonal_order tuple[int, int, int] \| None None Seasonal (P, D, Q) orders
include_mean bool True Include mean/intercept term
method str "CSS-ML" Estimation method: "CSS-ML", "ML", "CSS"
transform_pars bool True Transform parameters for stationarity
lambda_ float \| bool \| None None Box-Cox parameter
biasadj bool \| None None Bias adjustment for Box-Cox

With External Regressors

ARIMA supports external regressors (xreg) via the X parameter at fit time:

import numpy as np
from durbyn import ARIMA

# Training data with regressors
y = np.random.randn(100)
X = np.random.randn(100, 2)  # 2 regressors

model = ARIMA(order=(1, 1, 0)).fit(y, m=12, X=X)

# Future regressors must be provided (not yet wired through forecast)
fc = model.forecast(h=12)

AutoARIMA — Automatic Selection

Searches over ARIMA model space using information criteria.

from durbyn import AutoARIMA

# Default: stepwise search with AICc
model = AutoARIMA().fit(y, m=12)
fc = model.forecast(h=12, level=[80, 95])

# With constraints
model = AutoARIMA(
    max_p=3,
    max_q=3,
    d=1,          # fix differencing order
    D=1,          # fix seasonal differencing
    seasonal=True,
    stepwise=True,
    ic="bic",
).fit(y, m=12)

Parameters

Parameter Type Default Description
d int \| None None Differencing order. None for auto
D int \| None None Seasonal differencing. None for auto
max_p int 5 Maximum AR order
max_q int 5 Maximum MA order
max_P int 2 Maximum seasonal AR order
max_Q int 2 Maximum seasonal MA order
max_order int 5 Maximum total p + q + P + Q
max_d int 2 Maximum differencing order
max_D int 1 Maximum seasonal differencing
stationary bool False Restrict to stationary models
seasonal bool True Include seasonal terms
stepwise bool True Use stepwise search (faster)
trace bool False Print search progress
approximation bool True Use CSS approximation during search
ic str "aicc" Information criterion: "aicc", "aic", "bic"
test str "adf" Unit root test: "adf", "kpss", "pp"
seasonal_test str "ocsb" Seasonal unit root test
allowmean bool True Allow mean/intercept
allowdrift bool True Allow drift term
lambda_ float \| bool \| None None Box-Cox parameter
biasadj bool \| None None Bias adjustment

Example: Full Workflow

from durbyn import AutoARIMA

y = [112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118,
     115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 140,
     145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166]

model = AutoARIMA(ic="aicc").fit(y, m=12)

# Inspect the model
print(model.summary)
print(f"Residuals std: {model.residuals.std():.2f}")

# Forecast
fc = model.forecast(h=12, level=[80, 95])
df = fc.to_dataframe()
print(df)