Mean-Ulcer Index Optimization
The Ulcer Index is the root mean square of the drawdowns of the uncompounded cumulative return of the portfolio (Martin and McCann, 1989). Squaring the drawdowns penalizes deep and long drawdowns most, which is what makes holding an investment painful.
The formula for the Ulcer Index starts from the uncompounded cumulative return \(Y_{t}\) of the portfolio, with \(w_{i}\) the weight and \(r_{i , s}\) the return of asset i of the N assets in period s, and its drawdowns \(D_{t}\) below the running peak \(P_{t}\), the highest Y up to t and at least zero:
\[Y_{t} = \sum_{s=1}^{t} \sum_{i=1}^{N} w_{i} \cdot r_{i,s}\] \[D_{t} = P_{t} - Y_{t}\] \[\text{UI} = \sqrt{\frac{\sum_{t=1}^{T} D_{t}^{2}}{T}}\]A portfolio that recovers quickly from its falls has a low Ulcer Index even with a volatile return.
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. Mean-variance analysis measures risk by the variance; the mean-risk portfolios keep its trade-off between expected return and risk and measure the risk of the historical portfolio returns in another way. Measures that only count losses leave upside swings unpenalized, the dispersion measures count deviations in proportion to their size rather than their square, and the drawdown measures penalize deep and long falls, which are what investors feel and what ends strategies.
There are two objectives. The minimum risk portfolio minimizes the risk measure, at a target expected return when one is given. The maximum ratio portfolio maximizes the expected excess return over the risk measure, with the transformation of Charnes and Cooper (1962) that turns the ratio into a problem of the same kind as the minimum risk one; with the volatility as the measure, it would be the maximum Sharpe ratio portfolio.
Also known as: mean-Ulcer, UI.
In the Finance Toolkit this is get_mean_risk_weights with risk_measure="ulcer_index", the same function as Mean-Risk Weights.
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="ulcer_index", objective="maximum_ratio"
)[["Weight", "Expected Return", "Ulcer Index", "Ulcer Index Ratio"]]
| Parameter | Type | Description | Example |
|---|---|---|---|
risk_measure | str | The risk measure. Options are: “mad” (Mean Absolute Deviation, Konno and Yamazaki, 1991), “semideviation” (Semideviation, below the minimum acceptable return), “lower_partial_moment” (Lower Partial Moment, first order), “worst_realization” (Worst Realization, the worst return), “gini_mean_difference” (Gini Mean Difference, Yitzhaki, 1982), “tail_gini” (Tail Gini, Furman et al., 2017), “range” (Range, the best minus the worst return), “cvar_range” (Conditional Value at Risk Range, of the losses and of the gains), “tail_gini_range” (Tail Gini Range, of the losses and of the gains), “ulcer_index” (Ulcer Index, of the uncompounded cumulative return), “cvar” (Conditional Value at Risk, Rockafellar and Uryasev, 2002), “cdar” (Conditional Drawdown at Risk, Chekhlov et al., 2005), “maximum_drawdown” (Maximum Drawdown, of the uncompounded cumulative return), “average_drawdown” (Average Drawdown, of the uncompounded cumulative return). Defaults to “mad”. | "mad" |
objective | str | Options are: “minimum_risk” (the lowest risk), “maximum_ratio” (the highest average excess return per unit of risk). Defaults to “minimum_risk”. | "minimum_risk" |
target_return | float | None | The 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 |
alpha | float | The 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_return | float | str | The 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 |
period | str | The 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_returns | str | The 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_span | int | The span in periods of the exponentially weighted expected returns. Defaults to 180. | 180 |
minimum_weight | float | 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_weight | float | 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_bounds | dict[str, tuple[float, float]] | None | The 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_bounds | dict[str, tuple[float, float]] | None | The 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_exposure | float | The 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_exposure | float | None | The 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_weights | dict[str, float] | None | The 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_turnover | float | None | The 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_benchmark | bool | Whether to include the benchmark as an asset. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |
show_columns | str | list[str] | None | The 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 |
Which returns:
| Item | Weight | Expected Return | Ulcer Index | Ulcer Index Ratio |
|---|---|---|---|---|
| AAPL | 0.1358 | 0.1932 | 0.1107 | 0.0057 |
| MSFT | 0.3273 | 0.2017 | 0.1276 | 0.0052 |
| JNJ | 0.1378 | 0.0977 | 0.0786 | 0.0032 |
| XOM | 0.3991 | 0.2911 | 0.0847 | 0.0121 |
| Portfolio | 1.0000 | 0.2219 | 0.0335 | 0.0223 |
5 rows
References
- Paper Charnes, A. and Cooper, W. W. (1962). “Programming with Linear Fractional Functionals.” Naval Research Logistics Quarterly, 9(3-4), 181-186.
- Paper Martin, P. G. and McCann, B. B. (1989). “The Investor’s Guide to Fidelity Funds.” John Wiley & Sons, New York.