2

编辑:我修复了它,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 暗淡为双精度、变体等。 covar 和 covarInv 上的不同 ReDims。

4

1 回答 1

0

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

于 2013-11-12T14:06:00.143 回答