# Pricing Knock Out Barrier Options by solving Black Scholes PDE (MATLAB)

This question is based on MATLAB functions.

Suppose there is a stock S following the process

## $$dS_t=(r-q)S_tdt+\sigma(S_t,t)dW_t$$

r - risk-free rate, q - dividend yield, W - Weiner process

The Local Volatility Surface has been given

## $$\sigma(S,t)=0.25.e^{-t}(100/S)^\alpha$$

Option Price $$V(S,t)$$ being given as

## $$\frac{\delta V}{\delta t}+\frac{1}{2}\frac{\delta^{2}V}{\delta S^{2}}\sigma(S,t)^{2}S^{2}+(r-q)S\frac{\delta V}{\delta S}-rV=0$$

We are supposed to use Explicit, Implicit and Crank-Nicholson Finite Difference schemes respectively to solve for the option price. However, as you can see, this is a barrier call option.

The barrier being B = £130.

$$S_0=$$ £ 100, $$K=$$ £ 100, $$r=$$ 3% i.e the risk-free-rate

$$q=$$ 5% the dividend yield, time to maturity $$T=$$ 0.5, $$\alpha$$ in the local volatility function = 0.35

The pay-off function is given as

# $$h_{up-and-out{call}}(S_T)= max(S_T-K,0),\; if \;max_{0\leq{t}\leq{T}}S_t.

## {0 in other cases}

My attempt

I present my thought process here. I already have the Matlab code related to solving European Call option using the above three iteration methods described. In summary, I am unable to code the barrier option. I provide a picture below what I am aiming for. 1. The stock price is a random variable varying with time, the maturity date for options is 0.5; i.e $$t\in[0,0.5]$$
2. It is easier to solve when the $$\sigma$$ is a fixed value, here being a r.v. has made it difficult.
3. I have tried adding the if-else condition to a usual European Call pricing code, however it is giving me back error.
4. We need to modify the boundary condition to fit to that of barrier option (maybe)

I tried adding the following piece of code to the script below in link.

if S<=B
Vold = max(S-K,0)
else
Vold = 0
end