[FONT="]Hello fellow members, [/FONT]
[FONT="]I am new to this forum and to VBA and am seeking help in finding the error for my makro in VBA. I am trying to value a down-and-out put barrier option with the adjusted BS formula from Haug (I left out F because there is no Rebate). I inserted the formula I want to use and my VBA code plus sheet. [/FONT]
[FONT="]Any help is highly appreciated and karma will be given to you! [/FONT]
[FONT="]Thanks in advance!![/FONT]
[FONT="]John
Formula from BS, modified by Rubinstein and later by Haug:
[/FONT]
pdo(K>B) = A – B + C – D + F
Φ = -1 η = 1
A = ΦSe(cc-rf)TN(Φx1) - Φ Ke- rfTN(Φx1-Φσ√T)
B = ΦSe(cc- rf)TN(Φx2) - Φ Ke- rfTN(Φx2-Φσ√T)
C = ΦSe(cc- rf)T(B/S)2(μ+1)N(ηy1)-Φ Ke- rfT(B/S)2μN(ηy1-ησ√T)D = ΦSe(cc- rf)T(B/S)2(μ+1)N(ηy2)-Φ Ke- rfT(B/S)2μN(ηy2-ησ√T)F = PDCP*[(B/S)μ+λN(ηz)+(B/S)μ-λN(ηz-2ηλσ√T)]
x1 = [ln(S/K) / σ√T] + (1 + μ)σ√Ty1 = [ln(B2 / SK) / σ√T] + (1+μ)σ√Tz = [ln (B / S) / σ√T] + λσ√T
x2 = [ln(S/B) / σ√T]+(1+μ)σ√T
y2 = [ln(B/S) / σ√T] + (1+μ)σ√Tμ = (cc - σ2 / 2) /σ2 λ = [(μ2 + (2rf/σ2))]1⁄2
[FONT=Open Sans, Helvetica, Arial, sans-serif]My VBA makro:
[/FONT]Function DOP_BS(ByVal S0 As Double, _
ByVal X As Double, _
ByVal B As Double, _
ByVal T As Double, _
ByVal rf As Double, _
ByVal Vola As Double, _
ByVal m As Long, _
Optional ByVal q As Double)
Dim x_1 As Double, _
x_2 As Double, _
y_1 As Double, _
y_2 As Double, _
z As Double, _
u As Double, _
lambda As Double
If IsMissing(q) Then q = 0#
x_1 = (Log(S / X)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
x_2 = (Log(S / B)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
y_1 = (Log(B ^ 2 / S * X)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
y_2 = (Log(B / S)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
z = (Log(B / S)) / Vola * Sqr(T) + lambda * Vola * Sqr(T)
u = (rf - (Vola ^ 2) / 2) / Vola ^ 2
lambda = Sqr(u ^ 2 + ((2 * r) / Vola ^ 2))
Dim A As Double, _
B As Double, _
C As Double, _
D As Double, _
E As Double
A = -1 * S0 * Exp(-rf * T) * SNV(-x_1) + X * Exp(-rf * T) * SNV(-x_1 + Vola * Sqr(T))
B = -1 * S0 * Exp(-rf * T) * SNV(-x_2) + X * Exp(-rf * T) * SNV(-x_2 + Vola * Sqr(T))
C = -1 * S0 * Exp(-rf * T) * (B / S) * Exp(2 * (u + 1)) * SNV(y_1) + X * Exp(-rf * T) * (B / S) * Exp(2 * u) * SNV(y_1 - Vola * Sqr(T))
D = -1 * S0 * Exp(-rf * T) * (B / S) * Exp(2 * (u + 1)) * SNV(y_2) + X * Exp(-rf * T) * (B / S) * Exp(2 * u) * SNV(y_2 - Vola * Sqr(T))
DOP_BS = A - B + C - D
End Function
THANK YOU!
[FONT="]I am new to this forum and to VBA and am seeking help in finding the error for my makro in VBA. I am trying to value a down-and-out put barrier option with the adjusted BS formula from Haug (I left out F because there is no Rebate). I inserted the formula I want to use and my VBA code plus sheet. [/FONT]
[FONT="]Any help is highly appreciated and karma will be given to you! [/FONT]
[FONT="]Thanks in advance!![/FONT]
[FONT="]John
Formula from BS, modified by Rubinstein and later by Haug:
[/FONT]
pdo(K>B) = A – B + C – D + F
Φ = -1 η = 1
A = ΦSe(cc-rf)TN(Φx1) - Φ Ke- rfTN(Φx1-Φσ√T)
B = ΦSe(cc- rf)TN(Φx2) - Φ Ke- rfTN(Φx2-Φσ√T)
C = ΦSe(cc- rf)T(B/S)2(μ+1)N(ηy1)-Φ Ke- rfT(B/S)2μN(ηy1-ησ√T)D = ΦSe(cc- rf)T(B/S)2(μ+1)N(ηy2)-Φ Ke- rfT(B/S)2μN(ηy2-ησ√T)F = PDCP*[(B/S)μ+λN(ηz)+(B/S)μ-λN(ηz-2ηλσ√T)]
x1 = [ln(S/K) / σ√T] + (1 + μ)σ√Ty1 = [ln(B2 / SK) / σ√T] + (1+μ)σ√Tz = [ln (B / S) / σ√T] + λσ√T
x2 = [ln(S/B) / σ√T]+(1+μ)σ√T
y2 = [ln(B/S) / σ√T] + (1+μ)σ√Tμ = (cc - σ2 / 2) /σ2 λ = [(μ2 + (2rf/σ2))]1⁄2
[FONT=Open Sans, Helvetica, Arial, sans-serif]My VBA makro:
[/FONT]Function DOP_BS(ByVal S0 As Double, _
ByVal X As Double, _
ByVal B As Double, _
ByVal T As Double, _
ByVal rf As Double, _
ByVal Vola As Double, _
ByVal m As Long, _
Optional ByVal q As Double)
Dim x_1 As Double, _
x_2 As Double, _
y_1 As Double, _
y_2 As Double, _
z As Double, _
u As Double, _
lambda As Double
If IsMissing(q) Then q = 0#
x_1 = (Log(S / X)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
x_2 = (Log(S / B)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
y_1 = (Log(B ^ 2 / S * X)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
y_2 = (Log(B / S)) / Vola * Sqr(T) + (1 + u) * Vola * Sqr(T)
z = (Log(B / S)) / Vola * Sqr(T) + lambda * Vola * Sqr(T)
u = (rf - (Vola ^ 2) / 2) / Vola ^ 2
lambda = Sqr(u ^ 2 + ((2 * r) / Vola ^ 2))
Dim A As Double, _
B As Double, _
C As Double, _
D As Double, _
E As Double
A = -1 * S0 * Exp(-rf * T) * SNV(-x_1) + X * Exp(-rf * T) * SNV(-x_1 + Vola * Sqr(T))
B = -1 * S0 * Exp(-rf * T) * SNV(-x_2) + X * Exp(-rf * T) * SNV(-x_2 + Vola * Sqr(T))
C = -1 * S0 * Exp(-rf * T) * (B / S) * Exp(2 * (u + 1)) * SNV(y_1) + X * Exp(-rf * T) * (B / S) * Exp(2 * u) * SNV(y_1 - Vola * Sqr(T))
D = -1 * S0 * Exp(-rf * T) * (B / S) * Exp(2 * (u + 1)) * SNV(y_2) + X * Exp(-rf * T) * (B / S) * Exp(2 * u) * SNV(y_2 - Vola * Sqr(T))
DOP_BS = A - B + C - D
End Function
THANK YOU!