Quant Sandbox
DerivativesPortfolio & RiskFixed IncomeCorporate FinanceStochastic ModelsGuide
Guide
Derivatives pricing
01Forwards, calls and puts02Combining positions03Arbitrage and the forward price04Put–call parity05The one-step binomial model06Risk-neutral probabilities07Multi-step trees and backward induction08American options and early exercise09Delta and hedging10Geometric Brownian motion11The Black–Scholes formula12The Greeks: gamma, vega, theta and rho13Implied volatility and the volatility smile14Stochastic volatility and the Heston model15Static replication: Breeden–Litzenberger and Carr–Madan16Exotic options: barriers, Asians and digitals
Portfolio & risk
01Returns and volatility02Diversification and correlation03The efficient frontier and the capital market line04Risk aversion and the optimal complete portfolio05CAPM, beta and the security market line06Performance measures: Sharpe, Treynor, Jensen and information ratio07Factor models and systematic risk08Value at Risk and expected shortfall
Fixed income
01Bond prices and yields02Duration and convexity03Immunization and duration matching04Spot rates, forward rates and the yield curve05Bond futures and the cheapest-to-deliver06Interest rate swaps07Callable bonds and negative convexity08Credit risk: default probabilities and credit spreads
Corporate finance
01Interest, compounding and discounting02Annuities, perpetuities and loan amortization03Net present value and internal rate of return04The weighted average cost of capital05Capital structure and the Modigliani–Miller theorems06Discounted cash flow valuation07Relative valuation with multiples08Real options: the value of flexibility
Stochastic models
01Random walks and Brownian motion02Probability spaces, σ-algebras and random variables03Filtrations, adapted processes and stopping times04Conditional expectation and martingales05Properties of Brownian motion06The reflection principle and first passage times07The Brownian bridge08The Itô integral09Itô's lemma10Kolmogorov equations and the Feynman–Kac formula11Change of measure and Girsanov's theorem12Monte Carlo option pricing13Simulating SDEs: the Euler–Maruyama scheme14Mean reversion: Ornstein–Uhlenbeck and Vasicek15Jumps and the Merton jump-diffusion model
Knowledge graph

© 2026 Quant Sandbox · A study aid for quantitative finance

Privacy & dataNo cookies

This site does not use cookies and asks for no personal data. It keeps a few small settings in your browser's local storage — your chosen theme and language, the sidebar layout, and your progress and answers in the Guides — so it remembers them on your next visit. This data never leaves your device; clearing your browser storage removes it. Inputs you change can also be captured in the page URL, so you can share or bookmark a specific setup. The site uses Vercel Web Analytics, a privacy-friendly, cookieless service that records only anonymous, aggregated usage (such as page views) without identifying you or tracking you across other sites.

Guide/Stochastic models

Simulating SDEs: the Euler–Maruyama scheme

Lesson 13 of 15 · 1 min read

In "Monte Carlo option pricing" every terminal price was drawn in one step, because "Itô's lemma" gave the exact solution of geometric Brownian motion. Most models used in practice have no such formula. This lesson shows how to simulate a stochastic differential equation step by step with the Euler–Maruyama scheme, how to measure the error it makes, and how fast that error shrinks as the steps get smaller. Geometric Brownian motion serves as the test case, precisely because its exact solution is known.

Stochastic differential equations

A stochastic differential equation (SDE) describes how a quantity XtX_tXt​ changes over a short time dtdtdt:

dXt=a(Xt,t) dt+b(Xt,t) dWt.dX_t = a(X_t, t)\,dt + b(X_t, t)\,dW_t.dXt​=a(Xt​,t)dt+b(Xt​,t)dWt​.

The drift aaa is the expected rate of change, and the diffusion coefficient bbb scales the random shock dWtdW_tdWt​ of a Brownian motion. Geometric Brownian motion is the case a=μXa = \mu Xa=μX, b=σXb = \sigma Xb=σX. A mean-reverting interest rate, or the variance in "Stochastic volatility and the Heston model", has other coefficients, and for many of them no closed-form solution exists.

The Euler–Maruyama step

Split [0,T][0, T][0,T] into nnn steps of length Δt=T/n\Delta t = T/nΔt=T/n and freeze the coefficients at the start of each step. The Brownian increment over a step is normal with variance Δt\Delta tΔt, so it can be written ΔWk=Δt Zk\Delta W_k = \sqrt{\Delta t}\,Z_kΔWk​=Δt​Zk​ with ZkZ_kZk​ standard normal. The Euler–Maruyama scheme is

