Risk Contributions
Calculate how much each asset contributes to the risk of a portfolio, measured as its volatility, expected shortfall (CVaR), semideviation, mean absolute deviation or Conditional Drawdown at Risk (CDaR). The marginal contribution is the change in the portfolio’s risk from a small increase in an asset’s weight; the risk contribution is the weight times that, and the contributions add up to the portfolio’s risk (Euler allocation). A large position in a calm asset can contribute less risk than a small one in a volatile asset.
- risk_measure=”volatility”: the marginal contribution is (Σw)_i / σ_p, with Σ the annualized covariance matrix.
- risk_measure=”cvar”: the expected shortfall is the average loss in the periods in which the portfolio’s return is at or below its Value at Risk, and the marginal contribution of an asset is its average loss in those same periods, -E[r_i | r_p ≤ VaR], so the contributions show which assets lose in the portfolio’s worst periods. These are per period (e.g. daily), like the Finance Toolkit’s historical CVaR, and not annualized.
- risk_measure=”semideviation”: the downside deviation of the portfolio’s return below zero, SD⁻ = √(Σ min(r_p,t, 0)² / T), with the marginal contribution Σ min(r_p,t, 0) r_i,t / (T SD⁻): an asset contributes by losing in the periods in which the portfolio loses. Per period, not annualized.
- risk_measure=”mad”: the mean absolute deviation of the portfolio’s return, Σ |r_p,t - μ_p| / T, with the marginal contribution Σ sign(r_p,t - μ_p)(r_i,t - μ_i) / T. Per period, not annualized.
- risk_measure=”cdar”: the Conditional Drawdown at Risk, the average of the worst 1 - α share of the drawdowns of the uncompounded cumulative return (the drawdowns the minimum drawdown optimization minimizes). Each drawdown is the sum of the assets’ drawdowns from the portfolio’s peak, so the marginal contribution of an asset is its average drawdown over the portfolio’s worst drawdown periods (Goldberg and Mahmoud, 2017).
For more information, see the following papers:
- Litterman, R. (1996). “Hot Spots and Hedges.” The Journal of Portfolio Management, 23(5), 52-75.
- Tasche, D. (2000). “Conditional Expectations as Quantile Derivatives.” Working paper, arXiv math/0104190.
- Scaillet, O. (2004). “Nonparametric Estimation and Sensitivity Analysis of Expected Shortfall.” Mathematical Finance, 14(1), 115-129.
- Sortino, F. A. and Price, L. N. (1994). “Performance Measurement in a Downside Risk Framework.” The Journal of Investing, 3(3), 59-64.
- 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.
- Goldberg, L. R. and Mahmoud, O. (2017). “Drawdown: From Practice to Theory and Back Again.” Mathematics and Financial Economics, 11(3), 275-297.
Also known as: risk decomposition, marginal contribution to risk, risk budget, component expected shortfall, component CVaR, downside risk contribution, drawdown contribution.
Risk Contributions in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_risk_contributions 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_risk_contributions(
weights={"AAPL": 0.4, "MSFT": 0.3, "JNJ": 0.2, "XOM": 0.1},
risk_measure="cvar",
)
Or, after setting up the Finance Toolkit MCP, ask:
How much did each stock contribute to the 95% conditional value at risk of a portfolio of 40% Apple, 30% Microsoft, 20% Johnson & Johnson and 10% ExxonMobil from 2021 to 2025?
Which returns:
| Asset | Weight | Marginal Contribution | Risk Contribution | Percentage Contribution |
|---|---|---|---|---|
| AAPL | 0.4 | 0.0352 | 0.0141 | 0.5365 |
| MSFT | 0.3 | 0.0306 | 0.0092 | 0.3492 |
| JNJ | 0.2 | 0.0082 | 0.0016 | 0.0625 |
| XOM | 0.1 | 0.0136 | 0.0014 | 0.0518 |
| Total | 1 | nan | 0.0263 | 1 |
Parameters
get_risk_contributions accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
weights | dict[str, float] | None | The weight per asset. Defaults to None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights. | None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights |
risk_measure | str | “volatility”, “cvar” (the expected shortfall), “semideviation” (below a return of zero), “mad” (the mean absolute deviation) or “cdar” (the Conditional Drawdown at Risk). Defaults to “volatility”. | "volatility" |
confidence_level | float | The confidence level of the expected shortfall and the CDaR, e.g. 0.95 for the average of the worst 5% of periods or drawdowns. Defaults to 0.95. | 0.95 |
period | str | The frequency of the returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”. | "weekly" |
covariance | str | The estimator of the covariance matrix: “sample” (ddof=1), “ledoit_wolf” (towards the scaled identity, Ledoit and Wolf, 2004), “ledoit_wolf_constant_correlation” (towards the average correlation, Ledoit and Wolf, 2004), “ledoit_wolf_single_factor” (towards the covariance that the benchmark as a single factor implies, Ledoit and Wolf, 2003), “oas” (Chen et al., 2010), “semicovariance” (the co-movement below a zero return, Estrada, 2007), “exponential” (recent periods weigh most, RiskMetrics) or “denoised” (the eigenvalues of the correlation matrix that random returns could produce averaged, Laloux et al., 2000). The shrinkage and denoised estimators stabilize the weights when there are many assets compared to the number of periods. Defaults to “sample”. | "sample" |
covariance_span | int | The span in periods of the “exponential” covariance; the weight of a period halves after about span / 2.9 periods. Defaults to 180. | 180 |
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 |