mojolearn.GARCH#
- class mojolearn.GARCH(p=1, o=0, q=1, mean='Constant', dist='normal', power=2.0, numeric_mode=None)[source]#
Bases:
objectGARCH(p, o, q) conditional volatility model with normal errors.
Fits a constant- or zero-mean GARCH model by Gaussian maximum likelihood, following the arch package’s
arch_model(y, mean='Constant'|'Zero', vol='GARCH', p=p, o=o, q=q, dist='normal'): arch’s variance recursion, backcast, variance bounds and starting values.o > 0adds asymmetric (GJR) terms.fittakes one series of shape(n_obs,)or a batch of shape(batch_size, n_obs).- Parameters:
p (int, default 1) – Order of the lagged squared innovations (ARCH terms).
o (int, default 0) – Order of the asymmetric innovations; needs
p > 0.q (int, default 1) – Order of the lagged conditional variance (GARCH terms).
mean ({“Constant”, “Zero”}, default “Constant”) – Mean model. Other arch mean models (AR, HAR, LS) raise NotImplementedError.
dist ({“normal”}, default “normal”) – Error distribution; only
"normal"is supported.power (float, default 2.0) – Only 2.0 is supported (TARCH/APARCH powers raise NotImplementedError).
numeric_mode (str or None, default None) – Numeric mode for this model (
'identical','deterministic'or'fast'); None uses the process default (seemojolearn.set_numeric_mode()).
- Variables:
params_ (ndarray of shape (2 + p + o + q,) or (batch_size, 2 + p + o + q), float32) –
mu, omega, alpha[1..p], gamma[1..o], beta[1..q].loglikelihood_ (float32 or ndarray of shape (batch_size,)) – Maximized Gaussian log-likelihood.
n_iter_ (int64 or ndarray of shape (batch_size,)) – Nelder-Mead iterations used.
conditional_volatility_ (ndarray of shape (n_obs,) or (batch_size, n_obs), float32) – Fitted conditional volatility.
- Raises:
ValueError – If p, o or q is negative, all are zero, or
o > 0withp == 0.
Notes
Input must be float32; float64 raises TypeError. Rescaling is not supported: scale the data yourself if needed.
Examples
>>> import numpy as np, mojolearn >>> r = np.random.default_rng(0).standard_normal(500).astype(np.float32) >>> model = mojolearn.GARCH(p=1, q=1).fit(r) >>> model.forecast(5).shape (5,)
Methods
fit(y[, horizon])Fit the model to one series or a batch of series.
forecast([horizon])Analytic conditional variance forecasts.
- fit(y, horizon=1)[source]#
Fit the model to one series or a batch of series.
- Parameters:
y (array-like of shape (n_obs,) or (batch_size, n_obs)) – Returns (or other zero-centered data), float32, finite, at least 10 observations per series.
horizon (int, default 1) – Variance forecast horizon computed alongside the fit (at least 1).
- Returns:
self
- Raises:
TypeError – If
yis float64.ValueError – If a series has fewer than 10 observations or
yholds a non-finite value.
- forecast(horizon=1)[source]#
Analytic conditional variance forecasts.
- Parameters:
horizon (int, default 1) – Number of steps ahead. A horizon longer than the one computed at fit refits the stored series.
- Returns:
ndarray of shape (horizon,) or (batch_size, horizon), float32 – Forecast conditional variances.