Risk Parity
Calculate the risk parity weights: the portfolio in which every asset contributes the same share of the volatility, or the share set by a risk budget. Volatile assets get smaller weights, and correlated assets share their risk budget, so no single asset dominates the portfolio’s risk.
The weights solve w_i (Σw)_i / σ_p = b_i σ_p for every asset, found by minimizing the convex function 1/2 w’Σw - Σ b_i ln(w_i) and scaling the result to sum to one.
For more information, see the following papers:
- Maillard, S., Roncalli, T. and Teïletche, J. (2010). “The Properties of Equally Weighted Risk Contribution Portfolios.” The Journal of Portfolio Management, 36(4), 60-70.
- Spinu, F. (2013). “An Algorithm for Computing Risk Parity Weights.” SSRN Working Paper.
- Richard, J.-C. and Roncalli, T. (2019). “Constrained Risk Budgeting Portfolios: Theory, Algorithms, Applications & Puzzles.” arXiv:1902.05710.
Also known as: equal risk contribution, ERC, risk budgeting.
Risk Parity in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_risk_parity_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_risk_parity_weights(sector_bounds={"Healthcare": (0, 0.3)})
Or, after setting up the Finance Toolkit MCP, ask:
Which weights in Apple, Microsoft, Johnson & Johnson and ExxonMobil came closest to an equal share of the portfolio risk each, based on 2021 to 2025, with at most 30% in healthcare?
Which returns:
| Weight | Expected Return | Volatility | Sharpe Ratio | Risk Contribution | |
|---|---|---|---|---|---|
| AAPL | 0.1991 | 0.1932 | 0.2786 | 0.5725 | 0.2763 |
| MSFT | 0.2388 | 0.2017 | 0.2571 | 0.6534 | 0.2816 |
| JNJ | 0.3 | 0.0987 | 0.1673 | 0.3884 | 0.1575 |
| XOM | 0.2621 | 0.2911 | 0.2702 | 0.9524 | 0.2846 |
| Portfolio | 1 | 0.1925 | 0.1523 | 1.0429 | 1 |
Parameters
get_risk_parity_weights accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
risk_budget | dict[str, float] | None | The share of the risk per asset, e.g. {“AAPL”: 0.4, “MSFT”: 0.2, …}; it is scaled to sum to one. Defaults to None, an equal share for every asset. | None, an equal share for every asset |
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 |
minimum_weight | float | dict[str, float] | The lowest weight of every asset, or per asset, e.g. {“AAPL”: 0.05} (the others keep 0); it cannot be negative. 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 |
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 |