Build your own risk parity portfolio

October 15, 2022
Facebook logo.
Twitter logo.
LinkedIn logo.
Get this code in Google Colab

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

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:

  1. Get stock data
  2. Create a portfolio with equal risk weights
  3. 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

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

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

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

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.