Mean-Risk Weights

Calculate the weights of a mean-risk portfolio with a risk measure other than the volatility.

It is the portfolio with the lowest risk, the lowest risk at a target return, or the highest ratio of the average excess return to the risk.

The risk is measured on the historical returns, so measures that only count losses (the semideviation, the lower partial moment, the worst realization, the CVaR, the Tail Gini) leave upside swings unpenalized, and the Ulcer Index and the drawdown measures penalize deep and long drawdowns, which are what investors feel and what ends strategies. The minimum CVaR portfolio only looks at the losses in the tail, so it accounts for skewed and fat-tailed returns; its maximum ratio portfolio is the maximum STARR (CVaR ratio) portfolio of Martin, Rachev and Siboulet (2003), the maximum Sharpe ratio portfolio with the tail loss in place of the volatility.

The risk measures \(\rho (w)\) of the portfolio’s returns \(X_{t} = r_{t}' w\) over T periods, with \(\alpha\) the tail probability and \(\tau\) the minimum acceptable return, are:

  • The mean absolute deviation \(\sum \vert X_{t} - \bar{X} \vert / T\) (Konno and Yamazaki, 1991).
  • The semideviation: \(\sqrt{\sum \min (X_{t} - \tau , 0)^{2} / T}\), or \(\sqrt{\sum \min (X_{t} - \bar{X} , 0)^{2} / (T - 1)}\) below the mean (Markowitz, 1959; Estrada, 2008).
  • The first lower partial moment \(\sum \max (\tau - X_{t} , 0) / T\) (Bawa, 1975), or below each asset’s mean.
  • The worst realization: the largest loss -min \(X_{t}\) (Young, 1998).
  • The Gini mean difference: the average absolute difference between the returns of two periods, \(\sum_{i} \sum_{j} \vert X_{i} - X_{j} \vert / (T (T - 1))\) (Yitzhaki, 1982).
  • The Tail Gini: the Tail Gini of the losses beyond the \(\alpha\) quantile (Furman, Wang and Zitikis, 2017; Cajas, 2021).
  • The range: the largest gain plus the largest loss, \(\max X_{t} - \min X_{t}\).
  • The CVaR range: the CVaR of the losses plus that of the gains, the average of the best \(\alpha\) share of the returns minus the average of the worst (Cajas, 2021).
  • The Tail Gini range: the Tail Gini of the losses plus that of the gains.
  • The Ulcer Index: \(\sqrt{\sum D_{t}^{2} / T}\) with \(D_{t}\) the drawdowns of the uncompounded cumulative return (Martin and McCann, 1989).
  • The Conditional Value at Risk, the average loss in the worst \(\alpha\) share of the periods, \(\text{VaR} + \sum \max (0 , - X_{t} - \text{VaR}) / (\alpha T)\) at its minimum over the VaR (Rockafellar and Uryasev, 2000).
  • The Conditional Drawdown at Risk, the average of the worst \(\alpha\) share of the drawdowns \(D_{t}\), \(\zeta + \sum \max (0 , D_{t} - \zeta) / (\alpha T)\) at its minimum over \(\zeta\) (Chekhlov, Uryasev and Zabarankin, 2005).
  • The maximum drawdown: the largest drawdown \(\max D_{t}\).
  • The average drawdown \(\sum D_{t} / T\).

The drawdowns \(D_{t} = u_{t} - Y_{t}\) are those of the uncompounded cumulative return \(Y_{t} = \sum_{s \leq t} X_{s}\) below its running peak \(u_{t} = \max (0 , \max_{s \leq t} Y_{s})\), from \(u_{0} = 0\).

The objectives are:

\[\text{The minimum risk:}\;\; \text{minimize } \rho (w),\;\; \text{at the target return}\; \mu' w = \text{target when given}\] \[\text{The maximum ratio:}\;\; \frac{\text{maximize} \;(\mu - r_{f}) \;\text{'w}}{\rho(w)} \;\text{with the Charnes-Cooper transformation}\; y = \kappa w,\;\; \kappa > 0 \;(\text{Charnes and Cooper},\; 1962) \;\text{:} \;\text{maximize} \;(\mu - r_{f}) \;\text{'y} \;\text{subject to} \;\rho(y) \leq 1 \;\text{and the weight constraints},\;\; \text{then}\; w = \frac{y}{\kappa}\]

The mean absolute deviation, the lower partial moment, the worst realization, the ranges, the CVaR range, the CVaR and the drawdown measures are solved exactly as linear programmes with HiGHS. The Gini mean difference and the Tail Gini measures are ordered weighted averages of the sorted returns, convex because their weights rise with the rank (Cajas, 2021), and are solved exactly with cutting planes (Kelley, 1960) stabilized as in Ben-Ameur and Neto (2007): every sorted order of the returns gives a linear lower bound of the measure, which is added where the linear programme’s solution needs it. The semideviation and the Ulcer Index have continuous gradients and are minimized with SLSQP.

Also known as: mean-MAD, mean-semivariance, minimax, mean-Gini, mean-Ulcer, Sortino-optimal or Gini-optimal portfolio, minimum CVaR weights, minimum expected shortfall portfolio, mean-CVaR, tail risk optimization, maximum CVaR ratio weights, maximum STARR, stable tail adjusted return ratio, maximum return-to-CVaR, mean-CVaR tangency portfolio, minimum drawdown weights, minimum CDaR, minimum maximum drawdown, minimum average drawdown, drawdown optimization.

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

Install the Finance Toolkit with pip install financetoolkit -U, then call get_mean_risk_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_mean_risk_weights(
    risk_measure="gini_mean_difference", objective="maximum_ratio"
)[["Weight", "Expected Return", "Gini Mean Difference", "Gini Mean Difference 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 gave the highest return per unit of Gini mean difference, based on 2021 to 2025?

Which returns:

Parameters

get_mean_risk_weights accepts the following parameters.

ParameterTypeDescriptionExample
risk_measurestrThe risk measure. Options are: “mad” (mean absolute deviation, Konno and Yamazaki, 1991), “semideviation” (below the minimum acceptable return), “lower_partial_moment” (first order), “worst_realization” (the worst return), “gini_mean_difference” (Yitzhaki, 1982), “tail_gini” (Furman et al., 2017), “range” (the best minus the worst return), “cvar_range” (the CVaR of the losses and of the gains), “tail_gini_range” (the Tail Gini of the losses and of the gains), “ulcer_index” (of the uncompounded cumulative return), “cvar” (Rockafellar and Uryasev, 2002), “cdar” (Chekhlov et al., 2005), “maximum_drawdown” (of the uncompounded cumulative return), “average_drawdown” (of the uncompounded cumulative return). Defaults to “mad”."mad"
objectivestrOptions are: “minimum_risk” (the lowest risk), “maximum_ratio” (the highest average excess return per unit of risk). Defaults to “minimum_risk”."minimum_risk"
target_returnfloat | NoneThe annualized expected return the minimum risk portfolio must have, e.g. 0.12 for 12%, with the cash of a net exposure other than one at the risk free rate. Defaults to None, no target.None, no target
alphafloatThe tail probability of the CVaR, the CVaR range, the CDaR and the Tail Gini measures, e.g. 0.05 for the worst 5% of periods (or drawdowns). Defaults to 0.05.0.01
minimum_acceptable_returnfloat | strThe threshold of the semideviation and the lower partial moment, as a return per period of the chosen frequency (e.g. 0.0002 a day), or “mean” for each asset’s average return. Defaults to 0.0.001
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"
expected_returnsstrThe estimator of the expected returns of the ratio and the target return. 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, 0 for a market neutral one (which needs a negative minimum_weight). At 0 the portfolio with the lowest CVaR holds nothing, so all weights are 0, and for the drawdown measures a net exposure of 0 is refused, as holding nothing has no drawdown. 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 Konno, H. and Yamazaki, H. (1991). “Mean-Absolute Deviation Portfolio Optimization Model and Its Applications to Tokyo Stock Market.” Management Science, 37(5), 519-531.
  • Paper Markowitz, H. (1959). “Portfolio Selection: Efficient Diversification of Investments.” John Wiley & Sons, New York.
  • Paper Estrada, J. (2008). “Mean-Semivariance Optimization: A Heuristic Approach.” Journal of Applied Finance, 18(1), 57-72.
  • Paper Bawa, V. S. (1975). “Optimal Rules for Ordering Uncertain Prospects.” Journal of Financial Economics, 2(1), 95-121.
  • Paper Young, M. R. (1998). “A Minimax Portfolio Selection Rule with Linear Programming Solution.” Management Science, 44(5), 673-683.
  • Paper Yitzhaki, S. (1982). “Stochastic Dominance, Mean Variance, and Gini’s Mean Difference.” The American Economic Review, 72(1), 178-185.
  • Paper Furman, E., Wang, R. and Zitikis, R. (2017). “Gini-Type Measures of Risk and Variability: Gini Shortfall, Capital Allocations, and Heavy-Tailed Risks.” Journal of Banking & Finance, 83, 70-84.
  • Paper Cajas, D. (2021). “OWA Portfolio Optimization: A Disciplined Convex Programming Framework.” SSRN Working Paper 3988927.
  • Paper Martin, P. G. and McCann, B. B. (1989). “The Investor’s Guide to Fidelity Funds.” John Wiley & Sons, New York.
  • Paper Rockafellar, R. T. and Uryasev, S. (2000). “Optimization of Conditional Value-at-Risk.” Journal of Risk, 2(3), 21-41.
  • Paper Martin, R. D., Rachev, S. T. and Siboulet, F. (2003). “Phi-Alpha Optimal Portfolios and Extreme Risk Management.” Wilmott Magazine, November, 70-83.
  • Paper Chekhlov, A., Uryasev, S. and Zabarankin, M. (2005). “Drawdown Measure in Portfolio Optimization.” International Journal of Theoretical and Applied Finance, 8(1), 13-58.
  • Paper Charnes, A. and Cooper, W. W. (1962). “Programming with Linear Fractional Functionals.” Naval Research Logistics Quarterly, 9(3-4), 181-186.
  • Paper Kelley, J. E. (1960). “The Cutting-Plane Method for Solving Convex Programs.” Journal of the Society for Industrial and Applied Mathematics, 8(4), 703-712.
  • Paper Ben-Ameur, W. and Neto, J. (2007). “Acceleration of Cutting-Plane and Column Generation Algorithms: Applications to Network Design.” Networks, 49(1), 3-17.
  • Library Referenced against skfolio’s MeanRisk
  • Library Referenced against Riskfolio-Lib’s Portfolio.optimization
  • Library Referenced against Riskfolio-Lib’s Portfolio.owa_optimization (Tail Gini)
Share