Pricing European options using Monte Carlo Simulations in MATLAB

Sidratul Ahmed
4 min readApr 16, 2022

This article assumes some basic knowledge of stochastic processes, probability and MATLAB. If you are not familiar with such, I will address these in a future article.

Stock price simulation

We can think of stock price as a random variable x. By extension, option prices are a function of x i.e., f(x). When pricing an option we are essentially trying to calculate the expected value of f(x) i.e. E[f(x)]. We are then faced with the problem that most of the options in finance don’t have closed form solutions.

This is where numerical methods such as Monte Carlo Simulations can be very useful. Monte Carlo simulations depend on generating a large number of random samples to generate numeric solutions. Read more here.

The steps are following:

  1. Generate n samples for X, where n is a very large number
  2. For each of those Xs’ calculate f(x)
  3. Take the sample mean
Formula for sample mean

As it turns out, when n approaches infinity, our sample mean comes very close to the actual population mean. This is due to a probability theory known as the law of large numbers. Read more here.

Now let’s think about how we will go about generating this number of X values.

Generating X

Many theories in finance, including the Black Scholes Merton model for options pricing, assumes that stock prices follow a Geometric Brownian Motion. Read more about that here.

Under this assumption, stock price at some future time t+Δt can be written mathematically as

GBM process followed by stock price

where σ is volatility, μ is the expected rate of return and ε is a standard normal random variable. A standard normal variable is a normally distributed random variable with mean = 0 and standard deviation =1. The randomness of the stock price comes from ε.

The problem with is equation is that we don’t know the expected rate of return (μ). That’s why we apply a theory in finance known as Risk Neutral Valuation. It states that in the absence of dependency on risk aversion for derivative pricing we can simply assume that all investors are risk-neutral, therefore the expected return on any investment asset is the risk free rate and the discount rate used the expected payoff on any derivative on the asset is the risk-free rate.

Under Risk Neutral Valuation this model becomes,

Process followed by stock price under risk neutral valuation

where μ has been replaced by the risk-free rate (r).

Calculating f(x)

If we know strike price (K) and the underling stock price at the time of expiry (ST), European option values are very easy to calculate.

Value of a European Call Option at expiry = max(ST-K, 0)

Value of a European Put Option at expiry = max(K-ST, 0)

If you’re not familiar with the pay-off equations for call and put options, you can read more about them here and here. We can then discount these values using the risk free rate to find the price of the option at current time.

We are now ready to implement the Monte Carlo simulation in MATLAB

function price = MonteCarloPricer(S0, K, r, sigma, T, type, SampleSize)% S0 : stock price at time = 0
% K : strike price of the option
% r : risk free rate of return
% sigma : stock volatility
% T : time to expiry expressed in years
% type: option type i.e., put or call
% SampleSize: number of samples to use for the monte carlo simulation

% Generate a vector of terminal stock prices from random epsilons
% randn() generates a vector of normally distributed numbers
ST = S0 * exp((r-sigma^2/2) * T + sigma * randn(SampleSize, 1) * sqrt(T)); if type == "call"
price = exp(-r*T) * mean(max(ST-K, 0))
if type == "put"
price = exp(-r*T) * mean(max(K-ST, 0))
end

That’s it. You can now run this function by specifying the required inputs. Note that as sample size increases, so will the runtime of this code. Therefore, for fairly large sample sizes it can take a few seconds to generate an out. In a future article, I might explain how to make this more efficient and how to extend this to American and other exotic options.

--

--