Simulating Ornstein–Uhlenbeck Paths with Euler–Maruyama
Summary
The document asks how to simulate paths of two mean-reverting processes from their stochastic integral forms and conditional distributions. Its answer recommends discrete-time SDE approximation and gives the Euler–Maruyama update: each new value combines the previous value’s mean-reverting drift with a normally distributed random increment scaled by the time step and volatility. It also names Milstein and Runge–Kutta methods as alternatives.
The example is a basic recipe for one path of the first process, using independent standard normal draws at each step. It does not provide a MATLAB implementation or explain how to generate multiple paths, and it does not compare approximation accuracy or computational cost. Although the question emphasizes the known Gaussian transition distributions, the answer does not use them to give an exact discretization; Euler–Maruyama introduces time-step approximation error. The same approach can be applied to the second process by using its own parameters and Brownian increments.
Key ideas
- Euler–Maruyama advances a diffusion by combining its drift over a time step with a scaled normal shock.
- Independent standard normal draws provide the random increments used to simulate a path.
- The stated update is an approximation whose accuracy depends on the chosen time step.
- The same simulation pattern applies to both mean-reverting processes with their respective parameters.
Tags
Full text
# Modelling interest rate
# Modelling interest rate
Hi I want to model two stochastic integrals in Matlab, which is given by $ x(t) = x(s) e^{-a(t-s)} + \sigma \int_s^t e^{-a(t-u)} dW_1(u)$
$y(t) = y(s) e^{-b(t-s)} + \eta \int_s^t e^{-b(t-u)} dW_2(u)$
with
$E[x(t) \vert F_s] = x(s) e^{-a(t-s)}$
$Var[x(t) \vert F_s] = \frac{\sigma^2}{2a} [1-e^{-2a(t-s)}]$
The dynamics are given by :
$dx(t) = -a x(t) dt + \sigma dW_1(t), x(0) = 0 \\ dy(t) = -by(t) dt + \eta dW_2(t), y(0) = 0 $ $\\$
I want to implement this in Matlab without using the dynamics but the stochastic integral and the distribution property. I want to model paths for x(t) and y(t)
We have
$x(1) \sim N\left(x(0)e^{-at}, \frac{\sigma^2}{2a} [1-e^{-2at} \right)$
$x(2) \sim N\left(x(0)e^{-a(t-1)}, \frac{\sigma^2}{2a} [1-e^{-2a(t-1)} \right)$ .......
Knowing the distribution for each $t$, how can I model $x(t)$ for each $t$
## Answer by Phil-ZXX (score 1)
https://quant.stackexchange.com/a/39231
Generally, you can approximate any SDE through simulation in discrete time. Standard schemes for this are the Euler–Maruyama, Milstein or Runge–Kutta method:
- https://en.wikipedia.org/wiki/Euler%E2%80%93Maruyama_method
- https://en.wikipedia.org/wiki/Milstein_method
- https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_method_(SDE)
Using Euler–Maruyama, the below pseudo-code demonstrates how you could simulate one path of $x(t)$ over an interval $[0,T]$:
```
T = 2 # Total length of time
dt = 0.01 # discrete time step lengths
n = T / dt # number of time steps
x0 = 0 # Start value of x(t)
x = [x0]
Z = [Array of i.i.d. Standard Normal Samples of length n]
for i = 1 to n
x[i] = x[i-1] - a * x[i-1] * dt + sigma * sqrt(dt) * Z[i]
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.