quantlab.risk.base.ReturnCovariance#
- class quantlab.risk.base.ReturnCovariance(*args, **kwargs)[source]#
Bases:
ProtocolThe covariance of one-bar returns at a bar, over the symbols it covers: what a covariance estimator returns.
What a rule holding a covariance estimator may ask of its estimate, whatever the estimator. Three types satisfy it and stay separate types (ADR 0028): the dense
quantlab.portfolio.base.CovarianceEstimate, the low-rankquantlab.portfolio.base.LowRankCovarianceEstimate(Ledoit-Wolf) and a factor risk model’sFactorRiskForecast. A rule asks the estimate and does not tell the types apart.- Attributes:
- symbolsnp.ndarray
The
nsymbols covered, in the order of every per-symbol array.- covariancenp.ndarray
The dense
[n, n]covariance.- variancenp.ndarray
Each symbol’s variance,
[n].
Examples
>>> forecast = FactorRiskForecast( ... symbols=np.array(["AAA", "BBB"]), ... factor_names=("market",), ... exposures=np.array([[1.0], [0.5]]), ... factor_covariance=np.array([[0.04]]), ... specific_variance=np.array([0.01, 0.02]), ... ) >>> isinstance(forecast, ReturnCovariance) True
- factor_exposure(name, symbols)[source]#
Return each of
symbols’ exposure to risk factorname,[len(symbols)].NaN for a symbol the estimate does not cover. An estimate without risk factors raises
ValueError.
- factor_form()[source]#
Return
(B, F, D)when the covariance isB F B' + diag(D), elseNone.From the factor form an optimiser prices risk without the dense matrix.