我的MInverse功能在VBA中不起作用

时间:2013-11-12 10:43:03

标签: excel vba excel-vba

编辑:我修复它,ReDim和所有从0开始而不是1,所以我有一个空的单元格,不应该在那里! 它现在有效,谢谢你的帮助!

我正在尝试取一个矩阵并将其反转,但出于某种原因我得到了这个错误:

  

无法获取WorksheetFunction类的MInverse属性。

我的(相关)代码如下:

Dim covar() As Variant
ReDim covar(UBound(assetNames), UBound(assetNames))
Dim corr() As Double
ReDim corr(UBound(assetNames), UBound(assetNames))

Dim covarTmp As Double
For i = 0 To UBound(assetNames) - 1
    For j = 0 To UBound(assetNames) - 1
        covarTmp = 0
        For t = 1 To wantedT
            covarTmp = covarTmp + (Log((prices(histAmount + 1 - t, i + 1)) / (prices(histAmount - t, i + 1))) - mu(i) * dt) * (Log((prices(histAmount + 1 - t, j + 1)) / (prices(histAmount - t, j + 1))) - mu(j) * dt)
        Next t
        covar(i, j) = covarTmp * (1 / ((wantedT - 1) * dt))
        corr(i, j) = covar(i, j) / (sigma(i) * sigma(j))
    Next j
Next i


Dim covarInv() As Variant
ReDim covarInv(UBound(assetNames), UBound(assetNames))
'ReDim covar(1 To UBound(assetNames), 1 To UBound(assetNames))

covarInv = Application.WorksheetFunction.MInverse(covar)

最后一行是发生错误的地方。

我尝试过很多东西,covar和covarInv dim为double,variant等。在covar和covarInv上有不同的ReDims。

1 个答案:

答案 0 :(得分:0)

您没有说出您正在使用的Excel版本,但是使用Excel 2010时,似乎有一个Minverse最大限制为200 * 200(对于Excel 2003,它可能大约为80 * 80):您有多少资产名称?有?