Numerical metods for PDE in Finance - ENSTA - S1-1/MMMEF Finite difference metod for te Black and Scoles PDE (TP-1) November 2015 1 Te Euler Forward sceme We look for a numerical approximation of te European put function v = v(t, s), t [0, T ], s [0, S max ]. It satisfies in first approximation te Black and Scoles backward PDE on te truncated domain Ω = [S min, S max ] : s2 2 s 2 v rs s v + rv = 0, t (0, T ), s (S min, S max ) t v σ2 2 v(t, S min ) = v l (t) Ke rt S min, t (0, T ) v(t, S max ) = v r (t) 0, t (0, T ) v(0, s) = ϕ(s) := (K s) +, s (S min, S max ). On prendra les constantes numériques suivantes : K = 100, S min = 0, S max = 200, T = 1, σ = 0.2, r = 0.1 In particular, we aim at computing v(t, s) at final time t = T. We first introduce a discrete mes as follows. Let := Smax S min I+1 be (spatial) mes step, and t := T N be te time step. Ten s := S min +, = 0,..., I + 1 are te mes points, and t n = n t, n = 0,..., N te time mes. We are looking for U n, an approximation of v(t n, s ). For any function v C 2 (or v C 3 for (4)), we recall te following approximations, as 0, v (s ) = v(s ) v(s 1 ) v (s ) = v(s +1) v(s ) v (s ) = v(s +1) v(s 1 ) (1) + O() (2) + O() (3) + O( 2 ). (4) We terefore obtain several possible approximations by finite differences for te first order derivative : S v(t n, s ) U n U n 1 S v(t n, s ) U n +1 U n S v(t n, s ) U n +1 U n 1 (backward difference approximation) (5) (forward difference approximation) (6) (centered difference) (7) 1
Te first two approximations are said to be consistent of order 1 (in space), wile te second one is consistent of order 2. We also recall te approximation wic is consitent of order 2 in space. 2 SSv(t n, s ) U n 1 + 2U n U n +1 2, (8) Hence we obtain te so-called Euler Forward sceme (or Explicit Euler sceme), abreviated EE using te centered approximation, as follows : U n+1 U n t + σ2 2 s2 U n 1 + 2U n U n +1 2 rs U n +1 U n 1 + ru n = 0 n = 0,..., N 1, = 1,..., I U n 0 = v l (t n ) Ke rtn S min, n = 0,..., N (9) U n I+1 = v r (t n ) 0, U 0 = ϕ(s ) (K s ) +, n = 0,..., N = 1,..., I Let us remark tat we ave taken = 1 and = I as extremal indices in. For = 1, te sceme utilizes te known value U n 0 := v l(t n ) (left boundary value). For = I, te sceme utilizes te known value U n I+1 := v r(t n ) (rigt boundary value). 2 Programming Euler Forward 2.1 Preliminaries. We coose to work wit te unkown te vector corresponding to (v(t n, s )) =1,...,I : U n = U n 1. U n I. We would like to write (9) under te vector form as follows : U n+1 U n + AU n + q(t n ) = 0, (10) t were A is a square matrix of dimension I and q(t) is a column vector of size I. Let us denote α := σ2 s 2 2 2, β := r s. We look for A and q(t) suc tat ( α i + β i )U n i 1 + (2α i + r)u n i + ( α i β i )U n i+1 (AU + q(t n )) i. 2
By identification we see tat A is a tridiagonal matrix 2α 1 + r α 1 β 1 0 α 2 + β 2 2α 2 + r α 2 β 2......... A := α i + β i 2α i + r α i β i......... 0 α I + β I 2α I + r and q(t) will contain te known boundary values U 0 and U n+1 : ( α 1 + β 1 )v l (t) q(t) := 0.. 0 ( α I β I )v r (t) 2.2 Getting into te program. a) Download te working program 1 (tp1.m if using Matlab, or tp1.sci if using Scilab). Tis program as some lines to be completed in order to work properly. In te case of te matlab program, you will also ave to download oter function files BS.m and ploot.m (you can also take te solution file tp1sol.m) b) Ceck te program for te payoff function u0, ul (for v l ) and ur (for v r ) and program tem correctly. (notice tat te instruction y=max(k-s,0) works for s vector, K scalar, and return a vector of same size as s.) c) In te section MESH, complete te value of te mes step and program te vector s containing te (s ) 1 I values. Typically it sould look like : dt=t/n; =(Smax-Smin)/(I+1); s=smin+ (1:I) *; // column vector (s 1,..., s I ) T d) Program te matrix A and test te program. Under te matlab command window, type tp1. (Under Scilab, type exec tp1.sci or exec( tp1.sci,-1)) e) Program te function q(t). For instance in matlab : q = @(t) [(-alpa(1) + bet(1))* ul(t); zeros(i-2,1); (-alpa(end) - bet(end))* ur(t)]; In Scilab tis may look like function y=ul(t); y=k*exp(-r*t); endfunction function y=ur(t); y=0; endfunction; function y=q(t) y=zeros(s); // vector of zeros wit same size as te s vector y(1)= (-a(1)+b(1))*ul(t); u($)= (-a($)-b($))*ur(t); endfunction 1. See ttp ://people.mat.ussieu.fr/ boka/enseignement/2015/s11/ 3
2.2 Euler Forward sceme (or Euler Explicit sceme) a) Program te explicit form of te vector U n+1, in terms of U n, in te main loop, using te matrix A and te function q. In te end, it sould look like (in matlab) case EE P = (Id - dt*a)*p - dt*q(t); Note tat te grapic function ploot also plots te exact Black and Scoles formula (see te given function BS in te file BS.m). b) Correct te lign errli=0 in te main loop, in order to compute correctly te maximum norm. between te sceme values and te Black and Scoles values : U V BS = max 1 i I U i V BS (s i ) 2.3 Solution. A solution file is given in tp1sol.m 3 First numerical tests a) Test te Euler forward sceme (EE). First fix N = 10 and take I = 10, 20, 50,.... Ten take te following N = I values : 10, 20, 50, 100. Observe tat : - te sceme is not always numerically stable - it does not always give a positive solution (i.e. we do not always ave U n 0 n, ). b) Try to understand te origin of te oscillations wen tey occur. One sould look at te amplification matrix defined as B := I d ta (Te coefficients of B are tey positive? Do tey ave a modulus smaller tan 1?) c) Fill in te CFL number defined ere as µ := t 2 /( 1 σ 2 S max 2 ) and print it. Ceck tat tere is no stability problem wen ν is sufficiently small. d) In te case wen σ = 0.002 and for instance wit N = 10 and I = 50 : observe tat te sceme is stable but tat te solution given by te sceme is not positive. e) Order of te sceme. We first consider te following values of I and of N : I = 10, 20, 40, 80, 160, and N = I 2 /10 (tat is, N = 10, 40,...). Tis is in order to ave t 2. Fill in te following error table and compute te corresponding (spatial) order of te metod. More precisely, if te error is e k for a given parameter I = I k, we will compute te order at step k by te formula α k := log(e k 1/e k ) log( k 1 / k ) log(e k 1/e k ). log(2) Te idea is to try to detect a beavior of te form e k = C α k, were C est a constant and were k is te spatial mes size corresponding to I k. Te numerical (spatial) order sould be close to two. But ere setting N const I 2 is costly in terms of number of operations. More precisely, since t = const 2 one can see tat error also beaves as O( t), tat is, a first order error beavior wit respect to te time discretisation. 4
I N e k order α k 10 10 20 40 40 160 80 640 160 2540 Tis motivates te use of implicit scemes in order to avoid te time-step condition (or CFL condition). Exercice : backward and forward difference approximations a) Program in te same way te oter approximations (backward differences / décentrage droit : DROIT and te forward differences - décentrage gauce GAUCHE ). Te parameter CENTRAGE is defined at te begining of te program (section NUMERICAL DATA) and determines te type of finite difference approximation tat is used. b) Using te forward differences, fix temporarily σ = 0.002 and N = 10, I = 50, and ceck tat now te solution keeps positive. c) Using te backward differences, fix temporarily σ = 0.002 and N = 10, I = 50, and ceck tat now te numerical solution is unstable (understand te problem by looking at te coefficients of te amplification matrix). 4 Implicit Euler sceme (EI) Te CFL constraint imposes some restriction on te time step t. Implicit scemes may allow us to get rid of tis restriction. For instance, te implicit euler sceme, ereafter abrieviated EI (for Frenc Euler Implicit ), wit centered difference approximation for te first spatial derivatives reads U n+1 U n t + σ2 2 s2 U n+1 1 n+1 + 2U U+1 n+1 U+1 n+1 2 rs U 1 n+1 + ru n+1 = 0 n = 0,..., N 1, = 1,..., I U0 n+1 = v l (t n+1 ) Ke rt n+1 S min, n = 0,..., N 1 (11) U n+1 I+1 = v r(t n+1 ) 0, n = 0,..., N 1 U 0 = (K s ), = 1,..., I a) Write te sceme in vector form, in analogy wit (10). b) Program EI : set te parameter SCHEMA= EI at te begining of te program, and complete accordingly, in te main loop, te part case EI... Note tat in order to solve a linear system of te form Ax = b one may use te linear solver in matlab (resp. Scilab) as follows x=a\b; c) Ceck tat wit te EI sceme tere is no more stability problems (wit for instance N = 10 and I = 50). 5
5 Crank-Nicolson sceme a) Program te Crank-Nicolson sceme (CN) (tis is te θ-sceme wit θ = 1 2 ). b) Numerically study te convergence of te centered CN sceme. To do so, one can compute te numerical error obtained wit te following values N = I + 1 {10, 20, 40, 80, 160}. Ten do te same study as for te Euler implicit sceme and compare by making an error table (and wit an order estimation) One sould observe a second order beavior for CN, wile it sould be first order for EI. c) Ceck tat tese results are coerent wit te teory. 6 Exercices Exercice 2 : te Call option a) Using te put-call parity formula, do a function tat also computes te black and scoles formula for te call. b) Propose adequate left and rigt boundary conditions (tat is, at s = S min and s = S max ) for te call option, in te form (v(t, S min ) = v l (t) and v(t, S max ) = v r (t), were v l, v r are function to determine. 2 c) Propose an apropriate PDE for te call option, using tese boundary conditions. d) Write an Euler explicit sceme for te call option, and program it. Exercice 3 : using sparse matrices. Te matrix A as only a few non zero elements (about 3I non zero elements). It is possible to code only te non-zero elements of A by using te matrix type sparse. Type elp sparse or doc sparse for documentation in matlab (use A=spzeros(I,I) to initialize, type A or full(a) to ceck te values, use Id=speye(I,I) for te sparse identity matrix ; te rest of te code sould be oterwise uncanged.) Program in particular te EI sceme by using only sparse matrices, and compare te speed of te new code wit respect to te old one for large I values. Execution time can be evaluated by using te commands tic; toc; (resp. time() in Scilab) as follows : tic; % INSTRUCTIONS; %... t=toc; printf( cpu time : t=%5.2f, t); (t contains te time elapsed between te calls of tic and toc.) 2. v l (t, s) 0, v r(t, s) s Ke rt. 6