Xk+1=Xk+a(Xk,tk) Δt+b(Xk,tk) Δt Zk.X_{k+1} = X_k + a(X_k, t_k)\,\Delta t + b(X_k, t_k)\,\sqrt{\Delta t}\,Z_k.Xk+1​=Xk​+a(Xk​,tk​)Δt+b(Xk​,tk​)Δt​Zk​.

It is the natural first approximation: it keeps exactly the two terms that dominate the Itô expansion of the change over one step, the dtdtdt term and the dWdWdW term, and drops everything smaller. Think of it as walking along a curved road by taking straight steps in the direction you are facing; the shorter the steps, the closer you stay to the road.

For geometric Brownian motion one step reads Sk+1=Sk (1+μ Δt+σ ΔWk)S_{k+1} = S_k\,(1 + \mu\,\Delta t + \sigma\,\Delta W_k)Sk+1​=Sk​(1+μΔt+σΔWk​), while the exact solution over the same step is

Sk+1=Skexp⁡ ⁣((μ−12σ2)Δt+σ ΔWk).S_{k+1} = S_k \exp\!\Big(\big(\mu - \tfrac12\sigma^2\big)\Delta t + \sigma\,\Delta W_k\Big).Sk+1​=Sk​exp((μ−21​σ2)Δt+σΔWk​).

Example: S0=100S_0 = 100S0​=100, μ=8%\mu = 8\%μ=8%, σ=40%\sigma = 40\%σ=40%, Δt=0.25\Delta t = 0.25Δt=0.25 and Z=1Z = 1Z=1, so ΔW=0.5\Delta W = 0.5ΔW=0.5. Euler gives 100 (1+0.02+0.2)=122.00100\,(1 + 0.02 + 0.2) = 122.00100(1+0.02+0.2)=122.00. The exact value is 100 e(0.08−0.08)⋅0.25+0.2=100 e0.2=122.14100\,e^{(0.08 - 0.08) \cdot 0.25 + 0.2} = 100\,e^{0.2} = 122.14100e(0.08−0.08)⋅0.25+0.2=100e0.2=122.14. With Z=−1Z = -1Z=−1 Euler gives 82.0082.0082.00 against the exact 81.8781.8781.87. The step misses by about 0.130.130.13 either way, because it ignores the curvature of the exponential.

Strong and weak error

There are two ways to judge a simulation scheme, depending on what it is used for.

  • The strong error E[ ∣XT−X^T∣ ]\mathbb{E}\big[\,|X_T - \hat X_T|\,\big]E[∣XT​−X^T​∣] compares the simulated path X^\hat XX^ with the true path driven by the same Brownian motion. It matters when the path itself matters, for example when hedging along it.
  • The weak error ∣ E[f(XT)]−E[f(X^T)] ∣\big|\,\mathbb{E}[f(X_T)] - \mathbb{E}[f(\hat X_T)]\,\big|​E[f(XT​)]−E[f(X^T​)]​ compares only averages. It is what matters for Monte Carlo pricing, which needs the distribution of XTX_TXT​, not individual paths.

For smooth coefficients the Euler–Maruyama scheme has strong order 12\tfrac1221​ and weak order 1: the strong error shrinks like Δt\sqrt{\Delta t}Δt​, the weak error like Δt\Delta tΔt. Four times as many steps halve the strong error but cut the weak error to a quarter.

Geometric Brownian motion makes the weak error easy to compute. Each Euler step multiplies the expected value by 1+μ Δt1 + \mu\,\Delta t1+μΔt, so E[S^T]=S0 (1+μT/n)n\mathbb{E}[\hat S_T] = S_0\,(1 + \mu T/n)^nE[S^T​]=S0​(1+μT/n)n, against the exact S0 eμTS_0\,e^{\mu T}S0​eμT. With the numbers above, 100 e0.08=108.3287100\,e^{0.08} = 108.3287100e0.08=108.3287, and the gaps for n=4n = 4n=4, 161616 and 646464 are 0.08550.08550.0855, 0.02160.02160.0216 and 0.00540.00540.0054: a quarter each time.

Worked example

