sdes.pdf

25
Stochastic Differential Equations Case Study Mark Richardson May 2009 Contents 1 Introduction 2 2 Modelling Brownian Motion 3 2.1 The Wiener Process ............................... 3 2.2 Discretised Brownian Motion .......................... 3 2.3 Evaluating Functions along Brownian Paths .................. 4 3 Stochastic Integrals 6 3.1 Stochastic Quadrature .............................. 6 3.2 Theoretical Values ................................ 7 4 The Euler-Maruyama Method 8 4.1 Derivation of the formula ............................ 8 4.2 Implementing the method ............................ 9 4.3 Strong Convergence ............................... 10 4.4 Weak Convergence ................................ 12 5 Milnstein’s Higher Order Method 13 5.1 Ito’s Lemma .................................... 13 5.2 Deriving Milnstein’s Method .......................... 13 5.3 Implementing Milstein’s Method ........................ 15 5.4 Strong Convergence ............................... 16 6 Verifying the Stochastic Chain Rule 18 7 Conclusions 20 8 Appendix 21 1

Upload: luis-zuniga

Post on 19-Jan-2016

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SDEs.pdf

Stochastic Differential Equations Case Study

Mark Richardson

May 2009

Contents

1 Introduction 2

2 Modelling Brownian Motion 3

2.1 The Wiener Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Discretised Brownian Motion . . . . . . . . . . . . . . . . . . . . . . . . . . 32.3 Evaluating Functions along Brownian Paths . . . . . . . . . . . . . . . . . . 4

3 Stochastic Integrals 6

3.1 Stochastic Quadrature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2 Theoretical Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 The Euler-Maruyama Method 8

4.1 Derivation of the formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.2 Implementing the method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.3 Strong Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.4 Weak Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5 Milnstein’s Higher Order Method 13

5.1 Ito’s Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.2 Deriving Milnstein’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . 135.3 Implementing Milstein’s Method . . . . . . . . . . . . . . . . . . . . . . . . 155.4 Strong Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6 Verifying the Stochastic Chain Rule 18

7 Conclusions 20

8 Appendix 21

1

Page 2: SDEs.pdf

1 Introduction

In this case study, we will construct and implement numerical methods for solving ’Stochas-tic Differential Equations’ (SDEs) using MATLAB. An SDE is a differential equation inwhich one or more of the terms, and hence the solution itself, is a stochastic process.Studying stochastic processes requires a departure from the familiar deterministic settingof ordinary and partial differential equations, into a world where the evolution of a quantityhas an inherent random component and where the expected behaviour of this quantity canbe described in terms of probability distributions. To undertake a rigorous, analytic analy-sis of SDEs, one must be well versed in the theories of Measure and Probability. However,in this case study, we shall attempt to understand SDEs by taking a brute force approach,which will not require us to have a complete understanding of these topics.

One of the key methods that we will employ to understand our SDEs will be Monte-Carlo

Simulation. Monte-Carlo methods involve generating many sample paths, or sequences ofrandom variables that are distributed in some known way. During this case study, we willconsider models based upon the scalar Standard Brownian motion, which we shall formallydefine shortly. After generating one sample path for the stochastic term in the SDE, weconstruct a numerical method to compute the solution, given this input. Clearly, thisparticular solution is very likely to be different from the solution generated from anothersample path, so the question is: how is this in any way useful? To gain some insight, we willrun this simulation many times over, generating numerous random samples. By looking atthe behaviour of the SDE over many sample paths, we should be able to infer the expected

behaviour of the SDE.In addition to this, we will construct numerical methods that will give us a numerical

solution of sn SDE, for a given stochastic input. These will be constructed in direct analogywith deterministic methods such as Explicit Euler and Runge-Kutta.

We will first define the Wiener process (Brownian Motion), which is the main stochasticprocess that many physical systems are assumed to evolve according to. From this, wewill write code to simulate a discretised Brownian path. This will be used to compute theexpectation of a function of a Wiener process, which is shown to match the theoretical value.We examine the two main Stochastic integrals (Ito and Stratonvich) and then construct theEuler-Maruyama formula for finding the numerical solution of autonomous SDEs. Followingthis, we compute the orders of strong and weak convergence for the Euler-Maruyama methodand then attempt to improve the order of strong convergence by appending more termsin order to obtain the Milnstein higher order method. We compute the order of strongconvergence of this method and as an extension, we verify numerically the Stochastic Chainrule that arises from the Ito calculus.

2

Page 3: SDEs.pdf

2 Modelling Brownian Motion

2.1 The Wiener Process

Robert Brown was a 18th century Botanist and was the first scientist who would observe anddocument the seemingly random motion of certain particles moving of the surface of water.Brown was initially observing pollen particles under a microscope, and his first thoughtwas that the motion was caused by the particles being alive. He abandoned this theoryafter observing the same phenomenon with dust particles. It is after this scientist, and themathematician that first rigorously defined it in mathematical terms, Norbert Wiener, thatthe Wiener Process (or standard Brownian motion) is named.

Formally, a scalar standard Brownian Motion, or Standard Wiener Process over [0,T],is a random variable that depends continuously upon t ∈ [0, T ] and satisfies:

1. W (0) = 0, with probability 1.

2. For 0 ≤ s < t ≤ T , the random variable given by the increment W (t) − W (s) is nor-mally distributed, with mean zero and variance t−s. i.e. W (t)−W (s)

√t − sN(0, 1).

3. For 0 ≤ s < t < u < v ≤ T , W (t) − W (s) and W (v) − W (u) are independent.

2.2 Discretised Brownian Motion

We will now construct a discretised Brownian motion, meaning that we will generate asequence of n normally distributed random numbers that determine W (t) at a discretenumber of t values. We set ∆t = T

nfor n ∈ Z

+ and write Wj ≈ W (tj) = W (j∆t).Condition 1 above tells us that we must set W0 = 1, whilst conditions 2 & 3 tell us thatWj − Wj−1 = dWj for j = 1, 2, ..., n where dWj =

√∆tN(0, 1).

Thus, by setting W0 = 0 and using the MATLAB function randn to generate{dW1, dW2, . . . ,dWn}, we compute the discretised Brownian path, {W0, W1, W2, . . . , Wn}by cumulatively summing the above terms. Figure 1 shows the MATLAB code for gen-erating a discretised Wiener process, whilst figure 2 shows two sample Brownian pathsplotted.

Figure 1: MATLAB code for generating a discretised Wiener Process

