Time Series Model

class tsbootstrap.time_series_model.TimeSeriesModel(X: ndarray, y: ndarray | None = None, model_type: Literal['ar', 'arima', 'sarima', 'var', 'arch'] = 'ar', verbose: bool = True)[source]

A class for fitting time series models to data.

property X: ndarray

The input data.

fit(order: Integral | List[Integral] | tuple[Integral, Integral, Integral] | tuple[Integral, Integral, Integral, Integral] | None = None, **kwargs)[source]

Fits a time series model to the input data.

Parameters:
  • order (OrderTypes, optional) – The order of the model. If not specified, the default order for the selected model type is used.

  • **kwargs – Additional keyword arguments for the model.

Return type:

The fitted time series model.

Raises:

ValueError – If an invalid order is specified for the model type.

fit_ar(order=None, **kwargs)[source]

Fits an AR model to the input data.

Parameters:
  • order (Union[int, List[int]], optional) – The order of the AR model or a list of order to include.

  • **kwargs

    Additional keyword arguments for the AutoReg model, including:
    • seasonal (bool): Whether to include seasonal terms in the model.

    • period (int): The seasonal period, if using seasonal terms.

    • trend (str): The trend component to include in the model.

Returns:

The fitted AR model.

Return type:

AutoRegResultsWrapper

Raises:

ValueError – If an invalid period is specified for seasonal terms or if the maximum allowed lag value is exceeded.

fit_arch(order: int | None = None, p: int = 1, q: int = 1, arch_model_type: Literal['GARCH', 'EGARCH', 'TARCH', 'AGARCH'] = 'GARCH', mean_type: Literal['zero', 'AR'] = 'zero', **kwargs)[source]

Fits a GARCH, GARCH-M, EGARCH, TARCH, or AGARCH model to the input data.

Parameters:
  • order (int, optional) – The number of order to include in the AR part of the model.

  • p (int, default 1) – The number of order in the GARCH part of the model.

  • q (int, default 1) – The number of order in the ARCH part of the model.

  • arch_model_type (Literal["GARCH", "EGARCH", "TARCH", "AGARCH"], default "GARCH") – The type of GARCH model to fit.

  • mean_type (Literal["zero", "AR"], default "zero") – The type of mean model to use.

  • **kwargs – Additional keyword arguments for the ARCH model.

Return type:

The fitted GARCH model.

Raises:

ValueError – If the maximum allowed lag value is exceeded or if an invalid arch_model_type is specified.

fit_arima(order=None, **kwargs)[source]

Fits an ARIMA model to the input data.

Parameters:
  • order (Tuple[int, int, int], optional) – The order of the ARIMA model (p, d, q).

  • **kwargs

    Additional keyword arguments for the ARIMA model, including:
    • seasonal (bool): Whether to include seasonal terms in the model.

    • period (int): The seasonal period, if using seasonal terms.

    • trend (str): The trend component to include in the model.

Returns:

The fitted ARIMA model.

Return type:

ARIMAResultsWrapper

Raises:

ValueError – If an invalid period is specified for seasonal terms or if the maximum allowed lag value is exceeded.

Notes

The ARIMA model is fit using the statsmodels implementation. The default solver is ‘lbfgs’ and the default optimization method is ‘css’. The default maximum number of iterations is 50. These values can be changed by passing the appropriate keyword arguments to the fit method.

fit_sarima(order=None, arima_order=None, **kwargs)[source]

Fits a SARIMA model to the input data.

Parameters:
  • order (Tuple[int, int, int, int], optional) – The order of the SARIMA model (p, d, q, s).

  • arima_order (Tuple[int, int, int], optional) – The order of the ARIMA model (p, d, q). If not specified, the first three elements of order are used.

  • **kwargs

    Additional keyword arguments for the SARIMA model, including:
    • seasonal (bool): Whether to include seasonal terms in the model.

    • period (int): The seasonal period, if using seasonal terms.

    • trend (str): The trend component to include in the model.

Returns:

The fitted SARIMA model.

Return type:

SARIMAXResultsWrapper

Raises:

ValueError – If an invalid period is specified for seasonal terms or if the maximum allowed lag value is exceeded.

Notes

The SARIMA model is fit using the statsmodels implementation. The default solver is ‘lbfgs’ and the default optimization method is ‘css’. The default maximum number of iterations is 50. These values can be changed by passing the appropriate keyword arguments to the fit method.

fit_var(order: int | None = None, **kwargs)[source]

Fits a Vector Autoregression (VAR) model to the input data.

Parameters:
  • order (int, optional) – The number of order to include in the VAR model.

  • **kwargs – Additional keyword arguments for the VAR model.

Raises:

ValueError – If the maximum allowed lag value is exceeded.

Returns:

The fitted VAR model.

Return type:

VARResultsWrapper

Notes

The VAR model is fit using the statsmodels implementation. The default solver is ‘bfgs’ and the default optimization method is ‘css’. The default maximum number of iterations is 50. These values can be changed by passing the appropriate keyword arguments to the fit method.

property model_type: Literal['ar', 'arima', 'sarima', 'var', 'arch']

The type of model to fit.

property verbose: int

The verbosity level controlling suppression.

Verbosity levels: - 2: No suppression (default) - 1: Suppress stdout only - 0: Suppress both stdout and stderr

Returns:

The verbosity level.

Return type:

int

property y: ndarray | None

Optional array of exogenous variables.