0% found this document useful (0 votes)
17 views60 pages

QF5211 Lecture05 (2025) - Notes

The document discusses Monte Carlo methods in mathematical finance, focusing on importance sampling techniques for estimating expected values. It introduces methods such as mode matching and the cross-entropy method to choose alternative distributions that minimize variance. Examples illustrate the application of these methods in estimating tail probabilities and pricing binary call options.

Uploaded by

Li Xuan Guang
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)
17 views60 pages

QF5211 Lecture05 (2025) - Notes

The document discusses Monte Carlo methods in mathematical finance, focusing on importance sampling techniques for estimating expected values. It introduces methods such as mode matching and the cross-entropy method to choose alternative distributions that minimize variance. Examples illustrate the application of these methods in estimating tail probabilities and pricing binary call options.

Uploaded by

Li Xuan Guang
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/ 60

Monte Carlo Methods in

Mathematical Finance

Lecture 07:
i Importance sampling
The method of mode matching; the cross-entropy method
Introduction
Consider the problem of estimating the expected value
µ = E[h(X)].
f
Suppose X has the density f(x).
• Plain MC: draw iid samples from f(x), then compute the sample
average of h(x).
• Importance sampling: For arbitrary density g(x), we have
f (x) f (Y )
µ= h(x)f (x)dx = h(x) · g(x)dx = E h(Y ) ,
g(x) g(Y )
R R
g
where Y is a random variable with density g .
Draw iid samples from the density !, then compute the sample
average of ℎ(#)$(#)/!(#).
The weight $(#)/!(#) is called the likelihood ratio.
M E
g
Chen fi

MT
Generate in samples from the distribution
dep
of T

Y 72 Tn

Mn i
I
i
hiki
4
Variance of Mn

Varna Van En
É hiii
s I

É varlet fi
In Var chis gg
me O

g y c b ly fly
v

Vantil I Var E o

s
f chest fini dy c
In
gty.fm
i
R y
Introduction
q E Ch
Importance sampling for discrete random variables:
Suppose ! is a discrete random variable with distribution
P(X = xk ) = p(xk ), k = 1, 2, · ref
·· x x
Let " be an alternative random variable with probability
distribution or x y I
P(Y = xk ) = p̄(xk ), k = 1, 2, · · ·

Importance sampling: Generate iid samples for ", then use the
sample average of
p(Y )
h(Y ) ·
p̄(Y )
as the estimate.
How to choose the alternative distribution?
Principle of choosing alternative distributions:
The use of the alternative distribution should reduce the variance of
the estimate as much as possible.
The variance of the importance sampling estimate is
n
1 f(Yi ) 1 f(Y )
Var h(Yi ) · = Var h(Y ) · .
n i=1
g(Yi ) n g(Y )

Suppose h is nonnegative. Then the variance is minimized (=0) if


g(x) = c · h(x)f(x),
where ! is the normalization constant.

However, this choice is impractical!

Guideline of choosing ": " should be chosen to mimic ℎ($)%($).


How to choose the alternative distribution?

We will study the following methods for choosing alternative


distributions:

– Mode matching
– Cross-entropy method

matching
Match the mode of 9 x with mode of h x fix
I unto

Y info
Q argmax h x fix
x

441 fix 0 O

Into.tn x

y nfo.im a

O argmax hix Lex


x

ti ti x e x
all o

k 2 m

O Oz On
Normal Distributions

• Consider the problem of estimating the expected value


µ = E[h(X)]
where X is a standard normal random variable, whose density
! is "(0, 1).

• Choose the alternative distribution # to be a normal


distribution with the same variance: "($,1), for some $ ∊ &.

• The likelihood ratio is


f (x) 1
= exp x+ 2
g(x) 2
Normal Distributions

How to choose the parameter !?


É
O argue thex ha fix
The method of mode matching: ! is chosen so as to match
mode of " with the mode of ℎ($)%($).
• The mode of continuous distribution is the value x at which its
probability function has its maximum value.
• The mode of " is !, therefore, we choose
= argmaxx h(x)f (x),
i.e. the value x at which ℎ($)%($) attains its maximum.

N O 1
Example 1: Estimate tail probability

Example: Estimate the tail probability !(" > #) , where X is a


standard normal random variable and # is large.

Plain MC:
– Generate iid samples from $(0,1)
– Compute the sample average of 1{X>a}

Importance sampling:
– Generate iid samples from $(%,1) , where %=max(#, 0)
– Compute the sample average of
f (X) 1
1{X>a} · = 1{X>a} · exp X+ 2
f (X) 2
M P x at

El Lix all
of

E
g City as

Y N o 1

h x fix
O arguex
x

t a
h lx text
Ig a
fix
f O XE c

D a a o

I
Example 1: Estimate tail probability

300 300
a s

N O 1
200 200 a 5

100 100

0
−5 0
f5 0
−8 −6 −4 −2 0
x
2 4 d 6 8
x

d
Figure: Plain MC (left) and importance sampling (right). E
a = 5, N = 10000, exact value = 2.867 10 7
Plain MC estimate =0, IS estimate = 2.838 10 7
Example 2: Mode Matching for Binary Call

Example: Estimate the price of a binary call option with maturity


T and payoff
1{ST K}

where under the risk-neutral probability measure, the stock


price is a geometric Brownian motion
1
St = S0 exp r 2
t + Wt .
2
t X
s s et X woo

St Z K E

X leg er tilt

MEEE 1 Is
kl
r
e E C Lz x eat
Example 2: Mode Matching for Binary Call
Importance sampling scheme:
• The price of the option can be written as
v=E e rT
1{ST ⇥K} = E e rT
1{X⇥b} := E[h(X)],

where X is N (0, 1) , and b = ( T ) 1 log(K/S0 ) (r 2


/2)T .
• Let f be the probability density of N (0, 1) . Then
0, if x < b
h(x)f (x) =
e rT
f (x), if x b
whose mode (maxima) is = max{b, 0}.
• Using N ( , 1) as the alternative sampling distribution, the
importance sampling estimate is the sample of average of
f (Y ) 0, if Y < b
h(Y ) · =
g(Y ) exp rT Y + 2
/2 , if Y ⇥ b
Example 2: Mode Matching for Binary Call

Algorithm (importance sampling):


• set = max{b, 0}
• for i = 1, 2, · · · , n
generate a sample Y from N ( , 1)
set Hi = 0, if Y < b
exp rT Y + 2
/2 , if Y b
n
1
• compute the estimate v̂ = Hi
n i=1
n
1
• compute the standard error S.E. = Hi2 nv̂ 2
n(n 1) i=1
Example 2: Mode Matching for Binary Call

Experiments with parameters:


S0 = 50, r = 0.01, = 0.1, T = 1, n = 10000
K=60:
<latexit sha1_base64="EvbLiWWtTt3xh+esLCcu27qE/cc=">AAACQXicbZA9T9tAGMfPlJY0tMWUscuJqBIDtWwnkckQCdGFESRCqOIoOl+ekFPOL9w9jhRZ+WwsfAI2PkCXDqXqysIl8UBDH+mkv37P6/2jTAqNrvtgbbzZfPtuq/K+uv3h46cde/fzpU5zxaHDU5mqq4hpkCKBDgqUcJUpYHEkoRtNvi/y3SkoLdLkAmcZ9GN2nYiR4AwNGtg/QhwDsrbnBEHdP6ThTc6GdNquO0HT9+Gb6x+ukAbapk2n6bU8QxslLcLlCUUkc5grMGMagdtatM0Hds113GXQ18IrRY2UcTaw78NhyvMYEuSSad3z3Az7BVMouIR5Ncw1ZIxP2DX0jExYDLpfLPfP6VdDhnSUKvMSpEv6sqNgsdazODKVMcOxXs8t4P9yvRxHR/1CJFmOkPDVolEuKaZ04ScdCgUc5cwIxpUwt1I+ZopxNK5XjQne+pdfi47vtBz3vFE7PindqJAvZJ8cEI8E5JickjPSIZzckp/kN3m07qxf1h/r76p0wyp79sg/YT09A6SRqpY=</latexit>
= 1.7732, v = 3.7522e 02, se = 5.5191e 04, re = 1.4709e 02
<latexit sha1_base64="Rdczq8JxwCPkgRzEAFBe8U+/Mvk=">AAACQXicbZC7ThtBFIZnIYAxN0NKmlEspBSwmvUFTGHJIg2lI8WYyGtZs+NjPGL2wsxZS9bKz0bDE6TjAWgokog2Tcb2FglwpJF+fec6f5AoaZCxR2dl9cPa+kZhs7i1vbO7V9o/uDJxqgV0RKxifR1wA0pG0EGJCq4TDTwMFHSD2y/zfHcC2sg4+obTBPohv4nkSAqOFg1K330cA/Imc5mNY+rfpXxIJ82qW6vW63DCKsdLZIA2qec2vIpnaTWnmb84IQtUCjMNzbpbOaudzttmg1J5OZQx+lZ4uSiTPNqD0g9/GIs0hAiF4sb0PJZgP+MapVAwK/qpgYSLW34DPSsjHoLpZ4v9M3pkyZCOYm1fhHRB/+3IeGjMNAxsZchxbF7n5vC9XC/FUaOfyShJESKxXDRKFcWYzv2kQ6lBoJpawYWW9lYqxlxzgdb1ojXBe/3lt6JTcc9d9rVWbl3kbhTIIflEPhOPnJEWuSRt0iGC3JMn8pP8ch6cZ+e387IsXXHyno/kv3D+/AV3mqp9</latexit>
= 0.0000, v = 3.4355e 02, se = 1.8121e 03, re = 5.2746e 02
N O I T
K=70:
<latexit sha1_base64="7PhQaUgeQ3gJTmElGXvxDq0+0B0=">AAACQX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skm3ikQNyRE5JldSIIA/khbyRd+fReXU+nM+hdcIZ9ayTH3C+vgGAg6qB</latexit>
= 0.0000, v = 8.9104e 04, se = 2.9690e 04, re = 3.3320e 01

Matlab code: option_binary_IS.m


Example 3: Mode Matching for European Call

Example: Use importance sampling to estimate the price of an


European call option with maturity T and strike price K.

Compare with the plain Monte Carlo scheme.

Experiment with parameters


S0 = 50, r = 0.01, = 0.2, T = 1, n = 10000
K = 60, 80, 100, 120.

Matlab code: option_European_IS.m


n E
x Nia's

ha ha e
rt
sett FX
n étx

Y nta.IT fix

h t
O arg
x
y mode marching

ha Lex
0
Example 3: Mode Matching for European Call

• The price of the call option is


v = E[h(X)]
where X is a standard normal random variable, and
+
h(x) = S0 exp 1
2
2
T+ Tx e rT
K .

• Let ! be the probability density of "(0, 1), and # be the


alternative sampling density "($, 1) , where $ is the
maximizer of ℎ(&)!(&), which solves
1 2
ex
ex S0 exp ⇥ T +⇥ T (⇥ T )+e rT
K = 0.
2
t
1 I
Example 3: Mode Matching for European Call

Algorithm (importance sampling):

• Solve for ;
• For i = 1, 2, · · · , n
generate a sample Y from N ( , 1)
set Hi = h(Y ) exp Y + 2 /2 a
n
1
• Compute the estimate v̂ = Hi
n i=1

n
1
• Compute the standard error S.E. = Hi2 nv̂ 2
n(n 1) i=1
Extension to General Distributions

• In the previous examples, ! is a standard normal random variable


with density "; we choose the alternative sampling distribution
from the family of #($, 1), i.e. Six f x op
e
2
g(x) = e /2
· e x f (x).
x
t e
• Generalize this to general distributions: For a general random
variable, the alternative sampling distribution is chosen from the
exponential tilt family.
fpex c fix I C
ked fixidx
g
C

Exponential Tilt Family t


Eleox
• ! is continuous: Let " denote the density of ! . The exponential
tilt family consists of probability distributions with density
1
f (x) = e x
f (x), R.
E[e X ]
e.g. if X is normally distributed, then the exponential tilt family
consists of all normal distributions with the same variance.
• X is discrete: Let the probability mass function be p, i.e.
p(X = x) = p(x)
The exponential tilt family consists of probability distributions
with probability mass function
1
p (x) = e x
p(x), R.
E[e X ]
X Bernoulli random variable

or i of
Pfx if P PS x o i p

Y Bernoulli

or i ol

p f y 11 p P 37 01 i f

f Prob 7 11 Egg É r

É
e f Pros 14 01
Ed P
d p

o o

E eat p t i p p ed i p
Example 4: Application to Risk Analysis

Example: Consider a credit risk model with ! independent obligors.


Denote by pk the probability that the k-th obligor defaults and ck
the loss resulting from its default.

Assume ck = 1 for every k, and the total loss is


m m
L= ck Xk = Xk , he it de Laa
k=1 k=1 l o otherwise
where Xk is the default indicator for the k-th obligor; Xk ’s are
independent Bernoulli random variables:
P(Xk = 1) = pk , P(Xk = 0) = 1 pk .

Use importance sampling to estimate the tail probability P(L > x) ,


where " is a large threshold.
M Prob i x E It x

T
joint dist of Xi Yz Xm

1111
L

Importance sampling

Xie f t
of le 1,2 m

g Tp
P

Tk 1 o f
t
pi i pi

d.me
pi
É O

Choice of O

Recall E
me Rob X sa
f Ipx all
X n n lo I

Y N o d

ECT a a a
É
g
For the current problem

M E C 11L Cx xm x

E I Likelihood ratio
f L y em say

E E Y x

Z E Che x

I 1
pi t o i
pi x

Pic x
k

É o

Likelihood ratio

is a 1
111,4ft It
is Y
Ifi
o
I I 1
Example 4: Application to Risk Analysis
Important sampling scheme:
• Choose the alternative sampling distribution from the exponential
tilt family: Let Yk ’s be independent Bernoulli random variables
such that
1 pk e
p̄k = P(Yk = 1) = e · P(X k = 1) = ,
E[e Xk ] 1 + pk (e 1)
P(Yk = 0) = 1 p̄k , k = 1, 2, · · · , m
• The likelihood ratio is
m yk 1 yk
pk 1 pk
R(y1 , · · · , ym ) =
p̄k 1 p̄k
k=1

• The importance sampling estimate is the sample average of iid


copies of m
H = 1{L̄>x} · R(Y1 , · · · , Ym ), where L̄ = Yk
k=1
Example 4: Application to Risk Analysis

Choose to make the variance of the estimate as small as possible.


2
Var[H] = E[H 2 ] (E[H]) = E[H 2 ] µ2
m 2Yk 2(1 Yk )
pk 1 pk
E[H 2 ] = E 1{L̄>x}
p̄k 1 p̄k
k=1

= E 1{L̄>x} e 2 L̄+2⇥( )
, E[H 2 ] e 2 x+2⇥( )
.
m
where ⇥( ) = log 1 + pk (e 1) .
k=1
Minimize the upper bound to determine :

min 2 x + 2⇥( ) ⇥ ( ) = x.
Example 4: Application to Risk Analysis
Algorithm (importance sampling):
• Solve ⇥ ( ) = x for ;
• Compute the corresponding p̄k for k = 1, · · · , m
• For i = 1, 2, · · · , n
generate Yk from Bernoulli with parameter p̄k for k = 1, · · · , m
set L = Y1 + · · · + Ym Likelihood rasio
a Is xp
Yk 1 Yk
m pk 1 pk
set Hi = k=1 p̄k 1 p̄k if L > x; otherwise Hi = 0
n
1
• Compute the estimate v̂ = Hi
n i=1

n
• Compute the standard error S.E. = 1
Hi2 nv̂ 2
n(n 1) i=1
Example 4: Application to Risk Analysis

Experiments with parameters:


m = 1000 , pk = 0.01 · (1 + e ), k = 1, 2, · · · , m
k/m

n = 10000
X=20: PIL a
= 2.0726e 01, v = 1.4653e 01, se = 1.9288e 03
<latexit sha1_base64="bYgq8ofRjeMu6WGv5jplWR8F6Dk=">AAACfHicfVHbSiNBEO0Z11vWS9RHX5oNgtehJ2NifBBEX/ZRwaxCJoSeTsU09lzsrhHCkL/wy/Ztf8UX7VyQrIoFDYdTp05VV0WZkgYZ++e4cz/mFxaXlks/V1bX1ssbm39MmmsBTZGqVN9F3ICSCTRRooK7TAOPIwW30cPlKH/7BNrINLnBQQbtmN8nsicFR0t1ys8h9gE5PaNVj51U63DE/MPwMedd+nTme8f1WjBDFeG4YxGpHIYGrOC02mhYQTCkYVh692Ies2F5NuNV8wP2jVfg1RpBfezVKVcmDozRz8CfggqZxlWn/DfspiKPIUGhuDEtn2XYLrhGKRQMS2FuIOPigd9Dy8KEx2Daxbj/kO5Ypkt7qbYvQTpmZysKHhsziCOrjDn2zcfciPwq18qx12gXMslyhERMGvVyRTGlo1PQrtQgUA0s4EJLOysVfa65QHuwkl2C//HLn0Gz6p167Pq4cn4x3cYS2Sa/yC7xyQk5J7/JFWkSQV4c6uw5+86ru+MeuEcTqetMa7bIf+HW3wDAArfb</latexit>
= 0.0000e 00, v = 1.5130e 01, se = 3.5836e 03
X=40: PIL Got
= 9.2128e 01, v = 1.4905e 07, se = 3.8022e 09
<latexit sha1_base64="etwFLmzHOvQQNoIQK60Q5gtd5D0=">AAACfHicbVFNTxsxEPUu5SstENojF6sREuVj5V2gJIdIqL30SCVSkLJR5HUmxML7gT2LFK32X/DLeuOvcAEnWVGaMJKl5zdv3tgzUaakQcYeHXfpw/LK6tp67eOnjc2t+vbnPybNtYCOSFWqryNuQMkEOihRwXWmgceRgqvo9uckf3UP2sg0ucRxBr2Y3yRyKAVHS/XrDyGOADlt05YX+EETjph/GN7lfEDv27530mKnljqrqCKcdiwilUNpoH3sNVkQWEGrpGFYe/ViHrMBB4y9ei1Q817/BGW/3pjdGKOLwK9Ag1Rx0a//DQepyGNIUChuTNdnGfYKrlEKBWUtzA1kXNzyG+hamPAYTK+Y9i/prmUGdJhqexKkU/ZtRcFjY8ZxZJUxx5GZz03I93LdHIfNXiGTLEdIxKzRMFcUUzpZBR1IDQLV2AIutLRvpWLENRdoF1azQ/Dnv7wIOoHX8tjvk8b5j2oaa2SHfCV7xCdn5Jz8IhekQwR5cqjzzdl3nt1d98A9mkldp6r5Qv4L9/sLgdy3sg==</latexit>
= 0.0000e + 00, v = 0.0000e + 00, se = 0.0000e + 00

Matlab code: credit_risk_IS.m


The Cross-Entropy Method

Recall that the importance sampling estimate based on the


sampling density
1
g (x) = h(x)f (x)
µ
has zero variance (however, using this density as the alternative
sampling distribution is impractical).

The cross-entropy method chooses the density f (x) that is closest


to g (x) as the sampling density, i.e
g (x)
min R(g f )= log · g (x)dx,
R f (x)
where R(g f ) , the Kullback-Leibler cross entropy, measures
how close the two distributions are.
The Cross-Entropy Method

Note that 941 In hix fix

R(g f )= g (x) log g (x)dx g (x) log f (x)dx


R R

1
= g (x) log g (x)dx h(x)f (x) log f (x)dx.
R µ R

Therefore, d f
min R(g f ) max
IP
h(x)f (x) log f (x)dx.
R

max E [h(X) log f (X)] o


f
where the random variable X has density f .

m Ecg
f
The Cross-Entropy Method
• The maximizer is the solution to the equation
⇥ ⇥
0= E[h(X) log f (X)] = E h(X) log f (X) .
⇥ ⇥
of
• Replace the expected value by sample average:
N
1 ⇥
0= h(Xk ) log f (Xk ),
N ⇥
k=1
where Xk ’s are iid copies of X.
• The above equation can be exactly solved for normal distributions:
Suppose f (x) is the density of N (0, Im ) , f (x) is the density of
N ( , Im ), where = ( 1 , · · · , m ) Rm, then the solution is
N
ˆ= k=1 h(Xk )Xk
N
, GRM
k=1 h(Xk )

where Xk ’s are iid samples from N (0, Im ) .


X n w to I

Y n a
go y
E x 05
Go x e

O I É ha GE I ix or

o
Ég
Algorithm

Algorithm:
• Generate N iid pilot samples X1 , · · · , XN from density f (x);
• Compute the optimal tilting parameter ˆ ;
• For i = 1, 2, · · · , n
generate Yi from the alternative sampling density f ˆ(x)
set Hi = h(Yi ) · f (Yi )
f ˆ(Yi )
n
• Compute the estimate v̂ = 1 Hi
n i=1

n
1
• Compute the standard error S.E. = Hi2 nv̂ 2
n(n 1) i=1
Example 5: the CE method for European call

Example: Using the cross-entropy method to compute the price


of the European call option with strike price K and maturity T .

Compare the result with the plain Monte Carlo method.

Under the risk-neutral measure, the stock price is a geometric


Brownian motion
1 2
St = S0 exp r t + Wt .
2
Example 5: the CE method for European call

• The price of the call option is


v = E[h(X)]
where X is the standard normal random variable, and
+
1
h(x) = S0 exp 2
T+ Tx e rT
K .
2
• The alternative sampling density is chosen from the family !(",1).
• The likelihood ratio is
f (x)
l (x) = = exp x+ 2
/2
f (x)
Example 5: the CE method for European call

Algorithm:
• Generate N iid pilot samples X1 , · · · , XN from density N (0, 1)
• Set ˆ = N k=1 h(Xk )Xk /
N
k=1 h(Xk )
• For i = 1, 2, · · · , n
generate Yi from the alternative sampling density N ( ˆ, 1)
set Hi = h(Yi ) exp ˆYi + ˆ2 /2
n
• Compute the estimate v̂ = 1 Hi
n i=1

n
1
• Compute the standard error S.E. = Hi2 nv̂ 2
n(n 1) i=1
Example 5: the CE method for European call
Experiment with parameters
S0 = 50, r = 0.05, = 0.2, T = 1
N = 2000 pilot samples
n = 10000 samples in importance sampling
K=60:
<latexit sha1_base64="Yiv/E2rPIDCG12apGdMogkGeMZY=">AAACK3icbVDLSgNBEJz1GeMr6tHLYBAENcxKSMxBEL14jGCMkA1hdtIxg7MPZ3qFsOSDvPgrgngw4tX/cJLswVfBQHVVN91TfqykQcZGzszs3PzCYm4pv7yyurZe2Ni8NlGiBTREpCJ943MDSobQQIkKbmINPPAVNP2787HffABtZBRe4SCGdsBvQ9mTgqOVOoVzD/uA/MQtVSvl6oF3n/AufbBlxa2WYZ+xTEq9ya7UVwkMDdgGVjuuwCE7GtJOochKbAL6l7gZKZIM9U7hxetGIgkgRKG4MS2XxdhOuUYpFAzzXmIg5uKO30LL0pAHYNrp5IAh3bVKl/YibV+IdKJ+n0h5YMwg8G1nwLFvfntj8T+vlWDvuJ3KME4QQjFd1EsUxYiOk6NdqUGgGljChZb2Vir6XHOBNt+8DcH9/eW/pHFUqpXYZbl4epalkSPbZIfsEZdUySm5IHXSIII8kmfyRkbOk/PqvDsf09YZJ5vZIj/gfH4B2+ij7g==</latexit>
= 1.7647, v = 1.6174e + 00, se = 1.0986e 02
<latexit sha1_base64="zeloWIgTGDS+INOdrA4DynbJVHM=">AAACK3icbVDJSgNBFOxxjXGLevTSGARBHXpC3A4B0YtHBaNCJoSezotp0rPY/SYQhnyQF39FEA8qXv0POwviVtBQVL3iva4gUdIgY6/OxOTU9Mxsbi4/v7C4tFxYWb0ycaoFVEWsYn0TcANKRlBFiQpuEg08DBRcB53TgX/dBW1kHF1iL4F6yG8j2ZKCo5UahVMf24C8wlxmsePfpbxJuxXP3dvf82D7S8r84a4sUCn0DVTKrlfeL8EuK/Vpo1AcxRmjf4k3JkUyxnmj8OQ3Y5GGEKFQ3JiaxxKsZ1yjFAr6eT81kHDR4bdQszTiIZh6NjygTzet0qStWNsXIR2q3xMZD43phYGdDDm2zW9vIP7n1VJsHdYzGSUpQiRGi1qpohjTQXO0KTUIVD1LuNDS3kpFm2su0PabtyV4v7/8l1RL7pHLLsrF45NxGzmyTjbIFvHIATkmZ+ScVIkg9+SRvJBX58F5dt6c99HohDPOrJEfcD4+AaRPo80=</latexit>
= 0.0000, v = 1.5651e + 00, se = 4.1462e 02
K=100:

<latexit sha1_base64="hT+lO7jv0W4zelNrHurrW8PlNag=">AAACK3icbVDJSgNBEO2Je9yiHr00BsGDhs6iMYdA0ItHBaNCJoSeTiVp0rPYXSOEIR/kxV8RxIOKV//DTpyD24OGV69eUdXPi5Q0yNirk5mZnZtfWFzKLq+srq3nNjavTBhrAU0RqlDfeNyAkgE0UaKCm0gD9z0F197wdNK/vgNtZBhc4iiCts/7gexJwdFKndypiwNAXi8XqrVqZd+9jXmX3tVLhQo7qsIBK6dS4k53JZ6KYWzA+hkr16zhcEw7uTyz5QT0LymmJE9SnHdyT243FLEPAQrFjWkVWYTthGuUQsE468YGIi6GvA8tSwPug2kn0wPGdNcqXdoLtX0B0qn6fSLhvjEj37NOn+PA/O5NxP96rRh7x+1EBlGMEIivRb1YUQzpJDnalRoEqpElXGhpb6ViwDUXaPPN2hCKv7/8lzRLhVqBXVTyjZM0jUWyTXbIHimSKmmQM3JOmkSQe/JIXsir8+A8O2/O+5c146QzW+QHnI9P44ej8g==</latexit>
= 3.7974, v = 2.4067e 03, se = 3.0039e 05
<latexit sha1_base64="TNxs2vQwivLFcUt+5Se52q4gqOM=">AAACK3icbVDLSgMxFM34tr6qLt0Ei+BCh0yrqItCsRuXClaFTimZ9NaGZh4md4Qy9IPc+CuCuFBx63+YtrPwdSBwOOdc7s0JEiUNMvbmTE3PzM7NLywWlpZXVteK6xtXJk61gIaIVaxvAm5AyQgaKFHBTaKBh4GC66BfH/nX96CNjKNLHCTQCvltJLtScLRSu1j3sQfIq8xlFnv+Xco79L5acU/YoQf7rJJLmT/elQUqhaGBatktV9jBKDCk7WJpMs4Y/Uu8nJRIjvN28dnvxCINIUKhuDFNjyXYyrhGKRQMC35qIOGiz2+haWnEQzCtbHzAkO5YpUO7sbYvQjpWv09kPDRmEAY2GXLsmd/eSPzPa6bYPW5lMkpShEhMFnVTRTGmo+ZoR2oQqAaWcKGlvZWKHtdcoO23YEvwfn/5L2mU3ROXXRyUaqd5Gwtki2yTXeKRI1IjZ+ScNIggD+SJvJI359F5cd6dj0l0yslnNskPOJ9fpNujzQ==</latexit>
= 0.0000, v = 3.9051e 03, se = 2.2304e 03
Matlab code: option_European_CE.m
Example 5: the CE method for European call

K = 120:

<latexit sha1_base64="qU8l83rwLp2J2T4i6tgMeeq1k9Y=">AAACDXicbZC7SgNBFIZnvcZ4i1raDIaAhYSNCGoRCNpYhQhGhWwIZycnZnD24sxZISx5AhtfxcZCxdbezrdxNga8xB8GvvnPOcyc34+VNOS6H87U9Mzs3HxuIb+4tLyyWlhbPzdRogU2RaQifemDQSVDbJIkhZexRgh8hRf+9XFWv7hFbWQUntEgxnYAV6HsSQFkrU6h5FEfCXiV16G+490k0OW31W82mF06haJbdkfik1AZQ5GN1egU3r1uJJIAQxIKjGlV3JjaKWiSQuEw7yUGYxDXcIUtiyEEaNrpaJ0hL1mny3uRtickPnJ/TqQQGDMIfNsZAPXN31pm/ldrJdQ7aKcyjBPCUHw91EsUp4hn2fCu1ChIDSyA0NL+lYs+aBBkE8zbECp/V56E5m75sOye7hVrR+M0cmyTbbFtVmH7rMZOWIM1mWB37IE9sWfn3nl0XpzXr9YpZzyzwX7JefsE0SGaRA==</latexit>
= N aN, v = N aN, se = N aN

When K is large, the method does not produce meaning result.


This is due to the poor estimation of the tilting parameter.
Example 6: The CE method for Asian option

Example: Compute the price of a discretely monitored average


call option with payoff (S̄ K)+ and maturity T , where S̄ is the
arithmetic mean
m
1
S̄ = Stk
m
k=1
for a given set of dates 0 < t1 < · · · < tm = T .

Assume that under the risk-neutral probability measure, the


underlying asset is a geometric Brownian motion.
1 2
St = S0 exp r t + Wt .
2
Example 6 : The CE method for Asian option
• For k = 1, 2, · · · , m,
1
Stk = S0 exp r 2
tk + Wtk
2
1
= S0 exp r 2
(tk 1 + (tk tk 1 )) + Wtk + tk tk 1 Zk
2 1

1
= Stk exp r 2
(tk tk 1) + tk tk 1 Zk
1
2
where Z1 , · · · , Zm are iid standard normal random variables.

• The discounted option payoff can be written as a function of the


m-dimensional standard normal random vector:
h(X) = e rT
(S̄ K)+ .
Example 6 : The CE method for Asian option
• Denote the joint density function of X by f ,
m m
1 1
f (x) = exp x2i .
2 2
k=1
• Choose the alternative sampling distribution from the family
of N ( , Im ) , where Rm, i.e.
m m
1 1
f (x) = exp (xi i)
2
.
2⇥ 2
k=1

• The importance sampling estimate is the sampling average of


iid copies of
m m
f (Y ) 1
h(Y ) · = h(Y ) exp Y
i i + 2
,
f (Y ) 2 i
k=1 k=1

where Y has distribution N ( , Im ) .


Example 6 : The CE method for Asian option

Choice of the tilting parameter (cross-entropy algorithm):

Let X1 , · · · , XN be iid pilot samples from the original distribution


N (0, Im ), then is given by

N
ˆ= i=1 h(Xi )Xi
N
.
i=1 h(Xi )
Example 6 : The CE method for Asian option

Algorithm (computation of the tilting parameter):

• For k = 1, 2, · · · , N
for j = 1, 2, · · · , m
generate Zj from N (0, 1)
set Stj = Stj 1 exp r 2
/2 (tj tj 1) + tj tj 1 Zj

set Hk = e rT
(S̄ K)+
N
• Set ˆ = ( ˆ1 , · · · , ˆm ) = k=1 Hk Xk
N
k=1 Hk
Example 6 : The CE method for Asian option
Algorithm (cross-entropy):
• Compute the tilting parameter using pilot samples
• For i = 1, 2, · · · , n
for j = 1, 2, · · · , m
generate Yj from N ( ˆj , 1)
set Stj = Stj 1 exp r 2
/2 (tj tj 1 ) + tj tj 1 Yj

compute the discounted payoff x the likelihood ratio


m m
Hi = e rT
(S̄ K)+ · exp ˆj Yj + 1 ˆ2 ,
j=1
2 j=1
j

n
• Compute the estimate v̂ = 1
n i=1 Hi
n
1
• Compute the standard error S.E. = Hi2 nv̂ 2
n(n 1) i=1
Example 6 : The CE method for Asian option
Experiment with parameters
S0 = 50, r = 0.05, = 0.2 T = 1, m = 12, ti = i/m
N = 2000, n = 10000

K=50:
v = 3.0722e + 00,
<latexit sha1_base64="EMyFFqcayuN9JI7E0+p7V+dTfUk=">AAACGHicbVDLTgIxFO34RHyhLt00EhMTddIZMeiChOjGJSYiJEBIp1ygofOw7ZCQCb/hxl9x40KNW3b+jeWxUPAkNzk559723uNFgitNyLe1tLyyurae2khvbm3v7Gb29h9VGEsGZRaKUFY9qkDwAMqaawHVSAL1PQEVr3c79it9kIqHwYMeRNDwaSfgbc6oNlIzQ/qFC5vkXRdOCTmrP8W0hZP65N3EEzEMsYICduxLks/BOXGHzUyW2GQCvEicGcmiGUrNzKjeClnsQ6CZoErVHBLpRkKl5kzAMF2PFUSU9WgHaoYG1AfVSCYbDPGxUVq4HUpTgcYT9fdEQn2lBr5nOn2qu2reG4v/ebVYt68aCQ+iWEPAph+1Y4F1iMcx4RaXwLQYGEKZ5GZXzLpUUqZNmGkTgjN/8iIpu/a1Te5z2eLNLI0UOkRH6AQ5KI+K6A6VUBkx9Ixe0Tv6sF6sN+vT+pq2LlmzmQP0B9boB3G4nQs=</latexit>
se = 1.5074e 02
v = 3.1192e + 00,
<latexit sha1_base64="y4ehYKeXdVP0f0FkA8NxliciCaE=">AAACGHicbVBNS0JBFJ1nX2ZfVss2QxIE1WPeSygXgtSmpUGmoCLzxqsOzvtoZp4gD/9Gm/5KmxYVbd31bxo/FqUduHA4596Ze48XCa40Id9WamV1bX0jvZnZ2t7Z3cvuHzyqMJYMKiwUoax5VIHgAVQ01wJqkQTqewKqXv924lcHIBUPgwc9jKDp027AO5xRbaRWlgyKl7bjFFw4I+S88RTTNk4a03cTT8QwwgqKOG+7eVKAC+KOWtkcsckUeJk4c5JDc5Rb2XGjHbLYh0AzQZWqOyTSzYRKzZmAUaYRK4go69Mu1A0NqA+qmUw3GOETo7RxJ5SmAo2n6u+JhPpKD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N4V0z4RhCqdZUaHYC9+eRnU87lyzrotZKtX8zTS6Agdo1NkoxKqohtUQ3VE0SN6Rq/ozXgyXox342NmTRnznkP0p4zPHy12nPQ=</latexit>
02, se = 5.0079e 04
v = 2.1344e
<latexit sha1_base64="qXMhOh062gVXyW6imM7FtasV88Y=">AAACF3icbVDLTgIxFO3gC/GFunTTSExc6DgD+GBBQnTjEhMREoaQTucCDZ2HbYeETPgMN/6KGxdq3OrOv7E8FoqepMnJOee2t8eNOJPKsr6M1MLi0vJKejWztr6xuZXd3rmTYSwo1GjIQ9FwiQTOAqgppjg0IgHEdznU3f7V2K8PQEgWBrdqGEHLJ92AdRglSkvt7MmgnDftQrEIx1b+yLmPiYcTZ3Jv4vIYRlhCuWCentklnSiM2tmcZVoT4L/EnpEcmqHazn46XkhjHwJFOZGyaVuRaiVEKEY5jDJOLCEitE+60NQ0ID7IVjJZYIQPtOLhTij0CRSeqD8nEuJLOfRdnfSJ6sl5byz+5zVj1bloJSyIYgUBnT7UiTlWIR63hD0mgCo+1IRQwfSumPaIIFTpLjO6BHv+y39JLW+WTOummKtcztpIoz20jw6Rjc5RBV2jKqohih7QE3pBr8aj8Wy8Ge/TaMqYzeyiXzA+vgEhjZzt</latexit>
02, se = 3.5619e 03 (Plain MC)

Matlab code: option_asian_CE.m


Appendix
Matlab function for example 2
(mode matching for the binary option)
function [v, se] = option_binary_IS(s0, r, sigma, T, K, n)

% s0 - initial stock price; r - risk-free interest rate;


% sigma - volatility; T - terminal time; K - strike price; n - sample size.

b=1/(sigma*sqrt(T))*(log(K/s0)-(r-sigma^2/2)*T);
theta=max(b,0); % tilting parameter

y=theta+randn(n,1); % iid samples from the tilted distribution

H=(y>=b).*exp(-r*T-theta*y+theta^2/2); % discounted payoff x the likelihood ratio

v = sum(H)/n; % MC estimate of the value of the option


se = sqrt((sum(H.^2) - n*v^2)/n/(n-1)); % estimate of the standard error
re=se/v;

fprintf('\n theta=%8.4e, v=%8.4e, se=%8.4e, re=%8.4e\n',theta, v, se,re);


Matlab function for example 3
(mode matching for European call)
function [v, se, vexact] = option_European_IS(s0, r, sigma, T, K, n)
% s0 - initial stock price; r - risk-free interest rate;
% sigma - volatility; T - terminal time; K - strike price; n - sample size.
f=@(theta)fun(theta, s0, r, sigma, T, K); % define a function handle f
theta = fzero(f, 10); % find the zero of f; or using fsolve(f, 10)
y=theta+randn(n,1); % iid samples from the tilted distribution N O 1
H=max(s0*exp(-0.5*sigma^2*T+sigma*sqrt(T)*y)-exp(-r*T)*K, 0); %discouted payoff
H=H.*exp(-theta*y+theta^2/2); % discounted payoff x the likelihood ratio
v = sum(H)/n; % MC estimate of the value of the option
se = sqrt((sum(H.^2) - n*v^2)/n/(n-1)); % estimate of the standard error
% exact value from Black-Scholes formula
tmp=1/(sigma*sqrt(T))*log(K/s0)+(sigma/2-r/sigma)*sqrt(T);
vexact=s0*normcdf(sigma*sqrt(T)-tmp)-K*exp(-r*T)*normcdf(-tmp);
fprintf('\n theta=%8.4e, v=%8.4e, se=%8.4e, vexact=%8.4e\n',theta, v, se, vexact);
Matlab function for example 3
(mode matching for European call)

function F=fun(theta, s0, r, sigma, T, K)

F=s0*exp(-0.5*sigma^2*T+sigma*sqrt(T)*theta)*(sigma*sqrt(T)-theta) …
+exp(-r*T)*K*theta;

day fhlxl.fm I 0
Matlab function for example 4
(Application to Risk Analysis)
function [v, se] = credit_risk_IS(m, c, p, x, n)
% m: number of obligors; c(1:m): the loss from default
% p(1:m): probability of default; x: threshold; n - sample size.
f=@(theta)fun(theta, p, x); % define a function handle f
if x <= sum(c.*p)
theta=0; % use plain MC if x is not large
else
theta = fzero(f, 10); % find the zero of f;
end
pbar = p* exp(theta)./(1+ p*(exp(theta)-1)); % titled probability mass function
for i=1:n
y=rand(m,1)<=pbar; % iid samples from the tilted Bernoulli distribution
L =sum(c.*y); % total loss
lr=prod(((p./pbar).^y).*(((1-p)./(1-pbar)).^(1-y))); %likelihood ratio
H(i)=(L>x)*lr;
end
Matlab function for example 4
(Application to Risk Analysis)
v = sum(H)/n; % MC estimate
se = sqrt((sum(H.^2) - n*v^2)/n/(n-1)); % estimate of the standard error

fprintf('\n theta=%8.4e, v=%8.4e, se=%8.4e\n',theta, v, se);

function F=fun(theta, p, x)
F=sum(p*exp(theta)./(1+p*(exp(theta)-1))) -x;
Matlab function for example 5
(The CE method for European call)
function [v, se, vexact] = option_European_CE(s0, r, sigma, T, K, n)
% s0 - initial stock price; r - risk-free interest rate;
% sigma - volatility; T - terminal time; K - strike price; n - sample size.
h=@(x)payoff(x,s0,r,sigma,T,K); % define a handle for the discounted payoff function
% compute the titling parameter using pilot samples
N=2000; x=randn(N,1); tmp=h(x);
theta = sum(tmp.*x)/sum(tmp);
y=theta+randn(n,1); % iid samples from the tilted distribution
H=h(y).*exp(-theta*y+theta^2/2); % discounted payoff x the likelihood ratio
v = sum(H)/n; % MC estimate of the value of the option
se = sqrt((sum(H.^2) - n*v^2)/n/(n-1)); % estimate of the standard error
% exact value from Black-Scholes formula
tmp=1/(sigma*sqrt(T))*log(K/s0)+(sigma/2-r/sigma)*sqrt(T);
vexact=s0*normcdf(sigma*sqrt(T)-tmp)-K*exp(-r*T)*normcdf(-tmp);
fprintf('\n theta=%8.4e, v=%8.4e, se=%8.4e, vexact=%8.4e\n',theta, v, se, vexact);
Matlab function for example 5
(The CE method for European call)
function h = payoff(x,s0,r, sigma, T, K)
h=max(s0*exp(-0.5*sigma^2*T+sigma*sqrt(T)*x)-exp(-r*T)*K, 0);
Matlab function for example 6
(The CE method for Asian option)
function [v, se] = option_asian_CE(s0, r, sigma, T, m, K, n)
% s0 - initial stock price; r - risk-free interest rate;
% sigma - volatility; T - terminal time; m - number of monitor dates;
% K - strike price; N: number of pilot samples; n - sample size.
t=[0: 1/m: 1]*T; % m monitoring dates
dt=t(2:m+1)-t(1:m);
% compute the tilting parameter using the basic cross entropy method
tmp1=zeros(m,1);
tmp2=0;
N=2000; % number of pilot samples
for i=1:N
samplefrom N10,2m
z=randn(m,1);
stock price
s=gBM(s0, r, sigma, m, dt, z); path for
H=exp(-r*T)*max(sum(s(2:m+1))/m -K,0); % payoff for the k-th path
tmp1=tmp1+H*z;
tmp2=tmp2+H;
end
Matlab function for example 6
(The CE method for Asian option)
theta= tmp1/tmp2; % tilting parameter
% important sampling
for i=1:n % loops to generate n sample paths and payoffs
y=randn(m,1)+theta; NCO Imm
s=gBM(s0,r,sigma,m,dt,y);
H(i)=exp(-r*T)*max(sum(s(2:m+1))/m -K,0); %discounted payoff
H(i)=H(i)*exp(-sum(theta.*y)+0.5*sum(theta.^2)); % likelihood ratio
end
v=sum(H)/n;
se = sqrt((sum(H.^2) - n*v^2)/n/(n-1)); % estimate of the standard error
fprintf('\n v=%8.4e, se=%8.4e\n', v, se);
% generate a discrete path of geometric Bronian motion
function s=gBM(s0, r, sigma, m, dt, z)
s(1) =s0;
for k=2:m+1
s(k) = s(k-1)*exp((r-0.5*sigma^2)*dt(k-1)+sigma*sqrt(dt(k-1))*z(k-1));
end

You might also like