1 T=1; % Set time interval [0,T]2 n=1000; % Set number of steps to compute at in [0,T]3 dt=T/n; % Compute the time step4 %randn('state',0) % Repeatable trials on/off5 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements6 W=cumsum(dW); % Sum the array cummulativley7 t=0:dt:T; % Array of equal time steps8 W=[0,W]; % Set first value to be zero9 plot(t,W); % Plot the Wiener process

10 xlabel( 't' );ylabel( 'W(t)' , 'Rotation' ,0);title( 'Sample Wiener Process' )

Line 6 in Figure 1 above, randn(’state’,0) sets the ’state’ of the random number gen-erator, this is a useful feature if one wishes to repeat experiments. The number refersto a particular, predetermined path. Line 7, dW=sqrt(dt)*randn(1,n), is the line thatgenerates our terms that are defined by, dWj = Wj − Wj−1. Line 8, W=cumsum(dW), thensums these increments cumulatively and with the attachment of the first term, W0 = 0, weproduce the Wiener process, W ∈ R

n+1

3

Page 4: SDEs.pdf

Figure 2: Two Sample Brownian Paths

0 0.2 0.4 0.6 0.8 1−1.6

−1.4

−1.2

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

t

W(t)

Sample Wiener Process

(a)

0 0.2 0.4 0.6 0.8 1−0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

t

W(t)

Sample Wiener Process

(b)

2.3 Evaluating Functions along Brownian Paths

Now that we have obtained a Wiener Process, we may wish to evaluate a function alongthe path. For example, consider the following function and its discrete counterpart:

U [W (t)] = exp

(

t +1

2W (t)

)

(1)

Uj = exp

(

tj +1

2Wj

)

(2)

Figure 3: U[W(t)] for One and Five Brownian Paths

0 0.2 0.4 0.6 0.8 10.5

1

1.5

2

2.5

3

3.5

4

4.5

5

5.5

t

U[W(t)]

(a)

0 0.2 0.4 0.6 0.8 10

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

t

U[W(t)]

(b)

To plot equation (2), we simply use the matlab command plot(t,exp(t+0.5*W)) with thearrays t & W (t) defined as above. Figure 3 shows the function U[W (t)] evaluated along asingle Brownian path, and then five Brownian paths simultaneously.

It appears, at least over this small series of observations, that in spite of the randomnature of each indidual Brownian path, there may be some predictablility to be found overa series of experiments. Perhaps if we we were to run many trials and compute the ’average’path, this will give us something meaningful. This is, in essence, what the Monte-Carlomethod is. It can be shown that equation (2) does have a smooth ’average path’ andthat this path is U(t) = exp

(

9t8

)

. Figure 4 shows the MATLAB code for a function which

4

Page 5: SDEs.pdf

Figure 4: MATLAB function for evaluating U[W(t)] along a Brownian path

1 function [expW] = Wiener(n,T)2 if nargin==1, T=1; end % Sets T=1 if only 1 argument is input3 dt=T/n;4 dW=sqrt(dt) * randn(1,n);5 W=cumsum(dW); % Generates Brownian path6 t=[0:dt:T]; W=[0,W];7 expW=exp(t+0.5 * W); % Evaluates the function along the path8 end

generates a unique Brownian path and evaluates the function U[W(t)] along it, whilst Figure5 shows the code for plotting the results of the trials and the theoretical expectation.

Figure 5: MATLAB code for plotting the theoretical and experimental expectation

1 n=1000; M=10000; % Number of time steps/trials2 R=zeros(n+1,M); % Preallocate result matrix, R3 for i=1:M4 R(1:n+1,i)=Wiener(n); % Compute and store evaluated paths5 end6 expectation=sum(R,2)/M;7 plot(t,expectation,t,exp(9 * t/8), 'r −.' )8 title([ 'The mean of ' int2str(M) ' trials vs actual expectation' ]), ...9 xlabel( 't' ),ylabel( 'exp(t+0.5W(t))' )

10 legend( 'Experiment' , 'Theoretical expectation exp(9t/8)' , 'Location' , 'NW' )

Figure 6 shows the result of running this code with 10 000 sample Brownian paths. It isclear that the computed average and the theoretical expectation match very closely indeed.

Figure 6: The thoeretical and experimental expectation of U[W(t)]

0 0.2 0.4 0.6 0.8 11

1.5

2

2.5

3

3.5The mean of 10000 trials vs actual expectation

t

exp(

t+0.

5W(t

))

ExperimentTheoretical expectation exp(9t/8)

5

Page 6: SDEs.pdf

3 Stochastic Integrals

Let us momentarily return to the determinsistic setting and consider the following equalityfor integrating a known function, h(t) on the interval [0, T ].

∫ T

0

h(t)dt =N−1∑

j=0

∫ tj+1

tj

h(t)dt (3)

We can approximate the integral on the right hand side by a variety of quadrature methods,such as the triange or midpoint rules. Applying these to (3) gives us:

∫ T

0

h(t)dt ≈N−1∑

j=0

h(tj)(tj+1 − tj) (triangle rule) (4)

or ≈N−1∑

j=0

h

(

tj + tj+1

2

)

(tj+1 − tj) (midpoint rule) (5)

3.1 Stochastic Quadrature

A Stochastic integral is the integral of some function, h(t), over some interval [0, T ], butwith respect to a Brownian motion, W (t), instead of the usual integration variable, t.

∫ T

0

h(t)dW (t)

We can apply the above quadrature ideas do derive analagous formulae in the Stochasticsetting. Applying the triangle quadrature (4), with h(t) = W (t), gives us the Ito integral:

∫ T

0

W (t)dW (t) ≈N−1∑

j=0

W (tj)(W (tj+1) − W (tj)) (6)

And applying the midpoint quadrature (5), gives us the Stratonovich integral:

∫ T

0

W (t)dW (t) ≈N−1∑

j=0

W

(

tj + tj+1

2

)

(W (tj+1) − W (tj)) (7)

Implementing these quadrature methods in MATLAB is very straightforward if we noticethat W (tj+1)−W (tj) = dW (tj+1) in the construcution of our discretised brownian motion.We have all these values available to us in the vector of normal random variables, dW .

For the Ito integral, (6), all we have to do is use the vector innner (dot) product tocompute the finite sum which is the RHS of (6). This is accomplished using the commandIto = [0,W(1:n-1)]*dW’. Notice that we discard the last entry of W and shift the valuesalong by 1, adding a zero as the first entry.

For the Stratonovich integral, we must deal with the term slightly more troublesometerm, W (1

2(tj + tj+1)). It can in fact be shown (though the proof of this result is outside of

the scope of this report), that the following holds:

