Risk-based allocation: inverse volatility, risk parity and HRP
Long-only weights from the covariance alone: inverse volatility, equal risk contribution (risk parity) and hierarchical risk parity, with each asset's risk contribution and the portfolio's volatility.
- Model id
portfolio.risk_based_allocation, version 1- Domain
- Portfolio
- Evidence
- practitioner
- Cost class
- light: A short numerical method; a hosted run may take up to 10 seconds.
Formula
Where
- Asset i's inverse-volatility weight
weights - Volatility of asset i
volatilities - Asset i's contribution to the portfolio's volatility
risk_contributions - Covariance matrix of the assets' returns
covariance - The portfolio's volatility
volatility - The equal-risk-contribution (risk parity) weights
weights - The unscaled weights that solve the risk-parity problem
- Number of assets
- The correlation distance between assets i and j
- The correlation between assets i and j
correlations - The share given to the first of two clusters when a cluster is split
- Variance of the first cluster; V_2 is the second's
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Weights proportional to 1 / volatility (inverse_volatility): 5 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations, or returns |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Returnsreturnsreturn (array) (array) · each length min 1, max 100; each [-1, 5] | return (array) (array) | each length min 1, max 100; each [-1, 5] | The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used |
Calculationcalculationtext | text | Weights proportional to 1 / volatility |
Risk parity: every asset contributes the same risk (equal_risk_contribution): 5 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations, or returns |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Returnsreturnsreturn (array) (array) · each length min 1, max 100; each [-1, 5] | return (array) (array) | each length min 1, max 100; each [-1, 5] | The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used |
Calculationcalculationtext | text | Risk parity: every asset contributes the same risk |
Hierarchical risk parity: clustering and recursive bisection (hierarchical_risk_parity): 5 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Covariancecovarianceratio (array) (array) · each length min 1, max 100; each [-100, 100] | ratio (array) (array) | each length min 1, max 100; each [-100, 100] | Covariance matrix of the asset returns per period, as rows; or give volatilities and correlations, or returns |
Volatilitiesvolatilitiesvolatility (array) · each (0, 10] | volatility (array) | each (0, 10] | Volatility of each asset per period, with correlations |
Correlationscorrelationscorrelation (array) (array) · each length min 1, max 100; each [-1, 1] | correlation (array) (array) | each length min 1, max 100; each [-1, 1] | Correlation matrix of the asset returns, as rows, with volatilities |
Returnsreturnsreturn (array) (array) · each length min 1, max 100; each [-1, 5] | return (array) (array) | each length min 1, max 100; each [-1, 5] | The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used |
Calculationcalculationtext | text | Hierarchical risk parity: clustering and recursive bisection |
Outputs
Weights proportional to 1 / volatility (inverse_volatility): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Weightsweightsratio (array) · length max 100; each [0, 1] | ratio (array) | length max 100; each [0, 1] | Weight of each asset: long only, summing to 1 |
Risk contributionsrisk_contributionsvolatility (array) · length max 100; each [-10, 10] | volatility (array) | length max 100; each [-10, 10] | Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility |
Volatilityvolatilityvolatility · [0, 10] | volatility | [0, 10] | The portfolio's volatility per period |
Calculationcalculationtext | text | Weights proportional to 1 / volatility |
Risk parity: every asset contributes the same risk (equal_risk_contribution): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Weightsweightsratio (array) · length max 100; each [0, 1] | ratio (array) | length max 100; each [0, 1] | Weight of each asset: long only, summing to 1 |
Risk contributionsrisk_contributionsvolatility (array) · length max 100; each [-10, 10] | volatility (array) | length max 100; each [-10, 10] | Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility |
Volatilityvolatilityvolatility · [0, 10] | volatility | [0, 10] | The portfolio's volatility per period |
Calculationcalculationtext | text | Risk parity: every asset contributes the same risk | |
Iterationsiterationscount · [0, 200] | count | [0, 200] | Newton steps the solve took |
Hierarchical risk parity: clustering and recursive bisection (hierarchical_risk_parity): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Weightsweightsratio (array) · length max 100; each [0, 1] | ratio (array) | length max 100; each [0, 1] | Weight of each asset: long only, summing to 1 |
Risk contributionsrisk_contributionsvolatility (array) · length max 100; each [-10, 10] | volatility (array) | length max 100; each [-10, 10] | Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility |
Volatilityvolatilityvolatility · [0, 10] | volatility | [0, 10] | The portfolio's volatility per period |
Calculationcalculationtext | text | Hierarchical risk parity: clustering and recursive bisection | |
Orderordercount (array) · length max 100; each [0, 99] | count (array) | length max 100; each [0, 99] | The assets' quasi-diagonal order: their positions in the inputs, as the tree's leaves run, from 0 |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Live data runs on your own computer only
This model reads Twelve industry portfolios, monthly. Its source, Ken French Data Library, lets pyeconomics read the data on your own computer but not serve them from this website.
Here, enter your own values, or bring them as a file with "Use my own data". To run this page with every profile's live data, install the local app and start it: pip install "pyeconomics[app]" then pyeconomics serve.
Loading the calculator…
Worked example
Example four_assets_inverse_volatility. Inputs:
{
"calculation": "inverse_volatility",
"correlations": [
[1, 0.8, 0, 0],
[0.8, 1, 0, 0],
[0, 0, 1, -0.5],
[0, 0, -0.5, 1]
],
"covariance": null,
"returns": null,
"volatilities": [0.1, 0.2, 0.3, 0.4]
}Outputs:
{
"calculation": "inverse_volatility",
"risk_contributions": [
0.04028420771598156,
0.04028420771598156,
0.011190057698883763,
0.011190057698883768
],
"volatility": 0.10294853082973066,
"weights": [
0.48000000000000004,
0.24000000000000002, 0.16,
0.12000000000000001
]
}Assumptions
- The covariance is per period and given (or estimated from the returns given, divisor T - 1); no expected returns are used.
- The weights are long only and sum to one; there are no costs or constraints beyond that.
- Profile: default binds 120 months of the Ken French 12 industry portfolios' returns.
- The outputs follow from the inputs the user supplies, the same for every user: they are formula results, not investment advice.
Limitations
- A covariance matrix that is not symmetric and positive semidefinite, or an asset without variance, raises DomainError; so does a long portfolio with no risk (perfectly negatively correlated assets), whose risk contributions are undefined.
- The equal-risk-contribution solve raises ConvergenceError if it does not reach a relative tolerance of 1e-12 in 200 Newton steps.
- Hierarchical risk parity depends on the clustering: single linkage chains, and a tie between distances is broken by SciPy's order. Its bisection halves the ordered list, not the tree.
- The Ken French portfolios are library-only: fetched at run time and never stored.
Evidence
Status: practitioner. A widely used rule of thumb or convention.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Data
This model can read its data for you: each bound field names a data series, and the sources listed can fill it, in the order they are tried. This website reads only the sources whose terms let it serve their data (marked "hosted"); every source is available when you run pyeconomics on your own computer.
| Field | Concept | Read as | Sources (licence class; hosted) |
|---|---|---|---|
returns | Twelve industry portfolios, monthlyportfolios.industry12.us.monthly | the last 120 observations on or before the date; real time: as published by the date |
|
Citations
- Maillard, S., Roncalli, T. and Teiletche, J. (2010). The Properties of Equally Weighted Risk Contribution Portfolios. The Journal of Portfolio Management, 36(4), 60-70. doi:10.3905/jpm.2010.36.4.060 (The ERC portfolio and its risk contributions, the log-barrier problem whose solution it is, and the example of section 4.1)
- López de Prado, M. (2016). Building Diversified Portfolios that Outperform Out of Sample. The Journal of Portfolio Management, 42(4), 59-69. doi:10.3905/jpm.2016.42.4.059 (Stages 1-3, pp. 5-8 of the SSRN preprint: the distance of distances, single linkage, quasi-diagonalization and bisection of the ordered list)
- French, K. R. Data Library: 12 industry portfolios, monthly. Tuck School of Business, Dartmouth College. https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html (12 Industry Portfolios, value-weighted monthly returns)
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/portfolio.risk_based_allocation/run- MCP tool
run_modelwith the model's id,portfolio.risk_based_allocation. Connect an assistant- Command line
pyeconomics models run portfolio.risk_based_allocation --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"calculation": "inverse_volatility",
"correlations": [
[1, 0.8, 0, 0],
[0.8, 1, 0, 0],
[0, 0, 1, -0.5],
[0, 0, -0.5, 1],
],
"covariance": None,
"returns": None,
"volatilities": [0.1, 0.2, 0.3, 0.4],
}
result = pyeconomics.run("portfolio.risk_based_allocation", inputs)
print(result.to_json())
pyeconomics models run portfolio.risk_based_allocation --inputs - <<'JSON'
{
"calculation": "inverse_volatility",
"correlations": [
[1, 0.8, 0, 0],
[0.8, 1, 0, 0],
[0, 0, 1, -0.5],
[0, 0, -0.5, 1]
],
"covariance": null,
"returns": null,
"volatilities": [0.1, 0.2, 0.3, 0.4]
}
JSON