Stochastic differential equations
Study stochastic differential equations, existence and uniqueness, strong and weak solutions, linear equations and canonical Ornstein-Uhlenbeck, CIR and Langevin models.
After this lesson you can
- Prove existence and uniqueness under Lipschitz conditions using Picard iteration.
- Solve scalar and vector linear SDEs and obtain mean and covariance.
- Calculate Ornstein-Uhlenbeck transition and stationary laws and connect sampled OU to AR(1).
- Analyze CIR, its Feller condition and transition law, and simulate it without violating positivity.
- Explain why Langevin dynamics samples from e^{-U} and the role of temperature.
Before you start
Dynamics with perturbations
A particle may feel a force and thermal shocks; an interest rate may revert while receiving perturbations. A stochastic differential equation combines both effects:
The second equality is the definition in the Itô convention. Drift describes first-order conditional displacement and diffusion its local quadratic variation; it does not replace a full conditional distribution with a single path. Explore the dynamics and move the date: exact transitions and numerical approximations are identified in the figure.
Existence, uniqueness and explosion
A sufficient condition for global existence and uniqueness on a finite horizon is that and are measurable in time, globally Lipschitz in state and satisfy a uniform linear-growth bound. With and -measurable, and Brownian relative to that filtration, a continuous strong solution exists and is pathwise unique. These conditions are sufficient, not necessary.
Picard’s argument starts with and defines by substituting in both integrals. For , Cauchy-Schwarz controls the drift integral; Itô isometry and Doob’s maximal inequality control the stochastic integral. The Lipschitz assumption gives, with constant depending on the horizon and bounds,
Differences form a convergent series in the supremum norm ; the limit satisfies the equation by continuity of the integrals. For two solutions with the same noise, the same estimate and Gronwall force their difference to zero. Without global control there can be explosion: the deterministic equation , , has only until time 1.
A strong solution is constructed adapted to the given noise and initial data; in a weak solution the probability space and driving Brownian motion are also chosen. The Tanaka equation , , admits a weak solution but no strong solution relative to the natural filtration of the noise; the sign function is not Lipschitz at zero. See the ETH notes. Uniqueness in law and pathwise uniqueness are distinct statements.
Linear equations and Ornstein-Uhlenbeck
For the vector linear SDE with deterministic coefficients
let , . Then
If is independent of the noise and has covariance , the covariance is . With Gaussian or deterministic the process is Gaussian. Not every linear SDE with multiplicative diffusion has a Gaussian law: geometric Brownian motion is a counterexample.
The Ornstein-Uhlenbeck process, with and , satisfies . Multiplying by gives
The stationary law is and the half-life of an expected deviation is . On an equally spaced grid it is exactly an AR(1) with . A finite fit can give : then it does not represent a stable OU through . High frequency without a long horizon does not automatically eliminate bias in estimating reversion.
CIR and the zero boundary
The Cox-Ingersoll-Ross process satisfies , with positive parameters and . The square root is not Lipschitz at zero, but the model has its own existence and uniqueness theory. Define . If , zero is inaccessible from a positive state; if , it can be reached and the standard solution immediately leaves the boundary without becoming negative.
For the transition is exact:
The stationary law is Gamma with shape and scale . An exact sample at nodes does not reveal every possible contact with zero between dates. Careless Euler simulation can produce negative values; projecting them to zero changes the law and must be declared. The original paper by Cox, Ingersoll and Ross presents the rate model.
Langevin and temperature
One-dimensional overdamped Langevin dynamics is , with . If is integrable and appropriate boundary conditions hold, is invariant: in the Fokker-Planck equation current vanishes. With additional ergodicity assumptions, the law converges to that distribution. Temperature changes both noise and concentration in the wells.
For , minima lie at and and the barrier at zero has height . Kramers’ law describes exponential growth of transition time in the low-temperature asymptotic regime; the prefactor and assumptions are detailed in Berglund and Gentz. At finite temperature this is an approximation, not an exact equality. If a simulation ends before reaching the other well, its time is censored.
Lab: exact vector OU and estimation
For constant Hurwitz , all eigenvalues have negative real parts. Stationary covariance solves . If , the exact one-step innovation covariance is . Do not confuse this finite covariance with .
import numpy as np
from scipy.linalg import expm, solve_continuous_lyapunov
rng=np.random.default_rng(2626)
A=np.array([[-.8,.3],[-.4,-.6]])
G=np.array([[.5,0.],[.2,.35]])
[email protected]
P=solve_continuous_lyapunov(A,-Q)
T=2.; Phi=expm(A*T)
P_T=P-Phi@[email protected]
x0=np.array([1.,-1.]); media=Phi@x0
print("autovalores de A y residuo Lyapunov:",np.linalg.eigvals(A),np.max(abs(A@[email protected]+Q)))
print("media y covarianza exactas al horizonte:",media,P_T)
print("covarianza estacionaria:",P)
replicas=5000; pasos=200; dt=T/pasos
euler=np.broadcast_to(x0,(replicas,2)).copy()
for _ in range(pasos):
ruido=rng.normal(size=(replicas,2))
euler += ([email protected])*dt + np.sqrt(dt)*([email protected])
print("media y covarianza Euler en malla fina:",
euler.mean(axis=0),np.cov(euler,rowvar=False))
exactas=rng.multivariate_normal(media,P_T,size=replicas)
print("media y covarianza de transiciones exactas:",
exactas.mean(axis=0),np.cov(exactas,rowvar=False))Euler discretization is an approximation and the comparison includes Monte Carlo error. Equal moments alone do not prove equal laws. In the linear model with deterministic coefficients and fixed initial data, the exact solution is Gaussian.
An equally spaced OU transition is Gaussian regression with intercept. Its unrestricted maximum provides , intercept and innovation variance. Transformation to stable OU parameters is valid only if ; we do not clip invalid estimates to make them appear admissible.
def ou_mle(x,dt):
x=np.asarray(x,dtype=float)
if x.ndim!=1 or len(x)<4 or not np.all(np.isfinite(x)) or not np.isfinite(dt) or dt<=0:
raise ValueError("serie finita y paso positivo")
u=x[:-1]; v=x[1:]
centro=u-u.mean()
denom=np.dot(centro,centro)
if denom<=0:
raise ValueError("regresores constantes")
phi=np.dot(centro,v-v.mean())/denom
if not 0<phi<1:
raise ValueError("el máximo AR no restringido no es un OU estable interior")
intercepto=v.mean()-phi*u.mean()
residual=v-intercepto-phi*u
q=np.mean(residual**2)
if q<=0 or not np.isfinite(q):
raise ValueError("no hay máximo interior con varianza residual nula")
theta=-np.log(phi)/dt
mu=intercepto/(1-phi)
sigma=np.sqrt(2*theta*q/(-np.expm1(-2*theta*dt)))
return theta,mu,sigma
def simular_ou(m,pasos,dt,theta,mu,sigma,rng):
phi=np.exp(-theta*dt)
sd=sigma*np.sqrt(-np.expm1(-2*theta*dt)/(2*theta))
caminos=np.empty((m,pasos+1)); caminos[:,0]=mu
for i in range(pasos):
caminos[:,i+1]=mu+phi*(caminos[:,i]-mu)+sd*rng.normal(size=m)
return caminos
for horizonte in (5,60):
caminos=simular_ou(400,int(horizonte/.1),.1,.7,1.,.8,rng)
estimaciones=[]; invalidos=0
for camino in caminos:
try:
estimaciones.append(ou_mle(camino,.1))
except ValueError:
invalidos+=1
print("horizonte, válidos, no interiores y media de theta, mu, sigma:",
horizonte,len(estimaciones),invalidos,np.mean(estimaciones,axis=0))The printed means are conditional on the unrestricted AR maximum being interior. Short samples may yield estimates outside ; ignoring them also changes the summary. Constrained likelihood optimization with boundaries requires treating those cases, not silently replacing them with an interior value.
CIR transition without negative values
NumPy provides a sample from the noncentral chi-square law. We compare its first moment with the theoretical solution; positivity at discrete dates does not report every contact of the path with the boundary.
kappa,theta,sigma,x0,delta=1.2,.05,.4,.05,1.
c=sigma**2*(-np.expm1(-kappa*delta))/(4*kappa)
nu=4*kappa*theta/sigma**2
lam=np.exp(-kappa*delta)*x0/c
salida=c*rng.noncentral_chisquare(nu,lam,size=100000)
media=x0*np.exp(-kappa*delta)+theta*(-np.expm1(-kappa*delta))
print("CIR mínimo, media, error estándar y media teórica:",
salida.min(),salida.mean(),salida.std(ddof=1)/np.sqrt(len(salida)),media)
print("parámetros de la ley no central:",c,nu,lam)Exercises
Step 1 of 3. What is the differential of e^{θt}(Xₜ−μ)?
Step 1 of 3. Which tools control differences of the two integrals?
import numpy as np
def ou_mle(x,dt):
passAn SDE is an integral equation with explicit information and regularity. Exact solutions distinguish model properties, estimation uncertainty and discretization errors.
Check the numerical exercises after attempting them.
print("vida media, desviación OU y razón CIR:",
np.log(2)/2, .5/np.sqrt(2*2), 2*1.5*.04/.3**2)