13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.130 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.1313:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.13

.

.

Monday, February 22, 2010

Excel VBA - Functions

Function EndingMktVal(EndW As Single, ETFprcAtExp, CallStk, CallExPrice, CallPriceAtEntry, CallCalled, PutStk, PutCalled, PutExPrice, PutPriceAtEntry)


Dim EndValETF, PutPrem, CallPrem, CallDmg, PutDmg As Currency
Dim RedEndQ As Variant



RedEndQ = ((EndW / 100) * 100)
EndValETF = RedEndQ * ETFprcAtExp
CallPremium = RedEndQ * CallPrc
PutPremium = RedEndQ * PutPrc
CallDmg = ((RedEndQ * (ETFprcAtExp - CallStk)) + CallPremium)
PutDmg = ((RedEndQ * (PutStk - ETFprcAtExp)) + PutPremium)


If (CallCalled = "No" Or CallCalled = "no" And PutCalled = "No" Or PutCalled = "no") Then
EndingMktVal = EndValETF + CallInMoney + PutInMoney
ElseIf (CallCalled = "Yes" Or CallCalled = "yes" And PutCalled = "No" Or PutCalled = "no") Then
EndingMktVal = EndValETF + PutPremium + CallDmg
ElseIf (CallCalled = "No" Or CallCalled = "no" And PutCalled = "Yes" Or PutCalled = "yes") Then
EndingMktVal = EndValETF + CallPremium + PutDmg
ElseIf (CallCalled = "Yes" Or CallCalled = "yes" And PutCalled = "Yes" Or PutCalled = "yes") Then
EndingMktVal = EndValETF + CallDmg + PutDmg

End If
End Function

==================================================================

























Function SNorm(z)

Application.ScreenUpdating = False

c1 = 2.506628
c2 = 0.3193815
c3 = -0.3565638
c4 = 1.7814779
c5 = -1.821256
c6 = 1.3302744
If z > 0 Or z = 0 Then
w = 1
Else: w = -1
End If
y = 1 / (1 + 0.2316419 * w * z)
SNorm = 0.5 + w * (0.5 - (Exp(-z * z / 2) / c1) * _
(y * (c2 + y * (c3 + y * (c4 + y * (c5 + y * c6))))))

Application.ScreenUpdating = True

End Function

'**********************************************************************
'* Black-Scholes European Call Price Computation *
'**********************************************************************

Function Call_Eur(s, x, t, r, sd)

Application.ScreenUpdating = False
Dim a As Single
Dim b As Single
Dim c As Single
Dim d1 As Single
Dim d2 As Single

a = Log(s / x)
b = (r + 0.5 * sd ^ 2) * t
c = sd * (t ^ 0.5)
d1 = (a + b) / c
d2 = d1 - sd * (t ^ 0.5)
Call_Eur = s * SNorm(d1) - x * Exp(-r * t) * SNorm(d2)

Application.ScreenUpdating = True

End Function

'*********************************************************************
'* Black-Scholes European Put Price Computation *
'*********************************************************************

Function Put_Eur(s, x, t, r, sd)

Application.ScreenUpdating = False


Dim a As Single
Dim b As Single
Dim c As Single
Dim d1 As Single
Dim d2 As Single

a = Log(s / x)
b = (r + 0.5 * sd ^ 2) * t
c = sd * (t ^ 0.5)
d1 = (a + b) / c
d2 = d1 - sd * (t ^ 0.5)
CallEur = s * SNorm(d1) - x * Exp(-r * t) * SNorm(d2)
Put_Eur = x * Exp(-r * t) - s + CallEur

Application.ScreenUpdating = True

End Function
Equals (=)
Less than (<) Less than or equal to (<=) Greater than (>)
Greater than or equal to (>=)
Not equal to (<>)