Quant Memo
Advanced

The Euler-Maruyama Scheme

The simplest way to turn a stochastic differential equation into code: chop time into small steps, and at each one nudge the price by its drift plus a scaled random shock. Simple to implement, and simple to get subtly wrong.

Prerequisites: Pseudorandom Number Generation

A stochastic differential equation like geometric Brownian motion describes how a price evolves in continuous time — but a computer can't take infinitely many infinitely small steps. To simulate a price path, you need a rule for turning the continuous equation into a sequence of discrete jumps a computer can actually loop over. The Euler-Maruyama scheme is the simplest such rule: chop time into small intervals, and at each one, move the price by its expected drift over that interval plus a random shock scaled to match the interval's length.

The analogy: driving with your eyes closed for one second at a time

Imagine driving a car whose speed and steering constantly change, but you can only glance at the speedometer and update your grip once per second — for that whole second, you drive as if speed and direction were frozen at what you last observed, then you glance again and correct. If you check every second, your trajectory is a rough, slightly-wrong approximation of the smooth path you'd have driven with continuous awareness. Check every tenth of a second instead, and your approximation gets much closer to the truth, because "frozen for this interval" is a much better approximation over a shorter interval. Euler-Maruyama drives a simulated price the same way: freeze the drift and volatility for one small time step, take the step, then re-evaluate.

Writing it down

A general stochastic differential equation is written

dSt=μ(St,t)dt+σ(St,t)dWtdS_t = \mu(S_t, t)\,dt + \sigma(S_t, t)\,dW_t

where μ\mu (the drift) is the "expected direction of travel," σ\sigma (the diffusion coefficient) scales how much randomness gets injected, and dWtdW_t is an infinitesimal increment of Brownian motion — pure, unpredictable noise. This equation describes an infinite, continuous process; it isn't, by itself, something a loop can execute.

The Euler-Maruyama discretization replaces the infinitesimal dtdt and dWtdW_t with a small but finite time step Δt\Delta t and a correspondingly-scaled random shock:

St+Δt=St+μ(St,t)Δt+σ(St,t)Δt  Z,ZN(0,1).S_{t+\Delta t} = S_t + \mu(S_t, t)\,\Delta t + \sigma(S_t, t)\,\sqrt{\Delta t}\; Z, \qquad Z \sim N(0,1).

