Goal: I'm trying to frame target volatility investments given some view on what asset to overweight. For example, starting with a risk-parity allocation, tweak the marginal risk contribution of each asset (all equals in risk-parity) and derive the corresponding target weights of the portfolio.

Example: you want to invest in 3 assets. You are given the risk budget for each stock [0.5, 0.3, 0.2]. The goal is to derive the portfolio weights such that the marginal contribution of each asset to the variance of the portfolio is explained by respectively 50%, 30% and 20% for each asset. The goal is to find the portfolio weights $\mathbf{w} \in \mathbb{R}^3$ such that the target vol of the portfolio is $v \in \mathbb{R}^+$.

Question: what the relevant literature on portfolio construction from risk budgeting? A necessary condition for the answer is to provide references. Some python code which solves the example above for a given correlation matrix would be appreciated.

  • $\begingroup$ See the paper by Roncalli Managing Risk Exposures using the Risk Budgeting Approach. With only 3 stocks you don't even need Python, you can do it in Excel in 15 minutes from start to finish. $\endgroup$
    – Alex C
    Commented Jul 2, 2019 at 15:05
  • $\begingroup$ See also thie answers to this quant.stackexchange.com/questions/3114/… $\endgroup$
    – Alex C
    Commented Jul 2, 2019 at 15:34

2 Answers 2


What you want is to design a risk budgeting portfolio. If your constraints are only $\mathbf{1}^T\mathbf{w}=1$ and $\mathbf{w} \geq \mathbf{0}$, then the correct way to do it is to use the formulation proposed by Spinu [1]: $$\begin{array}{ll} \underset{\mathbf{w}}{\textsf{minimize}} & \frac{1}{2}\mathbf{w}^{T}\Sigma\mathbf{w} - \sum_{i=1}^{N}b_i\log(w_i)\\ \textsf{subject to} & \mathbf{1}^T\mathbf{w}=1. \end{array}$$ where $\mathbf{w}$ is the vector of portfolio weights, $\Sigma$ is the covariance matrix, and $b_i, i = 1, 2, ..., N,$ are the risk budgets.

I've implemented a solver for that optimization problem in both R and Python. The code is open source, you can check out the documentations at: https://github.com/dppalomar/riskParityPortfolio (R version) and https://github.com/dppalomar/riskparity.py (Python version).

As a code snippet, you can do it in one line of Python code:

import riskparityportfolio as rp
optimum_weights = rp.vanilla.design(cov, np.array([0.5, 0.3, 0.2]))

where cov is the covariance matrix of your assets.

[1] Florin Spinu, An Algorithm for Computing Risk Parity Weights, 2013. https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2297383


PyFENG package implements an improved cyclical coordinate descent (CCD) method based on Choi & Chen (2022):

Below is a 5 asset example. After installing PyFENG (pip install pyfeng), run

import numpy as np
import pyfeng as pf
cov = np.array([
        [ 94.868, 33.750, 12.325, -1.178, 8.778 ],
        [ 33.750, 445.642, 98.955, -7.901, 84.954 ],
        [ 12.325, 98.955, 117.265, 0.503, 45.184 ],
        [ -1.178, -7.901, 0.503, 5.460, 1.057 ],
        [ 8.778, 84.954, 45.184, 1.057, 34.126 ]

m = pf.RiskParity(cov=cov, budget=[0.1, 0.1, 0.2, 0.3, 0.3])


array([0.077, 0.025, 0.074, 0.648, 0.176])

See the PyFENG documentation for more options.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.