statsmodels.tsa.holtwinters.HoltWintersResults.simulate

HoltWintersResults.simulate(nsimulations, anchor=None, repetitions=1, error='add', random_errors=None, random_state=None)[source]

Random simulations using the state space formulation.

Parameters:
nsimulationsint

The number of simulation steps.

anchorint, str, or datetime, optional

First period for simulation. The simulation will be conditional on all existing datapoints prior to the anchor. Type depends on the index of the given endog in the model. Two special cases are the strings ‘start’ and ‘end’. start refers to beginning the simulation at the first period of the sample, and end refers to beginning the simulation at the first period after the sample. Integer values can run from 0 to nobs, or can be negative to apply negative indexing. Finally, if a date/time index was provided to the model, then this argument can be a date string to parse or a datetime type. Default is ‘end’.

repetitionsint, optional

Number of simulated paths to generate. Default is 1 simulated path.

error{“add”, “mul”, “additive”, “multiplicative”}, optional

Error model for state space formulation. Default is "add".

random_errorsoptional

Specifies how the random errors should be obtained. Can be one of the following:

  • None: Random normally distributed values with variance estimated from the fit errors drawn from numpy’s standard RNG (can be seeded with the random_state argument). This is the default option.

  • A distribution function from scipy.stats, e.g. scipy.stats.norm: Fits the distribution function to the fit errors and draws from the fitted distribution. Note the difference between scipy.stats.norm and scipy.stats.norm(), the latter one is a frozen distribution function.

  • A frozen distribution function from scipy.stats, e.g. scipy.stats.norm(scale=2): Draws from the frozen distribution function.

  • A np.ndarray with shape (nsimulations, repetitions): Uses the given values as random errors.

  • "bootstrap": Samples the random errors from the fit errors.

random_stateint or np.random.RandomState, optional

A seed for the random number generator or a np.random.RandomState object. Only used if random_errors is None. Default is None.

Returns:
simpd.Series, pd.DataFrame or np.ndarray

An np.ndarray, pd.Series, or pd.DataFrame of simulated values. If the original data was a pd.Series or pd.DataFrame, sim will be a pd.Series if repetitions is 1, and a pd.DataFrame of shape (nsimulations, repetitions) else. Otherwise, if repetitions is 1, a np.ndarray of shape (nsimulations,) is returned, and if repetitions is not 1 a np.ndarray of shape (nsimulations, repetitions) is returned.

Notes

The simulation is based on the state space model of the Holt-Winter’s methods. The state space model assumes that the true value at time \(t\) is randomly distributed around the prediction value. If using the additive error model, this means:

\[\begin{split}y_t &= \hat{y}_{t|t-1} + e_t\\ e_t &\sim \mathcal{N}(0, \sigma^2)\end{split}\]

Using the multiplicative error model:

\[\begin{split}y_t &= \hat{y}_{t|t-1} \cdot (1 + e_t)\\ e_t &\sim \mathcal{N}(0, \sigma^2)\end{split}\]

Inserting these equations into the smoothing equation formulation leads to the state space equations. The notation used here follows [1].

Additionally,

\[\begin{split}B_t &= b_{t-1} \circ_d \phi\\ L_t &= l_{t-1} \circ_b B_t\\ S_t &= s_{t-m}\\ Y_t &= L_t \circ_s S_t,\end{split}\]

where \(\circ_d\) is the operation linking trend and damping parameter (multiplication if the trend is additive, power if the trend is multiplicative), \(\circ_b\) is the operation linking level and trend (addition if the trend is additive, multiplication if the trend is multiplicative), and \(\circ_s\) is the operation linking seasonality to the rest.

The state space equations can then be formulated as

\[\begin{split}y_t &= Y_t + \eta \cdot e_t\\ l_t &= L_t + \alpha \cdot (M_e \cdot L_t + \kappa_l) \cdot e_t\\ b_t &= B_t + \beta \cdot (M_e \cdot B_t + \kappa_b) \cdot e_t\\ s_t &= S_t + \gamma \cdot (M_e \cdot S_t + \kappa_s) \cdot e_t\\\end{split}\]

with

\[\begin{split}\eta &= \begin{cases} Y_t\quad\text{if error is multiplicative}\\ 1\quad\text{else} \end{cases}\\ M_e &= \begin{cases} 1\quad\text{if error is multiplicative}\\ 0\quad\text{else} \end{cases}\\\end{split}\]

and, when using the additive error model,

\[\begin{split}\kappa_l &= \begin{cases} \frac{1}{S_t}\quad \text{if seasonality is multiplicative}\\ 1\quad\text{else} \end{cases}\\ \kappa_b &= \begin{cases} \frac{\kappa_l}{l_{t-1}}\quad \text{if trend is multiplicative}\\ \kappa_l\quad\text{else} \end{cases}\\ \kappa_s &= \begin{cases} \frac{1}{L_t}\quad\text{if seasonality is multiplicative}\\ 1\quad\text{else} \end{cases}\end{split}\]

When using the multiplicative error model

\[\begin{split}\kappa_l &= \begin{cases} 0\quad \text{if seasonality is multiplicative}\\ S_t\quad\text{else} \end{cases}\\ \kappa_b &= \begin{cases} \frac{\kappa_l}{l_{t-1}}\quad \text{if trend is multiplicative}\\ \kappa_l + l_{t-1}\quad\text{else} \end{cases}\\ \kappa_s &= \begin{cases} 0\quad\text{if seasonality is multiplicative}\\ L_t\quad\text{else} \end{cases}\end{split}\]

References

[1]

Hyndman, R.J., & Athanasopoulos, G. (2018) Forecasting: principles and practice, 2nd edition, OTexts: Melbourne, Australia. OTexts.com/fpp2. Accessed on February 28th 2020.


Last update: Dec 23, 2024