In words: the next price equals the current price, plus the drift times the length of the step (how far you'd move if there were no randomness at all), plus a random shock whose size scales with Δt\sqrt{\Delta t}, not Δt\Delta t. That square root is the single most important detail in the whole formula: Brownian motion's randomness accumulates with the square root of elapsed time (its variance grows linearly in time, so its standard deviation grows with t\sqrt{t}), so a discretized noise term has to match that scaling or the simulated path's volatility will be systematically wrong.

For geometric Brownian motion specifically, μ(St,t)=μSt\mu(S_t,t) = \mu S_t and σ(St,t)=σSt\sigma(S_t,t) = \sigma S_t (proportional drift and vol, the standard "stock returns are roughly log-normal" model), so the update becomes

St+Δt=St+μStΔt+σStΔt  Z=St(1+μΔt+σΔtZ).S_{t+\Delta t} = S_t + \mu S_t\, \Delta t + \sigma S_t \sqrt{\Delta t}\; Z = S_t\big(1 + \mu\,\Delta t + \sigma\sqrt{\Delta t}\,Z\big).

In words: multiply the current price by one, plus a small deterministic growth term, plus a small random shock term — each step is a slightly-nudged copy of the last price, and the nudges compound over the whole simulated path.

Path explorer
13055time →
end (bold path) 100.38spread of ends 58.966 independent paths, same settings

Every path in the explorer above is generated exactly this way, one small time step at a time. Watch what happens as you imagine coarsening the step size: with very few, very large steps, the path would look jagged and could jump by amounts a real continuous price never would; with many small steps, it smooths into something that looks like a genuinely continuous random walk.

dashed = true continuous path · solid = Euler-Maruyama with 5 large steps each straight segment freezes drift and vol for that step, then re-evaluates at the dot
The simulated path is a sequence of straight-line guesses that gets corrected at every step. Smaller steps (more dots, shorter segments) track the true continuous path more closely — at the cost of more computation.

Worked example 1: simulating one path, five steps by hand

Simulate a stock following geometric Brownian motion with S0=100S_0 = 100, drift μ=0.08\mu = 0.08 (8% per year), volatility σ=0.30\sigma = 0.30 (30% per year), over half a year using 5 steps, so Δt=0.1\Delta t = 0.1 years each. Suppose the 5 standard normal draws are Z=0.4,0.8,1.1,0.2,0.6Z = 0.4, -0.8, 1.1, -0.2, 0.6.

Step 1: S1=100(1+0.08×0.1+0.300.1×0.4)=100(1+0.008+0.0379)=100×1.0459=104.59S_1 = 100(1 + 0.08\times0.1 + 0.30\sqrt{0.1}\times0.4) = 100(1 + 0.008 + 0.0379) = 100 \times 1.0459 = 104.59.

Step 2: S2=104.59(1+0.008+0.300.1×(0.8))=104.59(1+0.0080.0759)=104.59×0.9321=97.49S_2 = 104.59(1 + 0.008 + 0.30\sqrt{0.1}\times(-0.8)) = 104.59(1+0.008-0.0759) = 104.59\times0.9321 = 97.49.

Step 3: S3=97.49(1+0.008+0.300.1×1.1)=97.49(1+0.008+0.1043)=97.49×1.1123=108.44S_3 = 97.49(1+0.008+0.30\sqrt{0.1}\times1.1) = 97.49(1+0.008+0.1043) = 97.49\times1.1123 = 108.44.

Step 4: S4=108.44(1+0.008+0.300.1×(0.2))=108.44(1+0.0080.0190)=108.44×0.9890=107.25S_4 = 108.44(1+0.008+0.30\sqrt{0.1}\times(-0.2)) = 108.44(1+0.008-0.0190) = 108.44\times0.9890 = 107.25.

Step 5: S5=107.25(1+0.008+0.300.1×0.6)=107.25(1+0.008+0.0569)=107.25×1.0649=114.21S_5 = 107.25(1+0.008+0.30\sqrt{0.1}\times0.6) = 107.25(1+0.008+0.0569) = 107.25\times1.0649 = 114.21.

After five steps and half a year, this one simulated path ends at $114.21. Repeat this whole process thousands of times with fresh random draws, and the distribution of ending prices across all the simulated paths is your Monte Carlo estimate of where the stock might land — average the payoff of an option across all those endpoints, discount back, and you have a Monte Carlo option price.

Worked example 2: the discretization error from taking steps too large

The exact solution to geometric Brownian motion is known in closed form (no simulation needed): St=S0exp((μσ2/2)t+σWt)S_t = S_0 \exp\big((\mu - \sigma^2/2)t + \sigma W_t\big). Compare Euler-Maruyama's approximation quality at a coarse step size versus a fine one, holding the total simulated randomness path fixed.

At a coarse step, Δt=1\Delta t = 1 year, one full step, with μ=0.08\mu=0.08, σ=0.30\sigma=0.30, and a single draw Z=0.5Z=0.5: Euler-Maruyama gives S1=100(1+0.08+0.30×0.5)=100×1.23=123.00S_1 = 100(1 + 0.08 + 0.30\times0.5) = 100\times1.23 = 123.00.

The exact GBM solution, using the same underlying random shock (mapping Z=0.5Z=0.5 to W1=0.5W_1 = 0.5, since a 1-year Brownian increment with variance 1 has W1=1ZW_1 = \sqrt{1}\,Z): S1=100exp((0.080.045)×1+0.30×0.5)=100exp(0.035+0.15)=100exp(0.185)=120.32S_1 = 100\exp\big((0.08 - 0.045)\times1 + 0.30\times0.5\big) = 100\exp(0.035+0.15) = 100\exp(0.185) = 120.32.

The one-step Euler-Maruyama approximation, $123.00, misses the exact answer, $120.32, by about $2.68 — a real, structural error from linearizing (approximating) the exponential growth with a single flat step over a whole year, not from the randomness itself (the same ZZ was used in both). Refining to 12 monthly steps, feeding in twelve smaller, correlated shocks that sum appropriately, brings the Euler-Maruyama path's endpoint distribution much closer to the exact solution's, because each small step's linear approximation of the true, curved exponential path is far more accurate over one-twelfth of a year than over a full year.

What this means in practice

  • Step size controls accuracy, and accuracy costs compute. Euler-Maruyama's error shrinks as you shrink Δt\Delta t, but so does your simulation speed — every options desk running Monte Carlo pricing under time pressure is making an explicit trade-off between step count and runtime.
  • It's the default first choice, not the best available. More accurate schemes exist (Milstein's scheme adds a correction term that improves accuracy for the same step size, particularly when σ\sigma itself depends on StS_t) but Euler-Maruyama remains the workhorse because it's simple to implement correctly and fast to run.
  • Path-dependent payoffs need every intermediate step, not just the endpoint. Pricing a barrier or Asian option means simulating and checking every discretized step along the path, not just where it ends up — and a step size too coarse can miss a barrier the true continuous path would have touched, systematically mispricing the option.
  • Negative prices are a known failure mode for the naive additive form. Simulating dSt=μStdt+σStdWtdS_t = \mu S_t dt + \sigma S_t dW_t directly in additive Euler-Maruyama form can, on a large unlucky random draw, push St+ΔtS_{t+\Delta t} below zero — nonsensical for a stock price. Simulating lnSt\ln S_t instead (which stays additive and well-behaved under log) and exponentiating at the end avoids this entirely.

Euler-Maruyama simulates a continuous stochastic process by freezing drift and volatility over each small time step: St+Δt=St+μΔt+σΔtZS_{t+\Delta t} = S_t + \mu\,\Delta t + \sigma\sqrt{\Delta t}\,Z. The Δt\sqrt{\Delta t} scaling on the noise term (not Δt\Delta t) is the detail that makes the discretization match how Brownian randomness actually accumulates over time.

If a simulated GBM path implementation is producing occasional negative or wildly unstable prices, check whether it's simulating the price directly or its logarithm — simulating lnSt\ln S_t and exponentiating at the end is both more numerically stable and structurally guarantees a positive price.

The classic confusion is scaling the random shock by Δt\Delta t instead of Δt\sqrt{\Delta t} — an easy typo to make since drift scales with Δt\Delta t and it's tempting to treat the noise term the same way. Get this wrong and, for small step sizes, the simulated volatility silently collapses toward zero (since Δt0\Delta t \to 0 far faster than Δt0\sqrt{\Delta t} \to 0), producing paths that look deceptively smooth and a Monte Carlo option price that understates the true option value — a bug that won't crash anything, will pass a casual visual check of "yeah, that looks like a price path," and will simply be wrong.

Related concepts

Practice in interviews

Further reading

  • Glasserman, Monte Carlo Methods in Financial Engineering (ch. 6)
  • Kloeden & Platen, Numerical Solution of Stochastic Differential Equations (ch. 9)
ShareTwitterLinkedIn