Learn R Programming

smfsb (version 1.5)

rdiff: Simulate a sample path from a univariate diffusion process

Description

This function simulates a single realisation from a time-homogeneous univariate diffusion process.

Usage

rdiff(afun, bfun, x0 = 0, t = 50, dt = 0.01, ...)

Value

An R ts object containing the sampled path of the process.

Arguments

afun

A scalar-valued function representing the infinitesimal mean (drift) of the diffusion process. The first argument of afun is the current state of the process.

bfun

A scalar-valued function representing the infinitesimal standard deviation of the process. The first argument of bfun is the current state of the process.

x0

The initial state of the diffusion process.

t

The length of the time interval over which the diffusion process is to be simulated. Defaults to 50 time units.

dt

The step size to be used both for the time step of the Euler integration method and the recording interval for the output. It would probably be better to have separate parameters for these two things (see StepSDE and simTs). Defaults to 0.01 time units.

...

Additional arguments will be passed into afun and bfun.

See Also

rcfmc, ts, StepSDE, simTs

Examples

Run this code
# simulate a diffusion approximation to an immigration-death process
# infinitesimal mean
afun<-function(x,lambda,mu)
{
        lambda-mu*x
}
# infinitesimal standard deviation
bfun<-function(x,lambda,mu)
{
        sqrt(lambda+mu*x)
}
# plot a sample path
plot(rdiff(afun,bfun,lambda=1,mu=0.1,t=30))

Run the code above in your browser using DataLab