Compute Minimum Variance Portfolio
This post will describe how to compute the minimum variance portfolio. Minimum variance portfolio is closely related to the Maximum Sharpe Ratio Portfolio. Minimum variance Portfolio is just a special case of the Maximum Sharpe Ratio Portfolio, where the returns of each asset is assumed to be equal, then the optimiser simply focuses on the variances. If the asset returns are incorporated into the optimiser, it will incorporate both factors while computing the optimal result.
Physical meaning: These three short videos offer an excellent explanation:
1. Video 1: https://www.youtube.com/watch?v=3SzYWjLDCSY
2. Video 2: https://www.youtube.com/watch?v=y-hADD-nwb4
3. Video 3: https://www.youtube.com/watch?v=fNIoVdDNFmk
Practical use: Asset Managers can use this formula to determine the weightage in which they should hold different assets to minimise variance. What is the interesting is that we need only covariance matrix to compute the minimum variance portfolio. This is why it is also important that the covariance matrix is denoised, so that we calculate this portfolio accurately.
Compute by hand: The three videos above also cover this.
Compute using Python: This blog post provides an excellent explanation of the formulae to compute the minimum variance portfolio analytically; https://breakingdownfinance.com/finance-topics/modern-portfolio-theory/minimum-variance-portfolio/
#File: Mean-Variance-Optimisation.py# Import Libraries
import numpy as np
import pandas as pd
# Raw data
mean = [[3], [5]] # Mean return of each asset
var = [1.5,4.2] # Variance of return of each asset
corr = -0.7 # Correlation between asset returns
# Compute Covariance matrix, in matrix format, using Linear Algebra
std = np.sqrt(var)
std = [[std[0],0],[0,std[1]]]
corr = [[1,corr],[corr,1]]
cov= np.dot(std,corr).dot(std) # Linear Algebra property
print(cov)
# Determine Minimum Variance Portfolio Analytically
# Only Covariance matrix is necessary to compute Minimum Variance Portfolio
def minimum_variance(cov):
inv = np.linalg.inv(cov)
mu = np.ones(shape=(inv.shape[0],1))
ones = np.ones(shape=(inv.shape[0],1))
w = np.dot(inv,mu)
w = w / (np.dot(ones.T,w))
return w
print(minimum_variance(cov))
# Determine Maximum Sharpe Ratio Portfolio Analytically
# Covariance matrix, and vector of mean returns are necessary to compute Maximum Sharpe Ratio Portfolio
def max_sharpe(cov,mean):
inv = np.linalg.inv(cov)
mu = np.ones(shape=(inv.shape[0],1))
mu = np.multiply(mean,mu)
ones = np.ones(shape=(inv.shape[0],1))
w = np.dot(inv,mu)
w = w / (np.dot(ones.T,w))
return w
print(max_sharpe(cov,mean))
Comments
Post a Comment