Build your own risk parity portfolio
![](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/6661e84812a8b7b6156c0e46_pyquant-newsletter-14.webp)
Build your own risk parity portfolio
Build your own risk parity portfolio
In today’s issue I’m going to show you how to build your own risk parity portfolio.
Risk parity is a strategy that uses risk to find the allocations of an investment portfolio. It allocates money to stocks based on a target risk level - usually volatility.
In other words, instead of equal dollar weights, risk parity portfolios have equal risk weights.
![Dollar to risk](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/66c8fcd957644a8b6dfb60f8_662df5a250c00927c48f0846_9O0ZL5vPRpNyFVBRTXTXRKjYPM5dGJBaDYosdFe70hchUVN34_XxXzUV87NvMQFBUJCdIV5S0YzMkWQW6PMpFp_HHYgu2o2SiBlPV24FlHeG96-T2hg9NZz4ktuiPpA%253Ds0-d-e1-ft.jpeg)
The first asset manager to use risk parity at scale was Bridgewater Associates in the 1990s. Their risk parity fund now has $25,000,000,000 under management. Risk parity is a complex strategy used by some of the most sophisticated investors in the world.
The goal of risk parity is to earn the optimal level of return at a targeted risk level
The problem with dollar-weighted portfolios is not every stock has the same risk. That means if you equally weigh two stocks, but one has higher risk, portfolio returns will be dominated by the higher-risk stock. Investors use risk parity to avoid this problem.
By the end of this issue, you’ll know how to:
- Get stock data
- Create a portfolio with equal risk weights
- Create a portfolio with a minimum return constraint
Risk parity took a decade for teams of PhDs to figure out.
I’m going to show you how to do it in 5 minutes in a few lines of Python.
Step 1: Get stock price data
Start by importing packages and getting data. I like to use yfinance for getting stock data. I’ll use the excellent Riskfolio-Lib package to create the risk parity portfolios.
1import yfinance as yf
2import riskfolio as rp
3import warnings
4warnings.filterwarnings("ignore")
Riskfolio-Lib prints out some warnings that are safe to ignore. So ignore them.
After the imports, create a list of tickers you want to use. Use any tickers you want. Since you can download data for more than one stock at a time, it’s one line of code to get all the data.
1# portfolio tickers
2assets = ["JCI", "TGT", "CMCSA", "CPB", "MO", "APA", "MMC", "JPM",
3 "ZION", "PSA", "BAX", "BMY", "LUV", "PCAR", "TXT", "TMO",
4 "DE", "MSFT", "HPQ", "SEE", "VZ", "CNP", "NI", "T", "BA"]
5
6# sort tickers
7assets.sort()
8
9#download data
10data = yf.download(assets, start="2016-01-01", end="2019-12-30")
11
12# compute non-compounding, daily returns
13returns = data['Adj Close'].pct_change().dropna()
Step 2: Create a portfolio with equal risk weights
First, setup a portfolio with equal risk weights. This means Riskfolio-Lib will find the weights that cause the risk contribution of each stock to be equal.
1port = rp.Portfolio(returns=returns)
2
3port.assets_stats(method_mu='hist', method_cov='hist', d=0.94)
4
5w_rp = port.rp_optimization(
6 model="Classic", # use historical
7 rm="MV", # use mean-variance optimization
8 hist=True, # use historical scenarios
9 rf=0, # set risk free rate to 0
10 b=None # don't use constraints
11)
First, build the portfolio object with the stock returns. Then estimate the expected returns and covariance based on historic data. Finally, use the classical mean-variance optimization to find the risk parity weights.
Riskfolio-Lib makes it easy to visualize the weights.
1ax = rp.plot_pie(w=w_rp)
![Equal risk weight](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/66c8fcd957644a8b6dfb60df_662df5a250c00927c48f0859_oDb8zo54wPOh3Ke65vjlE3BbFfvFRInOUo9zD-o8qtN39VpogBdR_3VVazsWVquw6jLM8AoU6tFQRrkW5g4-YyzkQCwMVzK1O7nfSjoYpyTBTrhvn3F0xZB-7sXu0eA%253Ds0-d-e1-ft.png)
You can see the weight of each stock is not equal. That’s because the portfolio is risk-weighted. Higher-risk stocks have lower weights to maintain the overall portfolio risk target.
What about the risk contributions.
1# show the risk contribution for each asset is equal
2ax = rp.plot_risk_con(
3 w_rp,
4 cov=port.cov,
5 returns=port.returns,
6 rm="MV",
7 rf=0,
8)
![Equal risk contribution](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/66c8fcd957644a8b6dfb60bf_662df5a250c00927c48f0843_afDRGpn5LLlqvTgA2S45Q0LkPhjT_BEH6F02OGnU7pXKkUWubUIlD3rkA0yf9mvA3jI-c4h1fkeGADDOQ3RiRpk7IxBknTmY83-LxW5DMW-ifSdMCw8wDihwMTIFuHU%253Ds0-d-e1-ft.png)
They’re equal! That’s exactly what to expect.
Step 3: Create a portfolio with a minimum return constraint
A criticism of risk parity is that without leverage, returns lag. So add a constraint to weight the stocks in a way to reach a minimum portfolio return. This adds weight to higher-risk stocks to push the portfolio returns higher.
1port.lowerret = 0.0008
2
3# estimate the optimal portfolio with risk parity with the constraint
4w_rp_c = port.rp_optimization(
5 model="Classic", # use historical
6 rm="MV", # use mean-variance optimization
7 hist=True, # use historical scenarios
8 rf=0, # set risk free rate to 0
9 b=None # don't use constraints
10)
Add a constraint for the minimum level of expected returns for the entire portfolio.
Again, plotting is easy.
1ax = rp.plot_pie(w=w_rp_c)
![Return constraint](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/66c8fcd957644a8b6dfb60c2_662df5a250c00927c48f085c_hcMYQdKPhGm9iSlZ7hQfHWdqRAqIlOi2ETZT949yoH8pxjN1H6xTwpg9AilN8ubui6vryMAM-1vhnA_BHfP0RtHaI49uzAh1FP56z3yBGv6VO5OvF1cFRiXYAyxYK0k%253Ds0-d-e1-ft.png)
MSFT dominates with a 15.3% weight. That's because to reach the minimum return threshold, risk parity overweights stocks with higher risk. And with higher risk comes higher return.
Plot the risk contributions.
1ax = rp.plot_risk_con(
2 w_rp_c,
3 cov=port.cov,
4 returns=port.returns,
5 rm="MV",
6 rf=0,
7)
![Return constraint](https://cdn.prod.website-files.com/6606adcab6ed6464b674ad71/66c8fcd957644a8b6dfb60dc_662df5a250c00927c48f084a_0i56-p9sWXTwDh0NRfvNsBHxxxqwKmJ2YikokKfYj526veneEYOhDqeF13QiNGoFcKsHIiNWCvWtahhfutRJc7-bITjYraB7TQdVRkBnZzXVI-6rpxNlcW0hb4JikcA%253Ds0-d-e1-ft.png)
They're no longer equal. That's because risk parity figured out the optimal risk weights to hit the minimum portfolio return constraint.
Risk parity is a great way to manage a predictable portfolio that performs consistently in most markets.
![Man with glasses and a wristwatch, wearing a white shirt, looking thoughtfully at a laptop with a data screen in the background.](https://cdn.prod.website-files.com/6604815bfffc39e4941bd158/66070439083cb3ca5c1d1c34_cta%20image.webp)