Professional Documents
Culture Documents
Numerical Methods
Jaime Casassus
Instituto de Economı́a
Pontificia Universidad Católica de Chile
g (X1 , Y1 ) + · · · + g (Xn , Yn )
θbn =
n
[ g (x1 ) + · · · + g (xn )
C (0)n =
n
Casassus (UC) CEMLA 23-Nov-23 5 / 30
Example: Black-Scholes-Merton Formula (cont.)
1import matplotlib . pyplot as plt
2import numpy as np
3
4S0 = 250;
5r = 0.03;
6sigma = 0.3;
7T = 1;
8K = 200;
9
10n = 100000;
11
12x = np . random . normal (0 , 1 , n )
13
14ST = S0 * np . exp (( r -0.5* sigma **2) * T + sigma * x * np . sqrt ( T ) )
15
16g = np . exp ( - r * T ) * np . fmax ( ST -K ,0)
17
18C0h = np . mean ( g )
19C0h
dSt = r St dt + σ St dWt
• Generate a simulated path {Sb0 , Sbh , Sb2h , . . . , Sbmh } to get one draw of SbT .
• Define g (ST ) = e −rT max[ST − K , 0], generate n random variables SbT ,i to estimate:
• Generate n simulated paths {(Sb0 , Vb0 ), (Sbh , Vbh ), . . . , (Sbmh , Vbmh )} and evaluate the g (SbT ,i )’s to get
[
C (0)n .
Casassus (UC) CEMLA 23-Nov-23 12 / 30
Example: Option Pricing Under Heston (cont.)
1:
2def simulate_path ( S0 , V0 ,r , kappa , theta , sigma , rho ,m , h ) :
3SV = [( S0 , V0 ) ]
4for j in range ( m ) :
5eS = np . random . normal (0 , 1)
6ei = np . random . normal (0 , 1)
7eV = rho * eS + np . sqrt (1 - rho **2) * ei
8Si = SV [ -1][0]
9Vi = SV [ -1][1]
10Sj = Si + r * Si * h + np . sqrt ( Vi ) * Si * np . sqrt ( h ) * eS
11Vj = Vi + kappa *( theta - Vi ) * h + sigma * np . sqrt ( Vi ) * np . sqrt ( h ) * eV
12SV . append (( Sj , Vj ) )
13return ( np . array ( SV ) )
14
15ST = []
16for i in range ( n ) :
17SV = simulate_path ( S0 , V0 ,r , kappa , theta , sigma , rho ,m , h )
18ST . append ( SV [ -1][0])
19:
• Consider for now the “central derivative” and also the standard approximation for the second
derivative, y ′′ (x)
dy yi+1 − yi−1 d 2y yi−1 − 2yi + yi+1
= and 2
=
dx 2h dx h2
Casassus (UC) CEMLA 23-Nov-23 16 / 30
One-dimensional ODEs (cont.)
• Let see the system of equations with an example: a rocket problem that we want to have at 50m
off the ground after 5 secs after launching. The ODE is
d 2y
= −g
dt 2
with the boundary conditions y (0) = 0 and y (5) = 50.
• Assume n = 10, therefore, h = 0.5. The finite difference equations are:
y (0) = 0
yi−1 − 2yi + yi+1 = −gh2 for i = 1, 2, . . . , n − 1
y (5) = 50
• or in matrix form
1 y0
0
1
−2 1 y1
−gh2
.. .. .. ...
= ...
. . .
1 yn−1 −gh2
1 −2
1 yn 50
• The discretized system of equations relates the inside points of the grid, however, there are
different ways of doing this.
Casassus (UC) CEMLA 23-Nov-23 20 / 30
The Explicit Finite Difference Method
• Consider the Black-Scholes PDE
1
0= fSS (t, S(t))σ 2 S(t)2 + fS (t, S(t))r S(t) + ft (t, S(t)) − r f (t, S(t))
2
with boundary condition f (T ) = max[S(T ) − K , 0]
• use a backward approximation for ft (S(t), t)
∂f fi,j − fi−1,j
=
∂t δt
• Therefore, inside the grid the PDE gives
1 fi,j+1 − 2fi,j + fi,j−1 2 fi,j+1 − fi,j−1 fi,j − fi−1,j
0= σ (j δS )2 + r (j δS ) + − r fi,j
2 δS2 2δS δt
• The PDE relates the known values at time t = i δt (i.e., fi,j−1 , fi,j and fi,j+1 ) with fi−1,j .
• There system of equation is really simple, but explicit finite difference method can be unstable.
• The PDE relates the known values at time t = (i + 1) δt (i.e., fi+1,j ) with fi,j−1 , fi,j and fi,j+1 :
• This method considers fi− 12 ,j , but a price will not be calculated for this node. Rather it is used as
a mathematical convenience that will not appear in the final equations.
• fi− 21 ,j relates in an explicit way with future values fi,j±1 and in an implicit way with previous values
fi−1,j±1 . It uses all three of the left side nodes based on the values of all three of the right side
nodes.
• It converges at a faster rate than the explicit/implicit methods.
Casassus (UC) CEMLA 23-Nov-23 23 / 30
Example: American Put Option Pricing
• Consider an American Put Option with maturity T .
• We know that in the continuation region (S(t) > B(t)) the American option solves:
1
0= PSS (S(t), t)σ 2 S(t)2 + PS (S(t), t)r S(t) + Pt (S(t), t) − r P(S(t), t)
2
• And in the exercise region (S(t) ≤ B(t)):
• Boundary condition for time: the price of the put option at maturity T is
• Reordering:
2 2 2 2
σ j rj 2 1 σ j rj Pi+1,j
− Pi,j−1 − σ j + + r Pi,j + + Pi,j+1 = − ∀i < N, j < M
2 2 δt 2 2 δt
• Boundary conditions:
PN,j = max[K − j δS , 0] ∀j
Pi,−1 − 2Pi,0 + Pi,1 = 0 ∀i
Pi,M−1 − 2Pi,M + Pi,M+1 = 0 ∀i