Skip to content
AI360XpertBeta

Stochastic Differential Equations Guide

Equations that mix deterministic drift with Brownian noise. Their solutions are random paths whose means follow the drift and whose spreads follow the volatility.

Mean-reverting paths with speed 2.0 and noise 0.5 pull from 0 toward level 5.0 and settle by time 2 into a band of width 0.5 set by the stationary spread 0.25
Mean-reverting paths with speed 2.0 and noise 0.5 pull from 0 toward level 5.0 and settle by time 2 into a band of width 0.5 set by the stationary spread 0.25

Why Does This Exist?

Ordinary differential equations dx/dt=μ(x)dx/dt = \mu(x) describe exact motion, but markets wobble, sensors err, and samplers inject noise on purpose. Adding a fixed noise trace onto an ODE solution understates the feedback: noise that enters early propagates through later drift. The solution has to be a random process defined jointly with its noise, not a deterministic curve plus frosting.

Stochastic differential equations dX=μ dt+σ dWdX = \mu\,dt + \sigma\,dW do that. They define Langevin samplers, Ornstein-Uhlenbeck models, and the forward noising of diffusion generative models. Their long-run behaviour is studied in diffusion processes, and reverse-time SDEs run them backwards for generation.

The one idea you need first

WtW_t is Brownian motion: continuous jitter with independent increments and variance tt. The SDE dXt=μ(Xt) dt+σ(Xt) dWtdX_t = \mu(X_t)\,dt + \sigma(X_t)\,dW_t says the change over a small dtdt is drift times dtdt plus volatility times the Brownian increment, which scales as dt\sqrt{dt}. When the drift μ\mu is Lipschitz, ∣μ(x)−μ(y)∣≤L∣x−y∣|\mu(x) - \mu(y)| \le L|x - y|, paths cannot explode and a unique solution exists.

Think of It Like This

A thermostat in a draughty room

A thermostat pulls the temperature toward 5 degrees with a strength proportional to the gap (drift), while draughts gust randomly (diffusion). The room never sits still: it wanders in a band around the setting, wider when the draughts strengthen, narrower when the thermostat stiffens.

SDE solutions live in that band. Drift centres, noise spreads, and the stationary width balances the two. Crank the thermostat (mean reversion) and the band tightens; open the windows (volatility) and it widens.

Where it stops: rooms have bounded air while SDE paths are unbounded with Gaussian tails. Thermostats also switch discretely; SDE drift acts continuously.

How It Actually Works

An SDE dXt=μ(Xt) dt+σ(Xt) dWtdX_t = \mu(X_t)\,dt + \sigma(X_t)\,dW_t with initial value X0X_0 has a unique strong solution when μ\mu and σ\sigma are Lipschitz and grow at most linearly. Here μ\mu is the drift (where the process heads), σ\sigma is the diffusion or volatility (how hard the noise shakes it), and WtW_t is Brownian motion.

The Ornstein-Uhlenbeck prototype dX=θ(m−X) dt+σ dWdX = \theta(m - X)\,dt + \sigma\,dW pulls toward the level mm at speed θ\theta. Its mean satisfies dE[X]/dt=θ(m−E[X])dE[X]/dt = \theta(m - E[X]), an ordinary equation, while its variance settles at σ2/2θ\sigma^2/2\theta. Mean from drift, spread from the tug of war between drift and noise.

Euler-Maruyama discretises with Xk+1=Xk+μ(Xk)Δ+σ(Xk)Δ ZkX_{k+1} = X_k + \mu(X_k)\Delta + \sigma(X_k)\sqrt{\Delta}\,Z_k for standard normal ZkZ_k and step Δ\Delta. Halving Δ\Delta halves the weak error in means and moments. Pathwise error shrinks only as Δ\sqrt{\Delta}, so single paths converge more slowly than averages do.

Worked example

