Simulating an SDE with Euler–Maruyama
The question
If you double the number of steps along the same Brownian path, how much does the simulation error change?
- 1 SeePredict how much the error changes.
- 2 TryChange the grid on one path.
- 3 ProveBuild an exact error formula.
- 4 ApplySolve step and error problems.
Before you start · 3 quick checks on slopes, standard deviation and absolute distance, about 3 min
Two ideas before you start
2 ideasStart each step at the current value
A straight segment shows how far a fixed slope moves the state during one time step.
For the drift alone, multiply the slope at the start by the time step. The segment shows the move that this frozen slope gives.
Exact definition
A scalar Itô stochastic differential equation (SDE) has the form \(dX_t=a(X_t)\,dt+b(X_t)\,dW_t\) here. The state is \(X_t\), \(W_t\) is standard Brownian motion, and the functions \(a\) and \(b\) give the drift and the diffusion coefficient. The notation describes a time integral of the drift and an Itô integral of the diffusion coefficient against \(W\).
Divide a fixed duration \(T\gt0\) into \(N\) equal steps of length \(h=T/N\), with \(t_n=nh\). Let \(Y_n\) approximate \(X_{t_n}\), starting at \(Y_0=X_0\). Euler–Maruyama evaluates both coefficients at \(Y_n\):
\[\begin{aligned} Y_{n+1} &= Y_n+a(Y_n)h\\ &\quad +b(Y_n)\Delta W_n . \end{aligned}\]Here \(\Delta W_n=W_{t_{n+1}}-W_{t_n}\). When \(b\) is identically zero, the update reduces to forward Euler.
The noise can move either way
The endpoint moves below or above the start as the chosen noise increment changes sign.
This example holds the diffusion coefficient positive and sets the drift to zero. Change the sign of the Brownian increment and watch the endpoint.
Exact definition
Over an interval of length \(h\), a standard Brownian motion has a normal increment with mean zero and variance \(h\). Increments over disjoint intervals are independent. You can simulate one as \(\Delta W_n=\sqrt h\,Z_n\) using a standard normal draw \(Z_n\), which has variance one.
The increment \(b(Y_n)\Delta W_n\), given the state and the past, has variance \(b(Y_n)^2 h\). Its standard deviation is \(|b(Y_n)|\sqrt h\). The two figure choices are example increments, not the two possible outcomes of a normal draw.
Fine print on solutions and simulated paths
For this time-independent scalar equation, globally Lipschitz drift and diffusion with at most linear growth and a fixed finite starting value ensure a strong solution on every finite interval, unique up to indistinguishability. A strong solution is built on the given probability space with the given Brownian motion and uses no future increments. A weak solution allows the probability space and driving Brownian motion to be chosen as part of the solution. These uses of “strong” and “weak” concern what it means to solve the equation.
Without the conditions, consider two deterministic SDEs (diffusion zero). On the nonnegative state space, \(dX=\sqrt X\,dt\) from zero has both \(X_t=0\) and \(X_t=t^2/4\) for \(t\ge0\), as direct differentiation shows. The slope \(\sqrt x\) is not Lipschitz at zero. For \(dX=X^2\,dt\) starting at \(x_0\gt0\), the exact solution \(x_0/(1-x_0t)\) grows without bound as \(t\) approaches \(1/x_0\) from below. The explicit formulas establish the two behaviors. A simulated path that grows rapidly cannot by itself establish explosion or nonuniqueness.
At a fixed step size with fresh independent increments, \(Y_n\) is a time-homogeneous Markov chain on the real line. The distribution of its next state, given its history, depends on its current state alone. The Markov chains lesson illustrates this property on a finite state space.
Halve the time step
- Pick how much of the original mean error you expect to remain.
- Check to run the comparison on paired Brownian paths.
Mean distance at the final time
| Updates \(N\) | Step \(h\) | Sample mean gap | Share of prior gap |
|---|
For each row, take the absolute difference between the simulated and exact endpoints on each path, then average the distances across paths. A positive deviation on one path cannot cancel a negative deviation on another. This sample average estimates the strong terminal error \(\mathbb E|Y_N-X_T|\).
To keep the comparison paired, generate the finest increments once per path. A coarse increment is the sum of the fine increments inside its interval. The exact endpoint in each comparison uses the sum of all the increments on that same path. Fresh Brownian paths for each row would still estimate each row’s error, but the ratio between rows would then also carry sampling noise from the change of paths.
What the rate refers to
For fixed \(T\), a fixed finite starting value and time-independent, globally Lipschitz coefficients of at most linear growth, Euler–Maruyama has an upper bound of order \(h^{1/2}\) for the root mean squared terminal error. By Cauchy–Schwarz, the same upper bound applies to the mean absolute error. This bounds the error by a constant times \(\sqrt h\) as the steps shrink. A bound alone does not establish a limiting ratio for mean absolute error. The prediction uses the square-root scaling benchmark and the table measures how closely the simulated mean gaps follow it.
Some equations have smaller errors. For constant drift and constant diffusion, adding the updates gives the exact solution at the grid times when the increments are shared. An individual path can also have a larger gap after a refinement, even when the mean gap falls.
One update, then a whole path
- Predict the next state from a frozen drift, a frozen diffusion coefficient and one supplied increment.
- After you check, change the grid on one paired path and meet the error goals.
Compare both endpoints on one path
Return to the equation from See, using the first Brownian path from the batch. Change the number of updates while keeping that path fixed. The axis rescales to fit both traces. The endpoint gap in the plot is for this one path, while the goal uses an exact average over all paths.
Goals
The root mean squared (RMS) error is the square root of the expected squared endpoint gap. It uses all possible paths under the model and weights large gaps more heavily than the mean absolute error. The next stage derives the RMS formula used here.
An exact squared-error formula
Assume \(dX_t=\sigma X_t\,dW_t\) for a constant \(\sigma\gt0\), a deterministic \(X_0=x_0\gt0\), standard Brownian motion and fixed \(T\gt0\). Use \(N\ge1\) equal steps of size \(h=T/N\) and drive the exact and numerical paths with the same increments. Set \(k=\sigma^2 h\gt0\). Then
\[\begin{aligned} &\mathbb E[(Y_N-X_T)^2]\\ &=x_0^2\big[e^{Nk}-(1+k)^N\big]. \end{aligned}\]Applying Itô’s lemma to the exponential shows that \(X_t=x_0\exp(\sigma W_t-\sigma^2t/2)\) solves the equation. The diffusion coefficient is linear in \(X\), so the existence and uniqueness conditions from Start apply. The proof multiplies one-step factors, using independence across intervals and sharing the increment within each pair.
Write \(A=1+U\) and \(B=\exp(U-k/2)\) for the Euler and exact factors on one step, where \(U=\sigma\Delta W\) is normal with mean zero and variance \(k\). The corresponding factors on interval \(j\) are \(A_j,B_j\). Completing the square in the normal density gives \(\mathbb E[e^{sU}]=e^{ks^2/2}\) for real \(s\), and \(\mathbb E[Ue^{sU}]=ks e^{ks^2/2}\) by differentiating. An exponential times a polynomial is integrable against the normal density for all real \(s\), so the derivative may pass inside the expectation.
Here \(O(N^{-2})\) denotes a term bounded in magnitude by a constant times \(N^{-2}\) for sufficiently large \(N\). Thus the squared error divided by \(h\) tends to \(x_0^2 e^q\sigma^4T/2\), a positive constant. Taking square roots proves the square-root rate for RMS in this example and makes the RMS ratio tend to \(1/\sqrt 2\) when \(N\) doubles.
Problems
Use the step rule or the paired error formula. Each problem has hints and a full solution.
Further reading
- D. J. Higham, “An Algorithmic Introduction to Numerical Simulation of Stochastic Differential Equations,” SIAM Review.
- D. J. Higham and P. E. Kloeden, An Introduction to the Numerical Simulation of Stochastic Differential Equations.
- P. E. Kloeden and E. Platen, Numerical Solution of Stochastic Differential Equations.