quantlab.portfolio.approximate.implementation#
- quantlab.portfolio.approximate.implementation(rule)[source]#
Return the module that decides
rulein the approximate backtest, or raise with the reason.Read from the rule’s exact class and config alone, so it is answered before any data is read. Refused: a rule (or covariance estimator) with no implementation, a subclass of one, and a field refused or unknown and not at its default. (
volatility_labelwith a factor risk model is refused when the optimiser is constructed.) The module’sdecide(rule, panel, prices, stopping)returns the panel’sPanelSolution.- Parameters:
- rulePortfolioConstructor
The rule.
- Returns:
- module
The rule’s implementation in
quantlab.portfolio.predefined.approximate.
- Raises:
- ValueError
If the approximate backtest cannot run the rule as configured; the message names the rule, the estimator or the field.
Examples
>>> from quantlab.portfolio.config import TopkDropoutConfig, TopNConfig >>> from quantlab.portfolio.predefined.top_n import TopNConstructor >>> from quantlab.portfolio.predefined.topk_dropout import TopkDropoutConstructor >>> implementation(TopNConstructor(TopNConfig(direction="long_only", top_n=2))).__name__ 'quantlab.portfolio.predefined.approximate.top_n' >>> implementation(TopkDropoutConstructor(TopkDropoutConfig(direction="long_only", topk=3, n_drop=1))).__name__ 'quantlab.portfolio.predefined.approximate.topk_dropout' >>> class EqualWeightTopN(TopNConstructor): ... pass >>> implementation(EqualWeightTopN(TopNConfig(direction="long_only", top_n=2))) Traceback (most recent call last): ValueError: EqualWeightTopN has no approximate implementation: the approximate backtest runs TopNConstructor, TopkDropoutConstructor, MeanVarianceOptimizer, ActiveRiskOptimizer, BlackLittermanOptimizer, as those exact classes