quantlab.portfolio.base.CovarianceEstimate#
- class quantlab.portfolio.base.CovarianceEstimate(symbols, covariance)[source]#
Bases:
objectA covariance estimator’s covariance of returns at one bar, over the symbols it covers.
The dense
quantlab.risk.base.ReturnCovariance: it has no factor form and no risk factors (LowRankCovarianceEstimateis the low-rank one).- Attributes:
- symbolsnp.ndarray
The symbols the estimate covers, the order of
covariance’s rows and columns; a symbol with too little history is left out.- covariancenp.ndarray
The dense
[n, n]covariance matrix.
Examples
>>> estimate = CovarianceEstimate( ... symbols=np.array(["AAA", "BBB"]), ... covariance=np.array([[0.04, 0.01], [0.01, 0.09]]), ... ) >>> estimate.variance array([0.04, 0.09]) >>> estimate.factor_form() is None True
- factor_exposure(name, symbols)[source]#
Refuse: a dense estimate has no risk factors.
A factor risk model’s
FactorRiskForecastanswers with its column ofB(ReturnCovariance.factor_exposure).- Raises:
- ValueError
Always.
Examples
>>> estimate.factor_exposure("market", np.array(["AAA"])) Traceback (most recent call last): ... ValueError: the covariance estimate has no risk factors, so no exposure to 'market'
- factor_form()[source]#
Return the factor form of the covariance, or
Nonewhen it has none.A dense estimate has none. A factor risk model’s
FactorRiskForecastreturns(exposures, factor_covariance, specific_variance), from which an optimiser builds a low-rank risk term instead of the dense one.Examples
>>> estimate.factor_form() is None True
- scaled(factor)[source]#
Return the estimate with every entry multiplied by
factor.Variance is linear in time, so a one-bar covariance times
nis the covariance ofn-bar returns.Examples
>>> estimate.scaled(5).variance array([0.2 , 0.45])
- subset(rows)[source]#
Return the estimate over the symbols at positions
rows, in that order.Examples
>>> estimate.subset(np.array([1])).symbols.tolist() ['BBB']
- property variance#
Each covered symbol’s variance, the covariance’s diagonal.
Examples
>>> estimate.variance array([0.04, 0.09])