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 and leverage=True correlates 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 the conditional_variance family: 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). fit returns a point-estimate record; sample returns 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:
  • endog (ArrayLike) – The observed series (returns, typically).

  • mean (str) – "constant" to estimate c, "zero" to fix it.

  • dist (str) – "normal" or "t" observation noise.

  • leverage (bool) – Whether to correlate the observation and log-variance innovations; estimated by the particle methods only.

Raises:
  • SpecificationError – If mean or dist is unrecognized, or dist="t" is combined with leverage=True.

  • DimensionError – If endog is not one-dimensional or has fewer than 50 observations.

  • NumericalError – If endog contains non-finite values.

See also

  • SVResult – what fit() returns.

  • 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 ...