- Joined
- 7/26/12
- Messages
- 5
- Points
- 11
I am just making up - out barrier option using Monte carlo method in EXCEL VBA
But I have some problems, the result of the below fuction is different from exact solutions.
-------------------------------------------------------------------
Here X is strike price
H is barrier
S is stock price
K is rebate
--------------------------------------------------------------------
I have tried 1 week for debugging. But failed.
Where am I wrong? I can't find it out....
Can anyone help me?
But I have some problems, the result of the below fuction is different from exact solutions.
-------------------------------------------------------------------
Here X is strike price
H is barrier
S is stock price
K is rebate
--------------------------------------------------------------------
Code:
Function MC_Barrier(TypeFlag As String, X As Double, _
h As Double, Sigma As Double, S As Double, K As Double, Start_date As Date, End_date As Date, _
r As Double, q As Double, N As Long)
Dim Stock As Double, Payoff As Double, Sum As Double, T As Double, NumPath As Double
Dim hit As Double
Dim i As Double, j As Long
Dim dt As Double, drift As Double, vsqrt As Double
Dim test2 As Double
T = (End_date - Start_date) / 365
NumPath = (End_date - Start_date)
dt = T / NumPath 'Time step
drift = (r - q - (Sigma ^ 2) / 2) * dt
vsqrt = Sigma * Sqr(dt)
Sum = 0
Application.StatusBar = "Calculating Barrier option using monte carlo method, please wait........."
For j = 1 To N
Stock = S
Payoff = 0
hit = 0
For i = 1 To NumPath
Randomize
Stock = Stock * Exp(drift + vsqrt * SNRnd())
Select Case TypeFlag
Case Is = "C_uo"
If Stock >= h Then
hit = 1
Exit For
End If
End Select
Next i
Select Case TypeFlag
Case Is = "C_uo"
If hit = 1 Then
Payoff = K
Else
Payoff = Application.Max(0, Stock - X)
End If
End Select
Sum = Sum + Payoff
Next j
MC_Barrier = (Sum / N) * Exp(-r * T)
End Function
Function SNRnd()
Randomize
'Randomize uses Number to initialize the Rnd function's random-number generator, giving it a new seed value.
SNRnd = Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() _
+ Rnd() + Rnd() + Rnd() + Rnd() + Rnd() - 6
End Function
Where am I wrong? I can't find it out....
Can anyone help me?