I have a dataset with 5 assets.
I apply mean-variance portfolio:
In<-rep(1,5) #identity vector
delta <- 5 #risk aversion parameter
covariance<-cov(sample.data) #covariance matrix
mu <- colMeans(sample.data) #mean returns
mu <- t(t(mu))
#I calculate the standard mean-variance weights:
xt <- 1/delta* solve(covariance) %*% mu
m.w <- as.vector(xt) / In %*% xt %*% t(In)
My problem is that sometimes it can happen that the denominator: In %*% xt #%*% t(In)
is a negative number.
Let us take the following example with 5 assets:
Mean returns: 6, 6, 1, 1, 1
Standard deviation of returns: 1, 1, 1, 1, 1
Portfolios with a mean of 6 are clearly superior, but the mean-variance calculation sometimes ends up putting large negative weights on the better assets.
This happens for the following reason:
Calculating xt
results in:
5.264789 6.134487 -5.267289 -3.337918 -2.79493
The denominator (In %*% xt #%*% t(In)
) is:
-0.0008615427 -0.0008615427 -0.0008615427 -0.0008615427 -0.0008615427
Since this denominator is negative and a really small number, the final weights end up being:
-6110.886 -7120.352 6113.787 3874.351 3244.1
Clearly this should be the other way round.
What am I missing?
EDIT: noob2 suggested that the problem might be that the covariance matrix is slightly negative definite, but it's not:
> eigen(covariance)
$values
[1] 4.90387493 0.12627889 0.11649928 0.09035977 0.07858112
$vectors
[,1] [,2] [,3] [,4] [,5]
[1,] -0.4529396 0.7235119 -0.1188464 -0.01716486 -0.50690946
[2,] -0.4664390 -0.2146771 -0.1914489 -0.81623850 0.18289445
[3,] -0.4511018 -0.6111482 -0.3089085 0.39903609 -0.41030564
[4,] -0.4289843 0.2157315 -0.2459586 0.41078039 0.73498045
[5,] -0.4356145 -0.1019909 0.8906754 0.07409282 0.03233327
Here's some example data with the properties described above:
https://www.dropbox.com/s/t3212c5sq7w1uug/example.Rdata?dl=0