Reputation: 17
Can somebody help with the below as i have been struggling for sometime.
Marginal contribution to risk= To find the marginal contribution of each asset, take the cross-product of the weights vector and the covariance matrix divided by the portfolio standard deviation.
Now multiply the marginal contribution of each asset by the weights vector to get total contribution. We can then sum the asset contributions and make sure it’s equal to the total portfolio standard deviation.
Relativeweights = np.array([0.02, -0.025, -0.015, 0.0, 0.02,0,0,0])
cov_matrix_a= 8x8 matrix
Port_volatility= 0.05882615906289199
So i have tried the following code;
MCTAR=(np.dot(Relativeweights,cov_matrix_a))/Port_volatility
TCTPR=MCTAR*Relativeweights
np.sum(TCTPR, axis=0)
This doesn't sum to the portfolio volatility so not sure what is wrong?
Any help appreciated. Thanks
Full code below;
import numpy as np
import ST as STPL
Assetreturns = STPL.get_Asset_returns()
cov_matrix_Assetreturns = Assetreturns.cov()
cov_matrix_Assetreturns
cov_matrix_a = cov_matrix_Assetreturns * 252
cov_matrix_a
Relativeweights = np.array([0.02, -0.025, -0.015, 0.0, 0.02,0,0,0])
Relativeweights
Portweights = np.array([0.49, 0.15, 0.125, 0.215, 0.02, 0, 0,0])
Portweights
Port_volatility = np.sqrt(np.dot(Portweights.T, np.dot(cov_matrix_a, Portweights)))
Port_volatility
MCTAR=(np.dot(Relativeweights,cov_matrix_a))/Port_volatility
TCTPR=MCTAR*Relativeweights
np.sum(TCTPR, axis=0)
Upvotes: 2
Views: 6285
Reputation: 108
If you equate Relativeweights = Portweights, then the multiplications work out to the answer you expect.
Upvotes: 1