cultivars.univariate.stochastic_volatility#

Stochastic volatility: variance as a latent state, not a function of the past.

A GARCH variance is a deterministic function of past observations; a stochastic-volatility variance is a latent process with its own innovation, observed only through the returns it scales,

\[y_t = c + \exp(h_t / 2)\,\varepsilon_t, \qquad h_{t+1} = \mu + \phi\,(h_t - \mu) + \sigma\,\eta_t, \qquad \varepsilon_t, \eta_t \sim N(0, 1).\]

That makes the model a nonlinear state space – the measurement is multiplicative in the state – and puts its likelihood \(p(y) = \int p(y \mid h)\,p(h)\,dh\) out of closed-form reach. Two honest routes exist and both are offered. The Kim-Shephard-Chib (1998) route linearizes by squaring and taking logs,

\[\log (y_t - c)^2 = h_t + \log \varepsilon_t^2,\]

then replaces the \(\log \chi^2_1\) error with a seven-component Gaussian mixture; conditional on the mixture indicators the model is linear-Gaussian and a Gibbs sampler is exact. The mixture is a very good approximation, not the truth. The particle route (Andrieu, Doucet, and Holenstein, 2010) makes no approximation: a bootstrap particle filter estimates \(p(y)\) without bias and a Metropolis-Hastings chain on that estimate targets the exact posterior, at the cost of a particle filter per draw. Point estimation is offered for the same model: the Harvey-Ruiz-Shephard quasi-maximum likelihood, which runs the Kalman filter on the linearized series with \(\log \varepsilon_t^2\) treated as Gaussian with mean \(-1.2704\) and variance \(\pi^2/2\) (fast, consistent, the warm start for everything else), and simulated maximum likelihood on the particle estimate under common random numbers.

Two commitments shape the surface. First, the two samplers are given the same prior – Gaussian on \(\mu\), Beta on \((\phi + 1)/2\), inverse-gamma on \(\sigma^2\) – so they should agree, and a disagreement is the diagnostic that the mixture is binding; the point estimates say in their summaries which criterion they maximized and that criteria are comparable only within one method. Second, the latent path is reported with its uncertainty: every record carries the smoothed log variance and its standard deviation, the volatility bands are exponentiated normal bands on that path, and the variance forecast carries the log-normal correction, so nothing volatility-related is read off a point path as if it were observed.

The second model here is Stock and Watson’s (2007) unobserved-components stochastic-volatility model,

\[y_t = \tau_t + \exp(h_t / 2)\,\varepsilon_t, \qquad \tau_{t+1} = \tau_t + \exp(q_t / 2)\,\eta_t,\]

a random-walk trend observed through an irregular, each innovation with a random-walk log variance of innovation standard deviation \(\gamma\). It is the workhorse of trend-inflation measurement and the model that joins the package’s structural decomposition to its volatility machinery; its estimator is the Gibbs sampler, with the trend drawn exactly by the simulation smoother under the current variance paths.

Layout. SV validates mean, dist and leverage on _StochasticVolatilityModel in _internals; _fit_quasi runs a _QuasiVolatilityObjective through _maximize_likelihood and smooths on the linear substrate, _fit_particle runs a _ParticleLikelihoodObjective from the QML start, _sample_gibbs and _sample_chain are the two samplers, and _SVPosterior in _internals._posteriors packs the draws. UCSV validates gamma on _TrendVolatilityModel and its _sample_gibbs packs a _UCSVPosterior. The emitters _volatility_state_space and _quasi_volatility_state_space in _internals._emitters build the nonlinear and linear substrates the results expose as state_space and quasi_state_space; the priors are VolatilityPrior and RandomWalkVolatilityPrior, with the Kim-Shephard-Chib defaults in _core. The observation-driven alternative is conditional_variance; the constant-variance trend models are unobserved_components.

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.

Stock, J. H., & Watson, M. W. (2007). Why has U.S. inflation become harder to forecast? Journal of Money, Credit and Banking, 39(s1), 3-33.

Example

QML as the warm start and the Gibbs sampler as the estimator, both reading the same latent path:

>>> import numpy as np
>>> from cultivars.engine._internals._simulators import _simulate_stochastic_volatility
>>> rng = np.random.default_rng(0)
>>> y, h = _simulate_stochastic_volatility(
...     500, mu=-1.0, phi=0.95, sigma2=0.05, mean=0.0, rng=rng
... )
>>> model = SV(y, mean="zero")
>>> point = model.fit()
>>> posterior = model.sample(n_draws=400, n_burn=100, seed=0)
>>> point.method, posterior.method, posterior.n_kept
('qml', 'gibbs', 300)
>>> bool(abs(point.phi - 0.95) < 0.05), bool(abs(posterior.phi_draws.mean() - 0.95) < 0.05)
(True, True)
>>> corr = np.corrcoef(np.vstack([h, point.log_variance, posterior.log_variance]))
>>> bool(corr[0, 1] > 0.5), bool(corr[0, 2] > 0.7)
(True, True)

Classes#

SV

The log-AR(1) stochastic-volatility model.

UCSV

Stock and Watson's unobserved-components stochastic-volatility model.

SVPosterior

SVResult

A point-estimated stochastic-volatility model.

UCSVPosterior