Euler–Maruyama method

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In Itô calculus, the Euler–Maruyama method (also called the Euler method) is a method for the approximate numerical solution of a stochastic differential equation (SDE). It is a simple generalization of the Euler method for ordinary differential equations to stochastic differential equations. It is named after Leonhard Euler and Gisiro Maruyama. Unfortunately the same generalization cannot be done for the other methods from deterministic theory,[1] e.g. Runge–Kutta schemes.

Consider the stochastic differential equation (see Itō calculus)

with initial condition X0 = x0, where Wt stands for the Wiener process, and suppose that we wish to solve this SDE on some interval of time [0, T]. Then the Euler–Maruyama approximation to the true solution X is the Markov chain Y defined as follows:

  • partition the interval [0, T] into N equal subintervals of width :
  • set Y0 = x0;
  • recursively define Yn for 1 ≤ n ≤ N by

The random variables ΔWn are independent and identically distributed normal random variables with expected value zero and variance .


Numerical simulation[edit]

Gene expression modelled as stochastic process

An area that has benefited significantly from SDE is biology or more precisely mathematical biology. Here the number of publications on the use of stochastic model grew, as most of the models are nonlinear, demanding numerical schemes.

The graphic depicts a stochastic differential equation being solved using the Euler Scheme. The deterministic counterpart is shown as well.

Computer implementation[edit]

The following Python code implements the Euler–Maruyama method and uses it to solve the Ornstein–Uhlenbeck process defined by

The random numbers for are generated using the numpy mathematics package.

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

num_sims = 5 ### display five runs

t_init = 3
t_end  = 7
y_init = 0
N      = 1000 ### Compute 1000 grid points 

c_theta = 0.7
c_mu    = 1.5
c_sigma = 0.06

def mu(y, t): 
    """Implement the Ornstein–Uhlenbeck mu.""" ### = \theta \cdot (\mu-Y_t)
    return c_theta * (c_mu - y)

def sigma(y, t): 
    """Implement the Ornstein–Uhlenbeck sigma.""" ### = \sigma
    return c_sigma
def dW(delta_t): 
    """Sample a random number at each call."""
    return np.random.normal(loc = 0.0, scale = np.sqrt(delta_t))

dt    = float(t_end - t_init) / N
ts    = np.arange(t_init, t_end, dt)
ys    = np.zeros(N)

ys[0] = y_init

for i_sim in range(num_sims):
    for i in range(1, ts.size):
        t_ = (i-1) * dt
        y_ = ys[i-1]
        ys[i] = y_ + mu(y_, t_) * dt + sigma(y_, t_) * dW(dt)
    plt.plot(ts, ys)

See also[edit]


  1. ^ Kloeden & Platen, 1992