Let's explain the asset allocation by the Black-Litterman model (with an execution example by Python)

Introduction

The Black-Litterman Model is the optimal portfolio selection method for investment. It is widely used in financial practice because of its ease of use because it provides intuitive and easy-to-understand results compared to optimization using the traditional average variance approach. In this article, I would like to give a rough explanation of what the Black-Litterman model is doing, using figures as well. See Resources for details such as deriving formulas.

Black-Litterman Model Overview-Comparison with Traditional Optimization Methods

Traditional optimization methods and their problems

Markovitz's mean diversification approach calculates the optimal portfolio by estimating the expected return and risk (covariance matrix) of each asset and solving the trade-off of maximizing return and minimizing risk by optimizing calculations. To do. BL1.PNG Although this approach is easy to understand, it has the following drawbacks for practical use. —— Risks are relatively stable and easy to estimate, but returns are difficult to predict --Nevertheless, optimization with the mean variance approach must specify the expected return for all assets. ――In addition, a slight change in expected return can significantly change the resulting portfolio. BL2.PNG

Therefore, in practice, it is dealt with by imposing various constraints (position size, turnover rate, etc.) in the optimization calculation. To avoid this problem, the Black-Litterman model was devised and widely used.

Black-Litterman optimization flow

The Black-Litterman model is easy to understand if you think about it in the following three steps.

1. Find equilibrium expected return by Reverse Optimization

Black-Litterman optimization does not directly estimate the expected return, which is difficult to estimate. Instead, the entire market selects the portfolio by optimization, that is, the market capitalization weight (= market portfolio) in the current market is the result of optimization that inputs the estimated return and risk assumed by the market. Suppose it was obtained. Based on this idea, the market capitalization weight (market portfolio) and estimated risk can be used to back-calculate the expected return (called equilibrium return or implied return) that the market expects. This method is called Reverse Optimization because it reverses the optimization calculation in the mean variance approach. BL3.PNG

2. Bayesian update blends investor view into equilibrium expected return

Use Bayesian statistics to blend the investor's view (outlook) with the equilibrium expected return obtained by Reverse Optimization in 1 and adjust the expected return value. The investor view is entered into the model in the form of forecasts, such as "A asset outperforms B asset by 3%" and "C asset returns 5%". You can enter any number of forecasts, and you can also enter the investor confidence for each forecast as a parameter. Highly confident forecasts have a greater impact on returns, and less confident forecasts have less impact on returns. BL4.PNG

3. Calculate portfolio by optimization calculation

Finally, the optimization process calculates the new portfolio based on the updated expected return and risk. BL5.PNG

Formula & Python execution example

Let's take a look at the formulas that appear in the Black-Litterman model, as well as the code implemented in Python. Here, [He & Litterman (1999) paper](https://www.google.co.jp/url?sa=t&rct=j&q=1esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwiNza-vodvLAhVI02MKHU2QAbkQFgguMAE&url=http % 3A% 2F% 2Ffaculty.fuqua.duke.edu% 2F ~ charvey% 2FTeaching% 2FIntesaBci_2001% 2FGS_The_intuition_behind.pdf & usg = AFQjCNFAMN5avO_btVZg9P3jbGlEU5VMjw) Reproduce the numerical example.

0. Preparation

The He & Litterman paper exemplifies a portfolio of equity indexes from seven countries (Australia, Canada, France, Germany, Japan, UK and the United States). Its market capitalization weight $ w $, correlation matrix, and volatility are given as inputs.

Prepare these data in Python. The covariance matrix $ \ Sigma $ (Sigma) is calculated from the correlation matrix (correlation) and volatility (std).

python


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#weight
w = np.array([[0.016, 0.022, 0.052, 0.055, 0.116, 0.124, 0.615]]).T
#Correlation matrix
correlation = np.array([
        [1, 0.488, 0.478, 0.515, 0.439, 0.512, 0.491],
        [0.488, 1, 0.664, 0.655, 0.310, 0.608, 0.779],
        [0.478, 0.664, 1, 0.861, 0.355, 0.783, 0.668],
        [0.515, 0.655, 0.861, 1, 0.354, 0.777, 0.653],
        [0.439, 0.310, 0.355, 0.354, 1, 0.405, 0.306],
        [0.512, 0.608, 0.783, 0.777, 0.405, 1, 0.652],
        [0.491, 0.779, 0.668, 0.653, 0.306, 0.652, 1]])
