Quant Trader Lab / OU Converge

Mean Reversion

The Ornstein-Uhlenbeck process models a spread that gets pulled back toward a long-run mean. In stat-arb language: if two cointegrated assets drift apart, the spread can be traded as a spring, not as a random walk.

Live convergence simulationBaseline spread
Theta3.50
Mu0.50
Sigma0.55
Half-life0.20y
Core mathematics

The SDE

dXt = θ(μ - Xt)dt + σdWt

What it describes

A process that feels a pull back toward its long-run mean. Brownian motion wanders; OU has a gravitational center. The farther the spread moves away from home, the stronger the pull becomes.

Trading use

  • Estimate theta from the autocovariance or AR(1) structure of the spread.
  • Enter when the spread deviates around two sigma from the mean.
  • Exit at the mean, or stop when the deviation regime breaks.
Python function

From code to convergence.

import numpy as np

theta, mu, sigma = 3.5, 0.5, 0.55
dt, T = 1 / 252, 1.0
n = int(T / dt)

rng = np.random.default_rng(0)
X = np.zeros(n + 1)
X[0] = 2.0

for i in range(n):
    dW = rng.standard_normal() * np.sqrt(dt)
    X[i + 1] = X[i] + theta * (mu - X[i]) * dt + sigma * dW

half_life = np.log(2) / theta

What the buttons change

The live chart above is the same logic in browser form. The theta button increases mean-reversion speed, the stress button increases volatility and starting dispersion, and baseline keeps the classic stat-arb spread setup.

Reference screenshots

Explaining the model visually.

Origin of Ornstein Uhlenbeck model
The origin / 1930
OU intuition explanation
The intuition
OU SDE mathematics
The SDE
Stat arb use of OU
The trade
Python simulate OU code
Python simulation
All paths converge chart
All paths converge
Quantitative finance / simulation

Brownian motion with a spring.

Back to projects