W

(

tj + tj+1

2

)

≈ 1

2(W (tj) + W (tj+1)) + ∆zj where ∆zj ∼ N(0,

∆t

4) (8)

Where ’≈’ is used in the sense that the value on the RHS is consistent with the threeconditions that a Wiener process must satisfy. The MATLAB implementation for this istherefore given by, Strat = [0.5*([0,W(1:n-1)]+W)+0.5*sqrt(dt)*randn(1,n)]*dW’.

6

Page 7: SDEs.pdf

3.2 Theoretical Values

The Ito integral is the limiting case (as N → ∞) of (6), above, and similarly, the Stratonovichintegral is the limiting case of (7). Consider the Ito integral, (6):

∫ T

0

W (t)dW (t) =N−1∑

j=0

W (tj)(W (tj+1) − W (tj))

=1

2

N−1∑

j=0

{

W (tj+1)2 − W (tj)

2 − [W (tj+1) − W (tj)]2}

=1

2

W (T )2 − W (0)2 −N−1∑

j=0

[W (tj+1) − W (tj)]2

The term∑N−1

j=0[W (tj+1) − W (tj)]

2 can be shown to have expected value T , and variance,O(∆t) so that as ∆t → 0, we have, for the Ito integral:

∫ T

0

W (t)dW (t) =1

2W (T )2 − 1

2T (9)

Consider now the Stratonovich integral (7).

∫ T

0

W (t)dW (t) =N−1∑

j=0

W

(

tj + tj+1

2

)

(W (tj+1) − W (tj))

=N−1∑

j=0

(

1

2(W (tj) + W (tj+1)) + ∆zj

)

(W (tj+1) − W (tj))

=N−1∑

j=0

(

1

2

(

W (tj+1)2 − W (tj)

2)

+ ∆zj(W (tj+1) − W (tj))

)

=1

2

(

W (T )2 − W (0)2)

+N−1∑

j=0

∆zj(W (tj+1) − W (tj))

The term∑N−1

j=0∆zj(W (tj+1) − W (tj)) can be shown to have expected value zero, with

variance O(∆t). Hence, the theoretical value for the Stratonovich integral is:∫ T

0

W (t)dW (t) =1

2W (T )2 (10)

Table 1 shows a comparison of the quadrature values with the theoretical values for eachof the Ito and Stratonovich integrals. The first column is the ’state’ of the random numbergenerator in MATLAB. The code that produced these values can be found in Figure 17, inthe appendix.

’state’ Ito Ito Th Strat Strat Th

1 0.2517 0.2611 0.7777 0.76112 0.9113 0.9302 1.4233 1.43023 -0.0901 -0.1093 0.4123 0.39074 -0.3757 -0.3826 0.1051 0.11745 -0.1318 -0.1446 0.3396 0.3554

Table 1: A comparison of the Ito and Stratonovich Quadratures with the theoretical values

7

Page 8: SDEs.pdf

4 The Euler-Maruyama Method

We now have the necessary machinery in place to allow us to solve a Stochastic DifferentialEquation numerically. As we discussed briefly earlier, a Stochastic Differential equation isa differential equation in which at least one term is a Stochastic Process. A general formfor an SDE is:

dX(t) = f(t, X(t))dt + g(t, X(t))dW (t)

X(0) = X0

Which can be interpreted as an integral equation:

X(t) = X0 +

∫ t

0

f(s, X(s))ds +

∫ t

0

g(s, X(s))dW (s)

However, in this report, we will consider autonomous SDEs, that is SDEs that do not haveany explicit dependence upon t:

X(0) = X0

dX(t) = f(X(t))dt + g(X(t))dW (t) (11)

⇒ X(t) = X0 +

∫ t

0

f(X(s))ds +

∫ t

0

g(X(s))dW (s) (12)

4.1 Derivation of the formula

The Euler-Maruyama method is constructed within the Ito integral framework. We willattempt to construct a numerical method from the integral form (12). We begin by settingδt = T

Lfor some integer, L and let τj = jδt for j = 0, ..., L. We also define the numerical

approximation to X(τj) as Xj . Setting successively t = τj and t = τj−1 in (12), we obtain:

X(τj) = X0 +

∫ τj

0

f(X(s))ds +

∫ τj

0

g(X(s))dW (s)

X(τj−1) = X0 +

∫ τj−1

0

f(X(s))ds +

∫ τj−1

0

g(X(s))dW (s)

If we subtract these equations, then we obtain:

X(τj) = X(τj−1) +

∫ τj

τj−1

f(X(s))ds +

∫ τj

τj−1

g(X(s))dW (s) (13)

We can now consider approximating each of the integral terms. For the first integral, wecan use the conventional determinstic quadrature:

∫ τj

τj−1

f(X(s))ds ≈ (τj − τj−1)f(Xj−1) = δtf(Xj−1)

And for the second integral, we use the Ito formula developed in the previous section:∫ τj

τj−1

g(X(s))dW (s) ≈ g(Xj−1)(W (τj) − W (τj−1))

Combining these together gives us the Euler-Maruyama formula:

X0 = X(0)

Xj = Xj−1 + δtf(Xj−1) + g(Xj−1)(W (τj) − W (τj−1)) (14)

8

Page 9: SDEs.pdf

4.2 Implementing the method

Before we set up our implementation for the Euler-Maruyama scheme, recall that our Brow-nian paths were generated with a step size defined by ∆t = L

n. For convenience, we shall

choose the step size in the Euler-Maruyama scheme, δt, to be an integer multiple of thestep size, so that the points τj correspond to points in the Brownian path.

The test problem that we will choose to implement our method on is:

X(0) = X0

dX(t) = λX(t)dt + µX(t)dW (t) (15)

This is an SDE from finance which models asset prices. The exact solution of this SDE is:

X(t) = X(0)exp

{(

λ − 1

2µ2

)

t + µW (t)

}

(16)

The MATLAB implementation for the Euler-Maruyama method is given Figure 7, whilsttwo sample solutions for two arbitrary Brownian paths are given in Figure 8. In eachdiagram, the Euler-Maruyama numerical solution is plotted against the exact solution forthat Wiener proces. We see that, at least in a qualitative sense, the solutions match well.

Figure 7: MATLAB code for Implementing the Euler-Maruyama method

