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.
Why Does This Exist?
Ordinary differential equations 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 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
is Brownian motion: continuous jitter with independent increments and variance . The SDE says the change over a small is drift times plus volatility times the Brownian increment, which scales as . When the drift is Lipschitz, , 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 with initial value has a unique strong solution when and are Lipschitz and grow at most linearly. Here is the drift (where the process heads), is the diffusion or volatility (how hard the noise shakes it), and is Brownian motion.
The Ornstein-Uhlenbeck prototype pulls toward the level at speed . Its mean satisfies , an ordinary equation, while its variance settles at . Mean from drift, spread from the tug of war between drift and noise.
Euler-Maruyama discretises with for standard normal and step . Halving halves the weak error in means and moments. Pathwise error shrinks only as , so single paths converge more slowly than averages do.
Worked example
Take , , , starting from . The mean path solves to . At , , so the mean is . The stationary variance is , so the stationary standard deviation is . After 2 time units the paths sit in with chance about 0.95, since is two standard deviations. The diagram shows that band: drift did the centring, set the scale, set the 2-unit settling time.
One Euler-Maruyama step by hand, with and a fixed draw : drift contributes , diffusion contributes , so . 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 = 2The 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 .
Watch Out For
Simulating with too large a step on stiff drift
With and , Euler-Maruyama multiplies deviations by per step and explodes in growing oscillations, while the true process is perfectly stable. Stability needs well below 1, or the discrete map overshoots the pull on every step.
Fix: keep below for explicit Euler, or switch to an implicit scheme for stiff drifts. Check one stationary variance before any long run: if it disagrees with , your step is the problem, not the model.
Reading pathwise convergence from weak convergence
Halving halves weak error in means and moments, but strong pathwise error shrinks only as . 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 .
- 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.