sde.sim: Simulation of multivariate SDE trajectories.

Description Usage Arguments Details Value Examples

View source: R/sde.sim.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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) ~ N(Y_t + dr(Y_t, θ) dt_(sim), df(Y_t, θ) dt_(sim)),

where dr(y, θ) is the SDE drift function and df(y, θ) 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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]))

Example output

Number of normal draws required: 25000
Running simulation...
Execution time: 0 seconds.
Bad Draws = 0

msde documentation built on Dec. 17, 2021, 9:07 a.m.