#standard deviation
std = np.array([[0.16, 0.203, 0.248, 0.271, 0.21, 0.2, 0.187]])
#Calculate the covariance matrix from the correlation matrix and standard deviation
Sigma = correlation * np.dot(std.T, std)
#The parameter delta value is He&Litterman(1999)Follow
delta = 2.5
#The parameter tau value is He&Litterman(1999)Follow
tau = 0.05

In addition, the symbols that appear in the following formulas are as follows. $ \ Pi $ Equilibrium expected return (nx1 vector) $ \ Pi'$ Expected return updated for investor view (nx1 vector) $ w $ Initial weight (nx1 vector) $ w'$ posterior weight (nx1 vector) $ \ Sigma $ Return covariance matrix $ P $, $ Q $ Matrix showing investor views $ \ Omega $ Matrix showing investor confidence in the view $ \ Delta $ parameter (represents investor risk aversion) $ \ tau $ parameter (represents confidence interval for covariance matrix)

  1. Reverse Optimization

The first step is reverse optimization. In other words, it is a calculation that reverses the optimization. As explained above, in normal optimization, "return" and "risk" are input, and the trade-off that maximizes the return and minimizes the risk is optimized and calculated to obtain the "portfolio (weight)". In reverse optimization, on the contrary, "portfolio (weight)" and "risk" are input and "return" is calculated.

The utility function in the optimization calculation is expressed by the following formula, and $ w $ that maximizes this $ U $ is the optimal portfolio. $ \ Delta $ in the formula is a parameter that specifies the degree of risk aversion.

U = w^T\Pi - \frac{\delta}{2} w^T \Sigma w

This $ U $ is differentiated by $ w $, and $ w $ where it becomes 0 is the optimal portfolio.

\frac{dU}{dw} = \Pi - \delta\Sigma w = 0

Solving this for $ \ Pi $

\Pi = \delta\Sigma w

You can use this formula to find the equilibrium expected return $ \ Pi $. In Python, do the following:

python


#Find an equilibrium return(reverse optimization)
r_eq = delta * np.dot(Sigma, w)

2. Blend the investor's view with the equilibrium return

Next, specify the investor's View (forecast or forecast) and blend this with the equilibrium return obtained earlier to obtain a new expected return. In the Black-Litterman model, the investor's View is represented by two matrices $ P $ and $ Q $. In the example of the He & Litterman paper,

P = \left( \begin{array}{cccccc} 0 & 0 & -0.295 & 1 & 0 & -0.705 & 0 \\\
0 & 1 & 0 & 0 & 0 & 0 & -1 \end{array} \right) \\\
Q = \left( \begin{array}{c} 0.05 \\\ 0.03 \end{array} \right)

It looks like this. This represents two views: "Germany outperforms other Europe (France, UK) by 5%" and "Canada outperforms the United States by 3%". Also, the confidence level for these two views is specified by the matrix $ \ Omega $. In the example of the paper, the values are as follows.

\Omega = \left( \begin{array}{cc} 0.001065 & 0 \\\ 0 & 0.000852 \end{array} \right)

Prepare these matrices in Python as well.

python


P = np.array([
        [0,0,-0.295,1,0,-0.705,0],
        [0,1,0,0,0,0,-1]]) # 2x7 matrix (2: number of views, 7: number of assets)
Q = np.array([[0.05],[0.03]]) # 2-vector
Omega = np.array([
        [0.001065383332,0],
        [0,0.0008517381]])

Finally, using Black-Litterman's "master equation", we blend the investor's view with the equilibrium return to find a new return. The formula is as follows (the derivation is explained in detail in the bibliographic article):

