ARIMA_FORECAST

This function fits an autoregressive integrated moving average model to a univariate time series and returns point forecasts for a specified number of future periods.

The ARIMA model combines autoregressive terms, differencing, and moving-average terms to model serial dependence in time-series data:

\phi(L)(1-L)^d y_t = c + \theta(L)\varepsilon_t

where p controls autoregressive order, d controls differencing order, and q controls moving-average order.

Excel Usage

=ARIMA_FORECAST(endog, p, d, q, seasonal_p, seasonal_d, seasonal_q, seasonal_s, steps, enforce_stationarity, enforce_invertibility)
  • endog (list[list], required): Time-series observations as a 2D range (data points).
  • p (int, optional, default: 1): Non-seasonal autoregressive order (lags).
  • d (int, optional, default: 0): Non-seasonal differencing order (differences).
  • q (int, optional, default: 0): Non-seasonal moving-average order (lags).
  • seasonal_p (int, optional, default: 0): Seasonal autoregressive order (lags).
  • seasonal_d (int, optional, default: 0): Seasonal differencing order (differences).
  • seasonal_q (int, optional, default: 0): Seasonal moving-average order (lags).
  • seasonal_s (int, optional, default: 0): Seasonal period length (periods).
  • steps (int, optional, default: 1): Number of future periods to forecast (periods).
  • enforce_stationarity (bool, optional, default: true): Whether to enforce stationarity constraints (true/false).
  • enforce_invertibility (bool, optional, default: true): Whether to enforce invertibility constraints (true/false).

Returns (list[list]): Row vector containing forecasted values for the requested forecast horizon.

Example 1: One-step ARIMA forecast with default orders

Inputs:

endog steps
10 12 13 15 14 16 18 17 1

Excel formula:

=ARIMA_FORECAST({10,12,13,15,14,16,18,17}, 1)

Expected output:

16.4953

Example 2: Two-step ARIMA forecast

Inputs:

endog p d q steps
3 4 6 7 9 11 10 12 1 1 0 2

Excel formula:

=ARIMA_FORECAST({3,4,6,7,9,11,10,12}, 1, 1, 0, 2)

Expected output:

Result
12.7183 12.9763
Example 3: Seasonal ARIMA structure with period four

Inputs:

endog p d q seasonal_p seasonal_d seasonal_q seasonal_s steps
20 22 25 23 21 24 27 26 24 26 29 28 1 0 0 1 0 0 4 1

Excel formula:

=ARIMA_FORECAST({20,22,25,23,21,24,27,26,24,26,29,28}, 1, 0, 0, 1, 0, 0, 4, 1)

Expected output:

25.8609

Example 4: Scalar normalization path with single numeric input wrapped

Inputs:

endog p d q steps
5 5 6 6 7 7 8 0 1 1 1

Excel formula:

=ARIMA_FORECAST({5,5,6,6,7,7,8}, 0, 1, 1, 1)

Expected output:

8

Python Code

import numpy as np
from statsmodels.tsa.arima.model import ARIMA as sm_ARIMA

def arima_forecast(endog, p=1, d=0, q=0, seasonal_p=0, seasonal_d=0, seasonal_q=0, seasonal_s=0, steps=1, enforce_stationarity=True, enforce_invertibility=True):
    """
    Fit an ARIMA model and return out-of-sample forecasts.

    See: https://www.statsmodels.org/stable/generated/statsmodels.tsa.arima.model.ARIMA.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        endog (list[list]): Time-series observations as a 2D range (data points).
        p (int, optional): Non-seasonal autoregressive order (lags). Default is 1.
        d (int, optional): Non-seasonal differencing order (differences). Default is 0.
        q (int, optional): Non-seasonal moving-average order (lags). Default is 0.
        seasonal_p (int, optional): Seasonal autoregressive order (lags). Default is 0.
        seasonal_d (int, optional): Seasonal differencing order (differences). Default is 0.
        seasonal_q (int, optional): Seasonal moving-average order (lags). Default is 0.
        seasonal_s (int, optional): Seasonal period length (periods). Default is 0.
        steps (int, optional): Number of future periods to forecast (periods). Default is 1.
        enforce_stationarity (bool, optional): Whether to enforce stationarity constraints (true/false). Default is True.
        enforce_invertibility (bool, optional): Whether to enforce invertibility constraints (true/false). Default is True.

    Returns:
        list[list]: Row vector containing forecasted values for the requested forecast horizon.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        endog = to2d(endog)

        if not isinstance(endog, list) or not all(isinstance(row, list) for row in endog):
            return "Error: Invalid input - endog must be a 2D list"

        series = []
        for row in endog:
            for value in row:
                try:
                    series.append(float(value))
                except (TypeError, ValueError):
                    continue

        if len(series) < 3:
            return "Error: endog must contain at least 3 numeric values"

        if steps < 1:
            return "Error: steps must be at least 1"

        model = sm_ARIMA(
            series,
            order=(int(p), int(d), int(q)),
            seasonal_order=(int(seasonal_p), int(seasonal_d), int(seasonal_q), int(seasonal_s)),
            enforce_stationarity=bool(enforce_stationarity),
            enforce_invertibility=bool(enforce_invertibility)
        )
        fitted = model.fit()
        forecast = np.asarray(fitted.forecast(steps=int(steps)), dtype=float).reshape(1, -1)
        return forecast.tolist()
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Time-series observations as a 2D range (data points).
Non-seasonal autoregressive order (lags).
Non-seasonal differencing order (differences).
Non-seasonal moving-average order (lags).
Seasonal autoregressive order (lags).
Seasonal differencing order (differences).
Seasonal moving-average order (lags).
Seasonal period length (periods).
Number of future periods to forecast (periods).
Whether to enforce stationarity constraints (true/false).
Whether to enforce invertibility constraints (true/false).