0
$\begingroup$

I tried to implement Matlab program computing the price of the European down and out call option using Monte Carlo and Euler discretization scheme. I have initial price S0=50, strike K=50, barrier level B=45 and time of expiration 6 months. The final price I obtain is very small(0.005). Even when I increase T to 1 or when I decrease the barrier, the price doesn't increase. I don't know what is the problem. I also have one additional question - how can I find Greeks(Delta,Vega,Gamma,Theta,Rho) with Monte Carlo simulation on this model? Here is my code:

function [Price]= BlackScholes (n,m,r,T,Var,S0,K,B)
Price=1:50;

for i=1:n
I=1;
for j = 0:(m-1);
Z(j+1)= randn (1 ,1); 
dW=sqrt (T/m)*Z(j+1);
if j==0 
S(j+1) = S0*exp((r-Var/2)*(T/m)+sqrt(Var)*dW);
if (I==1) & (S(j+1) <= B)
I = 0;
end
else 
S(j +1) = S(j)* exp ((r - Var /2) *(T/m) + sqrt ( Var )* dW); 
if all([ I==1 , S(j+1) <=B])
I = 0;
end
end
end 
C=zeros(n,1);
C(i)= exp(-r*T)* max ((S(m-1)-K), 0)*I;
Price = sum (C (1:n))/n; 
end

Thanks a lot!

$\endgroup$
  • $\begingroup$ Set $m=100$ and $n=10000$ $\endgroup$ – user16651 Jul 12 '16 at 9:07
  • $\begingroup$ You are pricing a down-and-out call with a barrier is below the strike: i.e. the option gets knocked-out when it is OTM... (1) What happens when you use for instance: $K=50$, $S_0=75$ and $B=60$? (2) What happens when you plot the option prices for different $S_0 \in [60, 80]$ with the same strike and barrier levels (3) The usual method to obtain Greeks is "bump & revalue", i.e. approximating Greeks by finite differences. In my experience, such a Naive approach is not always recommendable though, I'd rather try a "pathwise Greeks" approach. $\endgroup$ – Quantuple Jul 12 '16 at 9:14
  • $\begingroup$ Behrouz Maleki, when m=100, n=1000, price=2.6748e-04 @Quantuple (1) price =0.0037 (2) Nothing happens $\endgroup$ – Ксения Цочева Jul 12 '16 at 10:39
1
$\begingroup$

There are many things wrong with your code. I'll leave aside the manner in which it is implemented, but note that it is: (1) not Matlab friendly with all the for loops (you should vectorise), (2) the fact that you have splitted the case j==0 in the main loop is a poor coding practice.

for i=1:n

I=1;
for j = 0:(m-1);
    Z(j+1)= randn (1 ,1);
    dW=sqrt (T/m)*Z(j+1);
    if j==0
        S(j+1) = S0*exp((r-Var/2)*(T/m)+sqrt(Var)*dW);
        if (I==1) & (S(j+1) <= B)
            I = 0;
        end
    else
        S(j +1) = S(j)* exp ((r - Var /2) *(T/m) + sqrt ( Var )* dW);
        if all([ I==1 , S(j+1) <=B])
            I = 0;
        end
    end
end
C=zeros(n,1);                                           %%% [1] THIS IS WRONG
C(i)= exp(-r*T)* max ((S(m-1)-K), 0)*I;                 
Price = sum (C (1:n))/n;                                %%% [2] THIS IS USELESS

end

The reason you observe very small prices, is that only the last path of your MC simulation contributes to the option price. This is because at the line marked with [1] above, you always reinitialise the price vector as a vector full of zeros. Also note that the line [2] is pretty useless and should lie outside of the for loop.

I would recommend an implementation along the lines of:

function price = mc_pricer(n,m,r,T,var,S0,K,B)

rng(0);            
S = zeros(n,m);
S(:,1)=S0;
Z = randn(n,m-1);
t = linspace(0,T,m);
dt = diff(t);
for i=2:m
    S(:,i)=S(:,i-1).*exp( (r-var/2)*dt(i-1) + sqrt(var*dt(i-1))*Z(:,i-1) );
end
S_T = S(:,end);
payoff = max(S_T-K, 0).*(1-any(S<=B,2));
price = exp(-r*T)*mean(payoff);

end
$\endgroup$
  • $\begingroup$ Thank you very much! Now the price is 3.9. Is it good? I will be very thankful if you help me with finding Greeks. I found a formula for Delta only, but I don't know how to find the others. $\endgroup$ – Ксения Цочева Jul 12 '16 at 12:17
  • $\begingroup$ Simply use this: $\frac{\partial V}{\partial \theta} \approx \frac{V(\theta+\epsilon)-V(\theta-\epsilon)}{2\epsilon}$. So for instance for Vega, the model parameter you should bump is the volatility $\sigma$. You then run one pricing with $\sigma^+ = \sigma + \epsilon$, save the obtained price $V^+$, one pricing with $\sigma^- = \sigma - \epsilon$, save the obtained price $V^-$. Finally you write: $\text{Vega} = \frac{\partial V}{\partial \sigma} \approx \frac{V^+ - V^-}{2\epsilon}$. The quality of your Greek estimation will depend on the size of the wedge $\epsilon$. $\endgroup$ – Quantuple Jul 12 '16 at 12:27
  • $\begingroup$ Also note that this is the most naive way of doing things. $\endgroup$ – Quantuple Jul 12 '16 at 12:31
  • $\begingroup$ @Ксения Цочева If this Quantuple's answer gives the solution you were hoping for, or you found it to be the most useful, consider "accepting" it by clicking the little check mark under the arrows to the left of the answer. This is the best way to show Quantuple gratitude for assisting you. Your behavior is not fairly. $\endgroup$ – user16651 Jul 12 '16 at 19:01
  • $\begingroup$ @Behrouz Maleki thanks pal. Maybe one day we'll get QF SE out of beta! $\endgroup$ – Quantuple Jul 12 '16 at 21:59
2
$\begingroup$

Besides the code's problem, I highly recommend the Brownian Bridge correction method which can compensate the pricing error resulting from discretization of the continuous path.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.