\Pi' = \Pi + \tau \Sigma P^T \left( P \tau \Sigma P^T + \Omega \right)^{-1} \left( Q - P\Pi\right)

It is an expression that includes matrix multiplication and inverse matrix, but it looks like this when written in Python.

python


#Blending Investor View to Equilibrium Returns
r_posterior = r_eq + np.dot( np.dot( tau*np.dot(Sigma,P.T), np.linalg.inv(tau*np.dot(np.dot(P,Sigma),P.T)+Omega)), (Q-np.dot(P,r_eq)))

At the same time as the return $ \ Pi $, the covariance matrix $ \ Sigma $ is also updated as follows:

\Sigma' = \Sigma + \tau\Sigma - \tau\Sigma P^T \left( P \tau \Sigma P^T + \Omega \right)^{-1} P\tau\Sigma

Written in Python, it looks like this:

python


Sigma_posterior = Sigma + tau*Sigma - tau*np.dot( np.dot( np.dot(Sigma,P.T), np.linalg.inv(tau*np.dot(np.dot(P,Sigma),P.T)+Omega)), tau*np.dot(P,Sigma))

3. Find new weights by optimization

Finally, the optimization calculation is performed based on the updated return $ \ Pi'$ and the covariance matrix $ \ Sigma'$ to find the new optimal weight $ w'$. Here, the new weight $ w'$ is calculated by the following equation that solves the optimization problem analytically.

w' = \Pi' (\delta\Sigma')^{-1}

When written in code

python


#Perform Forward Optimization to find the optimum weight
w_posterior = np.dot(np.linalg.inv(delta*Sigma_posterior), r_posterior)

It will be.

Let's plot the old weight $ w $ and the new weight $ w'$ on the graph. I'm using the plot function of pandas.

python


df = pd.DataFrame([w.reshape(7),w_posterior.reshape(7)],
                  columns=['AUL','CAN','FRA','GER','JAP','UKG','USA'],
                  index=['Equilibrium Weights','Constrained Optimal Weights'])
df.T.plot(kind='bar', color='br')

The result looks like this. Blue represents the original market capitalization weight, and red represents the newly calculated portfolio weight that incorporates the investor's view. The result is that the weights of Canada and Germany will increase and the weights of France, the United Kingdom and the United States will decrease based on the outlook of investors. bl graph.png

in conclusion

In the implementation of the model, parameter setting such as $ \ delta, \ tau, \ Omega $ is important, and various setting methods are discussed and it is just a paper, but I omitted it this time. It's a Black-Litterman model with a sound that seems to be difficult, but wasn't it surprisingly easy? As explained in the article, it is an easy-to-use method because it rarely produces unexpected results like the conventional average-dispersion optimization method. If the number of assets is small, it can be calculated sufficiently even in Excel. Japanese literature is limited, so I hope it helps you to understand it.

References

--blacklitterman.org --Jay Walters' site -The Black-Litterman Model In Detail --Jay Walters' paper. In addition to the original BL model, it also covers various derivatives.

Recommended Posts

Let's explain the asset allocation by the Black-Litterman model (with an execution example by Python)
[Python] Explain the difference between strftime and strptime in the datetime module with an example
[Python] Get the script execution directory with an absolute path
[Python] Make the format function simpler (What is f-string? Explain the difference from the format function with an example)
[Python] Explains how to use the format function with an example
Let's tune the model hyperparameters with scikit-learn!
Let's read the RINEX file with Python ①
Let's develop an investment algorithm with Python 1
[Implementation example] Read the file line by line with Cython (Python) from the last line
Prepare the execution environment of Python3 with Docker
Let's write FizzBuzz with an error: Python Version
[Python] Clustering with an infinitely mixed Gaussian model
Solving the Lorenz 96 model with Julia and Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
Let's run jupyter natively supported by VS Code with python3.8
Why can I use the module by importing with python?
Let's get started with Python ~ Building an environment on Windows 10 ~
Let's tweet by hitting the terminal while screaming with Selenium! !!
Create an example game-like stage with just the Blender 2.80 script
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo