Worst-Case Mean-Variance Weights

Calculate the weights of a worst-case (robust) mean-variance portfolio.

It is the portfolio that is optimal for the least favourable expected returns within a confidence region around the estimates, instead of for the estimates themselves. The expected returns are the noisiest input of a mean-variance optimization, and the worst case penalizes the portfolios whose return rests most on them.

With \(\mu\) the annualized expected returns, \(\Sigma\) the annualized covariance matrix, \(\sum_{\mu} = \Sigma\) × (periods per year) / T the covariance of the annualized average over T periods and \(\alpha\) the confidence level, the worst-case return R(w) is:

\[\text{An ellipsoid:}\;\; \mu' w - \kappa \sqrt{w' \Sigma_{\mu} w} \;\text{with}\; \kappa^{2} = \chi_{n}^{2}(\alpha),\;\; \text{the lowest return over the joint confidence ellipsoid of the } n \text{ expected returns (Goldfarb and Iyengar, 2003)}\] \[\text{A box:}\;\; \mu' w - \delta' \left|w\right| \;\text{with}\; \delta_{i} = \frac{z_{1+\alpha}}{2 \sqrt{\Sigma_{\mu},\; \text{ii}}},\;\; \text{the lowest return when each expected return can lie anywhere in its own confidence interval (Tütüncü and Koenig, 2004)}\]

The objectives replace the expected return \(\mu' w\) by R(w):

  • The maximum Sharpe ratio: maximize \((R (w) - r_{f}) / \sqrt{w' \Sigma w}\), solved with the Charnes-Cooper transformation (Charnes and Cooper, 1962).
  • The utility: maximize \(R (w) - (\lambda / 2) w' \Sigma w\) with \(\lambda\) the risk aversion.
  • The minimum variance: minimize \(w' \Sigma w\) subject to R(w) ≥ the target return.

R(w) is concave, so every objective is a convex problem, solved with SLSQP.

Also known as: robust mean-variance, robust Markowitz, max-min portfolio, uncertainty set optimization.

Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_worst_case_mean_variance_weights:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT", "JNJ", "XOM"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.portfolio.get_worst_case_mean_variance_weights(
    confidence_level=0.9, maximum_weight=0.5
)[["Weight", "Expected Return", "Worst-Case Return", "Worst-Case Sharpe Ratio"]]

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Which weights in Apple, Microsoft, Johnson & Johnson and ExxonMobil, with at most 50% in any one stock, are best for the least favourable expected returns within a 90% confidence region, based on 2021 to 2025?

Which returns:

Parameters

get_worst_case_mean_variance_weights accepts the following parameters.

ParameterTypeDescriptionExample
uncertaintystrThe uncertainty set of the expected returns. Options are: “box” (a confidence interval per estimate), “ellipsoid” (the joint confidence region). Defaults to “box”."box"
confidence_levelfloatThe confidence level of the uncertainty set, e.g. 0.95. A higher level widens the set and gives more cautious weights. Defaults to 0.95.0.95
objectivestrOptions are: “maximum_sharpe” (the highest worst-case Sharpe ratio), “utility” (the highest worst-case utility), “minimum_variance” (the lowest variance, which needs a target return). Defaults to “maximum_sharpe”."maximum_sharpe"
risk_aversionfloatThe risk aversion \(\lambda\) of the utility; higher values give less risky portfolios. Defaults to 2.5.2.5
target_returnfloat | NoneThe lowest annualized worst-case return of the minimum variance objective, e.g. 0.1 for 10%, with the cash of a net exposure other than one at the risk free rate. Defaults to None.None
periodstrThe frequency of the returns. Options are: “daily” (daily returns), “weekly” (weekly returns), “monthly” (monthly returns), “quarterly” (quarterly returns), “yearly” (yearly returns). Defaults to “daily”."weekly"
covariancestrThe estimator of the covariance matrix, as in get_maximum_sharpe_weights. Options are: “sample” (the sample covariance, ddof=1), “ledoit_wolf” (shrunk towards the scaled identity, Ledoit and Wolf, 2004), “ledoit_wolf_constant_correlation” (shrunk towards the average correlation, Ledoit and Wolf, 2004), “ledoit_wolf_single_factor” (shrunk towards the covariance that the benchmark as a single factor implies, Ledoit and Wolf, 2003), “oas” (Oracle Approximating Shrinkage, Chen et al., 2010), “shrunk” (a fixed 10% towards the scaled identity), “semicovariance” (the co-movement below a zero return, Estrada, 2008), “exponential” (exponentially weighted, recent periods weigh most, RiskMetrics), “denoised” (the eigenvalues of the correlation matrix that random returns could produce averaged, Laloux et al., 2000), “denoised_spectral” (those eigenvalues set to zero), “denoised_shrink” (the noise correlations shrunk towards their diagonal, López de Prado, 2020), “gerber” (co-movements beyond half a standard deviation, Gerber et al., 2022), “factor” (the covariance of the Fama and French five factor model with OLS loadings, Fama and French, 1993), “minimum_covariance_determinant” (the reweighted covariance of the half of the periods with the smallest covariance determinant, robust to outliers, Rousseeuw and Van Driessen, 1999), “jlogo” (the sparse inverse covariance on the TMFG planar graph of the correlations, Barfuss et al., 2016), “geodesic” (10% towards the scaled identity along the geodesic of the positive definite matrices, Bhatia, 2007), “regime_adjusted_ew” (exponentially weighted with a half-life of 40 periods, rescaled by the recent realized against predicted risk, Paleologo, 2025), “nercome” (eigenvectors from one part of the periods and the variances along them from the other, averaged over random splits, Lam, 2016), “ccc_garch” (the next-period covariance of GARCH(1, 1) volatilities with constant correlations, Bollerslev, 1990), “mm” (the robust MM-estimator, Maronna et al., 2019), “rocke” (Rocke’s robust S-estimator, Maronna et al., 2019). Defaults to “sample”."sample"
covariance_spanintThe span in periods of the exponentially weighted covariance; the weight of a period halves after about span / 2.9 periods. Defaults to 180.180
expected_returnsstrThe estimator of the expected returns, as in get_maximum_sharpe_weights. Options are: “mean” (the historical average), “geometric” (the compounded average), “exponential” (the exponentially weighted average, recent periods weigh most), “exponential_geometric” (that average compounded over a year), “capm” (the returns the Capital Asset Pricing Model implies from each asset’s beta to the benchmark, Sharpe, 1964), “bayes_stein” (the averages shrunk towards that of the minimum variance portfolio, Jorion, 1986), “james_stein” (the averages shrunk towards their grand mean, James and Stein, 1961), “bodnar_okhrin_parolya” (the averages and their grand mean combined with optimal weights, Bodnar, Okhrin and Parolya, 2019). Defaults to “mean”."mean"
expected_returns_spanintThe span in periods of the exponentially weighted expected returns. Defaults to 180.180
minimum_weightfloat | dict[str, float]The lowest weight of every asset, or per asset, e.g. {“AAPL”: 0.05} (the others keep 0); a negative value allows short positions. Defaults to 0.0
maximum_weightfloat | dict[str, float]The highest weight of every asset, or per asset, e.g. {“AAPL”: 0.3} (the others keep 1). Defaults to 1.1
sector_boundsdict[str, tuple[float, float]] | NoneThe minimum and maximum total weight per sector, e.g. {“Technology”: (0, 0.4)}, with the sector of each asset from its company profile. Defaults to None.None
country_boundsdict[str, tuple[float, float]] | NoneThe minimum and maximum total weight per country, named in full or by its two-letter code, e.g. {“United States”: (0, 0.6)}, with the country of each asset from its company profile. Defaults to None.None
net_exposurefloatThe sum of the weights: 1 for a fully invested portfolio. The rest, 1 minus the net exposure, is a Cash row at the risk free rate (negative when borrowed above one), which the Portfolio’s Expected Return and Sharpe Ratio include. Defaults to 1.1
gross_exposurefloat | NoneThe highest sum of the absolute weights, which limits the leverage of a long-short portfolio, e.g. 1.6 for a 130/30 portfolio. Defaults to None, no limit.None, no limit
current_weightsdict[str, float] | NoneThe weights held now, e.g. {“AAPL”: 0.5, “MSFT”: 0.5} (an asset left out is not held), which the turnover is measured from; they add a Turnover column, \(\vert w_{i} - w_{0,i} \vert\) per asset and its sum for the portfolio. Defaults to None, which uses the latest weights of the Portfolio the Toolkit came from when a maximum turnover needs them.None, which uses the latest weights of the Portfolio the Toolkit came from when a maximum turnover needs them
maximum_turnoverfloat | NoneThe highest turnover \(\sum \vert w_{i} - w_{0,i} \vert\) from the current weights, e.g. 0.2 to trade at most 10% of the portfolio each way. Defaults to None, no limit.None, no limit
include_benchmarkboolWhether to include the benchmark as an asset. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Goldfarb, D. and Iyengar, G. (2003). “Robust Portfolio Selection Problems.” Mathematics of Operations Research, 28(1), 1-38.
  • Paper Tütüncü, R. H. and Koenig, M. (2004). “Robust Asset Allocation.” Annals of Operations Research, 132, 157-187.
  • Paper Charnes, A. and Cooper, W. W. (1962). “Programming with Linear Fractional Functionals.” Naval Research Logistics Quarterly, 9(3-4), 181-186.
  • Library Referenced against Riskfolio-Lib’s Portfolio.wc_optimization (box)
  • Library Referenced against skfolio’s MeanRisk (with an EmpiricalMuUncertaintySet)
Share