- Joined
- 11/5/14
- Messages
- 295
- Points
- 53
Hi friends,
I am trying to price a down-and-in barrier call option. Lyuu's book gives a simple combinatorial formula for the probability that the underlying hits the barrier and makes \(j\) upward moves, as
\({{n}\choose{n-2h+j}}p^{j}q^{n-j}\)
However, when I implement the algorithm in Python, the option value isn't close to the Black-Scholes price, no matter what \(n\)(number of time steps), I choose. Am I doing something fundamentally wrong? This is my code snippet:
If anybody has a piece of code that works, that would help as well.
Maybe binomial tree algorithms only have pedagogical value, simple and intuitive. As an aside, therefore, what method would a pricing engine in the real world use to price a barrier - numerically solve the PDE or Monte Carlo?
Thanks in advance guys,
Quasar
I am trying to price a down-and-in barrier call option. Lyuu's book gives a simple combinatorial formula for the probability that the underlying hits the barrier and makes \(j\) upward moves, as
\({{n}\choose{n-2h+j}}p^{j}q^{n-j}\)
However, when I implement the algorithm in Python, the option value isn't close to the Black-Scholes price, no matter what \(n\)(number of time steps), I choose. Am I doing something fundamentally wrong? This is my code snippet:
# Optimal algorithm for European down-and-in call barrier options
import numpy as np
import math
def priceDownAndInCall(S, X, H, r, sigma,
T, N, optionType):
# Binomial tree parameters
dt = T/N
u = math.exp(sigma*math.sqrt(dt))
d = 1/u
disc = math.exp(-r*T)
a = math.log(X/(S*(d**N)))/math.log(u/d)
a = math.ceil(a)
h = math.log(H/(S*(d**N)))/math.log(u/d)
h = math.floor(h)
# Risk-neutral probabilities
p = (math.exp(r*dt)-d)/(u-d)
q = 1-p
# Start at layer 2h
S = S * (u**(2*h)) * (d**(N-2*h))
b = 1 * (p**(2*h)) * (q ** (N-2*h))
C = b * (S-X)
for j in range(2*h-1,a-1,-1):
b = (p*(N-2*h+j+1)/(q*(2*h-j)))*b
S = S * (d/u)
C = C + b * (S-X)
return disc * C
C = priceDownAndInCall(100, 102, 97, 0.05, 0.20, 1, 50, 'C')
print(C)
If anybody has a piece of code that works, that would help as well.
Maybe binomial tree algorithms only have pedagogical value, simple and intuitive. As an aside, therefore, what method would a pricing engine in the real world use to price a barrier - numerically solve the PDE or Monte Carlo?
Thanks in advance guys,
Quasar
Last edited: