Time Series Simulator

class tsbootstrap.time_series_simulator.TimeSeriesSimulator(fitted_model, X_fitted: ndarray, rng=None)[source]

Class to simulate various types of time series models.

n_samples

Number of samples in the fitted time series model.

Type:

int

n_features

Number of features in the fitted time series model.

Type:

int

burnin

Number of burn-in samples to discard for certain models.

Type:

int

_validate_ar_simulation_params(params)[source]

Validate the parameters necessary for the simulation.

_simulate_ar_residuals(lags, coefs, init, max_lag)[source]

Simulates an Autoregressive (AR) process with given lags, coefficients, initial values, and random errors.

simulate_ar_process(resids_lags, resids_coefs, resids)[source]

Simulate AR process from the fitted model.

_simulate_non_ar_residuals()[source]

Simulate residuals according to the model type.

simulate_non_ar_process()[source]

Simulate a time series from the fitted model.

generate_samples_sieve(model_type, resids_lags, resids_coefs, resids)[source]

Generate a bootstrap sample using the sieve bootstrap.

property X_fitted: ndarray

Get the array of fitted values.

property fitted_model

Get the fitted model.

generate_samples_sieve(model_type: Literal['ar', 'arima', 'sarima', 'var', 'arch'], resids_lags: Integral | List[Integral] | None = None, resids_coefs: ndarray | None = None, resids: ndarray | None = None) ndarray[source]

Generate a bootstrap sample using the sieve bootstrap.

Parameters:
  • model_type (ModelTypes) – The model type used for the simulation.

  • resids_lags (Optional[Union[Integral, List[Integral]]], optional) – The lags to be used in the AR process. Can be non-consecutive.

  • resids_coefs (Optional[np.ndarray], optional) – The coefficients corresponding to each lag. Of shape (1, len(lags)).

  • resids (Optional[np.ndarray], optional) – The initial values for the simulation. Should be at least as long as the maximum lag.

Returns:

The bootstrap sample.

Return type:

np.ndarray

Raises:

ValueError – If resids_lags, resids_coefs, or resids are not provided.

property rng

Get the random number generator instance.

simulate_ar_process(resids_lags: Integral | List[Integral], resids_coefs: ndarray, resids: ndarray) ndarray[source]

Simulate AR process from the fitted model.

Parameters:
  • resids_lags (Union[Integral, List[Integral]]) – The lags to be used in the AR process. Can be non-consecutive, but when called from generate_samples_sieve, it will be sorted.

  • resids_coefs (np.ndarray) – The coefficients corresponding to each lag. Of shape (1, len(lags)). Sorted by generate_samples_sieve corresponding to the sorted lags.

  • resids (np.ndarray) – The initial values for the simulation. Should be at least as long as the maximum lag.

Returns:

The simulated AR process as a 1D NumPy array.

Return type:

np.ndarray

Raises:
  • ValueError – If resids_lags, resids_coefs, or resids are not provided. If resids_coefs is not a 1D NumPy array. If resids_coefs is not the same length as resids_lags. If resids is not the same length as X_fitted.

  • TypeError – If fitted_model is not an instance of AutoRegResultsWrapper. If resids_lags is not an integer or a list of integers.

simulate_non_ar_process() ndarray[source]

Simulate a time series from the fitted model.

Returns:

np.ndarray

Return type:

The simulated time series.