1 T=1; % Set interval [0,T]2 n=2ˆ8; % Number of points in Brownian path3 X0=1; % Intial condition4 dt=T/n; % Set stepsize5 dW=sqrt(dt) * randn(1,n); % Array of Brownian movements6 W=cumsum(dW); % Wiener process7 lambda=2;mu=1; % Set the Parameters8 f=@(x) lambda * x;9 g=@(x) mu* x; % Set the functions f & g

10 R=1; % Set the value of R (needs to be power of 2)11 δt=R * dt; % Set δt12 steps=n/R; % Number of steps in E −M iteration13 X=zeros(steps,1); % Create array for results14 Xold=X0; % Initialise Xold15 for i=1:steps16 % The EM iteration: Depending on R, we need to compute the sum o f the17 % elements in dW from 1 ∆−t to the next (eg if R=4 this is 4 terms)18 X(i) = Xold + ∆* f(Xold) + g(Xold) * sum(dW((R * (i −1)+1):R * i));19 Xold=X(i); % Update Xold20 end21 X=[X0;X]; Solution=X0 * exp((lambda −0.5 * muˆ2) * (dt:dt:T)+mu * W);22 plot(0: ∆:T,X, ' −g.' ,0:dt:T,[X0 Solution])23 title( 'Numerical solution of an SDE using the Euler −Maruyama Method' )24 xlabel( 't' ),ylabel( 'X(t)' , 'Rotation' ,0)25 legend( 'EM Approximation' , 'Exact Solution' , 'Location' , 'NW' )

Let us now take a particular Brownian path and compute the Euler-Maruyama solution fordifferent step sizes. Taking succesively δt = ∆t, 2∆t, 4∆t, 8∆t produces the plots in Figure9. As we would expect, the solution becomes less accurate as we increase the step size,δt of the method. In the next section, we will examine the convergence properties of theEuler-Maruyama method with more mathematical rigour.

9

Page 10: SDEs.pdf

Figure 8: Two examples of The Euler-Maruyama solution plotted against the true solution

0 0.2 0.4 0.6 0.8 10.5

1

1.5

2

2.5

3Numerical solution of an SDE using the Euler−Maruyama Method

t

X(t)

EM ApproximationExact Solution

(a)

0 0.2 0.4 0.6 0.8 11

1.5

2

2.5

3

3.5

4

4.5

5

5.5Numerical solution of an SDE using the Euler−Maruyama Method

t

X(t)

EM ApproximationExact Solution

(b)

Figure 9: The effect of increasing the step size in the Euler-Maruyama method

0 0.2 0.4 0.6 0.8 10

1

2

3

4

5

6

7

8R = 1

t

X(t)

EM ApproximationExact Solution

(a)

0 0.2 0.4 0.6 0.8 10

1

2

3

4

5

6

7

8R = 2

t

X(t)

EM ApproximationExact Solution

(b)

0 0.2 0.4 0.6 0.8 10

1

2

3

4

5

6

7

8R = 4

t

X(t)

EM ApproximationExact Solution

(c)

0 0.2 0.4 0.6 0.8 10

1

2

3

4

5

6

7

8R = 8

t

X(t)

EM ApproximationExact Solution

(d)

4.3 Strong Convergence

To consider the convergence properties of the Euler-Maruyama method, we must first con-sider how we will measure the error.

Definition Strong order of Convergence

We say that a method has a strong order of convergence, γ, if ∃ a constant, C such that:

E |Xn − X(τ)| ≤ Cδtγ

10

Page 11: SDEs.pdf

For any fixed τ = nδt ∈ [0, T ] and δt sufficiently small.Since this definition applies to all values of t in [0, T ], we shall focus our attention on

the endpoints of the interval and let:

estrongδt = E |Xn − X(τ)| ≤ Cδtγ where Lδt = T

Then, taking logs, we have:

log estrongδt ≈ log C + γ log δt

It is therefore possible to infer the value of the constant γ by plotting the log of meanerror of a series of experiments against the log of the step size, δt. The value of theconstant, γ will be the gradient of the line of best fit through the points. To constructthis experiment, we will choose ∆t = 2−9 as the time step of the Wiener process. We willthen use the Euler-Maruyama method to construct a numerical solution for, successively,δt = ∆t, 2∆t, 4∆t, 8∆t, 16∆t. For each Brownian path, the error at t = T is the absolutevalue of the difference between the E-M solution and the true solution computed using (16).If we run this over a large number of paths (say, 2000) and compute the average, then thisis our expected endpoint error, E |XL − X(T )| for a given step size.

Figure 10: MATLAB code for function to compute the the endpoint error

1 function [last error] = strong conv(k)2 T=1; % Set time interval [0,T]3 n=2ˆ9; % Set number of steps to compute at in [0,T]4 X0=1; % Initial Condition5 dt=T/n; % Compute the time step6 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements7 W=cumsum(dW); % Sum the array to obtain Wiener process8 lambda=2;mu=1; % Set the Parameters9 f=@(x) lambda * x; % Set the functions f & g

10 g=@(x) mu* x;11 R=2ˆ(k −1); % Set the value of R (needs to be power of 2)12 δt=R * dt; % Set δt13 steps=n/R; % Number of steps in E −M iteration14 Xold=X0; % Initialise Xold15 for i=1:steps16 X = Xold + ∆* f(Xold) + g(Xold) * sum(dW(R* (i −1)+1:R * i));17 Xold=X; % Update Xold18 end19 solution end=X0* exp((lambda −0.5 * muˆ2) * T+mu* W(end));20 last error=abs(X −solution end); % END OF FUNCTION21

22 % Compute the expectations, produce the loglog plot and eval uate γ

23

24 S=2000; K=5; % Sample Paths, Step sizes25 strong conv matrix=zeros(S,K); % Preallocate arrays26 for j=1:K27 for i=1:S28 strong conv matrix(i,j)=strong conv(j);29 end30 end31 mean error=sum(strong conv matrix)/S;32 loglog(dt * 2.ˆ(0:(K −1)),mean error);33 p = polyfit(log(dt * 2.ˆ(0:(K −1))),log(mean error),1); gamma strong=p(1)

11

Page 12: SDEs.pdf

Figure 10 shows the MATLAB function that produces the endpoint difference for eachBrownian path and the subsequent code that runs over 2000 paths and averages the endpointerror. The last line of the code uses MATLAB’s polyfit([],[],1) function to linearlyinterpolate in a least squares sense. The first coefficient of the resulting array is thereforethe gradient of the line. Running the code gives the value, gammastrong = 0.5230. Thelog-log plot is given in Figure 11.

4.4 Weak Convergence

