sde.sim {msde}R Documentation

Simulation of multivariate SDE trajectories.

Description

Simulates a discretized Euler-Maruyama approximation to the true SDE trajectory.

Usage

sde.sim(
  model,
  x0,
  theta,
  dt,
  dt.sim,
  nobs,
  burn = 0,
  nreps = 1,
  max.bad.draws = 5000,
  verbose = TRUE
)

Arguments

model

An sde.model object.

x0

A vector or a matrix of size ⁠nreps x ndims⁠ of the SDE values at time 0.

theta

A vector or matrix of size ⁠nreps x nparams⁠ of SDE parameters.

dt

Scalar interobservation time.

dt.sim

Scalar interobservation time for simulation. That is, interally the interobservation time is dt.sim but only one out of every dt/dt.sim simulation steps is kept in the output.

nobs

The number of SDE observations per trajectory to generate.

burn

Scalar burn-in value. Either an integer giving the number of burn-in steps, or a value between 0 and 1 giving the fraction of burn-in relative to nobs.

nreps

The number of SDE trajectories to generate.

max.bad.draws

The maximum number of times that invalid forward steps are proposed. See Details.

verbose

Whether or not to display information on the simulation.

Details

The simulation algorithm is a Markov process with Y_0 = x_0 and

Y_{t+1} \sim \mathcal{N}(Y_t + \mathrm{dr}(Y_t, \theta) dt_{\mathrm{sim}}, \mathrm{df}(Y_t, \theta) dt_{\mathrm{sim}}),

where \mathrm{dr}(y, \theta) is the SDE drift function and \mathrm{df}(y, \theta) is the diffusion function on the variance scale. At each step, a while-loop is used until a valid SDE draw is produced. The simulation algorithm terminates after nreps trajectories are drawn or once a total of max.bad.draws are reached.

Value

A list with elements:

data

An array of size ⁠nobs x ndims x nreps⁠ containing the simulated SDE trajectories.

params

The vector or matrix of parameter values used to generate the data.

⁠dt, dt.sim⁠

The actual and internal interobservation times.

nbad

The total number of bad draws.

Examples

# load pre-compiled model
hmod <- sde.examples("hest")

# initial values
x0 <- c(X = log(1000), Z = 0.1)
theta <- c(alpha = 0.1, gamma = 1, beta = 0.8, sigma = 0.6, rho = -0.8)

# simulate data
dT <- 1/252
nobs <- 2000
burn <- 500
hsim <- sde.sim(model = hmod, x0 = x0, theta = theta,
                dt = dT, dt.sim = dT/10,
                nobs = nobs, burn = burn)

par(mfrow = c(1,2))
plot(hsim$data[,"X"], type = "l", xlab = "Time", ylab = "",
     main = expression(X[t]))
plot(hsim$data[,"Z"], type = "l", xlab = "Time", ylab = "",
     main = expression(Z[t]))

[Package msde version 1.0.5 Index]