A (standard) Wiener process is a continuous-time stochastic process with initial value and instantaneous increments We can simulate such a process as follows. First, create a sequence of times at which to store the value of :
t_max = 100
dt = 1e-2
t = seq(0, t_max, by = dt)
Increasing t_max
creates a longer path, while decreasing dt
creates a smoother path.
Now simulate the random increments and take their cumulative sum:
dW = rnorm(length(t) - 1, mean = 0, sd = sqrt(dt))
W = c(0, cumsum(dW))
Here are three sample paths generated by this procedure:
We can use to construct an Ornstein-Uhlenbeck process .
This process has instantaneous increments
where controls the process’ tendency to mean-revert.
We can compute its values by iterating over dW
:
theta = 1
X = rep(0, length(dW))
i = 1
while (i < length(dW)) {
X[i + 1] = X[i] - theta * X[i] * dt + dW[i + 1]
i = i + 1
}
The chart below compares the sample paths obtained using different values. Each path uses the same realization of the underlying Wiener process . If then for all . The mean magnitude of falls as rises because this makes the process more mean-reverting.