Matlab → Simulations → Brownian Motion → Stock Price → Monte Carlo for Option Pricing

In Monte Carlo simulation for option pricing, the equation used to simulate stock price is

Where is the initial stock price, is interest rate ( is used to indicate risk-free interest rate), is volatility, is time, and is the random samples from standard normal distributions.

The standard error of our approximations is calculated as

Where is the standard deviation of the payoff results and is the number of trials (or simulations). Hence, a 95% confidence interval for the price of a derivative can be given as

__Monte Carlo simulations in Matlab to price European-style call option__

`function call=MonteCarlo(s0,k,r,v,t,n)`

st=s0*exp((r-1/2*v^2)*t+v*randn(n,1)*sqrt(t));

payoff=max(st-k,0);

call=exp(-r*t)*mean(payoff)

In the next example, we calculate call and put option prices in the same program using Matlab.

__European-style option pricing in Matlab using Monte Carlo method__

`function callPut=EuropeanOption(s0,k,r,v,t,n)`

st=s0*exp((r-1/2*v^2)*t+v*randn(n,1)*sqrt(t));

payoffCall=max(st-k,0);

payoffPut=max(k-st,0);

call=exp(-r*t)*mean(payoffCall)

put=exp(-r*t)*mean(payoffPut)

In the next example, standard error and confidence interval is also given with call option price.

__Matlab code for call option with standard error and confidence interval__

`function call=MonteCarlo(s0,k,r,v,t,n)`

st=s0*exp((r-1/2*v^2)*t+v*randn(n,1)*sqrt(t));

payoff=max(st-k,0);

call=exp(-r*t)*mean(payoff)

stderr=std(payoff)/sqrt(n)

CI=[call-1.96*stderr,call+1.96*stderr]