I am currently trying to price an up-and-out call with Monte Carlo simulation. For an option with these parameters :
- Barrier: 65
- $K$ = 50
- $\sigma$ = 30%
- $R $ = 1%
- $T$ = 1Y
- $S_0$ = 50
With 10.000 simulations and $dt = \frac{1}{500}$ I obtain an option price close to 0.80 (95% interval confidence : [0.76 ; 0.853]) whereas a pricer gives 0.73. When rising number of simulations the price increases so I am likely doing something wrong.
Here is the python chunk of code that I use:
all_final_payoffs = np.zeros((nb_simulations,1),dtype=float)
for i in tqdm(range(nb_simulations)):
path_generated_asset = np.zeros((1, nb_time), dtype=float)
path_generated_asset[0, 0] = S0
for j in range(1, nb_time):
X = np.random.randn(1)
path_generated_asset[0, j] = simulate_price(path_generated_asset[0, j - 1], interest_rate, volatility, dt, X)
all_final_payoffs[i,0] = compute_barrier_call_payoff(path_generated_asset[0,:],strike,barrier)
option_price = np.mean(all_final_payoffs)*math.exp(-interest_rate*maturity)
And the two functions used :
def compute_barrier_call_payoff(asset_path,strike,barrier):
if max(asset_path)>=barrier:
return 0
else:
if asset_path[-1]-strike>0:
return asset_path[-1]-strike
return 0
def simulate_price(S,R,Vol,dt,X):
return S*math.exp((R-(Vol**2)/2)*dt + Vol*math.sqrt(dt)*X)
Does someone know where my error is? Thanks a lot!
Edit: When increasing the number of simulations to 20.000 and time steps to 2000, I get the price in 3 minutes (very long) on Python. Same code in C# on the same Mac, the program gives me the result in 7 seconds. When increasing simulations to 50.000 and time steps to 4.000 it takes roughly 35 seconds to give me 0.74$.
Edit 2 : Launching the Python code with Cython and typed variables it takes 1 minute.