Risk Contributions
Calculate how much each asset contributes to the volatility of a portfolio. The marginal contribution is the change in portfolio volatility from a small increase in an asset’s weight, (Σw)_i / σ_p; the risk contribution is the weight times that, and the contributions add up to the portfolio’s volatility (Euler allocation). A large position in a calm asset can contribute less risk than a small one in a volatile asset.
For more information, see the following paper:
- Litterman, R. (1996). “Hot Spots and Hedges.” The Journal of Portfolio Management, 23(5), 52-75.
Also known as: risk decomposition, marginal contribution to risk, risk budget.
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}
)
Or, after setting up the Finance Toolkit MCP, ask:
How much did each stock contribute to the 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.2564 | 0.1025 | 0.5529 |
| MSFT | 0.3 | 0.2116 | 0.0635 | 0.3423 |
| JNJ | 0.2 | 0.0541 | 0.0108 | 0.0584 |
| XOM | 0.1 | 0.0862 | 0.0086 | 0.0465 |
| Total | 1 | nan | 0.1855 | 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 |
period | str | The frequency of the returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”. | "weekly" |
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 |