arch.univariate.LS.append¶
-
LS.append(y: ndarray | DataFrame | Series | float, x: ndarray | DataFrame | Series | ndarray[tuple[int, int], dtype[float64]] | None =
None) None¶ Append observations to the model in-place.
- Parameters:¶
- y: ndarray | DataFrame | Series | float¶
The observations to append. Must have the same type as the data used to construct the model. If the model was constructed using a pandas object, then the index of the new data must be unique and must not overlap the existing index. If the existing index is increasing, the index of the new data must also be increasing and must follow the existing observations. When the model was constructed using an ndarray or a list, a scalar can be appended to add a single observation.
- x: ndarray | DataFrame | Series | ndarray[tuple[int, int], dtype[float64]] | None =
None¶ The values of the exogenous regressors for the new observations. Must be provided if, and only if, the model includes exogenous regressors, must have the same type and number of columns as the exogenous regressors used to construct the model, and must have the same number of observations as
y. When the exogenous regressors are stored in an ndarray, a 1-d array with one value for each regressor is treated as a single observation.
- Raises:¶
TypeError – If the type of
yorxdiffers from the type of the data in the model, or ifxcannot be converted to numbers.ValueError – If
yis empty, contains non-finite values or, when using pandas, has an index that is not unique, overlaps the existing index, or does not follow an increasing index of the existing data. Also raised ifxis provided when the model does not have exogenous regressors, is not provided when the model does, contains NaN or inf, or does not have the same number of observations asy.RuntimeError – If the model was created without data.
Notes
Parameters are not re-estimated. Use
fitto re-estimate the model using the extended sample, orfixorforecastto use parameters estimated previously. Appending resets the estimation sample to the complete extended sample, subject tohold_back, and clears values that were computed using the previous sample, such as the backcast. Results objects returned before appending are not affected.If the data was rescaled when fitting the model, the new data is rescaled using the same factor. Exogenous regressors are never rescaled.
If the new data is not valid, an exception is raised and the model is not modified.
Examples
Estimate the model using the first part of a sample, and then use the estimated parameters to forecast after observing more data.
>>> import numpy as np >>> from arch.univariate import ARX, GARCH >>> y = np.random.RandomState(1234).standard_normal(1000) >>> mod = ARX(y[:800], lags=1, volatility=GARCH()) >>> res = mod.fit(disp="off") >>> mod.append(y[800:]) >>> forecasts = mod.forecast(res.params, horizon=3, reindex=False)Adding a single observation to a model that uses an ndarray.
>>> mod.append(0.1)