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
where (the drift) is the "expected direction of travel," (the diffusion coefficient) scales how much randomness gets injected, and 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 and with a small but finite time step and a correspondingly-scaled random shock:
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 , not . 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 ), 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, and (proportional drift and vol, the standard "stock returns are roughly log-normal" model), so the update becomes
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.
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.
Worked example 1: simulating one path, five steps by hand
Simulate a stock following geometric Brownian motion with , drift (8% per year), volatility (30% per year), over half a year using 5 steps, so years each. Suppose the 5 standard normal draws are .
Step 1: .
Step 2: .
Step 3: .
Step 4: .
Step 5: .
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): . 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, year, one full step, with , , and a single draw : Euler-Maruyama gives .
The exact GBM solution, using the same underlying random shock (mapping to , since a 1-year Brownian increment with variance 1 has ): .
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 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 , 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 itself depends on ) 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 directly in additive Euler-Maruyama form can, on a large unlucky random draw, push below zero — nonsensical for a stock price. Simulating 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: . The scaling on the noise term (not ) 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 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 instead of — an easy typo to make since drift scales with 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 far faster than ), 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)