Monte Carlo Setup for an Up-and-Out Barrier Option
Summary
This document presents a Monte Carlo approach to pricing an up-and-out call option. It simulates geometric Brownian motion paths from an initial stock price, computes each path’s maximum, and discounts the terminal call payoff only for paths that stay below the barrier. The example specifies the initial price, volatility, interest rate, strike, maturity, barrier, and simulation count, then reports a simulated price alongside a closed-form comparison.
The reported simulation estimate differs from the stated closed-form value, but the exchange contains no answer diagnosing the source. The code uses discrete observation dates, so the simulated barrier condition can miss a crossing between time steps; that can bias a barrier price. The function also refers to the strike through an external variable rather than taking it as an argument, and the displayed time-step calculation warrants scrutiny for fractional maturities. No variance reduction, convergence assessment, or corrected implementation is supplied, so this is an incomplete debugging example rather than a validated pricing recipe.
Key ideas
- The example simulates geometric Brownian motion paths and evaluates an up-and-out call payoff.
- A path contributes only when its simulated maximum remains below the barrier.
- The discounted Monte Carlo estimate is compared with a stated closed-form price.
- Discrete path observations can miss barrier crossings between time steps.
- The document reports a pricing discrepancy but does not identify or correct its cause.
Tags
Full text
# Monte Carlo Pricing of Barrier Options - can't figure out where I'm wrong
# Monte Carlo Pricing of Barrier Options - can't figure out where I'm wrong
I'm trying to price a simple Up-and-out Barrier option using Monte Carlo; haven't even implemented the variance reduction but it's already glitching.
The code seems right, but I'm not sure where it's going wrong.
```
nsims = 100000
discrete_freq = 252
S0 = 50
sig = .3
r = .05
K = 60
T = .25
H = 55
```
```
# simulates GBM paths
def simulate_gbm_paths(nsims, S0, sig, mu, T, discrete_freq):
'''
nsims: number of simulations to produce
S0: initial stock price
sig: volatility expressed as a percentage
mu: annualized drift expressed as a percentage
r: interest rate
T: time in years
discrete_freq: number of discrete time intervals per increment of T (252 would be 1 trading year)
'''
nparts = int(T)*discrete_freq + int(discrete_freq * (T - np.floor(T)))
dt = T / nparts
Xt = np.log(S0) + np.cumsum(( (mu - sig**2/2)*dt + sig*np.sqrt(dt) * np.random.normal(size=(nparts,nsims)) ), axis=0)
Xt = np.exp(Xt)
Xt = np.vstack([np.repeat(S0, nsims), Xt])
return Xt
def barrier_option_pricing_monte_carlo(nsims, S0, sig, r, T, discrete_freq, H, optype = "uop"):
gbm_sim = simulate_gbm_paths(nsims, S0, sig, r, T, discrete_freq)
max_array = np.max(gbm_sim, axis=0)
if optype == "uop":
return np.exp(-r*T) * np.sum((np.maximum(K - gbm_sim[-1], 0) * (max_array < H)*1)) * 1/nsims
```
```
barrier_option_pricing_monte_carlo(nsims, S0, sig, r, T, discrete_freq, H, optype="uop")
```
```
# 7.352723976215193
# real pricing according to closed form solution: $ 6.869
```
I've been staring at this for a while, and I can't figure out how it's wrong. I appreciate any help you can provide. ThanksShown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.