quantlab.portfolio.predefined.approximate.mean_variance#
The approximate backtest’s mean-variance: every decision bar’s Markowitz weights in compiled code.
The implementation quantlab.portfolio.approximate.implementation
chooses for a MeanVarianceOptimizer or an ActiveRiskOptimizer:
decide reads the rule’s config and the span its bind read, and maximises the per-bar rule’s
objective
w @ mu - risk_aversion / 2 * (w - b) @ Sigma @ (w - b) - turnover_penalty * |w - holdings|_1
(b the active-risk rule’s benchmark weights, zero otherwise) by
accelerated proximal gradient (_support.mean_variance_kernels, numba) rather than
cvxpy: forward in time when the decision reads the holdings (the turnover
penalty, or candidate_top_k keeping held names), in parallel over the
bars otherwise. mu and Sigma are those the per-bar rule computes on
each bar’s context with nothing locked: the covariance estimator’s
(quantlab.portfolio.approximate.estimate_all) scaled to the expected-return label’s span,
with volatility_label its volatilities the prediction over
sqrt(span); a symbol selectable when it is tradable and covered; and on
the selectable symbols with a prediction mu the rule’s
expected_return model (ExpectedReturnModel) gives, the same array
code the per-bar rule calls, handed sigma (the covariance’s diagonal on
the span) when it needs it.
Classes
What every bar's decision reads but its holdings: |
Functions
Return every bar's mean-variance weights of a decision panel: in time order when they read the holdings, at once otherwise. |