SV#
- class cultivars.univariate.stochastic_volatility.SV(endog, *, mean='constant', dist='normal', leverage=False)[source]
Bases:
_StochasticVolatilityModel[SVResult]The log-AR(1) stochastic-volatility model.
\[y_t = c + \exp(h_t / 2)\,\varepsilon_t, \qquad h_{t+1} = \mu + \phi\,(h_t - \mu) + \sigma\,\eta_t,\]with \(\varepsilon_t\) and \(\eta_t\) standard normal and independent in the base model;
dist="t"makes \(\varepsilon_t\) Student-t with estimated degrees of freedom andleverage=Truecorrelates the two innovations, but not both at once. The variance is a latent state rather than a function of past data, which is what separates this from theconditional_variancefamily: the likelihood is an integral over the log-variance path, and each estimator here is a way of doing that integral – the Harvey-Ruiz-Shephard linearization (fit, QML), simulated maximum likelihood on a particle estimate (fit(method="particle")), the Kim-Shephard-Chib mixture Gibbs sampler and particle marginal Metropolis-Hastings (sample).fitreturns a point-estimate record;samplereturns a posterior.- Variables:
_endog – The validated series.
_mean_spec –
"constant"or"zero"._tails – Whether the observation noise is Student-t.
_leverage – Whether the innovations are correlated.
- Parameters:
- Raises:
SpecificationError – If
meanordistis unrecognized, ordist="t"is combined withleverage=True.DimensionError – If
endogis not one-dimensional or has fewer than 50 observations.NumericalError – If
endogcontains non-finite values.
See also
UCSV– stochastic volatility on a random-walk trend and its irregular.GARCH– the observation-driven alternative.VolatilityPrior– the prior both samplers share.
References
Taylor, S. J. (1986). Modelling Financial Time Series. Wiley.
Harvey, A. C., Ruiz, E., & Shephard, N. (1994). Multivariate stochastic variance models. Review of Economic Studies, 61(2), 247-264.
Kim, S., Shephard, N., & Chib, S. (1998). Stochastic volatility: Likelihood inference and comparison with ARCH models. Review of Economic Studies, 65(3), 361-393.
Andrieu, C., Doucet, A., & Holenstein, R. (2010). Particle Markov chain Monte Carlo methods. Journal of the Royal Statistical Society B, 72(3), 269-342.
Example
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> n = 400 >>> h = np.empty(n) >>> h[0] = -1.0 >>> for t in range(1, n): ... h[t] = -1.0 + 0.95 * (h[t - 1] + 1.0) + 0.3 * rng.standard_normal() >>> y = np.exp(h / 2) * rng.standard_normal(n) >>> res = SV(y, mean="zero").fit() >>> bool(0.8 < res.phi < 1.0) True
The specification is validated at construction:
>>> SV(y, dist="t", leverage=True) Traceback (most recent call last): ... cultivars.exceptions.SpecificationError: heavy tails and leverage are not offered ...