2.6
SDEs and geometric Brownian motion
dS = μS dt + σS dW; solve via log S; the −½σ² correction (mean vs median, volatility drag); exact sampling vs Euler–Maruyama; where the √dt comes from.
A stochastic differential equation gives you a recipe for what happens over the next tiny step, but it does not yet give you a price you can use. The one on this page is Geometric Brownian motion (GBM), : over the next the price moves by for certain and by at random. This is a modelling choice, not something derived: it says the percentage move over the next is — 2.2's Brownian motion with a drift, applied to returns rather than to the price — so that a doubling of the price doubles the size of every move and the price can never go below zero. 2.11 is where that choice is tested. To turn that recipe into simulated prices, a developer has to make three decisions: whether to draw the final price directly or build a path step by step, how fine a grid to use if stepping is needed, and how to check that the simulation is actually correct. Each decision has an answer that looks reasonable and produces convincing numbers, yet is wrong, so the point of this page is to show what the right choices are and how to recognise the mistakes. The one piece of maths it needs, 2.5 already did.
What this page shows, and how
The page follows the three decisions in the order a developer meets them.
First, draw or step. If the payoff only depends on the final price, there is no grid at all: the model has a solution, and one normal number per path gives the final price exactly. The first table shows what that distribution looks like — Gaussian log-returns, a mean price of and a median price below it — and shows the one way to get it wrong, which is to leave the out of the exponent and make every price 8 % too high.
Second, if you step, what it costs. A payoff that looks at the path needs the path. For this model you can still step exactly, because the solution holds between any two grid points; the approximate step — Euler's, the recipe read literally — is what you are left with when a model has no solution, and this is the one model where its error can be measured against the truth. The second table does that: about 1 % per path at 100 steps, shrinking like , with mean zero — so a price, which is an average over paths, barely feels it, while a spread across paths keeps it.
Third, how you know the simulator is right. Three numbers a correct simulation must reproduce — the realised volatility of each path, the mean of the final price, its median — and the one common bug they catch, written in place of , which leaves the mean untouched and shrinks the volatility a hundredfold at ten thousand steps.
The why comes last and is short: 2.5's lemma on log S gave a line with no on the right, and adding up its steps is the solution. Nothing new is proved on this page; the three tables put numbers on what 2.5 already said.
The experiment — what was done
Every number on this page comes from one experiment. First, we generated exact GBM terminal prices by drawing a single normal random number for each path and evaluating the closed-form solution at , once for the working case and again for the comparison case . With the same parameters, and , we then drew 1,000 Brownian paths once on a very fine grid of steps and read those same paths on five nested grids, from 100 to steps. On each grid, the terminal price produced by Euler was compared with the exact solution built from exactly the same Brownian increments, while the common bug was run alongside on those same paths and grids. A second simulation generated 20,000 fresh Euler paths at 10,000 steps, for both values of , so that the mean and median of the Euler prices could be measured with no closed-form solution anywhere inside the simulation; the comparison with the exact on the same normals was made afterwards. Finally, a separate mean-reversion (Ornstein–Uhlenbeck) experiment was run inside the same seeded experiment (seed 20261001). Its results are recorded in the JSON file but are not used on this page.
path 1 of the experiment · n = 100 · μ = 0.1 · σ = 0.4 · S₀ = 100
What you are looking at. One Brownian path — the experiment’s path 1, 100 random draws Z₁ … Z₁₀₀ — fed through two different rules for moving the price one step. Both rules get the same draw on every step, so the two lines share every turn. They drift apart only because the rules differ at second order: the exact rule multiplies the price by e^((μ − ½σ²)·dt + σ·√dt·Z), the Euler rule by 1 + μ·dt + σ·√dt·Z. Summed over the path, Euler’s correction is −½σ²·Σ(ΔW)² where the exact rule’s is −½σ²·T; on this path Σ(ΔW)² = 1.44 against T = 1, so Euler sits below and ends 3.42 % lower. μ moves both lines together; on this path the gap goes from −3.38 % at μ = 0 to −3.46 % at μ = 0.2 — it is set by σ and Σ(ΔW)², not by μ.
- exact step — multiply by e^((μ − ½σ²)dt + σ√dt·Zᵢ)
- Euler step — multiply by 1 + μ dt + σ√dt·Zᵢ
- the bug — σ·dt·Zᵢ in place of σ·√dt·Zᵢ (toggle)
S_T over 10⁶ exact draws — mean 110.5, median 102.0; your live sample overlaid
- exact S_T
- 170.78
- Euler S_T, same draws
- 164.94
- gap, Euler − exact
- −3.42 %
- Σ(ΔW)² on this path (T = 1)
- 1.438
- rms gap over 1,000 paths
- 1.15 %
- paths at T
- 2,0000 off the bins
- mean S_T
- 111.28 ± 1.07correct: 110.52
- median S_T
- 101.10correct: 102.02
- realised vol
- 0.3991correct: 0.40
- 10⁶ exact: mean
- 110.47 ± 0.05median 102.05
- 10⁶ exact: below mean
- 57.9 %0.34 % are past 300
- fitted slope, against dt
- 0.495R² 0.9982
- the experiment’s, against n
- −0.501n = 100 … 10⁶
Generate draws new paths on this site’s generator, which is not numpy’s. The distribution’s line is a fresh sample stepped with the chosen increment; the bars are the committed histogram, drawn at σ = 40% only, because that is where it was run. The convergence chart always measures the correct step: its fitted slope is 0.495 over 300 paths at seven step counts, against a theoretical ½.
Draw directly
The first decision is whether you need a path at all. If the payoff depends only on the final price, there is no reason to build a grid and step through time. The solution of GBM gives the terminal price directly from a single normal random variable, so one draw produces one exact sample of . This is the distribution that later pages use inside Monte Carlo pricing and that 2.9 integrates analytically. The question for this section is therefore simple: if we draw terminal prices directly, what does the distribution actually look like, and what mistakes matter?
One normal per path, paths for each of the two drifts, ,
, . Seed 20261001, from the committed
experiments/2_6_sdes_and_gbm.json (exact.{log_return,S_T} for
, exact_p1.{log_return,S_T} for ). The expected columns
are the formulas, not measurements.
| exact draws | expected | expected | ||
|---|---|---|---|---|
| : mean | 0.0198 ± 0.0004 | −0.0800 ± 0.0004 | −0.0800 | |
| : variance | 0.1596 ± 0.0002 | 0.1603 ± 0.0002 | 0.1600 | |
| : skewness | −0.005 ± 0.002 | 0 | +0.002 ± 0.002 | 0 |
| : excess kurtosis | +0.001 ± 0.005 | 0 | +0.002 ± 0.005 | 0 |
| mean | 110.47 ± 0.05 | 100.02 ± 0.04 | 100.00 | |
| median | 102.05 ± 0.05 | 92.30 ± 0.05 | 92.31 | |
| paths ending below the mean | 57.9 % | % | 57.9 % | 57.9 % |
The table shows that the log-return behaves exactly as the theory predicts. Across one million paths, its mean is 0.0198 ± 0.0004 (± is one standard error, here and throughout) against the theoretical value 0.0200 and its variance 0.1596 against 0.1600; its skewness is −0.005 ± 0.002, 1.9 standard errors from zero, and its excess kurtosis +0.001 ± 0.005 — both inside the 5-s.e. tolerance the checks use, and the independent run gives +0.002 for the skewness — the opposite sign — and +0.002 for the kurtosis, which is what sampling noise looks like. In other words, the log-return is Gaussian. The price distribution inherited from that Gaussian also lands where it should. For the working case , the mean terminal price is 110.47 ± 0.05 against the theoretical 110.52, while the median is 102.05 against 102.02. For the comparison case , the mean comes back at 100.02, essentially equal to , while the median falls to 92.30. The final row provides perhaps the clearest picture of the shape of the distribution: 57.9 % of all paths finish below the mean.
The most common mistake is to use the exponent that would come from ordinary calculus and omit the volatility-drag term. If that happens, every simulated terminal price is multiplied by . With and , that factor is . In the case, the mean price then becomes 108.3 instead of 100. The error is not random and does not disappear as more paths are added. Every draw is wrong in the same direction, so every price computed from those draws is roughly 8 % too high.
The median deserves its own row because it answers a different question from the mean. The log-return is Gaussian, and the median of a Gaussian is its mean. Since the exponential function preserves ordering, the median price is obtained by exponentiating the mean log-return. The mean price, however, receives additional support from the relatively rare but very large outcomes in the right tail. That is why a single path is more likely than not to finish below the expected price. The proportion of paths below the mean is — is the probability that a standard normal is below its argument — which here is , independent of . The median tells you the point a single path is as likely to finish above as below; the mean tells you where the average of many paths lands. The gap between them is the numerical footprint of volatility drag.
If you step, know what it costs
The second decision appears when the payoff depends on the path rather than just the final price. A barrier option, an average-price option, or the hedging simulator in 2.7 all need prices along the way, so you must step and choose a grid size. For GBM, however, stepping does not mean approximating: the model can be stepped exactly,
That is how 2.7 will generate paths. Euler,
is the method you use when a model has no closed-form solution. GBM is valuable because it lets us measure Euler's error against the truth.
The 1,000 nested paths, each read on all five grids, Euler against the exact
solution on the same increments, from grids[*] of the same file:
gap_rel.rms, gap_log.rms_expected (the formula, not a measurement),
first_paths.{sum_dW_sq,gap_rel}[0], gap_log.{mean,se_of_mean}. The last
column is the gap in ; the rms and path-1 columns are the relative
gap in . The rms gap is Euler vs exact, on 1,000 paths.
| rms gap in | path 1: | path 1: gap in | mean of the gap ± s.e. | ||
|---|---|---|---|---|---|
| 100 | 1.15 % | 1.13 % | 1.438 | −3.42 % | −0.02 % ± 0.04 % |
| 1,000 | 0.361 % | 0.358 % | 1.041 | −0.32 % | −0.01 % ± 0.01 % |
| 10,000 | 0.109 % | 0.113 % | 1.002 | −0.014 % | +0.002 % ± 0.003 % |
| 100,000 | 0.034 % | 0.036 % | 0.9975 | +0.020 % | −0.0002 % ± 0.001 % |
| 1,000,000 | 0.012 % | 0.011 % | 0.9994 | +0.005 % | −0.0003 % ± 0.0004 % |
That error is not small on a single path. Using the same Brownian increments, the rms gap between Euler and the exact is 1.15 % at 100 steps, then 0.36 %, 0.11 %, 0.034 %, and 0.012 % as the grid is refined from to steps. Every 100× increase in the number of steps buys about a 10× reduction in the error, giving a measured slope of −0.501. On path 1 at , the gap is 3.4 %. That path happened to have
well above its limiting value of 1, so the Euler path drifted noticeably below the exact one.
The important result is that this error is a noise, not a bias. Its mean is zero on every grid, with −0.02 % ± 0.04 % at . That leads to the practical rule for simulation work:
Means ignore it; spreads keep it.
A price is an average across paths, so a zero-mean error largely cancels out. A spread, variance, hit-rate, or P&L distribution keeps the extra noise because variances add. Even with no term in any step, 20,000 Euler paths at produce a mean of 110.62 ± 0.32 against 110.52, and a median of 101.99 ± 0.36 against 102.02. The averages come out right because the stepping error averages away (for the mean of it is also exact algebra: at , being the Euler path's terminal price).
The reason is visible from the same -versus- effect that appeared in 2.5. Taylor's formula for log along the Euler path gives
while the exact solution has
Their difference is therefore
The whole leading error is the residual randomness in . On path 1,
against a measured gap of −0.0348. Euler's error is simply the finite-grid version of quadratic variation not yet having settled down to . That is why it behaves like a zero-mean noise, why it shrinks like , and why means largely ignore it while spreads do not.
Test the simulator
The third decision is whether to trust the paths you have generated. GBM gives three properties that are cheap to measure and precise enough to fail when something is wrong: the realised volatility of each path should be , the mean terminal price should be , and the median terminal price should be . Together these tests check both the distribution and the stepping rule. The mean and median catch mistakes involving the term. The realised-volatility test catches mistakes in the simulation itself.
The most common example is writing the noise term as instead of . Nothing crashes. The paths still look like prices. The mean terminal price still passes, because it is driven by the drift term , which is unchanged. Looking only at the mean therefore gives false confidence that everything is working.
The same 1,000 paths on the same grids, from grids[*]. The correct-step
column is realised_vol.demeaned_mean and the column is
realised_vol_bug.demeaned_mean, the per-step sd form the text below
defines; then realised_vol_bug.{demeaned_expected,factor_too_small} and
log_bug.{sd,sd_correct_expected}. The and
columns are formulas, not measurements. The of is across paths.
| realised vol, correct step | realised vol, step | factor too small | of , step | correct: | ||
|---|---|---|---|---|---|---|
| 100 | 0.3998 | 0.0399 | 0.0400 | 10 | 0.0385 | 0.400 |
| 1,000 | 0.4002 | 0.0127 | 0.0126 | 31.6 | 0.0122 | 0.400 |
| 10,000 | 0.3999 | 0.0040 | 0.0040 | 100 | 0.00385 | 0.400 |
| 100,000 | 0.4000 | 0.00126 | 0.00126 | 316 | 0.00122 | 0.400 |
| 1,000,000 | 0.4000 | 0.00040 | 0.00040 | 1,000 | 0.000385 | 0.400 |
The realised volatility immediately exposes the problem. Measured as
it should return whatever grid is used. The correct simulation gives 0.3998 at , 0.3999 at , and 0.4000 at . The buggy simulation instead gives 0.0399, 0.0040, and 0.00040. The volatility is too small by a factor of , and the error becomes worse as the grid is refined. The spread of terminal outcomes collapses with it: at , the standard deviation of is only 0.00385 instead of 0.40.
The reason is the same scaling introduced in 2.1. The volatility is independent of the grid because kicks of size contribute a total variance of
independent of the grid. Replacing by changes that to
which tends to zero as the grid is refined. The simulation becomes less random precisely when it should not.
There is a second visual tell. In a correct step, the random kick is much larger than the drift increment . At , they are roughly and respectively. With the bug, both become -sized. The drift is now about a quarter of each random kick, so the path climbs steadily with very little jitter. It looks smoother, not noisier. That apparent smoothness is the warning sign that the has been lost.
Solving the SDE: from a one-step rule to a formula for
The price model is , so its drift is and its volatility , both proportional to the price.
The mathematics behind this page begins with the last line of 2.5. Applying the general result to , with drift and volatility , gave
The comes from the curvature term : contributes , contributes , and the cancels.
The crucial thing to notice is what has disappeared. The original price equation contains on the right-hand side, so the next step depends on where the price is now. The equation for does not. Its drift is constant and its volatility is constant. That is the whole reason for taking the logarithm: it turns a state-dependent equation into one that can be added up directly.
Once that happens, the next step is simple. Add the equation over the intervals of a grid. The left-hand side telescopes:
The right-hand side adds just as easily. The drift terms produce , while the Brownian increments add to :
No limit is needed. Once has vanished from the right-hand side, the sum is exact.
The final step is to exponentiate:
This is the solution of GBM. No path was stepped and no approximation was made. The stochastic differential equation has been turned into a formula for the terminal price.
Using the result from 2.2,
where is a standard normal random variable, the solution becomes
One normal draw therefore produces one exact sample of .
This is what it means to solve an SDE: not to simulate it step by step, but to write the random variable of interest directly as a formula involving the underlying Brownian motion. Most SDEs cannot be solved in this way. GBM is special because taking logs removes the dependence on , leaving constant coefficients that can be summed exactly. That solvability is the reason closed-form results exist later in the course, including the formulas used in 2.9.
Why the mean and the median differ
The mean and the median differ because exponentials do not preserve averages. Starting from the solution,
the mean is
From 2.5, . Replacing by gives
which cancels the exactly. The result is
The volatility drag does not lower the mean price. It appears in the log-return and is exactly offset when the exponential is averaged.
The median is different. The log-return is Gaussian with mean , and the median of a Gaussian is its mean. Since the exponential function preserves order, the median price is
The mean sits above it because a small number of very large outcomes pull the average to the right. This is 2.5's observation that the mean of an exponential is not the exponential of the mean, now attached to a price distribution. The same asymmetry explains why more than half the paths finish below the mean:
For and , this threshold is 0.2, so the fraction below the mean is . The expected price and the point a single path is as likely to finish above as below are therefore different numbers, separated by the volatility drag.
Into 2.7
Into 2.7, the focus shifts from the price itself to an option value and to a portfolio that holds the option together with a position in the underlying. The general form from 2.5 is applied for the first time to a function of both time and price, using this page's drift and volatility, and , giving
The key idea is to choose a hedge ratio , which cancels the term and removes the randomness from the portfolio. What remains is locally risk-free and therefore must earn the risk-free rate rather than the stock's drift. In the process, disappears entirely. The result is the Black–Scholes partial differential equation, which 2.7 derives; this page only supplies the GBM model and the calculus needed to get there.
Check
dS = μS dt + σS dW with μ = 0, σ = 0.4, T = 1. Which is true of S_T?
You simulate S_T = S₀e^(μT + σ√T·Z) — the chain rule’s exponent, no −½σ² — and price a European option from 10⁶ draws. The price is:
Euler steps and the exact solution are built from the same normals. At n = 100 steps, and then at n = 10,000, how far apart are the two S_T?
Same Euler simulator, n = 100, 10⁵ paths. You read off (a) the mean of S_T — a price — and (b) the spread of S_T across paths. The 1 % per-path stepping error shows up:
A simulator writes the step as S_{i+1} = S_i(1 + μ dt + σZ·dt). At n = 10⁴, which test fails, and how?