Weak error of Euler for GBM with two steps

  1. With S0=100S_0 = 100S0​=100, μ=8%\mu = 8\%μ=8%, T=1T = 1T=1 and n=2n = 2n=2, each Euler step multiplies the expected value by this factor.

    1+μT/n\displaystyle 1 + \mu T/n1+μT/n=1.04
  2. Expected value of the Euler approximation at TTT.

    S0 (1+μT/n)n\displaystyle S_0\,(1 + \mu T/n)^nS0​(1+μT/n)n=108.16
  3. Exact expected value.

    S0 eμT\displaystyle S_0\,e^{\mu T}S0​eμT=108.3287
  4. Weak error: twice the gap at n=4n = 4n=4, as order 1 predicts.

    S0 eμT−S0 (1+μT/n)n\displaystyle S_0\,e^{\mu T} - S_0\,(1 + \mu T/n)^nS0​eμT−S0​(1+μT/n)n=0.1687

The same path on finer grids

To see the strong error you must compare a simulation with the exact path driven by the same randomness. The figure draws one Brownian path on a fine grid of 256 steps over one year, with S0=100S_0 = 100S0​=100, μ=8%\mu = 8\%μ=8% and σ=40%\sigma = 40\%σ=40%; the high volatility makes the error visible. The exact solution is drawn from that path, and the Euler approximation uses the same path on a coarser grid: each coarse increment is the sum of the fine increments it spans.

Choose n=4n = 4n=4, 161616, 646464 or 256256256 steps and watch the Euler path close in on the exact one; "New path" draws another Brownian path. Hover over the chart, or focus it and use the arrow keys, to compare the two values at a grid time. Below, the strong error at TTT averaged over 500 paths is plotted against Δt\Delta tΔt on log–log axes, next to a reference line of slope 12\tfrac1221​. It falls from about 4.824.824.82 at n=4n = 4n=4 to 2.342.342.34, 1.231.231.23 and 0.630.630.63 at n=256n = 256n=256: roughly halving with every fourfold refinement, as order 12\tfrac1221​ predicts. On the first path the terminal values at n=16n = 16n=16 are 177.23177.23177.23 exact against 183.44183.44183.44 for Euler.

Euler–Maruyama on the same Brownian pathOpen in Geometric Brownian Motion →
exact solutionEuler, 16 steps

Hover over the chart (or focus it and use the arrow keys) to compare the two values at one time.

Strong error at T against the time step (average over 500 paths, log–log scale)
Exact value at T
177.23
Euler value at T
183.44
Error on this path
6.22
Mean strong error (n = 16)
2.34

Simulating the logarithm instead

For geometric Brownian motion there is a better option than discretising SSS itself. By "Itô's lemma", ln⁡St\ln S_tlnSt​ follows

d(ln⁡St)=(μ−12σ2) dt+σ dWt,d(\ln S_t) = \big(\mu - \tfrac12\sigma^2\big)\,dt + \sigma\,dW_t,d(lnSt​)=(μ−21​σ2)dt+σdWt​,

whose coefficients are constant. Euler steps on ln⁡S\ln SlnS are therefore exact, whatever Δt\Delta tΔt is, and prices stay positive automatically. Euler on SSS can even produce a negative price if 1+μ Δt+σ ΔW1 + \mu\,\Delta t + \sigma\,\Delta W1+μΔt+σΔW falls below zero. Transforming a model into variables with simpler coefficients before discretising is a standard trick; when no such transformation exists, as for many mean-reverting or stochastic-volatility models, small steps and the error orders above are what you rely on.

Summary

  • An SDE dX=a dt+b dWdX = a\,dt + b\,dWdX=adt+bdW is simulated step by step with Euler–Maruyama: Xk+1=Xk+a Δt+bΔt ZkX_{k+1} = X_k + a\,\Delta t + b\sqrt{\Delta t}\,Z_kXk+1​=Xk​+aΔt+bΔt​Zk​.
  • The strong error (paths) has order 12\tfrac1221​ and the weak error (averages) order 1; Monte Carlo pricing only needs the weak one.
  • Coarse and fine grids must use the same Brownian path to be compared: coarse increments are sums of fine ones.
  • When a transformation gives constant coefficients, as ln⁡S\ln SlnS does for geometric Brownian motion, simulate that variable instead: the steps become exact.

The next lesson, "Mean reversion: Ornstein–Uhlenbeck and Vasicek", studies a process whose drift pulls it back towards a long-run level, and simulates it with exactly this kind of step.

Try itSimulate geometric Brownian motion paths in the GBM lab →
2 questions on this lesson at the end of the series →
← PreviousMonte Carlo option pricingNext →Mean reversion: Ornstein–Uhlenbeck and Vasicek
Connections
Simulating SDEs: the Euler–Maruyama sche…
Open the full graph →
Labs for this lesson
Geometric Brownian MotionMonte Carlo