0

在 R 版本 2.15.2 上,在 PerformanceAnalytics 中使用 ES 函数时:

ES(R=indexes, weights=w)

我收到以下错误:

Error in t(w) %*% M3 : requires numeric/complex matrix/vector arguments

w 是

      [,1]
[1,]  0.5
[2,]  0.5

is.matrix(w) 和 is.numeric(w) 都返回 TRUE

在不传递权重的情况下调用函数(即 ES(R=indexes) )有效。

我该如何解决这个问题?

4

1 回答 1

3

使用这个 edhec 数据(与包一起给出)和权重向量我可以重现错误(下次请给出一个可重现的例子,否则我们将无法确定以下答案是否有意义)

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

由于 M3 矩阵为空而导致的错误。您需要将参数portfolio_method从默认值更改singlecomponent. 帮助讨论Component ES部分中的权重,所以这是有道理的。否则,我认为您需要提供 m3,m4,mu ...(痛苦)

试试这个

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 
于 2013-01-27T14:20:28.873 回答