Autoregressive Moving Average (ARMA) models for stationary time series.

Classes

ARMA

class algorithms.timeseries.arma.ARMA(Regressor)

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:

  1. Center the time series by subtracting the mean.
  2. Estimate initial AR coefficients via Yule-Walker equations.
  3. Initialize MA coefficients to zero.
  4. Iteratively refine parameters using conditional sum of squares (CSS)
or simplified maximum likelihood estimation (MLE).
  1. Forecast by combining AR (lagged values) and MA (lagged residuals)
components, with future errors assumed to be zero.

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.
Using the lag operator L, the model can be written as:
\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
is the number of samples and (p, q) are the orders.
  • Prediction: O(p+q) for each forecasted step.
When to use ARMA:
  • 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.
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

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return JSON Schema for algorithm parameters.

get_capabilities (cls) -> List[str]

Return supported capabilities.

get_complexity (cls) -> str

Return complexity analysis.

get_references (cls) -> List[str]

Return academic citations.

fit (self, y: np.ndarray, _X: Optional[np.ndarray]=None) -> 'ARMA'

Fit the ARMA model to time series data.

Parameters
y
np.ndarray of shape (n_samples,)
Time series values to fit.
_X
np.ndarray = None
Ignored. Present for API consistency with regressors.
Returns
self
ARMA
Fitted estimator.
predict (self, steps: int=1, _X: Optional[np.ndarray]=None) -> np.ndarray

Forecast future values using the fitted ARMA model.

Parameters
steps
int = 1
Number of future time steps to forecast.
_X
np.ndarray = None
Ignored.
Returns
forecast
np.ndarray of shape (steps,)
Forecasted values.
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.