Autoregressive Moving Average (ARMA) models for stationary time series.
Classes
Autoregressive Moving Average (ARMA) model for stationary time series forecasting.
The \text{ARMA}(p, q) model combines autoregressive (AR) and moving average (MA) components to model stationary time series data.
Constructor
__init__( self, order: Tuple[int, int] = (), trend: str | None = 'c', method: str = 'css-mle', maxiter: int = 50, )
Overview
The ARMA model works through the following steps:
- Center the time series by subtracting the mean.
- Estimate initial AR coefficients via Yule-Walker equations.
- Initialize MA coefficients to zero.
- Iteratively refine parameters using conditional sum of squares (CSS)
- Forecast by combining AR (lagged values) and MA (lagged residuals)
Theory
The \text{ARMA}(p, q) model is defined as:
y_t = c + \sum_{i=1}^p \phi_i y_{t-i} + \epsilon_t + \sum_{j=1}^q \theta_j \epsilon_{t-j}
where:
- y_t: The value of the time series at time t.
- c: A constant (intercept) term.
- \phi_i: The autoregressive parameters.
- \theta_j: The moving average parameters.
- p: The AR order (number of lagged values).
- q: The MA order (number of lagged errors).
- \epsilon_t: The white noise error term at time t.
\Phi(L) y_t = c + \Theta(L) \epsilon_t
where \Phi(L) = 1 - \sum_{i=1}^p \phi_i L^i and \Theta(L) = 1 + \sum_{j=1}^q \theta_j L^j.
Parameters
order
tuple of (int, int), 0)
= (1
The :math:`(p, q)` order of the model:
- •:math:`p`: Autoregressive order.
- •:math:`q`: Moving average order.
trend
{"c", "ct", None}
= "c"
The trend component to include:
- •
"c": Include a constant term (intercept). - •
"ct": Include both a constant and a linear time trend. - •
None: No constant or trend.
method
{"css", "mle", "css-mle"}
= "css-mle"
The estimation method:
- •
"css": Conditional Sum of Squares. - •
"mle": Maximum Likelihood Estimation. - •
"css-mle": CSS for initial estimates followed by MLE refinement.
maxiter
int
= 50
Maximum number of iterations for the optimization process.
Attributes
ar_params_
np.ndarray of shape (p,)
Fitted autoregressive coefficients :math:`(\phi_1, \phi_2, \dots, \phi_p)`.
ma_params_
np.ndarray of shape (q,)
Fitted moving average coefficients :math:`(\\theta_1, \\theta_2, \dots, \\theta_q)`.
const_
float
The fitted constant (intercept) term.
resid_
np.ndarray of shape (n_obs,)
The estimated residuals from the fitted model.
sigma2_
float
The variance of the residuals (:math:`\sigma^2`).
n_obs_
int
The total number of observations used for fitting.
Notes
Complexity:
- Training: O(n \cdot \text{maxiter} \cdot (p+q)^2) where n
- Prediction: O(p+q) for each forecasted step.
- Stationary time series with both autocorrelation and moving average structure
- When differencing is not needed (no trend or unit root)
- Data where shocks persist for a limited number of periods
- As a building block before considering the full ARIMA framework
References
Box2015
Box, G. E., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015).
Time series analysis: forecasting and control.
John Wiley & Sons.
See Also
python
>>> import numpy as np
>>> from tuiml.algorithms.timeseries import ARMA
>>> # Generate synthetic data
>>> np.random.seed(42)
>>> n = 100
>>> y = np.cumsum(np.random.normal(size=n))
>>> y_stationary = np.diff(y) # ARMA assumes stationarity
>>> model = ARMA(order=(1, 1))
>>> model.fit(y_stationary)
>>> forecast = model.predict(steps=3)
Methods
fit_predict
(self, y: np.ndarray, steps: int=1) -> np.ndarray
fit_predict
(self, y: np.ndarray, steps: int=1) -> np.ndarray
Fit the model and forecast future values in one step.
Parameters
y
np.ndarray of shape (n_samples,)
Time series values to fit.
steps
int
= 1
Number of future time steps to forecast.
Returns
forecast
np.ndarray of shape (steps,)
Forecasted values.