Distributionally Robust CVaR Weights
Calculate the weights of the distributionally robust mean-CVaR portfolio.
It is the portfolio that minimizes the expected loss plus the risk aversion times the Conditional Value at Risk (CVaR) under the least favourable distribution of the returns within a Wasserstein ball around the historical returns. The historical returns are one sample of the distribution; the ball holds every distribution that lies within a transport distance \(\epsilon\) of it, so the portfolio is protected against distributions with heavier losses than the sample happened to show.
With \(X = \xi' w\) the portfolio return, \(\alpha\) the tail probability, \(\rho\) the risk aversion and \(\epsilon\) the radius, the weights minimize
- sup over Q in the ball of \(E_{Q} [- X] + \rho \text{CVaR}_{\alpha} , Q (- X)\),
where the distance between two distributions is the least average 1-norm change in the returns of the assets that turns one into the other (the type-1 Wasserstein distance), and returns stay at or above -100%. Mohajerin Esfahani and Kuhn (2018) show that this worst case is a linear programme: with the CVaR written as min over \(\tau\) of \(\tau + E [\max (- X - \tau , 0)] / \alpha\) the loss is the maximum of two linear pieces, and its worst case is \(\min \lambda \epsilon + \sum s_{t} / T\) over \(\lambda \geq 0\) with \(s_{t}\) bounding each piece in period t after the most harmful shift of the returns. Per asset that shift is either none or down to -100%, so the programme has n + 2 + T + 2n variables and is solved exactly with HiGHS. At a radius of 0 it is the historical mean-CVaR portfolio.
Also known as: Wasserstein robust CVaR, DRO CVaR, distributionally robust mean-CVaR.
Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_distributionally_robust_cvar_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_distributionally_robust_cvar_weights()[
["Weight", "Expected Return", "CVaR", "Worst-Case CVaR"]
]
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 hold up best against the worst-case CVaR around the 2021 to 2025 returns?
Which returns:
| Item | Weight | Expected Return | CVaR | Worst-Case CVaR |
|---|---|---|---|---|
| AAPL | 0.0581 | 0.1932 | 0.0390 | 0.0490 |
| MSFT | 0.2543 | 0.2017 | 0.0356 | 0.0456 |
| JNJ | 0.4117 | 0.0987 | 0.0227 | 0.0327 |
| XOM | 0.2759 | 0.2911 | 0.0373 | 0.0473 |
| Portfolio | 1.0000 | 0.1835 | 0.0199 | 0.0241 |
5 rows
Parameters
get_distributionally_robust_cvar_weights accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
alpha | float | The tail probability \(\alpha\) of the CVaR, e.g. 0.05 for the average of the worst 5% of periods. Defaults to 0.05. | 0.01 |
wasserstein_radius | float | The radius \(\epsilon\) of the Wasserstein ball, in returns per period of the chosen frequency: the average total change in the returns of all assets that the distributions considered may have. Defaults to 0.0005, which suits daily returns (see the Notes). | |
risk_aversion | float | The weight \(\rho\) of the CVaR against the expected loss; a high value gives the minimum worst-case CVaR portfolio. Defaults to 1. | 1 |
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" |
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. 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 |
References
- Paper Mohajerin Esfahani, P. and Kuhn, D. (2018). “Data-Driven Distributionally Robust Optimization Using the Wasserstein Metric: Performance Guarantees and Tractable Reformulations.” Mathematical Programming, 171(1-2), 115-166.
- Paper Rockafellar, R. T. and Uryasev, S. (2000). “Optimization of Conditional Value-at-Risk.” Journal of Risk, 2(3), 21-41.
- Library Referenced against skfolio’s DistributionallyRobustCVaR