The last sectioned was concerned with how the mean of the errors decayed as the step size,δt → 0. Weak convergences concerns the rate of decay of the error of the means.

Definition Weak order of Convergence

We say that a method has a weak order of convergence, γ, if ∃ a constant, C such that forall functions, p in some class,

|Ep(Xn) − Ep(X(τ))| ≤ Cδtγ

For any fixed τ = nδt ∈ [0, T ] and δt sufficiently small.Typically, the functions, p must satisfy smoothness and polynomial growth conditions.

Here, we will choose p to be the identity function and focus once more upon the endpointof the interval so that we will be considering:

eweakδt = |E(XL) − E(XT )| ≤ Cδtγ (17)

By using similar code to that which we used for finding the strong order of convergence(which can be found in Figure 18 in the appendix), we obtain a value gammaweak = 0.9804.Figure 11 shows the log-log plots for both the strong and weak cases.

Figure 11: log-log plot of error and stepsize for the Strong and Weak convergence of EM

10−3

10−2

10−1

10−2

10−1

100

log(stepsize)

log(

erro

r)

Strong ErrorWeak Error

12

Page 13: SDEs.pdf

5 Milnstein’s Higher Order Method

We now attempt to construct a method which achieves a higher rate of strong convergencethan Euler-Maruyama. In order to do this, we will first derive (in an informal way) theStochastic chain rule, using Ito calculus.

5.1 Ito’s Lemma

We begin with our autonomous SDE (12):

dX(t) = f(X(t))dt + g(X(t))dW (t)

Consider a function V = V (X). Applying Taylor’s theorem to V gives:

dV =dV

dXdX +

1

2

d2V

dX2dX2 + . . .

Substituting (12) into this expression gives:

dV =dV

dX{f(X)dt + g(X)dW} +

1

2

d2V

dX2

{

f(X)2dt2 + 2f(X)g(X)dtdW + g(X)2dW 2}

+ . . .

Where it is understood that V = V (X) and X = X(t). Now, it is statistical property, thatwe shall not prove here, but that is explained in more detail in [5], that as dt → 0, we have:

dW 2 → E(dW )2 = dt and dt2 → 0 and dtdW → 0

This gives us Ito’s Lemma (or the Stochastic chain rule):

dV =

(

f(X)dV

dX+

1

2g(X)2

d2V

dX2

)

dt + g(X)dV

dXdW (18)

In the extension exercise, we will verify numerically that Ito’s Lemma is valid.

5.2 Deriving Milnstein’s Method

Setting successively t = s and t = τj−1 in the equivalent Integral form of (18) and subtract-ing, gives:

V (X(s)) = V (X(τj−1)) +

∫ s

τj−1

