Programming help

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
--------------------------------------------------------------------
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
I have tried 1 week for debugging. But failed.

Where am I wrong? I can't find it out....

Can anyone help me?
 
Actually, I didn't fix whole code (I made this code not only for up-out but also down - out ..... whole kinds of basic barrier option). Anyway after fix discount terms for rebate, some barrier has almost zero errors from exact sol.


Input
K: rebate

S 100
K 3
T 0.5
r 0.08
b 0.04
σ 0.25
σ 0.3

Here all exact solutions.

Type X H σ = 0.25 σ = 0.3
C_do 90 95 9.0246 8.8334

9.0246 is the exact sol for 0.25 (std) ...
X: strike price H : barrier
 
Back
Top Bottom