Minimum CVaR
Calculate the weights of the minimum Conditional Value at Risk (CVaR) portfolio: the fully invested portfolio whose average loss in the worst periods is the smallest. Unlike variance, CVaR only looks at the losses in the tail, so it accounts for skewed and fat-tailed returns.
The problem is solved as a linear programme over the historical returns: minimize VaR + 1/((1 - α)T) Σ max(0, -r_t’w - VaR), with α the confidence level and T the number of periods.
For more information, see the following paper:
- Rockafellar, R.T. and Uryasev, S. (2000). “Optimization of Conditional Value-at-Risk.” Journal of Risk, 2(3), 21-41.
Also known as: minimum expected shortfall portfolio, mean-CVaR, tail risk optimization.
Minimum CVaR in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_minimum_cvar_weights as shown below.
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_minimum_cvar_weights()
Or, after setting up the Finance Toolkit MCP, ask:
Which weights in Apple, Microsoft, Johnson & Johnson and ExxonMobil minimized the 95% conditional value at risk, based on 2021 to 2025?
Which returns:
| Weight | Expected Return | Volatility | Sharpe Ratio | Risk Contribution | CVaR | |
|---|---|---|---|---|---|---|
| AAPL | 0 | 0.1932 | 0.2786 | 0.5725 | 0 | 0.039 |
| MSFT | 0.1827 | 0.2017 | 0.2571 | 0.6534 | 0.1513 | 0.0356 |
| JNJ | 0.5965 | 0.0987 | 0.1673 | 0.3884 | 0.6005 | 0.0227 |
| XOM | 0.2208 | 0.2911 | 0.2702 | 0.9524 | 0.2482 | 0.0373 |
| Portfolio | 1 | 0.16 | 0.136 | 0.9287 | 1 | 0.0191 |
Parameters
get_minimum_cvar_weights accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
confidence_level | float | The confidence level of the CVaR, e.g. 0.95 for the average of the worst 5% of periods. Defaults to 0.95. | 0.95 |
period | str | The frequency of the returns (daily, weekly, monthly, quarterly or yearly). 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, 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. 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, |w_i - w0_i| 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 or transaction cost needs them. | None, which uses the latest weights of the Portfolio the Toolkit came from when a maximum turnover or transaction cost needs them |
maximum_turnover | float | None | The highest turnover Σ |w_i - w0_i| 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 |