0% found this document useful (0 votes)
50 views91 pages

Monte Carlo Method: Numerical Methods in Quantitative Finance

Uploaded by

Francis Zhou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views91 pages

Monte Carlo Method: Numerical Methods in Quantitative Finance

Uploaded by

Francis Zhou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

Monte Carlo Method

Numerical Methods in Quantitative Finance


Li Hao
[email protected]

Numerical Methods in QF (QF5204) Monte Carlo Method 1 / 91


Martingality of Discounted Derivative Price

Risk neutral pricing theory tells us that the discounted price of a


derivative instrument is a martingale:
 
Vt VT
= EQ (1)
Bt BT

where Q is the risk neutral measure and Bt is the price of a money


market account starting at B0 = 1.

In our simplistic case of constant interest rate, Bt = e rt .

Note that (1) holds no matter Bt is stochastic or deterministic.

Pricing derivative ⇐⇒ calculating expectation

Numerical Methods in QF (QF5204) Monte Carlo Method 2 / 91


Expectation Through Monte Carlo

Expectation to be calculated:
Vt
= EQ [h(X)] (2)
Bt

▶ X is the random vector involved in determining the payoff h.

Monte Carlo offers a numerical method to approximate the


expectation

It offers a generic framework to price a wide range of derivative


products

Very useful when the dimension of the problem is high

Numerical Methods in QF (QF5204) Monte Carlo Method 3 / 91


Law of Large Numbers (LLN)
Let X1 , X2 ,. . ., Xn be independent trial process, with finite expected value
µ = E[h(Xi )] and finite variance v = V (h(X)). Let
n
1X
µ̂n = h(Xi ) (3)
n
i=1

Then for any ϵ > 0,


P(|µ̂n − µ| ≤ ϵ) → 1 as n → ∞. (4)

The average of the results obtained from a large number of


experiments should be close to the expected value, and will tend to
become closer as more experiments are performed
µ̂n is unbiased: E[µ̂n ] = n1 E [ ni=1 h(Xi )] = µ
P

Therefore, to calculate the expectation of h(X) we just need to


generate independent trail processes and take the average — Monte
Carlo simulation
Numerical Methods in QF (QF5204) Monte Carlo Method 4 / 91
Monte Carlo Algorithm

The overall algorithm for Monte Carlo is really simple:

Algorithm 1 µ̂n = MC (h)


1: s = 0
2: for i = 1 to n do
3: Generate Xi
4: hi = h(Xi )
5: s += hi
6: end for
7: µ̂n = s / n
8: return µ̂n

Numerical Methods in QF (QF5204) Monte Carlo Method 5 / 91


Monte Carlo As Integrator
R1
An integral 0 f (x)dx is an expectation E[f (x)] with uniformly
distributed random variable x from 0 to 1 (U(0, 1)):
Z 1 Z 1
f (x)dx = f (x)p(x)dx = E[f (x)] (5)
0 0

because p(x) = 1 for U(0, 1)

To integrate the interval [a, b]


Z b Z b Z b
1 1
E[f (x)] = f (x)p(x)dx = f (x) dx = f (x)dx
a a b−a b−a a
(6)
Rb
So a f (x)dx = (b − a)E[f (x)] for x ∼ U(a, b)

Numerical Methods in QF (QF5204) Monte Carlo Method 6 / 91


