2
votes

EDIT: I fixed it, the ReDim and all starts at 0 and not 1 so I had a cell that was empty which wasn't supposed to be there! It now works, thanks for the help!

I'm trying to take a matrix and invert it, but for some reason I get this error:

Unable to get the MInverse property of the WorksheetFunction class.

My (relevant) code is as following:

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)

This last row is where the error occurs.

I've tried many things, having covar and covarInv dim as double, variant etc. Different ReDims on covar and covarInv.

1
Unable to get the MInverse property of the WorksheetFunction class. - Sam

1 Answers

0
votes

You don't say what version of Excel you are using, but with Excel 2010 there seems to be a Minverse maximum limit of 200 * 200 (for Excel 2003 its probably around 80 * 80): How many asset names do you have?