E01 · Advanced Probability and Stochastic Calculus · Lesson 3 of 4
Stochastic Differential Equations
What an Itô integral is and why it is a martingale, the Itô isometry, explicit solutions and moments of geometric Brownian motion and Ornstein–Uhlenbeck, and simulating SDEs with Euler–Maruyama, including strong versus weak convergence.
20 min
What an SDE means
An SDE such as
dXt=a(t,Xt)dt+b(t,Xt)dWt,X0=x0,
is shorthand for the integral equation
Xt=x0+∫0ta(s,Xs)ds+∫0tb(s,Xs)dWs.
The first integral is ordinary. The second is an Itô integral, and Brownian paths are too rough for it to be a Riemann–Stieltjes integral. The objective of this lesson: know what the Itô integral is, compute its moments, solve the two SDEs interviewers ask about (GBM and OU) in closed form, and simulate any SDE when no closed form exists. Itô's lemma is assumed.
The Itô integral
For a process Ht that is adapted (its value at t uses only information up to t), define
∫0THtdWt=n→∞limi∑Hti(Wti+1−Wti),
the limit taken in mean square as the grid is refined. The integrand is evaluated at the left endpoint. This is the modelling choice that makes the integral a fair game: you choose your position Hti before seeing the next increment.
Example. Take H=W. Using WtiΔWi=21(Wti+12−Wti2)−21(ΔWi)2 and summing,
i∑WtiΔWi=21WT2−21i∑(ΔWi)2⟶21WT2−21T.
So ∫0TWtdWt=21(WT2−T), not the 21WT2 of ordinary calculus. Evaluating at the midpoint instead (the Stratonovich integral) gives 21WT2, but loses the martingale property.
Three properties you use constantly
For adapted H with E∫0THt2dt<∞:
Zero mean:E[∫0THtdWt]=0. Each term HtiΔWi has mean zero because ΔWi is independent of Hti.
Martingale:Mt=∫0tHsdWs is a martingale.
Itô isometry:
E(∫0THtdWt)2=E∫0THt2dt.
The isometry holds because cross terms E[HtiΔWiHtjΔWj] with i<j vanish (condition on time tj), and diagonal terms give E[Hti2]Δti. A useful special case: if Ht=h(t) is deterministic, the integral is Gaussian, ∫0Th(t)dWt∼N(0,∫0Th(t)2dt).
Check on the example: Var(21(WT2−T))=41Var(WT2)=41⋅2T2=21T2, and the isometry gives ∫0TE[Wt2]dt=∫0Ttdt=21T2.
Worked example
the integral of Brownian motion
Find the distribution of I=∫0TWtdt and its correlation with WT. (A classic interview question; it is also why a geometric-average Asian option has a closed form, since log prices are linear in W.)
Show solutionHide solution
Rewrite as an Itô integral. Itô's product rule on tWt (no cross-variation term, since t has none) gives d(tWt)=Wtdt+tdWt. Integrating from 0 to T,
I=∫0TWtdt=TWT−∫0TtdWt=∫0T(T−t)dWt.
Distribution. The integrand T−t is deterministic, so I is Gaussian with mean 0 and, by the isometry,
Var(I)=∫0T(T−t)2dt=3T3.
Correlation with WT. Write WT=∫0T1dWt. The polarised isometry, E[∫fdW∫gdW]=∫fgdt, gives
Sanity check by direct computation: Var(I)=∫0T∫0Tmin(s,t)dsdt=T3/3, and Cov(I,WT)=∫0Tmin(t,T)dt=T2/2. The isometry route is faster and generalises to any deterministic integrand.
When does an SDE have a solution?
If a and b are Lipschitz in x and grow at most linearly, the SDE has a unique strong solution (a process built from the given Brownian path). Both examples below satisfy this. Square-root diffusions such as CIR, b(x)=σx, are not Lipschitz at 0 and need a separate argument, which is one reason they are harder to simulate.
Geometric Brownian motion: moments
The Itô's lemma lesson solved dSt=μStdt+σStdWt as ST=S0exp((μ−21σ2)T+σWT). Moments follow from E[ecWT]=ec2T/2:
For example, S0=100, μ=8%, σ=20%, T=1: mean 108.33, standard deviation 21.88, median 106.18, and P(ST<100)=Φ(−0.06/0.2)=Φ(−0.3)≈0.382. You can also get the mean without solving: taking expectations of the SDE kills the dW term, so m(t)=E[St] solves m′=μm.
Ornstein–Uhlenbeck: the explicit solution
dXt=θ(μ−Xt)dt+σdWt,θ>0.
This is linear with additive noise, so use an integrating factor as for a linear ODE. By the product rule,
d(eθtXt)=eθt(θXtdt+dXt)=eθt(θμdt+σdWt).
Integrate from 0 to t and divide by eθt:
Xt=μ+(x0−μ)e−θt+σ∫0te−θ(t−s)dWs.
The stochastic integral has a deterministic integrand, so Xt is Gaussian with
The same calculation for two times s≤t gives Cov(Xs,Xt)=2θσ2(e−θ(t−s)−e−θ(t+s)), which tends to 2θσ2e−θ(t−s) in the stationary regime. The QR stochastic processes lesson used these formulas; this is where they come from.
Worked example
a Vasicek short rate
The short rate follows drt=0.5(0.03−rt)dt+0.02dWt (time in years) and is 8% today. Find the mean and standard deviation of r2, the probability that r2<0, and the long-run standard deviation.
Show solutionHide solution
This is OU with θ=0.5, μ=0.03, σ=0.02, x0=0.08, t=2, so θt=1.
Mean.0.03+0.05e−1=0.03+0.05×0.3679=0.04839, about 4.84%.
Variance.2×0.50.022(1−e−2)=0.0004×0.8647=0.000346, so the standard deviation is 0.01860, about 1.86%.
Negative rates.r2 is Gaussian, so P(r2<0)=Φ(−0.04839/0.01860)=Φ(−2.60)≈0.0046.
Long run.σ/2θ=0.02, so 2%. After two years the variance is already 86% of its stationary value, because 1−e−2θt approaches 1 at twice the rate the mean decays.
The non-zero probability of negative rates is the standard criticism of Vasicek, and the reason CIR uses σr noise.
Euler–Maruyama simulation
Most SDEs have no closed form. The Euler–Maruyama scheme freezes the coefficients over each step of length Δt:
Two errors are mixed here. The Monte Carlo error on the mean is about 0.0187/20000≈0.00013. The discretisation bias comes from the scheme itself: with Δt=0.04 the Euler mean is 0.03+0.05(1−0.5×0.04)50=0.04821 instead of 0.04839. For OU you can avoid the bias entirely by sampling the exact Gaussian transition, Xn+1=μ+(Xn−μ)e−θΔt+σ(1−e−2θΔt)/(2θ)Zn; for GBM, simulate lnS exactly instead. Euler is for the models where no such trick exists.
Strong versus weak convergence
There are two ways to ask whether the scheme is accurate as Δt→0:
Measures
Euler–Maruyama order
Matters for
Strong
E∣XTΔt−XT∣, path by path, same Brownian path
21 in general; 1 when b does not depend on x (additive noise, e.g. OU)
Hedging simulations, path-dependent payoffs, multilevel Monte Carlo
Weak
∣E[f(XTΔt)]−E[f(XT)]∣, distributions only
1
Pricing European payoffs
Halving Δt shrinks the strong error by about 2 and the weak error by about 2. The Milstein scheme adds the term 21b∂xb((ΔW)2−Δt), which comes from the next term in the Itô–Taylor expansion, and raises the strong order to 1.
The strong order is easy to see for GBM, where the exact solution on the same path is known:
import math
import random
S0, mu, sigma, T = 100.0, 0.08, 0.2, 1.0
rng = random.Random(1)
n_paths, fine = 4000, 256
# Brownian increments on the finest grid; coarser grids sum them, so every
# step size sees the same underlying paths.
paths = [[rng.gauss(0.0, math.sqrt(T / fine)) for _ in range(fine)] for _ in range(n_paths)]
for n in (16, 32, 64, 128, 256):
k, dt = fine // n, T / n
err = 0.0
for dws in paths:
s = S0
for j in range(n):
s += mu * s * dt + sigma * s * sum(dws[j * k : (j + 1) * k])
exact = S0 * math.exp((mu - sigma**2 / 2) * T + sigma * sum(dws))
err += abs(s - exact)
print(f"n={n:4d} strong error {err / n_paths:.4f}")
Each halving divides the error by about 1.40≈2: strong order 21. The weak error for f(x)=x can be done by hand: each Euler step multiplies the mean by 1+μΔt, so E[STΔt]=S0(1+μT/n)n. For n=10,20,40 that is 108.2942, 108.3114, 108.3201 against the exact 108.3287: errors 0.0345, 0.0173, 0.0087, halving each time.
Knowledge check
What is Var(∫02WtdWt)?
Knowledge check
An OU process has dXt=2(μ−Xt)dt+0.4dWt. What is its stationary standard deviation?
Knowledge check
You price a European option by Monte Carlo, simulating the underlying SDE with Euler–Maruyama. What happens to the discretisation bias in the price when you halve the time step?
In interviews
"Compute Var∫0TWtdt": rewrite as ∫0T(T−t)dWt and apply the isometry. Say the integration by parts out loud; that is the step being tested.
"Solve the OU SDE": state the integrating factor eθt, write the solution, then read off mean and variance. Finish with the limits t→∞ (stationary law) and the half-life ln2/θ.
"Is ∫0tWs2dWs a martingale?" Yes: it is an Itô integral with a square-integrable adapted integrand. By contrast ∫0tWs2ds is not.
"How would you simulate this?" Give Euler–Maruyama, then say whether an exact scheme exists (GBM in logs, OU Gaussian transitions), and distinguish bias (step size) from noise (path count).
Key takeaways
An Itô integral is a limit of left-endpoint sums; it has mean zero, is a martingale, and satisfies E[(∫HdW)2]=E∫H2dt.
With a deterministic integrand the Itô integral is Gaussian with variance ∫h2dt; this solves most "distribution of" questions.
∫0TWdW=21(WT2−T); the −21T is quadratic variation.
GBM: E[ST]=S0eμT, Var(ST)=S02e2μT(eσ2T−1). OU: solve with eθt; Gaussian with mean μ+(x0−μ)e−θt and variance 2θσ2(1−e−2θt).
Euler–Maruyama is strong order 21 and weak order 1; use exact transitions when they exist.