FactorSVResult.factor_volatility#

FactorSVResult.factor_volatility(factor, *, quantiles=(0.16, 0.5, 0.84))[source]#

Posterior quantiles of one factor’s standard deviation, (len(quantiles), T).

The quantiles of \(\exp(h_{jt} / 2)\) across draws at each date, so the default triple is the posterior median with a 68% band.

Parameters:
  • factor (int) – Factor index.

  • quantiles (Sequence[float]) – Probability levels, each in (0, 1).

Return type:

NDArray[double]

Returns:

An array of shape (len(quantiles), T).

Raises:

SpecificationError – If the index is out of range or a quantile is outside the open unit interval.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> n = 300
>>> h = np.zeros(n)
>>> for t in range(1, n):
...     h[t] = 0.95 * h[t - 1] + 0.3 * rng.standard_normal()
>>> f = np.exp(h / 2) * rng.standard_normal(n)
>>> y = np.outer(f, [1.0, 0.8, 0.6]) + 0.3 * rng.standard_normal((n, 3))
>>> res = FactorSV(y, n_factors=1).fit(n_draws=300, n_burn=100, seed=0)
>>> band = res.factor_volatility(0)
>>> band.shape, bool(np.all(band[0] <= band[1])), bool(np.all(band[1] <= band[2]))
((3, 300), True, True)
>>> bool(np.corrcoef(np.log(band[1]), h / 2)[0, 1] > 0.7)
True
>>> res.factor_volatility(1)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: factor index 1 is out of range for 1.