{

f(X(τ))dV

dX(X(τ)) +

1

2(g(X(τ))2

d2V

dX2(X(τ))

}

+

∫ s

τj−1

{

g(X(τ))dV

dX(X(τ))

}

dW (τ)

or: V (X(s)) = V (X(τj−1)) +

∫ s

τj−1

L0V (X(τ))dτ +

∫ s

τj−1

L1V (X(τ))dW (τ)

where: L0 = f(X(τ))d

dX+

1

2g(X(τ))2

d2

dX2, L1 = g(X(τ))

d

dX

Taking in turn V = f and V = g gives:

f(X(s)) = f(X(τj−1)) +

∫ s

τj−1

L0f(X(τ))dτ +

∫ s

τj−1

L1f(X(τ))dW (τ)

g(X(s)) = g(X(τj−1)) +

∫ s

τj−1

L0g(X(τ))dτ +

∫ s

τj−1

L1g(X(τ))dW (τ)

Substituting these equations into the integral from of the autonomous SDE (13), gives:

13

Page 14: SDEs.pdf

X(τj) = X(τj−1)

+

∫ τj

τj−1

{

f(X(τj−1)) +

∫ s

τj−1

L0f(X(τ))dτ +

∫ s

τj−1

L1f(X(τ))dW (τ)

}

ds

+

∫ τj

τj−1

{

g(X(τj−1)) +

∫ s

τj−1

L0g(X(τ))dτ +

∫ s

τj−1

L1g(X(τ))dW (τ)

}

dW (s)

Which can be re-written as:

X(τj) = X(τj−1) + δtf(X(τj−1)) + g(X(τj−1))

∫ τj

τj−1

dW (s)

+

∫ τj

τj−1

∫ s

τj−1

L0f(X(τ))dτds +

∫ τj

τj−1

∫ s

τj−1

L1f(X(τ))dW (τ)ds

+

∫ τj

τj−1

∫ s

τj−1

L0g(X(τ))dτdW (s) +

∫ τj

τj−1

∫ s

τj−1

L1g(X(τ))dW (τ)dW (s)

Note that the first line of this formula is The Euler-Maruyama method. To obtain Milstein’smethod, we expand the L1g(X(τ)) term using the definition of the operator L1 and theformula for g(X(s)), above to obtain:

L1g(X(τ)) = L1g(X(τj−1)) +

∫ s

τj−1

L0L1g(X(m))dm +

∫ s

τj−1

L1L1g(X(m))dW (m)

Substituting this into the previous equation and rearranging slightly gives:

X(τj) = X(τj−1) + δtf(X(τj−1)) + g(X(τj−1))

∫ τj

τj−1

dW (s)

+

∫ τj

τj−1

∫ s

τj−1

L1g(X(τj−1))dW (τ)dW (s)

+

∫ τj

τj−1

∫ s

τj−1

L0f(X(τ))dτds +

∫ τj

τj−1

∫ s

τj−1

L1f(X(τ))dW (τ)ds

+

∫ τj

τj−1

∫ s

τj−1

L0g(X(τ))dτdW (s)

+

∫ τj

τj−1

∫ s

τj−1

∫ τ

τj−1

L0L1g(X(m))dmdW (τ)dW (s)

+

∫ τj

τj−1

∫ s

τj−1

∫ τ

τj−1

L1L1g(X(m))dW (m)dW (τ)dW (s)

Milstein’s method follows from the first two lines of the above expression, which can bewritten as:

X(τj) = X(τj−1) + δtf(X(τj−1)) + g(X(τj−1))

∫ τj

τj−1

dW (s)

+g(X(τj−1))g′(X(τj−1))

∫ τj

τj−1

∫ s

τj−1

dW (τ)dW (s)

Finally, Milstein’s Higher order method is:

Xj = Xj−1 + δtf(Xj−1) + g(Xj−1)(W (τj) − W (τj−1))

+1

2g(Xj−1)g

′(Xj−1)((W (τj) − W (τj−1))2 − δt)

for j = 1, 2, . . . , L with X0 = X(0) (19)

14

Page 15: SDEs.pdf

5.3 Implementing Milstein’s Method

Let us return to our test problem (15) and implement Milstein’s method, in order to obtainsome kind of qualitative feel for whether the method has improved our accuracy. The codeis given in the appendix, in Figure 19. We have taken the same Brownian paths that wereused for the Euler-Maruyama solution in Figure 8 and have used the same step size. Theresults are shown in Figure 12. There is evidently a massive improvement (though in fairnessto the EM method, the two paths used were chosen because they are particularly ’jagged’and do a good job of highlighting the difference in performance of the two methods).

Figure 12: Two examples of The Milnstein solution plotted against the true solution

0 0.2 0.4 0.6 0.8 10.5

1

1.5

2

2.5

3Numerical solution of an SDE using Milnstein’s higher order method

t

X(t)

Milnstein ApproximationExact Solution

(a)

0 0.2 0.4 0.6 0.8 11

1.5

2

2.5

3

3.5

4

4.5

5

5.5Numerical solution of an SDE using Milnstein’s higher order method

t

X(t)

Milnstein ApproximationExact Solution

(b)

Now, we turn out attention to a new SDE that is used in population dynamics.

dX(t) = rX(t)(K − X(t))dt + βX(t)dW (t)

X(0) = X0 (20)

We will take the constants to be: r = 2, K = 1, β = 0.25 & X0 = 0.5.

Figure 13: MATLAB code for the Milstein method on the population dynamics SDE

1 T=1; n=2ˆ11; X0=0.5; dt=T/n;2 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements3 W=cumsum(dW); % Sum the array cummulativley4 f = @(X) 2 * X* (1 −X); % Set the functions f, g & gprime5 g = @(X) 0.25 * X;6 gprime = @(X) 0.25;7 R=1; % Set the value of R (needs to be power of 2)8 δt=R * dt; % Set δt9 steps=n/R; % Number of steps in E −M iteration

10 X=zeros(steps,1); % Create array for results11 Xold=X0; % Initialise Xold12 for i=1:steps13 X(i) = Xold + ∆* f(Xold) + g(Xold) * sum(dW((R * (i −1)+1):R * i)) ...14 + 0.5 * g(Xold) * gprime(Xold) * ((sum(dW((R * (i −1)+1):R * i)))ˆ2 −∆);15 Xold=X(i); % Update Xold16 end17 X=[X0;X]; plot(0: ∆:T,X);18 title( 'Numerical solution of an SDE using Milnstein''s higher ord er method' )19 xlabel( 't' ),ylabel( 'X(t)' , 'Rotation' ,0)

15

Page 16: SDEs.pdf

Figure 14: Computing the expected solution of the population dynamics SDE

0 0.2 0.4 0.6 0.8 10.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8

0.85

0.9

0.95The mean of 10000 trials plotted with 5 sample paths

t

Expected solution

Figure 13 shows the code used to generate the Milnstein solution for the poulation dynam-ics SDE, whilst Figure 14 shows five example solutions plotted with the mean of 10 000solutions. This can be thought of as the ’expected solution’ of the SDE.

5.4 Strong Convergence

In order to measure the rate of strong convergence of Milnstein’s method, we essentiallyproceed as we did before with Euler-Maruayma. We will attempt to obtain the strong orderof convergence in two way, using in turn, each of the SDEs we have studied so far. For thefinance SDE (15), we know the exact solution, so we procede exactly as before, only replacingthe Euler-Maruyama solver with the Milnstein solver. The code for this can be found inFigure 20 in the appendix. Running this code gives a value of MilnsteinStrongOrderA

= 0.9828. If we wish to compute the strong order of convergence using the populationdynamics SDE, then we must use a slightly different approach as we do not have theexact solution. Instead, we shall make the assumption that solution obtained by using thesmallest timestep possible (δt = ∆t) is a good approximation to the true solution. Wethen measure our strong rate of convergence by seeing how the expected error increasesrelative to this this value, for δt = 2∆t, 4∆t, 8∆t, 16∆t, 32∆t, 64∆t, 128∆t. Figure 15 onthe following page shows the MATLAB code for doing this. Executing the code gives avalue, MilnsteinStrongOrderB = 1.0764.

Running the codes multiple times give very similar values to the figures quoted above.The first value is almost always slightly below 1, whilst the second value is almost alwaysabove 1. A value of 1 therefore seems like a good guess as to the strong rate of convergenceof Milnstein’s higher order method. This is a marked improvement upon the value of 0.5obtained by Euler-Maruyama.

16

Page 17: SDEs.pdf

Figure 15: Computing the strong order of convergence using the population dynamics SDE

1 function [difference] = ms strong conv(k)2 T=1; % Set time interval [0,T]3 n=2ˆ11; % Set number of steps to compute at in [0,T]4 X0=1; % Initial Condition5 dt=T/n; % Compute the time step6 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements7 f = @(X) 2 * X* (1 −X); % Set the functions f, g & gprime8 g = @(X) 0.25 * X;9 gprime = @(X) 0.25;

10 R=2ˆk; % Set the value of R (needs to be power of 2)11 δt=R * dt; % Set δt12 Xold=X0; Yold=X0;13

14 for i=1:n15 X = Xold + dt * f(Xold) + g(Xold) * dW(i) ...16 + 0.5 * g(Xold) * gprime(Xold) * (dW(i)ˆ2 −dt);17 Xold=X;18 if mod(i,R)==0 % Computes Y every R steps19 Y = Yold + ∆* f(Yold) + g(Yold) * sum(dW((R * ((i/R) −1)+1):R * (i/R))) ...20 + 0.5 * g(Yold) * gprime(Yold) * ((sum(dW((R * ((i/R) −1)+1):R * (i/R))))ˆ2 −∆);21 Yold=Y;22 end23 end24 difference=abs(X −Y);25 end26

27 %%%%%%%%%%%%%%% Compute the strong order of convergence %%%%%%%%%%%%%%%%%%%%%28

29 S=1000; % Number of Sample Paths30 K=7; % Number of step sizes31 matrix=zeros(S,K); % Preallocate arrays32 for j=1:K33 for i=1:S34 matrix(i,j)=ms strong conv(j);35 end36 end37 mean error=sum(matrix)/S;38 dt=2ˆ( −11);39 loglog(dt * 2.ˆ(1:K),mean error);40 p = polyfit(log(dt * 2.ˆ(1:K)),log(mean error),1);41 MilnsteinStrongOrderB=p(1)

17

Page 18: SDEs.pdf

6 Verifying the Stochastic Chain Rule

Recall Ito’s lemma (18), which we derived in an informal way earlier.

dV =

(

f(X)dV

dX+

1

2g(X)2

d2V

dX2

)

dt + g(X)dV

dXdW

This is also known as the Stochastic Chain Rule for dV (X), where X(t) satisfies:

dX = f(X)dt + g(X)dW

Now consider the following SDE:

dX(t) = (α − X(t)) dt + β√

X(t)dW (t)

X(0) = X0 (21)

Let us suppose that we make some kind of change of variables, for example by lettingV (X) =

√X. We can use Ito’s lemma to derive a corresponding SDE for V (X) and solve

that using one of the methods described earlier. Then, if Ito’s lemma is correct, squaringour solution for V (X) should give us the same result as as solving (21) directly. Now,

V (X) =√

X ⇒ dV

dX=

1

2

1√X

⇒ d2V

dX2= −1

4

1

X√

X

Identifying f(X) = α − X and g(X) = β√

X and using Ito’s lemma (18) gives:

dV =

(

1

2(α − X)

1√X

− 1

8β2X

1

X√

X

)

dt +1

√X√X

dW

=

{(

1

2α − 1

8β2

)

1

V− 1

2V

}

dt +1

2βdW

so dV =

(

4α − β2

8V− 1

2V

)

dt +1

2βdW

V0 =√

X0 (22)

This is then the SDE that V (X) must satisfy. The code for solving the 2 SDEs (21) &(22) simultaneously is given in Figure 21 in the appendix. We use the Euler-Maruyamamethod to solve these SDES and three sample solutions are plotted on the following page,in Figure 16. For each example, we have plotted the two solutions V (X) and X(t) on theleft and then plotted V (X)2 and X(t) on the right. The solutions evidently match verywell, suggesting that the Stochastic Chain Rule is indeed valid.

Taking the infinity norm error for the last plot produces:

norm(X-V.^2,inf) = 0.0211

All solutions tested so far have an error of comparable magnitude.

18

Page 19: SDEs.pdf

Figure 16: Verifying the Stochastic Chain Rule

0 0.2 0.4 0.6 0.8 1

0.8

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6Verification of the Stochastic Chain Rule

t

X(t)V(t)

(a)

0 0.2 0.4 0.6 0.8 1

0.8

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6Verification of the Stochastic Chain Rule

t

X(t)

V(t)2

(b)

0 0.2 0.4 0.6 0.8 1

0.8

1

1.2

1.4

1.6

1.8

2Verification of the Stochastic Chain Rule

t

X(t)V(t)

(c)

0 0.2 0.4 0.6 0.8 1

0.8

1

1.2

1.4

1.6

1.8

2Verification of the Stochastic Chain Rule

t

X(t)

V(t)2

(d)

0 0.2 0.4 0.6 0.8 11

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6Verification of the Stochastic Chain Rule

t

X(t)V(t)

(e)

0 0.2 0.4 0.6 0.8 11

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6Verification of the Stochastic Chain Rule

t

X(t)

V(t)2

(f)

19

Page 20: SDEs.pdf

7 Conclusions

In this report, we have discussed various techniues for exploring the behaviour of systemswith a stochastic component. By defining Brownian motion in a formal way, we were ableto use MATLAB to generate discretised Wiener processes. These were then used as a basisfor Monte-Carlo style experiments, such as computing the expected path of a function ofstochastic process.

We went on to develop some basic numerical techniques for solving SDEs, such as theEuler-Maruyama and Milstein methods. We also performed some convergence analysis andfound that Milstein was the better performer in this respect (at least when it consideringstrong convergence). Finally, we verified the Stochastic chain rule by experimental meansby showing that the solution of one SDE and the solution of different SDE that was derivedfrom the first using the Stochastic Chain rule, were in relative agreement.

There are many possible extensions to this project. The study of Stochastic processes isa relatively young field and consequently, there is much work still to be done. For example,one could imagine adding more terms to the Milstein method in an attempt to achievean even higher strong rate of convergence or looking at solving SDEs in more than onedimension.

20

Page 21: SDEs.pdf

8 Appendix

Figure 17: MATLAB code for comparing the Ito and Stratonovich integrals

1 T=1; n=1000; dt=T/n; K=10;I=zeros(K,1); S=I;TI=I;TS=I;i i=I;2 for i=1:K3 randn( 'state' ,i)4 ii(i)=i;dW=sqrt(dt) * randn(1,n);W=cumsum(dW);5 I(i) = [0,W(1:n −1)] * dW';6 S(i) = [0.5 * ([0,W(1:n −1)]+W)+0.5 * sqrt(dt) * randn(1,n)] * dW';7 TI(i) = 0.5 * W(end)ˆ2 −0.5 * T;8 TS(i) = 0.5 * W(end)ˆ2;9 end

10 [ii,I,TI,S,TS]

Figure 18: MATLAB code computing the order of weak convergence of EM

1 function [last approx,last exact] = weak conv(k)2 T=1; n=2ˆ9; X0=1; dt=T/n; dW=sqrt(dt) * randn(1,n); W=cumsum(dW);3 lambda=2;mu=1; % Set the Parameters4 f=@(x) lambda * x;g=@(x) mu * x; % Set the functions f & g5 R=2ˆ(k −1); δ=R* dt; % Set the values of R and δ

6 steps=n/R; % Number of steps in E −M iteration7 X=zeros(steps,1); % Create array for results8 Xold=X0; % Initialise Xold9 for i=1:steps

10 X(i) = Xold + ∆* f(Xold) + g(Xold) * sum(dW(R* (i −1)+1:R * i));11 Xold=X(i); % Update Xold12 end13 Solution=X0 * exp((lambda −0.5 * muˆ2) * (dt:dt:T)+mu * W);14 last approx=X( end );last exact=Solution( end );15 end % END OF FUNCTION16 S=2000; K=5; % Number of Paths, steps17 weak conv matrix A=zeros(S,K); % Approximate final values18 weak conv matrix B=zeros(S,K); % Exact final values19 for j=1:K % for columns20 for i=1:S % for rows21 [weak conv matrix A(i,j),weak conv matrix B(i,j)]=weak conv(j);22 end23 end24 mean A=sum(weak conv matrix A)/S;mean B=sum(weak conv matrix B)/S;25 result matrix=abs(mean A−mean B);26 loglog(dt * 2.ˆ(0:(K −1)),result matrix, 'r' );27 p = polyfit(log(dt * 2.ˆ(0:(K −1))),log(result matrix),1); gamma weak=p(1)

21

Page 22: SDEs.pdf

Figure 19: MATLAB code for implementing the Milnstein method for the finance SDE

1 T=1; % Set time interval [0,T]2 n=2ˆ8; % Set number of steps to compute at in [0,T]3 X0=1; % Initial Condition4 dt=T/n; % Compute the time step5 %randn('state',14) % Repeatable trials on/off6 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements7 W=cumsum(dW); % Sum the array cummulativley8 lambda=2;mu=1; % Set the Parameters9 f=@(x) lambda * x; % Set the functions f & g

10 g=@(x) mu* x;11 gprime = @(X) mu;12 R=1; % Set the value of R (needs to be power of 2)13 δt=R * dt; % Set δt14 steps=n/R; % Number of steps in E −M iteration15 X=zeros(steps,1); % Create array for results16 Xold=X0; % Initialise Xold17 for i=1:steps18 X(i) = Xold + ∆* f(Xold) + g(Xold) * sum(dW((R * (i −1)+1):R * i)) ...19 + 0.5 * g(Xold) * gprime(Xold) * ((sum(dW((R * (i −1)+1):R * i)))ˆ2 −∆);20 Xold=X(i); % Update Xold21 end22 X=[X0;X];23 Solution=X0 * exp((lambda −0.5 * muˆ2) * (dt:dt:T)+mu * W);24 plot(0: ∆:T,X, ' −r.' ,0:dt:T,[X0 Solution])25 title( 'Numerical solution of an SDE using Milnstein''s higher ord er method' )26 xlabel( 't' ),ylabel( 'X(t)' , 'Rotation' ,0)27 legend( 'Milnstein Approximation' , 'Exact Solution' , 'Location' , 'NW' )

22

Page 23: SDEs.pdf

Figure 20: Strong convergence rate of Milnstein’s method using the finance SDE

1 function [answer] = milnstein strong(k)2

3 T=1; % Set time interval [0,T]4 n=2ˆ9; % Set number of steps to compute at in [0,T]5 X0=1; % Initial Condition6 dt=T/n; % Compute the time step7 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements8 W=cumsum(dW); % Obtain Wiener process9 lambda=2;mu=1; % Set the Parameters

10 f=@(x) lambda * x; % Set the functions f & g11 g=@(x) mu* x;12 gprime = @(X) mu;13 R=2ˆ(k −1); % Set the value of R (needs to be power of 2)14 δt=R * dt; % Set δt15 steps=n/R; % Number of steps in E −M iteration16 Xold=X0; % Initialise Xold17

18 for i=1:steps19 X = Xold + ∆* f(Xold) + g(Xold) * sum(dW((R * (i −1)+1):R * i)) ...20 + 0.5 * g(Xold) * gprime(Xold) * ((sum(dW((R * (i −1)+1):R * i)))ˆ2 −∆);21 Xold=X; % Update Xold22 end23

24 solutionend=X0 * exp((lambda −0.5 * muˆ2) * T+mu* W(end));25 answer=abs(X −Solutionend);26 end27

28 %%%%%%%%%% Code to compute the Strong order of convergence % %%%%%%%%%%%29

30 S=3000; % Number of Sample Paths31 K=6; % Number of step sizes32 matrix=zeros(S,K);33

34 for j=1:K35 for i=1:S36 matrix(i,j)=milnstein strong(j);37 end38 end39

40 mean error=sum(matrix)/S;41 dt=2ˆ( −9);42 loglog(dt * 2.ˆ(0:(K −1)),mean error);43 p = polyfit(log(dt * 2.ˆ(0:(K −1))),log(mean error),1);44 MilnsteinStrongOrderA=p(1)

23

Page 24: SDEs.pdf

Figure 21: MATLAB code for verifying the Stochastic Chain Rule

1 T=1; % Set time interval [0,T]2 n=200; % Set number of steps to compute at in [0,T]3 dt=T/n; % Compute the time step4 %randn('state',100) % Repeatable trials on/off5 dW=sqrt(dt) * randn(1,n); % Generate array of brownian movements6 alpha=2;beta=1; % Set the Parameters7 f=@(X) alpha −X;8 g=@(X) beta * sqrt(X);9 p=@(V) ((4 * alpha −betaˆ2)/(8 * V)−0.5 * V);

10 q=@(V) 0.5 * beta;11 X0=1; % Initial Condition12 R=1; % Set the value of R (needs to be power of 2)13 δt=R * dt; % Set δt14 steps=n/R; % Number of steps in E −M iteration15 X=zeros(steps,1); % Create array for results16 V=zeros(steps,1);17 Xold=X0; V0=sqrt(X0); Vold=V0;18

19 for i=1:steps20 X(i) = Xold + ∆* f(Xold) + g(Xold) * sum(dW((R * (i −1)+1):R * i));21 Xold=X(i);22

23 V(i) = Vold + ∆* p(Vold) + q(Vold) * sum(dW((R * (i −1)+1):R * i));24 Vold=V(i);25 end26

27 X=[X0;X];V=[V0;V];28 figure29 plot(0: ∆:T,X, ' −g.' ,0: ∆:T,V)30 title( 'Verification of the Stochastic Chain Rule' )31 xlabel( 't' ),legend( 'X(t)' , 'V(t)' , 'Location' , 'NW' )32 figure33 plot(0: ∆:T,X, ' −g.' ,0: ∆:T,V.ˆ2)34 title( 'Verification of the Stochastic Chain Rule' )35 xlabel( 't' ),legend( 'X(t)' , 'V(t)ˆ2' , 'Location' , 'NW' )

24

Page 25: SDEs.pdf

References

[1] Dr. Kathryn GillowCase Study in Scientific Computing Lecture Notes (SDEs) 2009MSc Mathematical Modelling and Scientific Computing, University of Oxford

[2] Desmond J. HighamAn Algorithmic Introduction to Numerical Simulation of SDEsSIAM REVIEW Vol. 43, No. 3 , pp. 525546

[3] D. J. Higham and N. J. HighamMATLAB GuideSIAM, Philadelphia, 2000

[4] B. OksendalStochastic Differential Equations5th ed., Springer-Verlag, Berlin, 1998

[5] Paul Wilmott, Sam Howison, and Jeff Dewynne.The Mathematics of Financial Derivatives: A student introductionCambridge University Press, Cambridge, UK, First edition, 1995.

25