quantlab.portfolio.predefined.factor_risk.FactorRiskStoreEstimator#

class quantlab.portfolio.predefined.factor_risk.FactorRiskStoreEstimator(config)[source]#

Bases: CovarianceEstimator

The covariance at a bar from a factor risk model’s estimate store.

It declares the factor risk model (declared_inputs()), so the decision inputs take its exposures from it (FactorRiskModel.exposures: the exposures factor’s store under exposure_data_strategy="read", computed under "cal"), exactly as its stores, factor attribution and bias statistics do, and its estimate store’s row, and hand their values at the bar in context.risk_exposures and context.risk_estimate. estimate(context) reads no store: it returns the model’s forecast from that row and those exposures (FactorRiskModel.forecast): B F B' + diag(D) of one-bar returns, in factor form, over the symbols the model covers at the bar (coverage is the model’s rule, shared with factor attribution and the bias statistics). It reads only what every factor risk model provides, so it works with any. There is no staleness filter: the model reads no return window, and a locked position is priced like any other.

Parameters:
configFactorRiskStoreEstimatorConfig

The factor risk model.

Examples

With use4 a Use4RiskModel whose stores are built and context a backtest’s context at a bar inside them (DecisionInputs.context):

>>> risk = FactorRiskStoreEstimator(FactorRiskStoreEstimatorConfig(risk_model=use4))
>>> risk.declared_inputs().risk_model is use4
True
>>> estimate = risk.estimate(context)
>>> exposures, factor_covariance, specific_variance = estimate.factor_form()
>>> exposures.shape[1] == factor_covariance.shape[0]
True
config_cls#

alias of FactorRiskStoreEstimatorConfig

declared_inputs()[source]#

The factor risk model, whose exposures and estimate row estimate reads from the context; no return window.

Examples

>>> risk.declared_inputs().risk_model is use4
True
estimate(context, volatility=None)[source]#

Return B F B' + diag(D) at the context’s bar over the covered symbols.

See the class docstring for the coverage.

Parameters:
contextPortfolioContext

The bar’s context; its risk_exposures hold the model’s exposures at the bar and its risk_estimate the estimate store’s row there.

volatilityNone

Refused: a factor risk model takes no predicted volatilities.

Returns:
FactorRiskForecast

The model’s forecast at the bar over the context’s symbols it covers, of one-bar returns.

Raises:
ValueError

If volatility is given, or the context has no risk_exposures or no risk_estimate (the estimate store has no row at the bar).

Examples

>>> estimate = risk.estimate(context)
>>> estimate.exposures.shape[1] == estimate.factor_covariance.shape[0]
True
takes_volatility = False#

The model’s forecast is its own; a volatility forecast does not replace it.