Estimating Probability Using Monte Carlo
We can estimate probability using Monte Carlo by representing them
as expectations.
In particular, P(X ∈ A) = E[IA (X)] where
(
1 if X ∈ A
IA (X) = (7)
0 otherwise

Example: knowing that a uniformly drawn random point in a 2 × 2


π
square has the probability to fall inside a the unit circle inscribed
4
within the square, we have
π
P= = E[IA (x)] (8)
4
where A represent x is inside the circle. We can use Monte Carlo to
estimate the right hand side, thus obtain an estimate of π.

Numerical Methods in QF (QF5204) Monte Carlo Method 7 / 91


How Large Is The Error?

Central Limit Theorem


Given a sequence of independent identically distributed variates ξi = h(Xi )
with expectation and variance

E[ξi ] = µ, V [ξi ] = σ 2 (9)


1 Pn
and the running sum µ̂n = n i=1 h(Xi ). Then for increasing n, the
composite variate
µ̂n − µ
en := √ (10)
σ/ n

converges in distribution to the standard normal distribution N (0, 1).

Numerical Methods in QF (QF5204) Monte Carlo Method 8 / 91


Error Estimation for Monte Carlo Methods
From central limit theorem we know that our estimator µ̂n
σ2
approaches a normal distributeion: µ̂n → N (µ, )
n
A statistical measure for the uncertainty in any one simulation of
result of µ̂n is then the standard deviation of µ̂n : √σn
In general we don’t actually know σ — it’s the standard deviation of
our h(Xi ) and our whole target is to estimate its expectation
We can estimate σ using the samples:
v !2
u n n
u1 X 1 X
σ̂n = t hi2 − hi . (11)
n n
i=1 i=1

σ̂n
And the Monte Carlo standard error is defined as: ϵn = √
n

Numerical Methods in QF (QF5204) Monte Carlo Method 9 / 91


Monte Carlo — Convergence

From the standard error ϵn = σ̂n / n we see that Monte Carlo

method converges at the rate of O( n) — to reduce the error by 10
times, you need to increase the number of samples by 100 times
The standard error tells you the standard deviation of the estimator
µ̂n — the probability that your estimation lies in µ ± ϵn is 68.27%
The 68 − 95 − 99.7 rule :

Numerical Methods in QF (QF5204) Monte Carlo Method 10 / 91


Monte Carlo — Confidence Interval

Confidence Interval
As n → ∞, a asymptotically valid 1 − δ confidence interval for µ is an the
interval

µ̂n − N −1 (1 − δ/2)ϵn , µ̂n + N −1 (1 − δ/2)ϵn


 

where N(·) is the standard cumulative normal function.

The interval covers the true value µ with probability 1 − δ

Note that the interval itself is random.

Rule of thumb: when δ = 0.05, N −1 (1 − δ/2) ≈ 1.96, i.e.,


µ̂n ± 1.96ϵn gives a 95% confidence interval,

Numerical Methods in QF (QF5204) Monte Carlo Method 11 / 91


Generation of Random Process Xi
The only non-trivial component in the Monte Carlo algorithm is the
generation of Xi
In the expectation of interest E[h(Xi )],
▶ h is the payoff function
▶ the random vector Xi is the underlying asset

The distribution of Xi might not be known analytically — they


depend on the diffusion model
▶ For Black-Scholes model the distribution is log-normal:
dS
S = (r − q)dt + σdWt
▶ For local volatility model the distribution has no closed form:
dS
S = (r − q)dt + σ(S, t)dWt

However they are both adapted to the random processes with known
distribution — Brownian motions
Therefore we only need to generate the Brownian motions

Numerical Methods in QF (QF5204) Monte Carlo Method 12 / 91


Generation of Brownian Motions
To simulate Brownian motions we need to be able to generate random
numbers with normal distribution — any interval of a Brownian
motion, Wt − Ws , is normally distributed with 0 mean and variance
t − s, and is independent from other non-overlapping intervals
Random numbers with normal distribution, or any other non-uniform
distribution, can be generated from uniform random variates, using
e.g.,
▶ Approximation using central limit theorem
▶ Box-Muller method
▶ Inverse transformation method

We discuss the generation of uniform random number U(0, 1) first


then the transformation

Numerical Methods in QF (QF5204) Monte Carlo Method 13 / 91


Random Number Generator

Computer programs are designed to follow instructions in a


deterministic way — in other words, they are predictable

Computer will not be able to generate true random numbers unless


the randomness comes as input. For example, random.org provides
random number API whose randomness comes from atmospheric
noise.

Computer generated random numbers are referred to as


pseudo-random numbers (PRN) because they are not truly random

But is pseudo random number bad for us? Not really.

Numerical Methods in QF (QF5204) Monte Carlo Method 14 / 91


Desired Properties of Random Numbers in QF
The random numbers we use should behave similarly to realization of
independent, identically distributed random variables with a certain
distribution. True randomness is better but pseudo randomness can
achieve this with certain limitations.
We use random numbers as a statistical tool for integration — true
randomness does not add much value on this compared to pseudo
randomness
We need to be able to reproduce the random numbers — pricing an
option twice using Monte-Carlo you do not want to see two different
prices. In other words, we want it to be deterministic despite Monte
Carlo errors. And pseudo random number wins.
Be aware that there is no flawless pseudo random number generator
— it’s good practice to keep several alternatives of the pseudo
random number generator in your library and cross test each other

Numerical Methods in QF (QF5204) Monte Carlo Method 15 / 91


PRNG — General Principle

1 Given the current value of one or more state variables (usually stored
internally in the generator)

2 Apply a mathematical iteration algorithm to obtain a new set of


values for the state variables

3 Use a specific formula to obtain a new uniform (0, 1) variate from the
current state variables

Numerical Methods in QF (QF5204) Monte Carlo Method 16 / 91


PRNG — Middle-Square Method
The very first algorithm for the computer generation of pseudo
random numbers due to John von Neumann et al.
One state variable: xi
Iteration xi+1 : extract the middle four digits of xi2
Random number: xi+1
Example: start from the seed x0 = 0.9876

x0 = 0.9876
x02 = 0.97535376
x1 = 0.5353
x12 = 0.28654609
x2 = 0.6546

Numerical Methods in QF (QF5204) Monte Carlo Method 17 / 91


Middle-Square Method — Example

1 import matplotlib.pyplot as plt


2
0.5
xi

3 xs = [0] * 100
4 xs[0] = 0.2372 # seed
5 for i in range(1, 100):
6 xs[i]=(int(xs[i-1]**2*1.0e6)
%1e4)/1.0e4
0 7 plt.scatter(range(100), xs)
8 plt.show()
0 50 100
i
PRNs — mid-square method seed at 0.2372

Numerical Methods in QF (QF5204) Monte Carlo Method 18 / 91


Middle-Square Method — Problem
Problem of mid-pointe method: very likely to end up in a short
periodic orbit or be absorbed at 0.
1 1

0.5
xi

xi
0.5

0
0
0 50 100 0 50 100
i i
PRNs — mid-square method seed at 0.9876 PRNs — mid-square method seed at 0.5649

Seed 0.9876: sequence starts to repeat from x46 , and is able to


generate four numbers afterwards: 0.96, 0.16, 0.56, 0.36
Seed 0.5649: sequence absorbed at 0 at x84
Numerical Methods in QF (QF5204) Monte Carlo Method 19 / 91
Congruential Generators
Congruential generators update the state variable by the integer
operation:

mn+1 = (a mn + c) mod M (12)

where all the numbers are integers, and mi ∈ [0, M − 1]


mi
mi ’s can be scaled to [0, 1] by xi =
M −1
If we choose a and M to be co-prime and c ̸= 0, the sequence won’t
be absorbed at a fixed point

When c = 0 this is called linear congruential generator. The system


won’t be absorbed at a fixed point if a and M are co-prime and the
starting point is not 0.

Numerical Methods in QF (QF5204) Monte Carlo Method 20 / 91


Congruential Generators — Example
For small M it’s still easy to show that the sequence generated by
congruential generators is periodic:
M = 11, a = 3, c = 0, m0 = 3:
3, 9, 5, 4, 1, 3, 9, ...
The maximum length of the period is M − 1, but of course M − 1 is
not guaranteed — example above
With very large M we can have very long period such that the
repetition becomes invisible to our application
The values M and a have to be very carefully chosen [1]
▶ In IBM’s early days it used a = 65539, M = 231 , and m0 = 1 — this
was reported to be highly inadequate
▶ A choice of a = 517 , M = 240 , and m0 = 1 was reported to work well
with period 238

Numerical Methods in QF (QF5204) Monte Carlo Method 21 / 91


Congruential Generators — Extensions

The minimal standard generator Rand0 : a linear congruential


generator with a = 16807 and M = 231 − 1

Rand1 : enhancement of Rand0 using a careful shuffling algorithm

Rand2 : coupling two linear congruential generators to construct one


of a much longer period

Numerical Methods in QF (QF5204) Monte Carlo Method 22 / 91


Mersenne Twister
Presented by Matsumoto and Nishimura in 1998
Utilizes many existing methods to rectify most of the flaws found in
older PRNGs
Full algorithm can be found at Wikipedia
The period of the sequence is a Mersenne prime number: 2n − 1
The popular one is mt19937: n = 19937 and period 219937 − 1 —
equivalent to infinity periodicity for us
mt19937 has equidistribution property in at least 623 dimensions
(linear congruential generator has 5 dimensions in contrast)
The PRNG of choice: provides fast generation of high-quality pseudo
random numbers. Python random package generates numbers using
mt19937.

Numerical Methods in QF (QF5204) Monte Carlo Method 23 / 91


Uniform To Normal Distribution — Central Limit Theorem
Now we have random numbers from the uniform distribution U(0, 1)
To generate random numbers with normal distribution, one simple
way is to utilize the central limit theorem:
µ̂n − µ
▶ Recall that √ ∼ N (0, 1)
σ/ n
▶ The variance of U(0, 1) is
R1 1
0
(x − 0.5)2 dx = 12 = σ2
▶ So we draw 12 uniform random numbers
ui , and let
12
X
mk = ui − 6 (13)
i=1

▶ m approximates standard normal


distribution due to central limit theorem
▶ probability density function (blue) and error
is shown at the right
Numerical Methods in QF (QF5204) Monte Carlo Method 24 / 91
Uniform To Normal Distribution — Box Muller Method
Box-Muller method is another easy to implement algorithm to
transform uniform distribution to normal distribution
It is based on the property of the bivariate normal distribution: if
Z ∼ N (0, I2 ), then
▶ R = Z12 + Z22 is exponentially distributed with mean 2:
x
P(R ≤ x) = 1 − e − 2

▶ Given R,
√ the point (Z1 , Z2 ) is uniformly distributed on the circle of
radius R centered at origin
The algorithm is
1. Generate independent U1 , U2 from U(0, 1)
2. R ← −2 log(U1 ) — uniform to exponential distribution (inverse CDF)
3. V ← 2πU2 — the angle to determine the point on the circle
√ √
4. Z1 ← R cos(V ), Z2 ← R sin(V )
Transform a pair (U1 , U2 ) to (Z1 , Z2 )

Numerical Methods in QF (QF5204) Monte Carlo Method 25 / 91


Acceptance Rejection Method

The previous two methods are specific to normal distribution

Acceptance rejection method is generic to transform sample from one


distribution (typically more convenient to generate) to another (not
that convenient to generate)

Let g (x) be the pdf of a distribution we know how to sample, and


f (x) be the pdf of the target distribution, and f (x) ≤ cg (x) for all x.

Idea is to generate x, then accept it as a sample for f with probability


f (x)
, to decide whether to accepte the sample x we can just draw a
cg (x)
f (x)
random number u from U(0, 1) and accept x if u <
cg (x)

Numerical Methods in QF (QF5204) Monte Carlo Method 26 / 91


Why Acceptance Rejection Method Works?
The generated sample, denoted as y , has the distribution:
 
f (x)
P(y ∈ A) = P x ∈ A|u ≤
cg (x)
 
f (x)
P x ∈ A, u ≤ cg (x)
= f (x)
P(u ≤ cg (x) )
f (x) f (x)
For a given x, the probability u ≤ cg (x) is simply cg (x) , so the
denominator reads
  Z
f (x) f (x) 1
P u≤ = g (x)dx = (14)
cg (x) X cg (x) c
Thus y has the desired distribution:
  Z Z
f (x) f (x)
P(y ∈ A) = c P x ∈ A, u ≤ =c g (x)dx = f (x)dx
cg (x) A cg (x) A
(15)
(14) also tells the acceptance rate: larger c — more expensive
Numerical Methods in QF (QF5204) Monte Carlo Method 27 / 91
Acceptance Rejection — Algorithm

Algorithm 2 AcceptanceRejection
1: repeat
2: Generate x from distribution g
3: Generate u from U(0, 1)
4: until U ≤ f (x)/cg (x)
5: return x

The idea of acceptance rejection is used by many methods


One example is the modified Box-Muller method for normal random
number generation, namely polar rejection method (or Marsaglia-Bray
algorithm),
▶ Main modification to Box-Muller is to use acceptance rejection to
generate uniformly distributed points in a unit disc
▶ Avoid computing sin and cos as in Box-Muller method

Numerical Methods in QF (QF5204) Monte Carlo Method 28 / 91


Polar Rejection Method
Algorithm 3 PolarRejection
1: repeat
2: Generate u1 , u2 ∼ U(0, 1)
3: u1 ← 2u1 − 1
4: u2 ← 2u2 − 1 {(u1 , u2 ) uniformly distributed over [−1, −1] × [1, 1]}
5: x ← u12 + u22
6: until x ≤ 1 {x ∼ U(0, 1) after acceptance
√ rejection}

7: y ← −2 log x {y is equivalent to R in Box-Muller}
√ √
8: Z1 ← y × u1 / x {u 1 / x — cos(V ) in Box-Muller}
√ √
9: Z2 ← y × u2 / x {u2 / x — sin(V ) in Box-Muller}
10: return x

An algorithm similar to Box-Muller method for generating normal


random numbers
π
Faster than Box-Muller despite the acceptance rate at first step is
4
Numerical Methods in QF (QF5204) Monte Carlo Method 29 / 91
Inverse Transformation Method
Another generic way to transform random samples from uniform
distribution to any other distribution is through the inverse
cumulative density function of the target distribution
We want to generate random variable X with property that
P(X ≤ x) = CDF (x) for all x. Inverse transformation method sets

X = CDF −1 (u), u ∼ U(0, 1) (16)

Draw u from U(0, 1) and from


CDF −1 (·) we get the sample x
We used the inverse
transformation method to
convert uniform random number
to exponential distribution in
Box-Muller

Numerical Methods in QF (QF5204) Monte Carlo Method 30 / 91


Inverse Transformation Method — Considerations

The inverse CDF is not always one-to-one

There can be many to one (jump in CDF), one to many (flat CDF)

If we use inverse transformation method we need to handle the one to


many case with pre-defined conventions

Numerical Methods in QF (QF5204) Monte Carlo Method 31 / 91


Inverse Transformation Method For Normal Distribution
CDF of normal distribution is not analytic — inverse of it is non-trivial
Typical procedure:
▶ Use an analytic formula that approximates N −1 , and use it as initial
guess
▶ Apply root search algorithm to find the solution

Not necessarily fast


Has the nice property of being monotonic (N(·) is strictly increasing)
with respect to the uniform — helps in variance reduction techniques,
e.g., antithetic variates
Use exactly 1 uniform random number to generate 1 normal random
number — preserve dimensionality and periodicity of the uniform
PRNG

Numerical Methods in QF (QF5204) Monte Carlo Method 32 / 91


PRNG — Implementation
1 import numpy as np
2 import math
3 from matplotlib import pyplot as plt
4
5 np.random.seed(0) # we want to fix the seed so the numbers are reproducible
6 data = np.random.normal(0, 1, 10000)
7 bins = np.linspace(math.ceil(min(data)),math.floor(max(data)),50) # fixed number of bins
8 plt.xlim([min(data)-0.5, max(data)+0.5])
9 plt.hist(data, bins=bins)
10 plt.xlabel(’variable X (50 evenly spaced bins)’)
11 plt.ylabel(’count’), plt.show()

Numerical Methods in QF (QF5204) Monte Carlo Method 33 / 91


Brownian Motion Generation

1 np.random.seed(0)
2 # generate 3 brownian motions for 1Y
3 nBrownians, nTimeSteps = 3, 366
4 brownians = np.zeros((nBrownians, nTimeSteps))
5 # each time step is 1 day,
6 # so standard deviation is sqrt(1/365.0)
7 stdev = math.sqrt(1/365.0)
8 for i in range(nBrownians):
9 for j in range(1, nTimeSteps):
10 dw = np.random.normal(0, stdev)
11 brownians[i,j] = brownians[i,j-1] + dw
12
13 plt.plot(range(nTimeSteps), brownians[0])
14 plt.plot(range(nTimeSteps), brownians[1])
15 plt.plot(range(nTimeSteps), brownians[2])
16 plt.show()

Numerical Methods in QF (QF5204) Monte Carlo Method 34 / 91


Pricing European Option With Monte Carlo

Pricing European option with Monte Carlo is easy, if the model is


Black-Scholes

We do not need to use the whole Brownian motion, because we have


ST in closed form:
1 2 )T +σW
ST = S0 e (r −q− 2 σ T
(17)

Only the end value of the Brownian motion is needed

So instead of simulating 365 time steps we only need to simulation 1


step

Numerical Methods in QF (QF5204) Monte Carlo Method 35 / 91


MC European Implementation

1 import math
2 from numpy.random import random
3 import numpy as np
4
5 def mcEuropean(S0, T, r, q, vol, nPaths, trade):
6 random.seed(0)
7 sum,hsquare = 0,0
8 stdev = np.math.sqrt(T)
9 for i in range(nPaths):
10 wT = np.random.normal(0, stdev)
11 h = trade.payoff(S0 * math.exp((r - q - 0.5*vol*vol) * T + vol * wT))
12 sum += h
13 hsquare += h * h
14
15 pv = math.exp(-r*T) * sum / nPaths
16 stderr = math.sqrt((hsquare/nPaths - (sum/nPaths) * (sum/nPaths)) / nPaths)
17 return pv, stderr

Numerical Methods in QF (QF5204) Monte Carlo Method 36 / 91


MC European Convergence

mcPrice - analyticPrice
Standard Error
0.2

103 104 105 106


Number of MC Paths
European call option, K = 100, S = 100, r = 5%, q = 2%, T = 1, σ = 15%

Numerical Methods in QF (QF5204) Monte Carlo Method 37 / 91


Model Without The Closed Form Solution
Black Scholes model is a special case, normally we do not have closed
form solution to our SDE
Look at the SDE of local volatility model:

dS = S(r − q)dt + Sσ(S, t)dWt (18)

Closed form solution does not exist since σ(S, t) is state dependent
Consider a process X that satisfies the below SDE of a general form:

dX (t) = a(X (t))dt + b(X (t))dW (t). (19)

Integrating (19) we have


Z ti+1 Z ti+1
X (ti+1 ) = X (ti ) + a(X (u))du + b(X (u))dWu (20)
ti ti

To solve the integrals we need to discretize them


Numerical Methods in QF (QF5204) Monte Carlo Method 38 / 91
Euler Discretization Scheme
Using time step ∆t, the Euler discretization scheme approximates
Z t+∆t
a(X (u))du = a(X (t))∆t (21)
t
Z t+∆t √
b(X (u))dWu = b(X (t))∆W = b(X (t)) ∆tZ (22)
t

where Z ∼ N(0, 1)
The stepwise induction is

X (t + ∆t) = X (t) + a(X (t))∆t + b(X (t)) ∆tZ (23)

The truncation error of the drift term is O(∆t)



The truncation error of the diffusion term is O(∆W ), i.e., O( ∆t)

The overall convergence order of Euler scheme is therefore O( ∆t)

Numerical Methods in QF (QF5204) Monte Carlo Method 39 / 91


Euler Scheme For Black Scholes Model
For Black Scholes model Euler scheme can be written as

St+∆t = St (1 + µ∆t + σ∆Wt ) (24)

5Y simulation of spot with S0 = 10, σ = 30%, µ = 10%


16 18 Exact
Euler
14 16
14
12
12
10
10
8
0 2 4 0 2 4
t (5 steps) t (20 steps)

Numerical Methods in QF (QF5204) Monte Carlo Method 40 / 91


Change of State Variable
State variable is the variable we record in each step of Monte Carlo
simulation
It is not necessary for us to use the spot price as state variable
We only need to be able to reconstruct the spot price from the state
variable
If we choose X = log S at state variable, the diffusion can be written
as
1 ∂2X 2
 
∂X 1 2
dX = dS + dS = µ − σ dt + σdWt (25)
∂S 2 ∂S 2 2

Euler scheme now gives us the exact solution:


1
Xt+∆t = Xt + (µ − σ 2 )∆t + σ∆Wt ← Euler scheme (26)
2
(µ− 12 σ 2 )∆t+σ∆Wt
St+∆t = St e ← Reconstruction (27)

This is due to the linearity of the diffusion process of X


Numerical Methods in QF (QF5204) Monte Carlo Method 41 / 91
Local Volatility Model Diffusion
We can use the same state variable for the diffusion of local volatility
model:
 
1 2
dX = µ − σ(S, t) dt + σ(S, t)dWt (28)
2

Again the simplified constant drift does not affect the generality of
our formulation, replacing it with a term structure µ(t) is trivial

The diffusion can be discretized by Euler scheme as:


1
Xt+∆t = Xt + (µ − σ(X , t)2 )∆t + σ(X , t)∆Wt (29)
2
But now we are not exact — no closed form exact solution

Our discretization error is O( ∆t)

Numerical Methods in QF (QF5204) Monte Carlo Method 42 / 91


MC Local Volatility — Implementation

1 def mcLocalVol(S0, T, r, q, lv, nT, nPaths, trade):


2 random.seed(0)
3 sum, hsquare = 0, 0
4 dt = T / nT
5 sqrtdt = math.sqrt(dt)
6 for i in range(nPaths):
7 X = math.log(S0)
8 for j in range(1, nT+1):
9 vol = lv.LV((j-1)*dt, math.exp(X))
10 a = (r - q - 0.5*vol * vol) * dt # drift
11 b = np.rand.normal(0, sqrtdt) * vol # diffusion
12 X += a + b # update state variable
13 h = trade.payoff(math.exp(X))
14 sum += h
15 hsquare += h * h
16 pv = math.exp(-r * T) * sum / nPaths
17 stderr = math.sqrt((hsquare/nPaths-(sum/nPaths)*(sum/nPaths))/nPaths)
18 return pv, stderr

Numerical Methods in QF (QF5204) Monte Carlo Method 43 / 91


MC Local Volatility — Convergence
·10−2
mcPrice - analyticPrice
2 Standard Error

−2

103 104 105 106


Number of MC Paths
European call option, K = 5.2, S = 6, r = 5%, q = 2%, T = 1, iv = 12.93%

Numerical Methods in QF (QF5204) Monte Carlo Method 44 / 91


Milstein Discretization Scheme

We can achieve higher order convergence on discretization

One popular scheme for Monte Carlo is the Milstein scheme.

The target is to achieve O(∆t), since the drift term is already


O(∆t), we need to refine only the diffusion term

In Euler we just use b(X (t)) for the period t → t + ∆t, this is the
place of truncation error so we need to refine this part

Numerical Methods in QF (QF5204) Monte Carlo Method 45 / 91


Milstein Discretization Scheme
The diffusion process of b(X (t)) is
∂b 1 ∂2b 1
db(X (t)) = dX + dX 2 = b ′ (a · dt + b · dWt ) + b ′′ b 2 dt
∂X 2 ∂X 2 | {z } 2
dX
1
= (ab ′ + b 2 b ′′ ) dt + b(X (t)b ′ (X (t)dWt .
| {z2 }
c(X (t))

So
Z u Z u

b(X (u)) = b(X (t)) + b(X (s))b (X (s))dWs + c(X (s))ds
t t
Ru
Since t c(X (t))dt is of order O(u − t) and is higher than we need

(because of the multiplication with ∆Wt is order O( ∆t), we can
omit it. Therefore
Z u
b(X (u)) ≈ b(X (t)) + b(X (s))b ′ (X (s))dWs
t

Numerical Methods in QF (QF5204) Monte Carlo Method 46 / 91


Milstein Discretization Scheme
Approximating the integral using Euler
Z u
b(X (u))b ′ (X (u))dWu = b(X (t))b ′ (X (t))(Wu − Wt ) + O(u − t)
t
(30)

Therefore

b(X (u)) = b(X (t)) + b(X (t))b ′ (X (t))(Wu − Wt ) + O(u − t). (31)

Now, come back to the target integral (20), the result is


Z ti+1 √ 1
b(X (u))dWu = b(X (t)) ∆tZ + b(X (t))b ′ (X (t))∆t(Z 2 − 1)
ti | {z } |2 {z }
Euler term
Milstein correction term
(32)

Numerical Methods in QF (QF5204) Monte Carlo Method 47 / 91


Milstein Discretization Scheme
And here is the last step of derivation of (32):
Z t+∆t Z t+∆t
b(X (u))dWu = [b(X (t)) + b(X (t))b ′ (X (t))(Wu − Wt )]dWu
t t
 
Z 
 t+∆t 

= b(X (t))(Wt+∆t − Wt ) + b(X (t))b (X (t))  Wu dWu −Wt (Wt+∆t − Wt )
 
 t 
| {z } 
d ( 21 W 2 − 12 t )=WdW
 
1 2 1 1
= b(X (t))(Wt+∆t − Wt ) + b(X (t))b ′ (X (t)) Wt+∆t − Wt2 − ∆t − Wt (Wt+∆t − Wt )
2 2 2
1
= b(X (t))(Wt+∆t − Wt ) + b(X (t))b ′ (X (t))[(Wt+∆t − Wt )2 − ∆t]
2
√ 1
= b(X (t)) ∆tZ + b(X (ti ))b ′ (X (ti ))∆t(Z 2 − 1)
| {z } |2 {z }
Euler term
Milstein correction term

Discretizing local volatility model diffusion we have:


σ(X , t)2 σ(X , t) ∂σ(X , t)
Xt+∆t = Xt + (µ − )∆t + σ(X , t)∆Wt + (∆Wt2 − ∆t)
2 2 ∂X
(33)
Numerical Methods in QF (QF5204) Monte Carlo Method 48 / 91
Error of Milstein Scheme
We illustrate the error of Milstein scheme using Black Scholes model
with state variable S. Milstein scheme is:
σ2
St+∆t = St (1 + µ∆t + σ∆Wt + (∆Wt2 − ∆t)) (34)
2
5Y simulation of spot with S0 = 10, σ = 30%, µ = 10%
16 Exact
Euler
Milstein
14

12

10

8
0 1 2 3 4 5
t (5 steps)
Numerical Methods in QF (QF5204) Monte Carlo Method 49 / 91
Monte Carlo Method — Pros and Cons

Pros:
Easy to implement

Easy to extend

Dimension friendly

Cons:
Monte Carlo noise

Slow for low dimension problems compared to PDE or Tree

Not efficient and reliable for American style options

Numerical Methods in QF (QF5204) Monte Carlo Method 50 / 91


Two Factor Monte Carlo — Correlating Brownian Motions
When we have more than one model factors who are correlated with
each other, we need to construct correlated Brownian motions
The correlation of the increments of two Brownian motions is
Covar E(∆W1 ∆W2 ) − E(∆W1 )E (∆W2 )
ρ= √ = p (35)
Var1 · Var2 Var (∆W1 ) · Var (∆W2 )
E(∆W1 ∆W2 )
= (36)
dt
So
E(∆W1 ∆W2 ) = ρdt (37)

∆W1 = ξ1 dt (38)

∆W2 = ξ2 dt (39)
where ξ1 and ξ2 are two standard normal random variates, and
E(ξ1 ξ2 ) = ρ (40)

Numerical Methods in QF (QF5204) Monte Carlo Method 51 / 91


If we represent the correlation matrix as
 
1 ρ
C= (41)
ρ 1

And the random samples for ξ1 and ξ2 (to generate the correlated
Brownian increments) are vectors:

ξ̂ 1 = ξˆ1,0 , ξˆ1,1 , . . . , ξˆn,1 ,


 
(42)
ξ̂ 2 = ξˆ2,1 , ξˆ2,2 , . . . , ξˆ2,n
 
(43)

and
  h i ξ̂ · ξ̂ , ξ̂ · ξ̂   n, nρ
ξ̂ 1 ⊤ ⊤ 1 1 1 2
× ξ̂ 1 , ξ̂ 2 = = = n C (44)
ξ̂ 2 ξ̂ 2 · ξ̂ 1 , ξ̂ 2 · ξ̂ 2 nρ, n

Numerical Methods in QF (QF5204) Monte Carlo Method 52 / 91


If we decompose C to the product of a matrix and its transpose:

C = LL⊤ (45)

We have
  h
ξ̂ 1 ⊤ ⊤
i
× ξ̂ 1 , ξ̂ 2 = n LL⊤ (46)
ξ̂ 2

So
  h
−1 ξ̂ 1 ⊤ ⊤
i
L × ξ̂ 1 , ξ̂ 2 (L⊤ )−1 = n I (47)
ξ̂ 2

where I is an identity matrix.

Numerical Methods in QF (QF5204) Monte Carlo Method 53 / 91


Correlating Standard Normal Vectors
If we let
   
ζ̂ 1 −1 ξ̂ 1
= (L) (48)
ζ̂ 2 ξ̂ 2

Therandom vectors vectors ζ 1 and ζ 2 are uncorrelated because



ζ̂ 1 h
⊤ ⊤
i
× ζ̂ 1 , ζ̂ 2 = n I.
ζ̂ 2

So if we generate independent standard normal random vectors ζ 1


and ζ 2 , we can correlate them by
   
ξ̂ 1 ζ̂
=L 1 (49)
ξ̂ 2 ζ̂ 2

Numerical Methods in QF (QF5204) Monte Carlo Method 54 / 91


Cholesky Decomposition
If a matrix is symmetric and positive definite, a special LU
decompositiion — Cholesky decomposition is faster than the other LU
decomposition and satisfies the property that:

C = LL⊤ (50)

and L is a lower triangular matrix.


The requirement that the Cholesky decomposition exists is the matrix
C is symmetric positive definite. This is true if ρ ̸= ±1:
  h
⊤ 1 ⊤ ξ̂ 1 ⊤ ⊤
i ∥y∥
x Cx = x × ξ̂ 1 , ξ̂ 2 x = ≥0 (51)
n ξ̂ 2 | {z } n
| {z } y n×1
(y⊤ )1×n

So (50) exists by definition.

Numerical Methods in QF (QF5204) Monte Carlo Method 55 / 91


Now to generate two correlated Brownian motions we can
1. Generate two independent standard normal samples ζ 1 and ζ 2

2. Decompose the correlation matrix using Cholesky:
  C=  LL 
ξ̂ 1 ζ̂
3. Generate the correlated normal variates by: =L 1
ξ̂ 2 ζ̂ 2
And this routine works in general, for m random variates.
The Cholesky decomposition algorithm is straight-forward:
  
L11 0 0 L11 L21 L31
C = LL⊤ = L21 L22 0   0 L22 L23  (52)
L31 L23 L33 0 0 L33
 2 
L11 (symmetric)
= L21 L11 L221 + L222  (53)
P3 2
L31 L11 L31 L21 + L32 L22 i=1 L3i

Just need to start from the top-left corner and progressively solve for
each Lij
In python implementation: L = np.linalg.cholesky(C)
Numerical Methods in QF (QF5204) Monte Carlo Method 56 / 91
Correlated Brownian Motions — Examples
Now we can generate brownian motions with correlations (example
brownians with different ρ)
0.4 0.4
0.2 0.2
0 0
−0.2 W0
−0.2 W0
W1 , ρ = 80% W1 , ρ = 20%
−0.4 −0.4
0 5 · 10−2 0.1 0.15 0 5 · 10−2 0.1 0.15
t t
0.4 0.4
0.2 0.2
0 0
−0.2 W0
−0.2 W0
W1 , ρ = −20% W1 , ρ = −80%
−0.4 −0.4
0 5 · 10−2 0.1 0.15 0 5 · 10−2 0.1 0.15
t t
Numerical Methods in QF (QF5204) Monte Carlo Method 57 / 91
Pricing Spread Option — MC with Two Assets under BS
1 def mcSpread(payoff, S1, S2, T, r, q1, q2, vol1, vol2, rho, nPaths, nT):
2 np.random.seed(0)
3 sum, hsquare, C = 0, 0, np.identity(2)
4 C[0, 1] = C[1, 0] = rho
5 L = np.linalg.cholesky(C)
6 for i in range(nPaths):
7 brownians = np.zeros((2, nT))
8 dt = T / nT
9 stdev = math.sqrt(dt)
10 # generate brownian increments
11 for j in range(2):
12 brownians[j] = np.random.normal(0, stdev, nT)
13 brownians = np.matmul(L, brownians)
14 x1, x2 = math.log(S1), math.log(S2)
15 for j in range(nT):
16 # simulate asset 1
17 a = (r-q1-0.5*vol1*vol1) * dt # drift for asset 1
18 b = brownians[0, j] * vol1 # diffusion term for asset 1
19 x1 += a + b # update state variable
20 # simulate asset 2
21 a = (r-q2-0.5*vol2*vol1) * dt # drift for asset 1
22 b = brownians[1, j] * vol2 # diffusion term for asset 1
23 x2 += a + b # update state variable
24 h = payoff(math.exp(x1), math.exp(x2))
25 sum += h
26 hsquare += h*h
27 pv = math.exp(-r * T) * sum / nPaths
28 se = math.sqrt((hsquare/nPaths - (sum/nPaths)*(sum/nPaths))/nPaths)
29 return pv, se

Numerical Methods in QF (QF5204) Monte Carlo Method 58 / 91


MC Spread Option Convergence
·10−2
MC - Margrabe formula
Standard Error
2

103 104 105 106


Number of MC Paths
S1 = 10, S2 = 10, r = 10%, q1 = 2%, q2 = 1%, T = 1, σ1 = 15%, σ2 = 10%, ρ = 50%

Numerical Methods in QF (QF5204) Monte Carlo Method 59 / 91


Generic Monte Carlo Framework
Similar to our Binomial tree framework, we can decompose the Monte
Carlo pricer to obtain a generic MC framework
The MC framework can be much more generic than the tree
framework due to the capability of Monte Carlo — very natural to
handle path dependant products
Major components:
▶ Market
▶ Random number generator
▶ Monte Carlo product
▶ Monte Carlo diffusion model
▶ MC pricer that plumbs the above all

Numerical Methods in QF (QF5204) Monte Carlo Method 60 / 91


MC Framework — Steps

We want to handle trade with multiple underlying assets — the


market should provide the correlation of all the relevant model factors

The pricer uses random number generator to generate Brownian


motions and then correlate them.

The job of diffusion model is to take a Brownian motion, and


simulate underlying asset’s price process. For each asset there should
be one diffusion model.

Each simulation path gives one realization of the market, the trade
should be able to take that to return the discounted cash flows of this
realization — the h(Xi ) in our expectation

Numerical Methods in QF (QF5204) Monte Carlo Method 61 / 91


Implementation
mcPricer.py
1 def mcPricer(trade, models, corrmat, nPaths):
2 assetNames = trade.assetNames() # get all the assets involved for the payoff
3 numFactors = corrmat.size() # get total number of factors (brownians)
4 L = np.linalg.cholesky(corrmta) # cholesky decomposition
5 dts = [] # get simulation time steps
6 for a in assetNames:
7 dts.append(models[a].GetTimeSteps(trade.AllDates()))
8 dts = np.unique(dts)
9 sum, hsquare, nT = 0, 0, dts.size()
10 for i in range(nPaths):
11 # generate independent bronian increments,
12 for j in range(numFactors):
13 brownians[j] = np.random.normal(0, 1, nT)
14 brownians = np.matmul(L, brownians) # correlate them using L
15 bidx, fobs = 0, dict() # fobs is a dict from asset name to observable,
16 # each observable if a function from t to the observation price
17 for k in assetNames.size():
18 # pass the brownians to the model to generate the observation functions
19 model = models[assetNames[k]]
20 nF = model.NumberOfFactors()
21 bs = brownians.project(bidx, bidx + nF)
22 fobs[assetNames[k]] = model.Diffuse(dts, bs)
23 bidx += nF
24 # call the payoff function to obtain the discounted cashflows
25 h = trade.DiscountedMCPayoff(fobs)
26 sum += h
27 hsquare += h*h
28 pv = sum / nPaths
29 se = math.sqrt((hsquare/nPaths - pv*pv)/nPaths)
30 return pv, se

Numerical Methods in QF (QF5204) Monte Carlo Method 62 / 91


mcPricer requires a diffusion model to provide below functions:
Model diffusion that returns an observable - a function that takes a
future date and returns the asset price of that date:
1 fobs[assetNames[k]] = model.Diffuse(dts, bs)

Number of factors - number of brownian motion needed to diffuse the


model
1 nF = model.NumberOfFactors()

Given a list of event dates from the trade, the intermediate times
steps the model requires to diffuse properly:
1 models[a].GetTimeSteps(trade.AllDates())

Numerical Methods in QF (QF5204) Monte Carlo Method 63 / 91


A concrete diffusion model — Black-Scholes
1 class BlackScholes:
2 def __init__ (self, S0, vol, r, q):
3 self.vol, self.S0, self.r, self.q = vol, S0, r, q
4 def NumberOfFactors(self):
5 return 1
6 def GetTimeSteps(self, eventDates):
7 # black scholes diffusion is exact, no need to add more dates
8 return eventDates
9 def Diffuse(self, dts, bs):
10 xs = [math.log(self.S0)]
11 for i in (1, dts.size()):
12 a = (self.r - self.q - 0.5 * self.vol * self.vol) * dts[i]
13 b = self.vol * bs[0, i] * math.sqrt(dts[i])
14 xs.append(xs[i-1] + a + b)
15 return (lambda t: np.interp(t, dts, xs))

Numerical Methods in QF (QF5204) Monte Carlo Method 64 / 91


The trade is then able to take all the relevant observables and
determine the payoff of this simulation path:
1 h = trade.DiscountedMCPayoff(fobs)

Besides the discounted payoff, the trade needs to provide


1 trade.assetNames() # get all the assets involved for the payoff
2 trade.AllDates() # critical event dates for the trade

Spread option implementation:


1 class SpreadOption():
2 def __init__(self, asset1, asset2, expiry):
3 self.expiry = expiry
4 self.asset1, self.asset2 = asset1, asset2
5 def payoff(self, S1, S2):
6 return max(S1-S2, 0)
7 def valueAtNode(self, t, S1, S2, continuation):
8 return continuation
9 def AssetNames(self):
10 return [self.asset1, self.asset2, "DF.USD"]
11 def AllDates(self):
12 return [self.expiry]
13 def DiscountedMCPayoff(self, fobs):
14 df = fobs["DF.USD"](self.expiry)
15 s1 = fobs[self.asset1](self.expiry)
16 s2 = fobs[self.asset2](self.expiry)
17 return df * max(s1 - s2, 0)

Numerical Methods in QF (QF5204) Monte Carlo Method 65 / 91


The main Function For Pricing
1 asset1,asset2 = "STOCK1","STOCK2"
2 trade = SpreadOption(asset1, asset2, 1.0)
3 models = dict( asset1 = BlackScholes(10, 0.15, 0.10, 0.02),
4 asset2 = BlackScholes(10, 0.10, 0.10, 0.01), )
5 corrmat = 0, 0, np.identity(2)
6 corrmat[0, 1] = corrmat[1, 0] = 0.5
7 pv, se = mcPricer(trade, models, corrmat, nPaths = 1024*32);

More trade types — Asian Option


An Asian call option pays the option holder at option maturity T :
n
!
1X
max S(ti ) − K , 0 (54)
n
i=1

To create an Asian option is straight-forward now:


1 class AsianOption:
2 ...
3 def AllDate(self):
4 return self.fixings
5 def DiscountedMCPayoff(self, fobs):
6 df = fobs["DF.USD"](self.fixings[-1])
7 avg = 0
8 for t in self.fixings:
9 avg += fobs[self.asset](t)
10 return df * self.payoffFun(avg / self.nFix)

Numerical Methods in QF (QF5204) Monte Carlo Method 66 / 91


Target Redemption Forward
A structured product which consists of a strip of forwards each of
which has its payout as the difference between the underlying rate on
a given fixing and a predefined strike level:
Ci = S(ti ) − K (55)
The overall structure is limited by the requirement that once the total
payout exceeds a target level, the structure terminates (knocks out).
A generalized version allows the coupon Ci itself being a structure
(call, put, risk reversal, etc).
1 class TRF: # all that matters is implementation of DiscountedMCPayoff()
2 ...
3 def DiscountedMCPayoff(self, fobs):
4 df = fobs["DF.USD"](self.fixings[-1])
5 accum, discountedPO = 0
6 for t in self.fixings:
7 df = fobs["DF.USD"](t)
8 po = self.payoffFun(fobs[self.asset])(t)
9 accum += po
10 discountedPO += df * po;
11 if (accum > self.targetGain):
12 break # triggers knockout
13 return discountedPO

Numerical Methods in QF (QF5204) Monte Carlo Method 67 / 91


Variance Reduction Techniques

The commonly discussed techniques to reduce Monte-Carlo noise are


Antithetic sampling

Variates recycling

Control variates

Stratified sampling

Importance sampling

Numerical Methods in QF (QF5204) Monte Carlo Method 68 / 91


Antithetic Sampling

When we simulation Brownian motion by constructing sample paths,


we can make use of the fact that for any one drawn path its mirror
image has equal probability

If we draw a Brownian path Wi , and use it to evaluate the payoff


h(Wi ), we can also use −Wi and obtain h(−Wi ).

1
We use ĥi = (h(Wi ) + h(−Wi )) as our random sample of the
2
n
1X
payoff. The estimator becomes ĥi .
n
i=1

Numerical Methods in QF (QF5204) Monte Carlo Method 69 / 91


Antithetic Sampling
The variance of the new estimator is
 
1 1 1
Var (h(Wi ) + h(−Wi )) = Var [h(Wi )] + Cov [h(Wi ), h(−Wi )]
2 2 2
(56)

When we compare the variance with the standard Monte Carlo, we


should compare with the case with twice amount of simulation paths,
whose variance is 21 Var [h(Wi )]
So if Cov [h(Wi ), h(−Wi )] < 0 the Monte Carlo variance is reduced by
antithetic sampling — always true if h is monotonic w.r.t W
Antithetic sampling favours asymmetric payoff.
For symmetric payoff such as straddle, it does not help but does not
make it worse either — the payoff is symmetric on the spot which is
exponential of W , and the payoff is not necessarily centerred at S0 .

Numerical Methods in QF (QF5204) Monte Carlo Method 70 / 91


Antithetic Sampling — Implementation

Implementation is trivial, and saves cost of random number


generation — so nearly always turned on in practice.

We take our mcEuropean as example:


1 sum,hsquare = 0,0
2 stdev = math.sqrt(T)
3 for i in range(nPaths):
4 wT = np.random.normal(0, stdev)
5 hA = trade.payoff(S0 * math.exp((r-q-0.5*vol*vol)*T + vol*wT))
6 hB = trade.payoff(S0 * math.exp((r-q-0.5*vol*vol)*T - vol*wT))
7 h = 0.5 * (hA + hB)
8 sum += h
9 hsquare += h * h
10 pv = math.exp(-r*T) * sum / nPaths
11 stderr = math.sqrt((hsquare/nPaths - (sum/nPaths)*(sum/nPaths))/nPaths)

Numerical Methods in QF (QF5204) Monte Carlo Method 71 / 91


Antithetic Sampling — Result (Call Option)
0.4 normal MC PV error
antithetic PV error
normal MC stderr
0.2
antithetic stderr

−0.2

−0.4

−0.6
103 104 105 106
Number of MC Paths
European call option, K = 100, S = 100, r = 5%, q = 2%, T = 1, σ = 15%

Numerical Methods in QF (QF5204) Monte Carlo Method 72 / 91


Antithetic Sampling — Result (Straddle)
0.5 normal MC PV error
antithetic PV error
normal MC stderr
antithetic stderr
0

−0.5

−1

103 104 105 106


Number of MC Paths
European straddle, K = 100, S = 100, r = 5%, q = 2%, T = 1, σ = 15%

Numerical Methods in QF (QF5204) Monte Carlo Method 73 / 91


Variates Recycling
Greeks (risk or sensitivities) are more important than the prices, when
our pricer is numerical the usual way to calculate greeks is finite
difference:
For example the delta of an instrument is approximated by

∂PV PV (S + ∆S) − PV (S − ∆S)


δ= ≈ (57)
∂S 2∆S
The variance of delta is then
1
(Var (PVS+∆S ) + Var (PVS−∆S ) − 2Cov (PVS+∆S , PVS−∆S ))
4∆S 2
If we reuse the same random samples to estimate the PV+ and PV− ,
we can maximize the covariance term and thus reduce the noise on
our Greeks.
This is also a reason why we would like our “random” numbers to be
replicable
Numerical Methods in QF (QF5204) Monte Carlo Method 74 / 91
Control Variates
We are trying to estimate the expectation of a function h(X)
If we know the expectation of a function g (X) analytically, we can
use the estimator:
n
1X
E[h(X)] ≈ (h(Xi ) + β(g ∗ − g (Xi ))) (58)
n
i=1

where g ∗ is the known expectation of g (X) and β is a parameter.


The variance of the samples is

Var [h] + β 2 Var [g ] − 2βCov [h, g ] (59)

Taking the first derivative w.r.t β, the variance is minimized for


Cov [h, g ]
β= (can be estimated using simulation samples)
Var [g ]

Numerical Methods in QF (QF5204) Monte Carlo Method 75 / 91


Control Variates
The minimized variance is
Cov [h, g ]2
Var [h] − = Var [h](1 − ρ2 ) (60)
Var [g ]

The higher correlation g and h is, the more effective the technique is.

Examples of control variates


▶ Use forward as control variate for call option

▶ Use geometric Asian option as control variate for arithmetic Asian


option (possible only with Black-Scholes model).

Cannot be applied in a general way, need to fine tune based on the


problem

Numerical Methods in QF (QF5204) Monte Carlo Method 76 / 91


Stratified Sampling
Idea is to divide the domain into k disjoint sets and calculate the
expectation by
k
X
E[h(X)] = E[h(X|X ∈ Aj ]p(X ∈ Aj ) (61)
j=1

Depending on the function h, we can assign more paths to Aj whose


h value varies more and less paths to the A’s whose h value are more
constant
Inverse transformation method helps here because it allows us to draw
uniform random numbers corresponding to each strata due to
monotonicity
However, this technique is difficult to generalize and the choice of
strata is very problem-specific, difficult to define strata for
multi-dimensional problem as well

Numerical Methods in QF (QF5204) Monte Carlo Method 77 / 91


Importance Sampling
Idea is to apply a change of measure such that the probability mass is
shifted to the more important region
Z Z
q(X)
EQ [h(X)] = h(X)q(X)dX = h(X) p(X)dX (62)
p(X)
 
q(X)
= EP h(X) (63)
p(X)

We can design a p(X) such that it is centerred around the important


region of h(X), effectively more paths will be drawn on the important
region and fewer paths on the non-varying region.
Intrinsically the same as stratified sampling, so suffer the same
problem:
▶ very problem specific and difficult to generalize
▶ difficult to apply to multi-dimensional problem

Numerical Methods in QF (QF5204) Monte Carlo Method 78 / 91


Summary of Variance Reduction Techniques
We have discussed
▶ Antithetic sampling
▶ Variates recycling
▶ Control variates
▶ Stratified sampling
▶ Importance sampling

The simple ones are easy to implement and generalize (our preference)
The complicated ones are difficult to implement and generalize but
more effective when tackled in the right way
But overall the improvement they can make on the convergence is the
1
constant factor in front of O(n− 2 ). Is there any technique that can
change the convergence in terms of magnitude?

Numerical Methods in QF (QF5204) Monte Carlo Method 79 / 91


Monte Carlo Versus Quadrature
The Monte Carlo convergence rate is O(n−1/2 ). In contrast, the
simple trapezoidal rule (quadrature equivalent to Heun’s method)
estimates the integral of twice continuously differentiable function f ’s
integral by
n−1
f (0) + f (1) 1 X
α≈ + f (i/n).
2n n
i=1

whose error is O(n−2 ).


y
y = f (x)

x
1 j−1 j n−1
n n n n 1

Numerical Methods in QF (QF5204) Monte Carlo Method 80 / 91


It can be seen that Monte Carlo method is not a competitive method
for one-dimensional integration.
However, if we have a 2 dimensional problem and we discretize it to
m points for each dimension, the total number n = m2 . And a
quadrature rule basically says
Z 1Z 1
1 XX 1 XX
f (x, y )dxdy ≈ 2 f (xi , yj ) = f (xi , yj ) (64)
0 0 m n
i j i j

The error of the 2D integration is y


O(m−2 , m−2 ) — the lower order of the
two dimensions, so O(n−1 ).
When the dimension d grows, the error
of the quadrature remains the maximum
1
of the dimensions. And since m = n d in
general the trapezoid rule’s error is x
O(n−2/d ) for d dimensional problem,
Numerical Methods in QF (QF5204) Monte Carlo Method 81 / 91
Monte Carlo method remains O(n−1/2 ) due to central limit theorem.
Therefore Monte Carlo method is attractive in evaluating high
dimensional integrals.

But let’s have a look again at the Monte Carlo estimator:


Z n
1X
f (X)dX ≈ f (Xi ) (65)
A n
i=1

and compare it with the d dimensional quadrature with equal spacing:


Z n
1X
f (X)dX = f (Xi ) (66)
A n
i=1

It’s the same formula: taking average of sample evaluations of


function f (X). So what’s the difference?

Numerical Methods in QF (QF5204) Monte Carlo Method 82 / 91


The difference lies in the sample points chosen: quadrature chooses
regular grid points while Monte Carlo chooses random points:
y y mt19937

x x

Which one looks better? And why?

The error is associated with the density of the points when you
project them to each dimension. Random number is better in the
sense that after projection there are still n points.

Numerical Methods in QF (QF5204) Monte Carlo Method 83 / 91


Quasi Monte Carlo
Monte Carlo is good at higher dimension but if we can sample more
regularly on each dimension, just like what quadrature does in one
dimension, can the convergence rate be better?
Quasi random numbers were proposed to be used with Monte Carlo
for calculating integrations — Quasi Monte Carlo.
The idea is to generate low discrepancy sequence — uniformly
distributed without clustering
The discrepancy is measured by
(d) nS(y)
DN = sup | − Πdk=1 yk | (67)
y∈[0,1]d N

(log n)d
 
Quasi Monte Carlo (QMC) has a convergence rate O ,
n
and for d << n it’s approximately O(n−1 ).

Numerical Methods in QF (QF5204) Monte Carlo Method 84 / 91


Halton Sequence
Each dimension has a prime number base pi
From a generating number γ(n) for the n-th draw, convert it to each
dimension’s base
mni
X
γ(n) = aki pik−1 (68)
k=1
The quasi random number of the n-th draw for dimension i is then
mni
X
u(n) = aki pi−k (69)
k=1
For example, first dimension we let γ(n) = n and p1 = 2, the
sequence is
1 −→12 −→0.12 −→ 0.5
2 −→102 −→0.012 −→ 0.25
3 −→112 −→0.112 −→ 0.75
4 −→1002 −→0.0012 −→ 0.125
Numerical Methods in QF (QF5204) Monte Carlo Method 85 / 91
Example implementation of Halton sequence:
y mt19937 y Halton

x x

Numerical Methods in QF (QF5204) Monte Carlo Method 86 / 91


QMC European Convergence
mt19937 Error
Halton Error
0.2

103 104 105 106


Number of MC Paths
European call option, K = 100, S = 100, r = 5%, q = 2%, T = 1, σ = 15%

Note that to convert from uniform distribution to normal distribution,


only inverse transformation method works for quasi random numbers

Numerical Methods in QF (QF5204) Monte Carlo Method 87 / 91


Quasi Random Numbers in Monte Carlo
When using quasi random numbers in Monte Carlo simulation, we
have to be very careful on drawing random numbers
Each Brownian increment is one dimension, so if we have 100 time
steps, we need to draw random vectors of length 100
The limitation of Halton sequence is very obvious now: when the base
number becomes larger, the discrepancy is not that low
y Halton with base 57, 59

Numerical Methods in QF (QF5204) Monte Carlo Method 88 / 91


Commonly Used Quasi Random Sequences
Sobol sequences, Niederreiter, and Scrambled version of them

Numerical Methods in QF (QF5204) Monte Carlo Method 89 / 91


QMC — Dimensionality

Quasi random numbers (low discrepancy sequences) have limited


dimension and the quality of the dimension decreases with larger base.

It is therefore important to be able utilize the good quality dimensions


whose varieties are the most to the important simulation events, for
example, option expiries. This can be achieved through
▶ Brownian bridge construction: use the first dimension to construct the
sample of the expiry date, the second dimension to construct the time
in the middle, etc.

▶ PCA construction: use the lower dimension numbers to construct the


principal components of the Brownian motion, i.e., the skeleton of it.

▶ See [2] for more details.

Numerical Methods in QF (QF5204) Monte Carlo Method 90 / 91


References and Future Readings

P. Jäckel.
Monte Carlo Methods in Finance.
2002.
P. Glasserman.
Monte Carlo Methods in Financial Engineering.
Springer, 2003.

Numerical Methods in QF (QF5204) Monte Carlo Method 91 / 91

You might also like