Reputation: 5
On R version 2.15.2, while using the ES function in PerformanceAnalytics:
ES(R=indexes, weights=w)
I get the following error:
Error in t(w) %*% M3 : requires numeric/complex matrix/vector arguments
where w is
[,1]
[1,] 0.5
[2,] 0.5
both is.matrix(w) and is.numeric(w) return TRUE
Calling the function without passing weights (i.e. ES(R=indexes) ) works.
How do I resolve this?
Upvotes: 0
Views: 2391
Reputation: 121608
Using this edhec data (given with package) and the weights vector I can reproduce the error ( Please give a reproducible example next time, otherwise we will not be sure to give sense to the following answer)
weights <- c(0.2, 0.2, 0.1, 0.1, 0.5) ## must be to number of columns in R"
ES(R = edhec[,1:5], weights= weights)
Error in t(w) %*% M3 : requires numeric/complex matrix/vector arguments
The error because the M3 matrix is null. You need to change the argument portfolio_method
from the default single
to component
. The help talk about weights in the Component ES part, so this make sense. Otherwise , I think you need to suplly m3,m4, mu...(painful)
Try this
ES(R = edhec[,1:5], weights= weights,
portfolio_method= 'component')
$MES
[,1]
[1,] 0.0331994
$contribution
Convertible Arbitrage CTA Global Distressed Securities Emerging Markets Equity Market Neutral
0.015504952 -0.006116166 0.004702236 0.007760899 0.011347477
$pct_contrib_MES
Convertible Arbitrage CTA Global Distressed Securities Emerging Markets Equity Market Neutral
0.4670251 -0.1842252 0.1416362 0.2337662 0.3417977
Upvotes: 3