Take θ=2.0\theta = 2.0, m=5.0m = 5.0, σ=0.5\sigma = 0.5, starting from X0=0X_0 = 0. The mean path solves to E[Xt]=5(1−e−2t)E[X_t] = 5(1 - e^{-2t}). At t=2t = 2, e−4≈0.0183e^{-4} \approx 0.0183, so the mean is 5×0.9817=4.915 \times 0.9817 = 4.91. The stationary variance is σ2/2θ=0.25/4=0.0625\sigma^2/2\theta = 0.25/4 = 0.0625, so the stationary standard deviation is 0.250.25. After 2 time units the paths sit in 5.0±0.55.0 \pm 0.5 with chance about 0.95, since ±0.5\pm 0.5 is two standard deviations. The diagram shows that band: drift did the centring, σ\sigma set the 0.250.25 scale, θ\theta set the 2-unit settling time.

One Euler-Maruyama step by hand, with Δ=0.01\Delta = 0.01 and a fixed draw Z=0.6Z = 0.6: drift contributes 2.0×(5.0−0)×0.01=0.102.0 \times (5.0 - 0) \times 0.01 = 0.10, diffusion contributes 0.5×0.01×0.6=0.030.5 \times \sqrt{0.01} \times 0.6 = 0.03, so X1=0+0.10+0.03=0.13X_1 = 0 + 0.10 + 0.03 = 0.13. Small steps keep the discrete path glued to the true one; the Code section repeats this loop.

Code

One Euler-Maruyama step of the worked Ornstein-Uhlenbeck process, written plainly so each term matches the hand calculation. Standard library only.

import math

def ou_step(x: float, theta: float, m: float, sigma: float, dt: float, z: float) -> float:    """Advance one Euler-Maruyama step with a fixed normal draw z."""    return x + theta * (m - x) * dt + sigma * math.sqrt(dt) * z

print(round(ou_step(0.0, 2.0, 5.0, 0.5, 0.01, 0.6), 4))  # -> 0.13print(round(0.5 ** 2 / (2 * 2.0), 4))  # -> 0.0625 stationary varianceprint(round(5 * (1 - math.exp(-4)), 4))  # -> 4.9084 mean at t = 2

The three prints are the three numbers in the worked example: the first step 0.13, the stationary variance 0.0625, and the mean 4.9084 at t=2t = 2.

Watch Out For

Simulating with too large a step on stiff drift

With θ=20\theta = 20 and Δ=0.2\Delta = 0.2, Euler-Maruyama multiplies deviations by 1−θΔ=−31 - \theta\Delta = -3 per step and explodes in growing oscillations, while the true process is perfectly stable. Stability needs θΔ\theta\Delta well below 1, or the discrete map overshoots the pull on every step.

Fix: keep Δ\Delta below 0.1/θ0.1/\theta for explicit Euler, or switch to an implicit scheme for stiff drifts. Check one stationary variance before any long run: if it disagrees with σ2/2θ\sigma^2/2\theta, your step is the problem, not the model.

Reading pathwise convergence from weak convergence

Halving Δ\Delta halves weak error in means and moments, but strong pathwise error shrinks only as Δ\sqrt{\Delta}. Judging a sampler by single paths looks slow while its moments already converged, and tightening the step to fix the paths wastes compute on statistics that were already right.

Fix: match the error type to the use. Densities and means need weak convergence; pathwise couplings need strong convergence with finer steps.

The Quick Version

  • SDEs define random paths jointly with their driving noise, not ODE curves plus frosting.
  • Lipschitz drift plus linear growth guarantee a unique solution; Euler-Maruyama steps need small Δ\Delta.
  • Ornstein-Uhlenbeck with speed 2.0 and noise 0.5 centres at 5.0 with stationary standard deviation 0.25.
  • After 2 units the mean sits at 4.91 inside a 0.5 band with chance 0.95.
  • Stiff drifts need tiny or implicit steps, and weak versus strong errors scale differently.