Finite difference and finite element methods Lecture 1
Scope of the course Analysis and implementation of numerical methods for pricing options. Models: Black-Scholes, stochastic volatility, exponential Lévy. Options: European, American, Asian, barrier, compound... In this course: Focus on deterministic (PDE based) methods Finite difference methods (FDM) Finite element methods (FEM) This course will be complemented by the course Monte Carlo methods in autumn 2009.
Organization of the course 14 lectures (2 hours) + 13 exercise classes (1 hour). No lectures on April, 14. Testat: 70% of solved homework assignments (theoretical exercises + MATLAB programming). Examination: On Tuesday, May 26, 15 17. Written, closed-book examination includes theoretical and MATLAB programming problems. Examination takes place on ETH-workstations running MATLAB under LINUX. Own computer will NOT be required.
Outline Partial differential equations (PDEs)
Definitions and notation Let α = (α 1,..., α d ) N d 0 be a multiindex. Set α = d i=1 α i. For u : R, x = (x 1,..., x d ) R d define Let k N 0. Then D α u(x) := α u(x) x α 1 1 xα d d = α 1 x 1 α d x d u. D k u(x) := {D α u(x) : α = k} is the set of all partial derivatives of order k. If k = 1, we regard the elements of D 1 u(x) =: Du(x) as being arranged in a vector Du = ( x1 u,..., xd u).
If k = 2, we regard the elements of D 2 u(x) as being arranged in a matrix x1 x1 u x1 xd u D 2 u =.... xd x1 u xd xd u In the following: write xi x j instead of xi xj. Hence, the Laplacian u of u can be written as u := d xi x i u = tr(d 2 u). i=1 A partial differential equation (PDE) is an equation involving an unknown function of two or more variables and certain of its derivatives.
Let R d be open, x = (x 1,..., x d ) and N k 1. Definition An expression of the form F (D k u(x), D k 1 u(x),..., Du(x), u(x), x) = 0, x is called a k-th order PDE, where F : R dk R dk 1 R d R R is given and is the unknown. u : R
Let a ij (x), b i (x), c(x) and f(x) be given functions. For a linear 2nd order PDE in d + 1 variables, F has the form F (D 2 u, Du, u, x) = d d a ij (x) xi x j u+ b i (x) xi u+c(x)u f(x). i,j=0 Assume that the matrix A(x) := {a ij (x)} d i,j=0 is symmetric with real eigenvalues λ 0 (x) λ 1 (x) λ d (x). i=0 Definition Let S = {0,..., d}. At x R d+1, the PDE is called (i) elliptic λ i (x) 0, i sign(λ 0 (x)) =... = sign(λ d (x)) (ii) parabolic!j S : λ j (x) = 0 rank(a(x), b(x)) = d + 1 (iii) hyperbolic λ i (x) 0, i!j S : signλ j (x) signλ k (x), k S \ {j} The PDE is called elliptic, parabolic, hyperbolic on, if it is elliptic, parabolic, hyperbolic x.
Examples t u u = f(t, x) is parabolic (set x 0 = t). The Poisson equation u = f(x) is elliptic. The wave equation tt u u = f(t, x) is hyperbolic (set x 0 = t) The Black Scholes equation for the value of a European option v(t, s) t v 1 2 σ2 s 2 ss v rs s v + rv = 0 with σ, r 0 is parabolic at (t, s) (0, T ) (0, R) and degenerates to a ordinary differential equation as s 0. Note: PDEs can have infinitely many solutions. To obtain a unique solution, we have to pose boundary conditions.
Outline Partial differential equations (PDEs) Partial differential equations (PDEs)
The PDE Partial differential equations (PDEs) Let = (a, b) R be a open interval and let J := (0, T ), T > 0. Find u : J R such that Remark t u xx u = f(t, x) in J u = 0 on J u(0, ) = u 0 in (i) The equation u(0, ) = u 0 in is the initial condition. (ii) The equation u = 0 on J is the boundary condition. Here it is of Dirichlet type and homogeneous. oal: approximate u(t, x).
Discretization of the domain Computational domain J is replaced by discrete grid: {(t m, x i )}, i = 0,..., N + 1, m = 0,..., M, where x i are space grid points with space step size h and t m are the time levels with time step size k: x i = a + ih, h = b a N + 1, t m = mk, k = T M. We represent the exact solution u(t, x) by its values on the grid: u(t, x) {u m i = u(t m, x i )}, i = 0,..., N +1, m = 0,..., M. The goal is to approximate the values {u m i }. Values of the solution between grid points are then found by some interpolation.
Difference Quotients (= Finite Differences) We want to approximate the derivatives of u using only its values on the grid. First, let us consider a function f(x) of one variable. Assume that f C 2. Then, using Taylor s formula, f (x) = f(x + h) f(x) h + h 2 f (ξ), ξ [x, x + h]. If f i = f(x i ) are the values of f on the grid {x i }, we obtain f (x i ) = f i+1 f i h Similarly, for f C 4 + O(h) =: ( δ + x f) i + O(h). f (x i ) = f i+1 2f i + f i 1 h 2 + O(h 2 ) =: ( δ xx f ) i + O(h2 ).
FD scheme Partial differential equations (PDEs) Let θ [0, 1]. We replace the PDE t u xx u = f by the set of algebraic equations E m i = θf m+1 i + (1 θ)f m i i = 1,..., N, m = 0,..., M 1 u 0 i = u 0 (x i ) i = 1,..., N u m k = 0 k {0, N + 1}, m = 0,..., M, where E m i Ei m := k 1( u m+1 i u m i is the finite difference operator = um+1 i k u m i [θ um+1 i+1 2um+1 ) [ θ(δxx u) m+1 i + (1 θ)(δ xx u) m i i + u m+1 i 1 h 2 + (1 θ) um i+1 2um i + u m ] i 1 h 2. ]
FD scheme in matrix form Introduce the column vectors u m = (u m 1,..., um N ), E m = (E m 1,..., E m N ), f m = (f m 1,..., f m N ) and the tridiagonal N N matrix = h 2 tridiag( 1, 2, 1). Then the FD-scheme E m = θf m+1 + (1 θ)f m becomes, in matrix form: iven u 0 = (u 0 (x 1 ),..., u 0 (x N )) R N, for m = 0,..., M 1 find u m+1 R N such that ( I } + {{ θk } =:B or ) u m+1 + ( I + (1 θ)k }{{} =: C ) u m = k[θf m+1 + (1 θ)f m ], }{{} =:F m Bu m+1 = Cu m + kf m, m = 0,..., M 1.
Variational formulation We do not require the PDE to be hold pointwise. Take a smooth test function v C0 () satisfying v(a) = v(b) = 0. Multiply the PDE with v and integrate by parts: t uv dx xx uv dx = fv dx d dt uv dx [ x u(t, x)v(x)] x=b x=a + }{{} x u x v dx = fv dx =0 The variational or weak formulation of the heat equation reads: Find u such that u(0) = u 0 and such that v C0 () d u(t, x)v(x)dx + u (t, x)v (x)dx = f(t, x)v(x)dx. dt
alerkin discretization Let V N be a finite (N) dimensional subspace of H 1 0 (). The idea is to approximate u(t, x) by an element u N (t, x) V N, for each t J. Find u N (t, x) V N such that u N (0, x) = u 0,N (x) and such that v N V N d dt u N (t, x)v N (x)dx+ Let {b j } N j=1 be a basis of V N. Then u N (t, x) = N j=1 u N,j(t)b j (x), where u N(t, x)v N (x)dx = u N (t) = (u N,1 (t), u N,2 (t),..., u N,N (t)) is a vector of unknown functions. Similarly, v N V N v N (x) = N i=1 v N,ib i (x). f(t, x)v N (x)dx.
Hence (we skip the argument x in ) d u N (t)v N + u N dt (t)v N = f(t)v N, v N V N d ( )( ) u N,j (t)b j v N,i b i dt j i ( ) ( ) + u N,j (t)b j v N,i b i = f(t) v N,i b i j i i [ ] v N,i u N,j b j b i + u N,j b jb i f(t)b i = 0 i j [ ] v N M u N (t) + Au N (t) f N (t) = 0, v N R N M u N (t) + Au N (t) = f N (t).
Semi discrete scheme Thus, d dt (u N (t), v N ) + a ( ) u N (t), v N = (f(t), vn ), is equivalent to the ODE M u N (t) + Au N (t) = f N (t), v N V N where M (mass matrix) and A (stiffness matrix) are N N matrices with M ij = b j (x)b i (x)dx, A ij = b j (x)b i (x)dx. Similarly, f N (t) R N with entries f N,i (t) = f(t, x)b i (x)dx.
Fully discrete scheme We discretize in time. Write u m N := u N(t m ), f m N := f N(t m ), where the time levels t m, m = 0,..., M are as before. Proceeding exactly as in the FDM, the fully discrete scheme reads: iven u 0 N = (u 0(x i )) N i=1 RN, for m = 0,..., M 1 find R N such that u m+1 N Mk 1( u m+1 N um N ) ( ) +A θu m+1 N +(1 θ)um N = θf m+1 N +(1 θ)f m N.
Choice of V N Setting B := M + kθa, C := M k(1 θ)a and F m m+1 N := θf + (1 θ)f m this can be written as N N Bu m+1 N = Cu m N + kf m N, m = 0,..., M 1. It remains to chose a space V N. Probably the simplest choice: V N is the space of piecewise linear, continuous functions. Let T := {a = x 0 < x 1 < < x N+1 = b} = {K i } N+1 i=1 be an equidistant mesh on with K i := (x i 1, x i ). (x i as before). Set V N = S 1 0 := { u C 0 0 () : u K i is affin linear on K i T }. Note: dimv N = N.
g replacements A basis {b i } N i=1 of V N is given by the so-called hat-functions b i : [a, b] R 0, b i (x) = max{0, 1 h 1 x x i }, i = 1,..., N. b 1 (x) b 2 (x) b k (x) b N (x) a = x 0 x 1 x 2 x k 1 x k x k+1 x N 1 x N x N+1 = b With this basis, we find for the mass- and stiffness matrix M = h/6 tridiag(1, 4, 1), A = h 1 tridiag( 1, 2, 1).
For both FDM and FEM, we have to solve M systems of N linear equations of the form Bu m+1 = Cu m + kf m, m = 0,..., M 1. where F m = θf m+1 + (1 θ)f m and FDM FEM u m vector of u m i u(t m, x i ) coeff. vector of u N (t m, x) B I + kθ M + kθa C I k(1 θ) M k(1 θ)a f m = h 2 tridiag( 1, 2, 1) A = h 1 tridiag( 1, 2, 1) f(t m, x i ) f m = i f(t m, x)b i (x)dx
Matlab coding (FDM) function error = heateq_fdm(a,b,t,n,theta) h = (b-a)/(n+1); k = h; e = ones(n,1); I = speye(n); = h^(-2)*spdiags([-e 2*e -e],-1:1,n,n); B = I+k*theta*; C = I-k*(1-theta)* x = [a+h:h:b-h] ; u0 = x.*sin(pi*x); f = -(1-pi^2)*x.*sin(pi*x)-2*pi*cos(pi*x); u = zeros(n,t/k+1); u(:,1) = u0; for j = 1:T/k F = k*f*(theta*exp(-j*k)+(1-theta)*exp(-(j-1)*k)); u(:,j+1) = B\(C*u(:,j)+F); err(j) = norm(u(:,j+1)-exp(-k*j)*u0); end error = sqrt(h)*max(err)
Example Partial differential equations (PDEs) Let = (0, 1), T = 1, and u(x, t) = e t x sin(πx). We measure the discrete L (0, T ; L 2 ())-error defined by e := sup h 1 2 ɛ m l2, m ɛ m 2 l 2 := i u(t m, x i ) u m i 2. For θ = 0.5 and k = h, we obtain, in terms of the mesh width h, convergence both of FDM and FEM of second order, i.e., e = O(h s ), s = 2.
10 3 10 4 FDM FEM 10 5 e 10 6 eplacements 10 7 10 8 s = 2.0 10 4 10 3 10 2 10 1 h