Volatility¶
sequential_analysis.procedures.volatility
¶
Volatility: the GARCH(1,1) filter, with an optional leverage term (GJR).
Returns r_t = mu + e_t with e_t = sigma_t z_t, the z_t independent with mean 0 and variance 1 (normal, or Student t scaled to unit variance), and
sigma^2_t = omega + alpha e^2_{t-1} + gamma e^2_{t-1} 1{e_{t-1} < 0} + beta sigma^2_{t-1}
(Bollerslev 1986; gamma > 0 is the leverage effect of Glosten, Jagannathan and Runkle 1993: falls raise volatility more than rises). Given the parameters the filter is exact: sigma^2_t is known before r_t arrives, so each step gives the one-step predictive density, the standardized residual z_t (independent, unit variance under the model) and the forecast of the next variances. With persistence p = alpha + beta + gamma / 2 below 1,
E[sigma^2_{t+h}] = v + p^(h-1) (sigma^2_{t+1} - v), v = omega / (1 - p),
and the variance of the sum of the next h returns is the sum of these, as
the returns are uncorrelated. The intervals for h > 1 use the predictive
law's shape with that variance: an approximation, as the h-step law is a
scale mixture. Fit the parameters on a history with fit_garch, which
matches the arch package.
Cost per step (PERFORMANCE.md): constant, 6 microseconds with a 10-step forecast.
GARCH
¶
Bases: Procedure
GARCH(1,1) or GJR-GARCH(1,1) filter with fixed parameters; see the module docstring.
distribution "normal" or "t" (with df > 2). initial_variance
is sigma^2 of the first return; None takes the unconditional variance,
which needs persistence below 1.
forecast(variance)
¶
Expected conditional variances of the next 1..horizon returns, from sigma^2 of the next one.
garch_log_density(error, variance, df)
¶
Log density of a residual with the given variance: normal (df None) or unit-variance Student t.
sequential_analysis.garch_fit
¶
Fitting GARCH(1,1) and GJR-GARCH(1,1) to a history of returns (see procedures.volatility).
fit_garch maximizes the Gaussian or Student t likelihood as the arch
package does: residuals r_t - mu, the recursion started from the backcast
v0 = sum_i w_i e_i^2 over the first min(75, n) residuals with weights
proportional to 0.94^i, so that sigma^2_1 = omega + (alpha + gamma / 2 + beta) v0.
As in arch, v0 is computed once, from the residuals around the sample
mean (or 0 with zero_mean), and held fixed while mu varies.
The parameters are found by Nelder-Mead over mu, log omega, the
persistence p = alpha + beta + gamma / 2 in (0, 1) (logit) and its split
between the terms (softmax), and log(df - 2) for Student t, from the best
of a small grid. The fitted GARCH procedure starts from that sigma^2_1, so
a run over the history reproduces the fitted likelihood and continues
live from state.
backcast(residuals)
¶
arch's starting value: an exponentially weighted mean of the first min(75, n) squared residuals.
garch_log_likelihood(returns, mean, omega, alpha, beta, gamma=0.0, df=None, v0=None)
¶
The log-likelihood arch maximizes: Gaussian (df None) or unit-variance Student t, from the backcast v0.
v0 defaults to the backcast of the residuals around the sample mean, as arch computes it.
fit_garch(inputs, *, distribution='normal', asymmetric=False, zero_mean=False, input='r', horizon=1, coverage=0.9, max_evaluations=4000)
¶
Maximum-likelihood GARCH(1,1), or GJR-GARCH(1,1) with asymmetric; see the module docstring.