Euler–Maruyama method

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 an extension 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 any arbitrary deterministic method.

Consider the stochastic differential equation (see Itô calculus)


 * $$\mathrm{d} X_t = a(X_t, t) \, \mathrm{d} t + b(X_t, t) \, \mathrm{d} W_t,$$

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 $$\Delta t>0$$:


 * $$0 = \tau_{0} < \tau_{1} < \cdots < \tau_{N} = T \text{ and } \Delta t = T/N;$$


 * set Y0 = x0
 * recursively define Yn for 0 ≤ n ≤ N-1 by


 * $$\, Y_{n + 1} = Y_n + a(Y_n, \tau_n) \, \Delta t + b(Y_n, \tau_n) \, \Delta W_n,$$


 * where


 * $$\Delta W_n = W_{\tau_{n + 1}} - W_{\tau_n}.$$

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

Numerical simulation


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
The following Python code implements the Euler–Maruyama method and uses it to solve the Ornstein–Uhlenbeck process defined by


 * $$ dY_t=\theta \cdot (\mu-Y_t) \, {\mathrm d}t + \sigma \, {\mathrm d}W_t$$


 * $$ Y_0=Y_\mathrm{init}.$$

The random numbers for $${\mathrm d}W_t$$ are generated using the NumPy mathematics package.



The following is simply the translation of the above code into the MATLAB (R2019b) programming language: