sde.sim {sde} | R Documentation |
Generic interface to different scheme of simulations of solutions to stochastic differential equations.
sde.sim(t0 = 0, T = 1, X0 = 1, N = 100, delta, drift, sigma, drift.x, sigma.x, drift.xx, sigma.xx, scheme = c("euler", "milstein", "KPS", "milstein2"), alpha = 0.5, eta = 0.5, pred.corr = T)
t0 |
time origin |
T |
horizon of simulation |
X0 |
initial value of the process |
N |
number of simulation steps |
delta |
time-step of the simulation |
drift |
drift coeffcient: a expression of two variables t and x |
sigma |
diffusion coeffcient: a expression of two variables t and x |
drift.x |
partial derivative of drift coeffcient wrt to x : a function of two variables t and x |
sigma.x |
partial derivative of diffusio coeffcient wrt to x : a function of two variables t and x |
drift.xx |
second partial derivative of drift coeffcient wrt to x : a function of two variables t and x |
sigma.xx |
second partial derivative of diffusion coeffcient wrt to x : a function of two variables t and x |
scheme |
scheme of simulation, see details |
alpha |
weight alpha of the predictor-corrector scheme |
eta |
weight eta of the predictor-corrector scheme |
pred.corr |
boolean: wheter to apply the predictor-correct adjustment. See details. |
The function returns a ts
object of length N+1
, i.e. X0
and
the new N
simulated values. If delta
is not specified, then delta = (T-t0)/N
.
If delta
is specified, then N
values of the solution of the sde are generated and
the time horizon T
is adjusted to be N * delta
.
If d.x
and/or d.xx
and/or s.x
and/or s.xx
are not specified,
then numerical derivation is attempted.
If s
is not specified, it is assumed to the constant function 1
The scheme
of simulation can be one among: euler
, milstein
,
milstein2
or KPS
. No assumption on the coefficients is checked: the
user is responbile for using the right scheme for the process object of simulation.
x |
returns and invisible ts object |
This package is a companion to the book `Simulation and Inference for Stochastic Differential Equation, Springer, NY.
Stefano Maria Iacus
See Chapter 2 of the book
# Ornstein-Uhlenbeck process # beta = 5 # sigma = 3.5 set.seed(123) d <- expression(-5 * x) s <- expression(3.5) sde.sim(X0=10,drift=d, sigma=s) -> X plot(X,main="Ornstein-Uhlenbeck") # Cox-Ingersoll-Ross (CIR-1) # a = 3 # theta = 2 # lambda = 5 set.seed(123) d <- expression( 3*(2-x) ) s <- expression( 5*sqrt(x) ) sde.sim(X0=10,drift=d, sigma=s) -> X plot(X,main="Cox-Ingersoll-Ross")