Thread: MMult and MInv
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
tedy tedy is offline
external usenet poster
 
Posts: 7
Default MMult and MInv

Hi Bob,

Thanks for your reply! It works....

I'm now trying to implement the test sub into the actual sub, but
instead, i got the same error message on the MINVERSE rather than the
previous MMULT. The problem is when i tried to inverse the array1 into
array1inv....

Here is my sub:

Public Function NeutraliseAll(type1 As String, s1 As Single, x1 As
Single, t1 As Single, r1 As Single, sd1 As Single, q1 As Single, type2
As String, s2 As Single, x2 As Single, t2 As Single, r2 As Single, sd2
As Single, q2 As Single, deltaPort As Single, gammaPort As Single,
vegaPort As Single)

Dim delta1 As Single
Dim delta2 As Single
Dim gamma1 As Single
Dim gamma2 As Single
Dim vega1 As Single
Dim vega2 As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim array1(1 To 2, 1 To 2) As Single
Dim array1inv
Dim array2(1 To 2) As Single
Dim arrayresult

'calculate delta of option 1

If type1 = "Call" Then
delta1 = Delta_Call(s1, x1, t1, r1, sd1, q1)
Else
delta1 = Delta_Put(s1, x1, t1, r1, sd1, q1)
End If

'calculate delta of option 2

If type2 = "Call" Then
delta2 = Delta_Call(s2, x2, t2, r2, sd2, q2)
Else
delta2 = Delta_Put(s2, x2, t2, r2, sd2, q2)
End If


'calculate gamma of option 1 and 2
gamma1 = Gamma(s1, x1, t1, r1, sd1, q1)
gamma2 = Gamma(s2, x2, t2, r2, sd2, q2)

'calculate vega of option 1 and 2
vega1 = Vega(s1, x1, t1, r1, sd1, q1)
vega2 = Vega(s2, x2, t2, r2, sd2, q2)

array1(1, 1) = gamma1
array1(1, 2) = gamma2
array1(2, 1) = vega1
array1(2, 2) = vega2

array2(1) = gammaPort * -1
array2(2) = vegaPort * -1

array1inv = Application.WorksheetFunction.MInverse(array1())
arrayresult = Application.WorksheetFunction.MMult(array1inv,
Application.Transpose(array2))

n1 = arrayresult(1, 1)
n2 = arrayresult(2, 1)

n3 = -1 * ((n1 * delta1) + (n2 * delta2) + deltaPort)

GreeksHedgingForm.txtNewAsset.Value = n3
GreeksHedgingForm.txtNewOpt1.Value = n1
GreeksHedgingForm.txtNewOpt2.Value = n2

End Sub

Any help is much appreciated!