# Monte Carlo simulation for option pricing in Matlab

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 $S(T)=S(0)\textrm{exp}[(\mu-\frac{1}{2}\sigma^2)T+\sigma \varepsilon \sqrt{T}]$

Where $S(0)$ is the initial stock price, $\mu$ is interest rate ( $r$ is used to indicate risk-free interest rate), $\sigma$ is volatility, $T$ is time, and $\varepsilon$ is the random samples from standard normal distributions.

The standard error of our approximations is calculated as $\textrm{Standard Error} = \frac{w}{\sqrt{M}}$

Where $w$ is the standard deviation of the payoff results and $M$ is the number of trials (or simulations). Hence, a 95% confidence interval for the price $f$ of a derivative can be given as $\mu -\frac{1.96w}{M}

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] Posted