Skip to content

Portfolio

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

wiIV=1/σi∑j1/σjw_i^{\mathrm{IV}} = \frac{1/\sigma_i}{\sum_j 1/\sigma_j}RCi=wi(Σw)iσp,∑iRCi=σp=w′ΣwRC_i = \frac{w_i (\Sigma w)_i}{\sigma_p}, \quad \sum_i RC_i = \sigma_p = \sqrt{w'\Sigma w}wERC=y∗1′y∗,y∗=arg⁡min⁡y>012y′Σy−1N∑ilog⁡yiw^{\mathrm{ERC}} = \frac{y^*}{\mathbf{1}'y^*}, \quad y^* = \arg\min_{y > 0} \tfrac{1}{2} y'\Sigma y - \tfrac{1}{N}\sum_i \log y_idij=12(1−ρij),α=1−V1V1+V2d_{ij} = \sqrt{\tfrac{1}{2}(1 - \rho_{ij})}, \quad \alpha = 1 - \frac{V_1}{V_1 + V_2}

Where

wiIVw_i^{\mathrm{IV}}
Asset i's inverse-volatility weight weights
σi\sigma_i
Volatility of asset i volatilities
RCiRC_i
Asset i's contribution to the portfolio's volatility risk_contributions
Σ\Sigma
Covariance matrix of the assets' returns covariance
σp\sigma_p
The portfolio's volatility volatility
wERCw^{\mathrm{ERC}}
The equal-risk-contribution (risk parity) weights weights
y∗y^*
The unscaled weights that solve the risk-parity problem
NN
Number of assets
dijd_{ij}
The correlation distance between assets i and j
ρij\rho_{ij}
The correlation between assets i and j correlations
α\alpha
The share given to the first of two clusters when a cluster is split
V1V_1
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
Inputs of the calculation inverse_volatility
NameDescription
Covariancecovarianceratio (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 of each asset per period, with correlations
Correlationscorrelationscorrelation (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]The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used
CalculationcalculationtextWeights proportional to 1 / volatility
Risk parity: every asset contributes the same risk (equal_risk_contribution): 5 inputs
Inputs of the calculation equal_risk_contribution
NameDescription
Covariancecovarianceratio (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 of each asset per period, with correlations
Correlationscorrelationscorrelation (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]The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used
CalculationcalculationtextRisk parity: every asset contributes the same risk
Hierarchical risk parity: clustering and recursive bisection (hierarchical_risk_parity): 5 inputs
Inputs of the calculation hierarchical_risk_parity
NameDescription
Covariancecovarianceratio (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 of each asset per period, with correlations
Correlationscorrelationscorrelation (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]The assets' returns, as rows: one per period, one value per asset; their sample covariance (divisor T - 1) is used
CalculationcalculationtextHierarchical risk parity: clustering and recursive bisection

Outputs

Weights proportional to 1 / volatility (inverse_volatility): 4 outputs
Outputs of the calculation inverse_volatility
NameDescription
Weightsweightsratio (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]Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility
Volatilityvolatilityvolatility · [0, 10]The portfolio's volatility per period
CalculationcalculationtextWeights proportional to 1 / volatility
Risk parity: every asset contributes the same risk (equal_risk_contribution): 5 outputs
Outputs of the calculation equal_risk_contribution
NameDescription
Weightsweightsratio (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]Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility
Volatilityvolatilityvolatility · [0, 10]The portfolio's volatility per period
CalculationcalculationtextRisk parity: every asset contributes the same risk
Iterationsiterationscount · [0, 200]Newton steps the solve took
Hierarchical risk parity: clustering and recursive bisection (hierarchical_risk_parity): 5 outputs
Outputs of the calculation hierarchical_risk_parity
NameDescription
Weightsweightsratio (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]Each asset's contribution to the volatility, w_i (Sigma w)_i / sigma_p; they sum to the volatility
Volatilityvolatilityvolatility · [0, 10]The portfolio's volatility per period
CalculationcalculationtextHierarchical risk parity: clustering and recursive bisection
Orderordercount (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.

Profile: Default
FieldConceptRead asSources (licence class; hosted)
returnsTwelve industry portfolios, monthlyportfolios.industry12.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)

Citations

  1. 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)
  2. 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)
  3. 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_model with 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:

Python
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())
Command line
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