Learn R Programming

goffda (version 0.1.2)

r_ou: Simulation of an Ornstein--Uhlenbeck process

Description

Simulation of trajectories of the Ornstein--Uhlenbeck process \(\{X_t\}\). The process is the solution to the stochastic differential equation $$\mathrm{d}X_t = \alpha (X_t - \mu)\mathrm{d}t + \sigma \mathrm{d}W_t, $$ whose stationary distribution is \(N(\mu, \sigma^2 / (2 \alpha))\), for \(\alpha, \sigma > 0\) and \(\mu \in R\).

Given an initial point \(x_0\) and the evaluation times \(t_1, \ldots, t_m\), a sample trajectory \(X_{t_1}, \ldots, X_{t_m}\) can be obtained by sampling the joint Gaussian distribution of \((X_{t_1}, \ldots, X_{t_m})\).

Usage

r_ou(n, t = seq(0, 1, len = 201), mu = 0, alpha = 1, sigma = 1,
  x0 = rnorm(n, mean = mu, sd = sigma/sqrt(2 * alpha)))

Value

Random trajectories, an fdata object of length n and t as argvals.

Arguments

n

number of trajectories to sample.

t

evaluation times for the trajectories, a vector.

mu

mean of the process, a scalar.

alpha

strength of the drift, a positive scalar.

sigma

diffusion coefficient, a positive scalar.

x0

a vector of length n giving the initial values of the Ornstein--Uhlenbeck trajectories. By default, n points are sampled from the stationary distribution. If a single scalar is passed, then the same x0 is employed for all the trajectories.

Author

Eduardo García-Portugués.

Examples

Run this code
# Same initial point
plot(r_ou(n = 20, x0 = 5), col = viridisLite::viridis(20))

# Different initial points
plot(r_ou(n = 100, alpha = 2, sigma = 4, x0 = 1:100),
     col = viridisLite::viridis(100))

Run the code above in your browser using DataLab