Sim DiffProc
Sim DiffProc
DiffProc’
November 8, 2020
Type Package
Version 4.8
Date 2020-11-08
Title Simulation of Diffusion Processes
Author Arsalane Chouaib Guidoum [cre, aut],
Kamal Boukhetala [aut]
Maintainer Arsalane Chouaib Guidoum <[email protected]>
Depends R (>= 3.0.0)
Imports Deriv (>= 3.8.0), MASS (>= 7.3-30), parallel
Suggests deSolve (>= 1.11), knitr (>= 1.10), rgl (>= 0.93.991),
rmarkdown (>= 0.8), scatterplot3d (>= 0.3-36), sm (>= 2.2-5.3)
BugReports https://github.com/acguidoum/Sim.DiffProc/issues
URL https://github.com/acguidoum/Sim.DiffProc
VignetteBuilder knitr
Encoding UTF-8
Description It provides users with a wide range of tools to simulate, estimate, analyze, and visual-
ize the dynamics of stochastic differential systems in both forms Ito and Stratonovich. Statisti-
cal analysis with parallel Monte Carlo and moment equations meth-
ods of SDEs <doi:10.18637/jss.v096.i02>. Enabled many searchers in different do-
mains to use these equations to modeling practical problems in financial and actuarial model-
ing and other areas of application, e.g., modeling and simulate of first passage time prob-
lem in shallow water using the attractive center (Boukhetala K, 1996) ISBN:1-56252-342-2.
License GPL (>= 2)
Classification/MSC 37H10, 37M10, 60H05, 60H10, 60H35, 60J60, 65C05,
68N15, 68Q10
NeedsCompilation yes
Repository CRAN
Date/Publication 2020-11-08 16:10:02 UTC
1
2 Sim.DiffProc-package
R topics documented:
Sim.DiffProc-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
BM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
bridgesde1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
bridgesde2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
bridgesde3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
fitsde . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
fptsde1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
fptsde2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
fptsde3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
HWV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Irates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
MCM.sde . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
MEM.sde . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
moment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
plot2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
rsde1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
rsde2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
rsde3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
snssde1d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
snssde2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
snssde3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
st.int . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
TEX.sde . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Index 71
Description
It provides users with a wide range of tools to simulate, estimate, analyze, and visualize the dy-
namics of stochastic differential systems in both forms Ito and Stratonovich. Statistical analysis
with parallel Monte Carlo and moment equations methods of SDEs <doi:10.18637/jss.v096.i02>.
Enabled many searchers in different domains to use these equations to modeling practical prob-
lems in financial and actuarial modeling and other areas of application, e.g., modeling and simulate
of first passage time problem in shallow water using the attractive center (Boukhetala K, 1996)
ISBN:1-56252-342-2.
Details
Package: Sim.DiffProc
Type: Package
Version: 4.8
Date: 2020-11-08
License: GPL (>= 2)
Sim.DiffProc-package 3
1. Simulation of solution to 1,2 and 3-dim stochastic differential equations of Itô and Stratonovich
types, with different methods.
2. Simulation of solution to 1,2 and 3-dim diffusion bridge of Itô and Stratonovich types, with
different methods.
3. Simulation the first-passage-time (f.p.t) in 1,2 and 3-dim sde of Itô and Stratonovich types.
4. Calculate symbolic ODE’s of moment equations (means and variances-covariance) for 1,2 and
3-dim SDE’s.
5. Monte-Carlo replicates of a statistic applied to 1,2 and 3-dim SDE’s at any time t.
6. Computing the basic statistics (mean, var, median, ...) of the processes at any time t using the
Monte Carlo method.
7. Random number generators (RN’s) to generate 1,2 and 3-dim sde of Itô and Stratonovich
types.
8. Approximate the transition density 1,2 and 3-dim of the processes at any time t.
9. Approximate the density of first-passage-time in 1,2 and 3-dim SDE’s.
10. Computing the Itô and Stratonovich stochastic integrals.
11. Estimate drift and diffusion parameters by the method of maximum pseudo-likelihood of the
one-dim stochastic differential equation.
12. Converting Sim.DiffProc objects to LaTeX.
13. Displaying an object inheriting from class "sde" (1,2 and 3 dim).
For more examples see demo(Sim.DiffProc), and for an overview of this package, see browseVignettes('Sim.DiffProc')
for more informations.
Requirements
R version >= 3.0.0
Citation
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Licence
This package and its documentation are usable under the terms of the "GNU General Public Li-
cense", a copy of which is distributed with the package.
4 Sim.DiffProc-package
Author(s)
A.C. Guidoum <[email protected]> and K. Boukhetala <[email protected]> (Dept. Prob-
ability and Statistics, USTHB, Algeria).
Please send comments, error reports, etc. to the author via the addresses email.
References
Argyrakisa, P. and G.H. Weiss (2006). A first-passage time problem for many random walkers.
Physica A. 363, 343–347.
Aytug H., G. J. Koehler (2000). New stopping criterion for genetic algorithms. European Journal
of Operational Research, 126, 662–674.
Boukhetala, K. (1994). Simulation study of a dispersion about an attractive centre. In proceedings
of 11th Symposium Computational Statistics, edited by R.Dutter and W.Grossman, Wien , Austria,
128–130.
Boukhetala, K. (1996). Modelling and simulation of a dispersion pollutant with attractive centre. ed
by Computational Mechanics Publications, Southampton ,U.K and Computational Mechanics Inc,
Boston, USA, 245–252.
Boukhetala, K. (1998a). Estimation of the first passage time distribution for a simulated diffusion
process. Maghreb Math.Rev, 7(1), 1–25.
Boukhetala, K. (1998b). Kernel density of the exit time in a simulated diffusion. les Annales
Maghrebines De L ingenieur, 12, 587–589.
Ding, M. and G. Rangarajan. (2004). First Passage Time Problem: A Fokker-Planck Approach.
New Directions in Statistical Physics. ed by L. T. Wille. Springer. 31–46.
Ait-Sahalia, Y. (1999). Transition densities for interest rate and other nonlinear diffusions. The
Journal of Finance, 54, 1361–1395.
Ait-Sahalia, Y. (2002). Maximum likelihood estimation of discretely sampled diffusions: a closed-
form approximation approach. Econometrica. 70, 223–262.
Roman, R.P., Serrano, J. J., Torres, F. (2008). First-passage-time location function: Application
to determine first-passage-time densities in diffusion processes. Computational Statistics and Data
Analysis. 52, 4132–4146.
Roman, R.P., Serrano, J. J., Torres, F. (2012). An R package for an efficient approximation of first-
passage-time densities for diffusion processes based on the FPTL function. Applied Mathematics
and Computation, 218, 8408–8428.
Kessler, M. (1997). Estimation of an ergodic diffusion from discrete observations. Scand. J. Statist.,
24, 211-229.
Gardiner, C. W. (1997). Handbook of Stochastic Methods. Springer-Verlag, New York.
Friedman, A. (1975). Stochastic differential equations and applications. Volume 1, ACADEMIC
PRESS.
Henderson, D. and Plaschko,P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
Croissant, Y. (2014). Ecdat: Data sets for econometrics. R package version 0.2-5.
Vasicek, O. (1977). An Equilibrium Characterization of the Term Structure. Journal of Financial
Economics, 5, 177–188.
Sim.DiffProc-package 5
Bladt, M. and Sorensen, M. (2007). Simple simulation of diffusion bridges with application to
likelihood inference for diffusions. Working Paper, University of Copenhagen.
Ozaki, T. (1992). A bridge between nonlinear time series models and nonlinear stochastic dynami-
cal systems: A local linearization approach. Statistica Sinica, 2, 25-83.
Shoji, L., Ozaki, T. (1998). Estimation for nonlinear stochastic differential equations by a local
linearization method. Stochastic Analysis and Applications, 16, 733-752.
Nicolau, J. (2004). Introduction to the estimation of stochastic differential equations based on
discrete observations. Autumn School and International Conference, Stochastic Finance.
F C Klebaner, F.C. (2005). Introduction to stochastic calculus with application. 2nd edn. Imperial
College Press (ICP).
Henderson, D. and Plaschko, P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
See Also
Description
The (S3) generic function for simulation of brownian motion, brownian bridge, geometric brownian
motion, and arithmetic brownian motion.
Usage
BM(N, ...)
BB(N, ...)
GBM(N, ...)
ABM(N, ...)
## Default S3 method:
BM(N =1000,M=1,x0=0,t0=0,T=1,Dt=NULL, ...)
## Default S3 method:
BB(N =1000,M=1,x0=0,y=0,t0=0,T=1,Dt=NULL, ...)
## Default S3 method:
GBM(N =1000,M=1,x0=1,t0=0,T=1,Dt=NULL,theta=1,sigma=1, ...)
## Default S3 method:
ABM(N =1000,M=1,x0=0,t0=0,T=1,Dt=NULL,theta=1,sigma=1, ...)
BM 7
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value of the process at time t0 .
y terminal value of the process at time T of the BB.
t0 initial time.
T final time.
Dt time step of the simulation (discretization). If it is NULL a default ∆t = T −t0
N .
theta the interest rate of the ABM and GBM.
sigma the volatility of the ABM and GBM.
... potentially further arguments for (non-default) methods.
Details
The function BM returns a trajectory of the standard Brownian motion (Wiener process) in the time
interval [t0 , T ]. Indeed, for W (dt) it holds true that W (dt) → W (dt) − W (0) → N (0, dt), where
N (0, 1) is normal distribution Normal.
The function BB returns a trajectory of the Brownian bridge starting at x0 at time t0 and ending at
y at time T ; i.e., the diffusion process solution of stochastic differential equation:
y − Xt
dXt = dt + dWt
T −t
The function GBM returns a trajectory of the geometric Brownian motion starting at x0 at time t0 ;
i.e., the diffusion process solution of stochastic differential equation:
The function ABM returns a trajectory of the arithmetic Brownian motion starting at x0 at time t0 ;
i.e.,; the diffusion process solution of stochastic differential equation:
Value
X an visible ts object.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Allen, E. (2007). Modeling with Ito stochastic differential equations. Springer-Verlag, New York.
Jedrzejewski, F. (2009). Modeles aleatoires et physique probabiliste. Springer-Verlag, New York.
Henderson, D and Plaschko, P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
8 bridgesde1d
See Also
This functions BM, BBridge and GBM are available in other packages such as "sde".
Examples
## Brownian motion
set.seed(1234)
X <- BM(M = 100)
plot(X,plot.type="single")
lines(as.vector(time(X)),rowMeans(X),col="red")
## Brownian bridge
set.seed(1234)
X <- BB(M =100)
plot(X,plot.type="single")
lines(as.vector(time(X)),rowMeans(X),col="red")
par(op)
Description
The (S3) generic function bridgesde1d for simulation of 1-dim bridge stochastic differential equa-
tions,Itô or Stratonovich type, with different methods.
Usage
bridgesde1d(N, ...)
## Default S3 method:
bridgesde1d(N = 1000, M=1, x0 = 0, y = 0, t0 = 0, T = 1, Dt,
drift, diffusion, alpha = 0.5, mu = 0.5, type = c("ito", "str"),
method = c("euler", "milstein", "predcorr", "smilstein", "taylor",
bridgesde1d 9
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value of the process at time t0.
y terminal value of the process at time T.
t0 initial time.
T final time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
drift drift coefficient: an expression of two variables t and x.
10 bridgesde1d
Details
The function bridgesde1d returns a trajectory of the diffusion bridge starting at x at time t0 and
ending at y at time T.
The methods of approximation are classified according to their different properties. Mainly two
criteria of optimality are used in the literature: the strong and the weak (orders of) convergence.
The method of simulation can be one among: Euler-Maruyama Order 0.5, Milstein Order 1,
Milstein Second-Order, Predictor-Corrector method, Itô-Taylor Order 1.5, Heun Order 2
and Runge-Kutta Order 1,2 and 3.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
bridgesde1d returns an object inheriting from class "bridgesde1d".
X an invisible ts object.
drift drift coefficient.
diffusion diffusion coefficient.
C indices of crossing realized of X(t).
type type of sde.
method the numerical method used.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Bladt, M. and Sorensen, M. (2007). Simple simulation of diffusion bridges with application to
likelihood inference for diffusions. Working Paper, University of Copenhagen.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York
bridgesde1d 11
See Also
Examples
## Example 1: Ito bridge sde
## Ito Bridge sde
## dX(t) = 2*(1-X(t)) *dt + dW(t)
## x0 = 2 at time t0=0 , and y = 1 at time T=1
set.seed(1234)
## End(Not run)
f <- expression((2-x)/(2-t))
g <- expression(x)
mod2 <- bridgesde1d(type="str",drift=f,diffusion=g,M=1000,x0=2,y=2)
mod2
summary(mod2,at = 0.25) ## Monte-Carlo statistics at 0.25
summary(mod2,at = 0.5) ## Monte-Carlo statistics at 0.5
summary(mod2,at = 0.75 )## Monte-Carlo statistics at 0.75
## Not run:
plot(mod2)
lines(time(mod2),apply(mod2$X,1,mean),col=2,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[1,],col=4,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[2,],col=4,lwd=2)
legend("topright",c("mean path",paste("bound of", 95," percent confidence")),
inset = .01,col=c(2,4),lwd=2,cex=0.8)
## End(Not run)
12 bridgesde2d
Description
The (S3) generic function bridgesde2d for simulation of 2-dim bridge stochastic differential equa-
tions,Itô or Stratonovich type, with different methods.
Usage
bridgesde2d(N, ...)
## Default S3 method:
bridgesde2d(N = 1000, M = 1, x0 = c(0, 0),
y = c(0, 0),t0 = 0, T = 1, Dt,drift, diffusion, corr = NULL,
alpha = 0.5, mu = 0.5,type = c("ito", "str"),method =
c("euler", "milstein","predcorr", "smilstein", "taylor",
"heun", "rk1", "rk2", "rk3"), ...)
plot(x, ...)
## S3 method for class 'bridgesde2d'
lines(x, ...)
## S3 method for class 'bridgesde2d'
points(x, ...)
## S3 method for class 'bridgesde2d'
plot2d(x, ...)
## S3 method for class 'bridgesde2d'
lines2d(x, ...)
## S3 method for class 'bridgesde2d'
points2d(x, ...)
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value (numeric vector of length 2) of the process Xt and Yt at time t0 .
y terminal value (numeric vector of length 2) of the process Xt and Yt at time T .
t0 initial time.
T final time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
drift drift coefficient: an expression of three variables t, x and y for process Xt and
Yt .
diffusion diffusion coefficient: an expression of three variables t, x and y for process
Xt and Yt .
corr the correlation structure of two Brownian motions W1(t) and W2(t); must be a
real symmetric positive-definite square matrix of dimension 2.
alpha, mu weight of the predictor-corrector scheme; the default alpha = 0.5 and mu = 0.5.
type if type="ito" simulation diffusion bridge of Itô type, else type="str" simula-
tion diffusion bridge of Stratonovich type; the default type="ito".
method numerical methods of simulation, the default method = "euler"; see snssde2d.
x, object an object inheriting from class "bridgesde2d".
at time between t0 and T. Monte-Carlo statistics of the solution (Xt , Yt ) at time
at. The default at = T/2.
digits integer, used for number formatting.
... potentially further arguments for (non-default) methods.
Details
The function bridgesde2d returns a mts of the diffusion bridge starting at x at time t0 and ending
at y at time T. W1(t) and W2(t) are two standard Brownian motion independent if corr=NULL.
The methods of approximation are classified according to their different properties. Mainly two
criteria of optimality are used in the literature: the strong and the weak (orders of) convergence.
14 bridgesde2d
The method of simulation can be one among: Euler-Maruyama Order 0.5, Milstein Order 1,
Milstein Second-Order, Predictor-Corrector method, Itô-Taylor Order 1.5, Heun Order 2
and Runge-Kutta Order 1,2 and 3.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
bridgesde2d returns an object inheriting from class "bridgesde2d".
X, Y an invisible mts (2-dim) object (X(t),Y(t)).
driftx, drifty drift coefficient of X(t) and Y(t).
diffx, diffy diffusion coefficient of X(t) and Y(t).
Cx, Cy indices of crossing realized of X(t) and Y(t).
type type of sde.
method the numerical method used.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Bladt, M. and Sorensen, M. (2007). Simple simulation of diffusion bridges with application to
likelihood inference for diffusions. Working Paper, University of Copenhagen.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York
See Also
bridgesde1d for simulation of 1-dim SDE.
DBridge in package "sde".
Examples
## dX(t) = 4*(-1-X(t)) dt + 0.2 dW1(t)
## dY(t) = X(t) dt + 0 dW2(t)
## x01 = 0 , y01 = 0
## x02 = 0, y02 = 0
## W1(t) and W2(t) two correlated Brownian motion with matrix Sigma=matrix(c(1,0.7,0.7,1),nrow=2)
set.seed(1234)
fx <- expression(4*(-1-x) , x)
gx <- expression(0.2 , 0)
Sigma= matrix(c(1,0.7,0.7,1),nrow=2)
res <- bridgesde2d(drift=fx,diffusion=gx,Dt=0.005,M=500,corr=Sigma)
res
summary(res) ## Monte-Carlo statistics at time T/2=2.5
summary(res,at=1) ## Monte-Carlo statistics at time 1
summary(res,at=4) ## Monte-Carlo statistics at time 4
bridgesde3d 15
##
plot(res,type="n")
lines(time(res),apply(res$X,1,mean),col=3,lwd=2)
lines(time(res),apply(res$Y,1,mean),col=4,lwd=2)
legend("topright",c(expression(E(X[t])),expression(E(Y[t]))),lty=1,inset = .7,col=c(3,4))
##
plot2d(res)
Description
The (S3) generic function bridgesde3d for simulation of 3-dim bridge stochastic differential equa-
tions,Itô or Stratonovich type, with different methods.
Usage
bridgesde3d(N, ...)
## Default S3 method:
bridgesde3d(N=1000,M=1, x0=c(0,0,0),
y=c(0,0,0), t0 = 0, T = 1, Dt, drift, diffusion, corr = NULL,
alpha = 0.5, mu = 0.5,type = c("ito", "str"), method =
c("euler", "milstein","predcorr","smilstein", "taylor",
"heun","rk1", "rk2", "rk3"), ...)
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value (numeric vector of length 3) of the process Xt , Yt and Zt at time t0 .
y terminal value (numeric vector of length 3) of the process Xt , Yt and Zt at time
T.
t0 initial time.
T final time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
drift drift coefficient: an expression of four variables t, x, y and z for process Xt ,
Yt and Zt .
diffusion diffusion coefficient: an expression of four variables t, x, y and z for process
Xt , Yt and Zt .
corr the correlation structure of three Brownian motions W1(t), W2(t) and W3(t);
must be a real symmetric positive-definite square matrix of dimension 3.
alpha weight alpha of the predictor-corrector scheme; the default alpha = 0.5.
mu weight mu of the predictor-corrector scheme; the default mu = 0.5.
type if type="ito" simulation diffusion bridge of Itô type, else type="str" simula-
tion diffusion bridge of Stratonovich type; the default type="ito".
method numerical methods of simulation, the default method = "euler"; see snssde3d.
x, object an object inheriting from class "bridgesde3d".
at time between t0 and T. Monte-Carlo statistics of the solution (Xt , Yt , Zt ) at
time at. The default at = T/2.
digits integer, used for number formatting.
display "persp" perspective and "rgl" plots.
... potentially further arguments for (non-default) methods.
bridgesde3d 17
Details
The function bridgesde3d returns a mts of the diffusion bridge starting at x at time t0 and ending
at y at time T. W1(t), W2(t) and W3(t) three standard Brownian motion independent if corr=NULL.
The methods of approximation are classified according to their different properties. Mainly two
criteria of optimality are used in the literature: the strong and the weak (orders of) convergence.
The method of simulation can be one among: Euler-Maruyama Order 0.5, Milstein Order 1,
Milstein Second-Order, Predictor-Corrector method, Itô-Taylor Order 1.5, Heun Order 2
and Runge-Kutta Order 1,2 and 3.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
bridgesde3d returns an object inheriting from class "bridgesde3d".
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Bladt, M. and Sorensen, M. (2007). Simple simulation of diffusion bridges with application to
likelihood inference for diffusions. Working Paper, University of Copenhagen.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York
See Also
bridgesde1d for simulation of 1-dim SDE. DBridge in package "sde".
bridgesde2d for simulation of 2-dim SDE.
Examples
## dX(t) = 4*(-1-X(t))*Y(t) dt + 0.2 * dW1(t) ; x01 = 0 and y01 = 0
## dY(t) = 4*(1-Y(t)) *X(t) dt + 0.2 * dW2(t) ; x02 = -1 and y02 = -2
## dZ(t) = 4*(1-Z(t)) *Y(t) dt + 0.2 * dW3(t) ; x03 = 0.5 and y03 = 0.5
## W1(t), W2(t) and W3(t) are three correlated Brownian motions with Sigma
set.seed(1234)
18 fitsde
Description
The (S3) generic function "fitsde" of estimate drift and diffusion parameters by the method of
maximum pseudo-likelihood of the 1-dim stochastic differential equation.
Usage
fitsde(data, ...)
## Default S3 method:
fitsde(data, drift, diffusion, start = list(), pmle = c("euler","kessler",
"ozaki", "shoji"), optim.method = "L-BFGS-B",
lower = -Inf, upper = Inf, ...)
Arguments
data a univariate time series (ts class).
drift drift coefficient: an expression of two variables t, x and theta a vector of
parameters of sde. See Examples.
diffusion diffusion coefficient: an expression of two variables t, x and theta a vector
of parameters of sde. See Examples.
start named list of starting values for optimizer. See Examples.
pmle a character string specifying the method; can be either: "euler" (Euler pseudo-
likelihood), "ozaki" (Ozaki pseudo-likelihood), "shoji" (Shoji pseudo-likelihood),
and "kessler" (Kessler pseudo-likelihood).
optim.method the method for optim.
lower, upper bounds on the variables for the "Brent" or "L-BFGS-B" method.
object an object inheriting from class "fitsde".
parm a specification of which parameters are to be given confidence intervals, either
a vector of names (example parm='theta1'). If missing, all parameters are
considered.
level the confidence level required.
... potentially further arguments to pass to optim.
Details
The function fitsde returns a pseudo-likelihood estimators of the drift and diffusion parameters
in 1-dim stochastic differential equation. The optim optimizer is used to find the maximum of the
negative log pseudo-likelihood. An approximate covariance matrix for the parameters is obtained
by inverting the Hessian matrix at the optimum.
The pmle of pseudo-likelihood can be one among:"euler": Euler pseudo-likelihood), "ozaki":
Ozaki pseudo-likelihood, "shoji": Shoji pseudo-likelihood, and "kessler": Kessler pseudo-
likelihood.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
fitsde returns an object inheriting from class "fitsde".
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Kessler, M. (1997). Estimation of an ergodic diffusion from discrete observations. Scand. J. Statist.,
24, 211-229.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York.
20 fitsde
Iacus, S.M. (2009). sde: Simulation and Inference for Stochastic Differential Equations. R package
version 2.0.10.
Iacus, S.M. and all. (2014). The yuima Project: A Computational Framework for Simulation and
Inference of Stochastic Differential Equations. Journal of Statistical Software, 57(4).
Ozaki, T. (1992). A bridge between nonlinear time series models and nonlinear stochastic dynami-
cal systems: A local linearization approach. Statistica Sinica, 2, 25-83.
Shoji, L., Ozaki, T. (1998). Estimation for nonlinear stochastic differential equations by a local
linearization method. Stochastic Analysis and Applications, 16, 733-752.
Dacunha, D.C. and Florens, D.Z. (1986). Estimation of the Coefficients of a Diffusion from Discrete
Observations. Stochastics. 19, 263–284.
Dohnal, G. (1987). On estimating the diffusion coefficient. J. Appl.Prob., 24, 105–114.
Genon, V.C. (1990). Maximum constrast estimation for diffusion processes from discrete observa-
tion. Statistics, 21, 99–116.
Nicolau, J. (2004). Introduction to the estimation of stochastic differential equations based on
discrete observations. Autumn School and International Conference, Stochastic Finance.
Ait-Sahalia, Y. (1999). Transition densities for interest rate and other nonlinear diffusions. The
Journal of Finance, 54, 1361–1395.
Ait-Sahalia, Y. (2002). Maximum likelihood estimation of discretely sampled diffusions: a closed-
form approximation approach. Econometrica. 70, 223–262.
B.L.S. Prakasa Rao. (1999). Statistical Inference for Diffusion Type Processes. Arnold, London
and Oxford University press, New York.
Kutoyants, Y.A. (2004). Statistical Inference for Ergodic Diffusion Processes. Springer, London.
See Also
dcEuler, dcElerian, dcOzaki, dcShoji, dcKessler and dcSim for approximated conditional law
of a diffusion process. gmm estimator of the generalized method of moments by Hansen, and
HPloglik these functions are useful to calculate approximated maximum likelihood estimators
when the transition density of the process is not known, in package "sde".
qmle in package "yuima" calculate quasi-likelihood and ML estimator of least squares estimator.
Examples
##### Example 1:
lower=c(0,0))
fres
summary(fres)
coef(fres)
logLik(fres)
AIC(fres)
BIC(fres)
vcov(fres)
confint(fres,level=0.95)
fptsde1d Approximate densities and random generation for first passage time in
1-D SDE
Description
Kernel density and random generation for first-passage-time (f.p.t) in 1-dim stochastic differential
equations.
Usage
fptsde1d(object, ...)
dfptsde1d(object, ...)
## Default S3 method:
fptsde1d(object, boundary, ...)
## S3 method for class 'fptsde1d'
summary(object, digits=NULL, ...)
## S3 method for class 'fptsde1d'
mean(x, ...)
## S3 method for class 'fptsde1d'
Median(x, ...)
## S3 method for class 'fptsde1d'
Mode(x, ...)
## S3 method for class 'fptsde1d'
quantile(x, ...)
## S3 method for class 'fptsde1d'
kurtosis(x, ...)
## S3 method for class 'fptsde1d'
skewness(x, ...)
## S3 method for class 'fptsde1d'
min(x, ...)
## S3 method for class 'fptsde1d'
max(x, ...)
## S3 method for class 'fptsde1d'
moment(x, ...)
## S3 method for class 'fptsde1d'
22 fptsde1d
cv(x, ...)
## Default S3 method:
dfptsde1d(object, ...)
## S3 method for class 'dfptsde1d'
plot(x, hist=FALSE, ...)
Arguments
object an object inheriting from class snssde1d for fptsde1d, and fptsde1d for dfptsde1d.
boundary an expression of a constant or time-dependent boundary.
x an object inheriting from class dfptsde1d.
hist if hist=TRUE plot histogram. Based on truehist function.
digits integer, used for number formatting.
... potentially further arguments for (non-default) methods, such as density for
dfptsde1d.
Details
The function fptsde1d returns a random variable τ(X(t),S(t)) "first passage time", is defined as :
And dfptsde1d returns a kernel density approximation for τ(X(t),S(t)) "first passage time". with
S(t) is through a continuous boundary (barrier).
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
dfptsde1d gives the density estimate of fpt. fptsde1d generates random of fpt.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Argyrakisa, P. and G.H. Weiss (2006). A first-passage time problem for many random walkers.
Physica A. 363, 343–347.
Aytug H., G. J. Koehler (2000). New stopping criterion for genetic algorithms. European Journal
of Operational Research, 126, 662–674.
Boukhetala, K. (1996) Modelling and simulation of a dispersion pollutant with attractive centre. ed
by Computational Mechanics Publications, Southampton ,U.K and Computational Mechanics Inc,
Boston, USA, 245–252.
Boukhetala, K. (1998a). Estimation of the first passage time distribution for a simulated diffusion
process. Maghreb Math.Rev, 7(1), 1–25.
fptsde1d 23
Boukhetala, K. (1998b). Kernel density of the exit time in a simulated diffusion. les Annales
Maghrebines De L ingenieur, 12, 587–589.
Ding, M. and G. Rangarajan. (2004). First Passage Time Problem: A Fokker-Planck Approach.
New Directions in Statistical Physics. ed by L. T. Wille. Springer. 31–46.
Roman, R.P., Serrano, J. J., Torres, F. (2008). First-passage-time location function: Application
to determine first-passage-time densities in diffusion processes. Computational Statistics and Data
Analysis. 52, 4132–4146.
Roman, R.P., Serrano, J. J., Torres, F. (2012). An R package for an efficient approximation of first-
passage-time densities for diffusion processes based on the FPTL function. Applied Mathematics
and Computation, 218, 8408–8428.
Gardiner, C. W. (1997). Handbook of Stochastic Methods. Springer-Verlag, New York.
See Also
fptsde2d and fptsde3d simulation fpt for 2 and 3-dim SDE.
FPTL for computes values of the first passage time location (FPTL) function, and Approx.fpt.density
for approximate first-passage-time (f.p.t.) density in package "fptdApprox".
GQD.TIpassage for compute the First Passage Time Density of a GQD With Time Inhomogeneous
Coefficients in package "DiffusionRgqd".
Examples
# SDE 1d
f <- expression( -4*x )
g <- expression( 0.5 )
mod <- snssde1d(drift=f,diffusion=g,x0=2,M=1000)
# boundary
St <- expression(0)
# random
out <- fptsde1d(mod, boundary=St)
out
summary(out)
# density approximate
den <- dfptsde1d(out)
den
plot(den)
# SDE 1d
f <- expression( 0.5*x*t )
g <- expression( sqrt(1+x^2) )
mod2 <- snssde1d(drift=f,diffusion=g,x0=2,M=1000,type="srt")
# boundary
St <- expression(-0.5*sqrt(t)+exp(t^2))
# random
out2 <- fptsde1d(mod2,boundary=St)
out2
summary(out2)
# density approximate
plot(dfptsde1d(out2,bw='ucv'))
# random
out3 <- fptsde1d(mod,boundary=St)
out3
summary(out3)
# density approximate:
library("fptdApprox")
# Under `fptdApprox':
# Define the diffusion process and give its transitional density:
OU <- diffproc(c("alpha*x + beta","sigma^2",
"dnorm((x-(y*exp(alpha*(t-s)) - beta*(1 - exp(alpha*(t-s)))/alpha))/
(sigma*sqrt((exp(2*alpha*(t-s)) - 1)/(2*alpha))),0,1)/
(sigma*sqrt((exp(2*alpha*(t-s)) - 1)/(2*alpha)))",
"pnorm(x, y*exp(alpha*(t-s)) - beta*(1 - exp(alpha*(t-s)))/alpha,
sigma*sqrt((exp(2*alpha*(t-s)) - 1)/(2*alpha)))"))
# Approximate the first passgage time density for OU, starting in X_0 = 3
# passing through 5+0.25*sin(2*pi*t) on the time interval [0,10]:
res <- Approx.fpt.density(OU, 0, 10, 3,"5+0.25*sin(2*pi*t)", list(alpha=-0.5,beta=0.5*5,sigma=1))
##
plot(dfptsde1d(out3,bw='ucv'),main = 'fptsde1d vs fptdApproximate')
lines(res$y~res$x, type = 'l',lwd=2)
legend('topright', lty = c('solid', 'dashed'), col = c(1, 2),
legend = c('fptdApproximate', 'fptsde1d'), lwd = 2, bty = 'n')
## End(Not run)
fptsde2d 25
fptsde2d Approximate densities and random generation for first passage time in
2-D SDE’s
Description
Kernel density and random generation for first-passage-time (f.p.t) in 2-dim stochastic differential
equations.
Usage
fptsde2d(object, ...)
dfptsde2d(object, ...)
## Default S3 method:
fptsde2d(object, boundary, ...)
## S3 method for class 'fptsde2d'
summary(object, digits=NULL, ...)
## S3 method for class 'fptsde2d'
mean(x, ...)
## S3 method for class 'fptsde2d'
Median(x, ...)
## S3 method for class 'fptsde2d'
Mode(x, ...)
## S3 method for class 'fptsde2d'
quantile(x, ...)
## S3 method for class 'fptsde2d'
kurtosis(x, ...)
## S3 method for class 'fptsde2d'
skewness(x, ...)
## S3 method for class 'fptsde2d'
min(x, ...)
## S3 method for class 'fptsde2d'
max(x, ...)
## S3 method for class 'fptsde2d'
moment(x, ...)
## S3 method for class 'fptsde2d'
cv(x, ...)
## Default S3 method:
dfptsde2d(object, pdf=c("Joint","Marginal"), ...)
## S3 method for class 'dfptsde2d'
plot(x,display=c("persp","rgl","image","contour"),
hist=FALSE, ...)
Arguments
object an object inheriting from class snssde2d for fptsde2d, and fptsde2d for dfptsde2d.
26 fptsde2d
Details
The function fptsde1d returns a random variable (τ(X(t),S(t)) , τ(Y (t),S(t)) ) "first passage time", is
defined as :
τ(X(t),S(t)) = {t ≥ 0; Xt ≥ S(t)}, if X(t0 ) < S(t0 )
τ(Y (t),S(t)) = {t ≥ 0; Yt ≥ S(t)}, if Y (t0 ) < S(t0 )
and:
τ(X(t),S(t)) = {t ≥ 0; Xt ≤ S(t)}, if X(t0 ) > S(t0 )
τ(Y (t),S(t)) = {t ≥ 0; Yt ≤ S(t)}, if Y (t0 ) > S(t0 )
And dfptsde2d returns a kernel density approximation for (τ(X(t),S(t)) , τ(Y (t),S(t)) ) "first passage
time". with S(t) is through a continuous boundary (barrier).
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
dfptsde2d gives the kernel density approximation for fpt. fptsde2d generates random of fpt.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Argyrakisa, P. and G.H. Weiss (2006). A first-passage time problem for many random walkers.
Physica A. 363, 343–347.
Aytug H., G. J. Koehler (2000). New stopping criterion for genetic algorithms. European Journal
of Operational Research, 126, 662–674.
Boukhetala, K. (1996) Modelling and simulation of a dispersion pollutant with attractive centre. ed
by Computational Mechanics Publications, Southampton ,U.K and Computational Mechanics Inc,
Boston, USA, 245–252.
Boukhetala, K. (1998a). Estimation of the first passage time distribution for a simulated diffusion
process. Maghreb Math.Rev, 7(1), 1–25.
Boukhetala, K. (1998b). Kernel density of the exit time in a simulated diffusion. les Annales
Maghrebines De L ingenieur, 12, 587–589.
fptsde2d 27
Ding, M. and G. Rangarajan. (2004). First Passage Time Problem: A Fokker-Planck Approach.
New Directions in Statistical Physics. ed by L. T. Wille. Springer. 31–46.
Roman, R.P., Serrano, J. J., Torres, F. (2008). First-passage-time location function: Application
to determine first-passage-time densities in diffusion processes. Computational Statistics and Data
Analysis. 52, 4132–4146.
Roman, R.P., Serrano, J. J., Torres, F. (2012). An R package for an efficient approximation of first-
passage-time densities for diffusion processes based on the FPTL function. Applied Mathematics
and Computation, 218, 8408–8428.
Gardiner, C. W. (1997). Handbook of Stochastic Methods. Springer-Verlag, New York.
See Also
fptsde1d for simulation fpt in sde 1-dim. fptsde3d for simulation fpt in sde 3-dim.
FPTL for computes values of the first passage time location (FPTL) function, and Approx.fpt.density
for approximate first-passage-time (f.p.t.) density in package "fptdApprox".
GQD.TIpassage for compute the First Passage Time Density of a GQD With Time Inhomogeneous
Coefficients in package "DiffusionRgqd".
Examples
# SDE's 2d
fx <- expression(5*(-1-y)*x , 5*(-1-x)*y)
gx <- expression(0.5 , 0.5)
mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(2,-2),M=100)
# boundary
St <- expression(-1+5*t)
# random fpt
# Marginal density
# Joint density
28 fptsde3d
fptsde3d Approximate densities and random generation for first passage time in
3-D SDE’s
Description
Kernel density and random generation for first-passage-time (f.p.t) in 3-dim stochastic differential
equations.
Usage
fptsde3d(object, ...)
dfptsde3d(object, ...)
## Default S3 method:
fptsde3d(object, boundary, ...)
## S3 method for class 'fptsde3d'
summary(object, digits=NULL, ...)
## S3 method for class 'fptsde3d'
mean(x, ...)
## S3 method for class 'fptsde3d'
Median(x, ...)
## S3 method for class 'fptsde3d'
Mode(x, ...)
## S3 method for class 'fptsde3d'
quantile(x, ...)
## S3 method for class 'fptsde3d'
kurtosis(x, ...)
## S3 method for class 'fptsde3d'
skewness(x, ...)
## S3 method for class 'fptsde3d'
min(x, ...)
## S3 method for class 'fptsde3d'
max(x, ...)
## S3 method for class 'fptsde3d'
moment(x, ...)
## S3 method for class 'fptsde3d'
cv(x, ...)
## Default S3 method:
fptsde3d 29
Arguments
object an object inheriting from class snssde3d for fptsde3d, and fptsde3d for dfptsde3d.
boundary an expression of a constant or time-dependent boundary.
pdf probability density function Joint or Marginal.
x an object inheriting from class dfptsde3d.
digits integer, used for number formatting.
display display plots.
hist if hist=TRUE plot histogram. Based on truehist function.
... potentially arguments to be passed to methods, such as density for marginal
density and sm.density for joint density.
Details
The function fptsde3d returns a random variable (τ(X(t),S(t)) , τ(Y (t),S(t)) , τ(Z(t),S(t)) ) "first pas-
sage time", is defined as :
And dfptsde3d returns a marginal kernel density approximation for (τ(X(t),S(t)) , τ(Y (t),S(t)) , τ(Z(t),S(t)) )
"first passage time". with S(t) is through a continuous boundary (barrier).
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
dfptsde3d gives the marginal kernel density approximation for fpt. fptsde3d generates random of
fpt.
Author(s)
A.C. Guidoum, K. Boukhetala.
30 fptsde3d
References
Argyrakisa, P. and G.H. Weiss (2006). A first-passage time problem for many random walkers.
Physica A. 363, 343–347.
Aytug H., G. J. Koehler (2000). New stopping criterion for genetic algorithms. European Journal
of Operational Research, 126, 662–674.
Boukhetala, K. (1996) Modelling and simulation of a dispersion pollutant with attractive centre. ed
by Computational Mechanics Publications, Southampton ,U.K and Computational Mechanics Inc,
Boston, USA, 245–252.
Boukhetala, K. (1998a). Estimation of the first passage time distribution for a simulated diffusion
process. Maghreb Math.Rev, 7(1), 1–25.
Boukhetala, K. (1998b). Kernel density of the exit time in a simulated diffusion. les Annales
Maghrebines De L ingenieur, 12, 587–589.
Ding, M. and G. Rangarajan. (2004). First Passage Time Problem: A Fokker-Planck Approach.
New Directions in Statistical Physics. ed by L. T. Wille. Springer. 31–46.
Roman, R.P., Serrano, J. J., Torres, F. (2008). First-passage-time location function: Application
to determine first-passage-time densities in diffusion processes. Computational Statistics and Data
Analysis. 52, 4132–4146.
Roman, R.P., Serrano, J. J., Torres, F. (2012). An R package for an efficient approximation of first-
passage-time densities for diffusion processes based on the FPTL function. Applied Mathematics
and Computation, 218, 8408–8428.
Gardiner, C. W. (1997). Handbook of Stochastic Methods. Springer-Verlag, New York.
See Also
fptsde1d for simulation fpt in sde 1-dim. fptsde2d for simulation fpt in sde 2-dim.
FPTL for computes values of the first passage time location (FPTL) function, and Approx.fpt.density
for approximate first-passage-time (f.p.t.) density in package "fptdApprox".
GQD.TIpassage for compute the First Passage Time Density of a GQD With Time Inhomogeneous
Coefficients in package "DiffusionRgqd".
Examples
# SDE's 3d
# boundary
St <- expression(-3+5*t)
# random
# Marginal density
# Multiple isosurfaces
## Not run:
denJ <- dfptsde3d(out,pdf="J")
denJ
plot(denJ,display="rgl")
## End(Not run)
Description
The (S3) generic function for simulation of Hull-White/Vasicek or gaussian diffusion models, and
Ornstein-Uhlenbeck process.
Usage
HWV(N, ...)
OU(N, ...)
## Default S3 method:
HWV(N = 100, M = 1, x0 = 2, t0 = 0, T = 1, Dt = NULL, mu = 4, theta = 1,
sigma = 0.1, ...)
## Default S3 method:
OU(N =100,M=1,x0=2,t0=0,T=1,Dt = NULL,mu=4,sigma=0.2, ...)
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value of the process at time t0 .
t0 initial time.
32 HWV
T final time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
mu parameter of the HWV and OU; see details.
theta parameter of the HWV; see details.
sigma the volatility of the HWV and OU.
... potentially further arguments for (non-default) methods.
Details
The function HWV returns a trajectory of the Hull-White/Vasicek process starting at x0 at time t0 ;
i.e., the diffusion process solution of stochastic differential equation:
The function OU returns a trajectory of the Ornstein-Uhlenbeck starting at x0 at time t0 ; i.e., the
diffusion process solution of stochastic differential equation:
Constraints: µ, σ > 0.
Please note that the process is stationary only if µ > 0.
Value
X an visible ts object.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Vasicek, O. (1977). An Equilibrium Characterization of the Term Structure. Journal of Financial
Economics, 5, 177–188.
See Also
rcOU and rsOU for conditional and stationary law of Vasicek process are available in "sde".
Examples
## Hull-White/Vasicek Models
## dX(t) = 4 * (2.5 - X(t)) * dt + 1 *dW(t), X0=10
set.seed(1234)
## Ornstein-Uhlenbeck Process
## dX(t) = -4 * X(t) * dt + 1 *dW(t) , X0=2
set.seed(1234)
Description
monthly observations from 1946–12 to 1991–02
number of observations : 531
observation : country
country : United–States
Usage
data(Irates)
Format
A time serie containing :
Source
McCulloch, J.H. and Kwon, H.C. (1993). U.S. term structure data, 1947–1991, Ohio State Working
Paper 93–6, Ohio State University, Columbus
These datasets Irates are in package "Ecdat".
34 MCM.sde
References
Croissant, Y. (2014). Ecdat: Data sets for econometrics. R package version 0.2–5.
Examples
data(Irates)
rates <- Irates[,"r1"]
rates <- window(rates, start=1964.471, end=1989.333)
fx <- expression(theta[1]+theta[2]*x)
gx <- expression(theta[3]*x^theta[4])
fitmod <- fitsde(rates,drift=fx,diffusion=gx,pmle="euler",start = list(theta1=1,theta2=1,
theta3=1,theta4=1),optim.method = "L-BFGS-B")
theta <- coef(fitmod)
N <- length(rates)
res <- snssde1d(drift=fx,diffusion=gx,M=1000,t0=time(rates)[1],T=time(rates)[N],
Dt=deltat(rates),x0=rates[1],N=N)
plot(res,type="n",ylim=c(0,35))
lines(rates,col=2,lwd=2)
lines(time(res),apply(res$X,1,mean),col=3,lwd=2)
lines(time(res),apply(res$X,1,bconfint,level=0.95)[1,],col=4,lwd=2)
lines(time(res),apply(res$X,1,bconfint,level=0.95)[2,],col=4,lwd=2)
legend("topleft",c("real data","mean path",
paste("bound of", 95," confidence")),inset = .01,
col=2:4,lwd=2,cex=0.8)
Description
Generate R Monte-Carlo (version parallel) replicates of a statistic applied to SDE’s (1,2 and 3 dim)
for the two cases Ito and Stratonovich interpretations.
Usage
MCM.sde(model, ...)
## Default S3 method:
MCM.sde(model, statistic, R = 100, time, exact = NULL,
names = NULL, level = 0.95, parallel = c("no", "multicore", "snow"),
ncpus = getOption("ncpus", 1L), cl = NULL, ...)
Arguments
model an object from class snssde1d, snssde2d and snssde3d.
statistic a function which when applied to model returns a vector containing the statis-
tic(s) of interest.
R the number of Monte-Carlo replicates. Usually this will be a single positive
integer "R > 1".
time the time when estimating the statistic(s) of interesttime between t0 and T. The
default time = T.
exact a named list giving the exact statistic(s) if it exists otherwise exact = NULL.
names named the statistic(s) of interest. The default names=c("mu1","mu2",...).
level the confidence level(s) of the required interval(s).
parallel the type of parallel operation to be used (if any). The default parallel = "no".
ncpus integer: number of processes to be used in parallel operation: typically one
would chose this to the number of available CPUs.
cl an optional parallel or snow cluster for use if parallel = "snow".
x an object inheriting from class "MCM.sde".
index the index of the variable of interest within the output of "MCM.sde".
type the type of plot of the Monte-Carlo estimation of the variable of interest. The
default type = "all".
... potentially further arguments for (non-default) methods.
Details
We have here developed Monte-Carlo methods whose essence is the use of repeated experiments to
evaluate a statistic(s) of interest in SDE’s. For example estimation of moments as: mean, variance,
covariance (and other as median, mode, quantile,...). With the standard error and the confidence
interval for these estimators.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
The returned value is an object of class "MCM.sde", containing the following components:
Note
When parallel = "multicore" is used are not available on Windows, parallel = "snow" is pri-
marily intended to be used on multi-core Windows machine where parallel = "multicore" is not
available. For more details see Q.E.McCallum and S.Weston (2011).
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Paul Glasserman (2003). Monte Carlo Methods in Financial Engineering. Springer-Verlag New
York.
Jun S. Liu (2004). Monte Carlo Strategies in Scientific Computing. Springer-Verlag New York.
Christian Robert and George Casella (2010). Introducing Monte Carlo Methods with R. Springer-
Verlag New York.
Nick T. Thomopoulos (2013). Essentials of Monte Carlo Simulation: Statistical Methods for Build-
ing Simulation Models. Springer-Verlag New York.
Q. Ethan McCallum and Stephen Weston (2011). Parallel R. O’Reilly Media, Inc.
See Also
MEM.sde moment equations methods for SDE’s.
Examples
## Example 1 : (1 dim)
## dX(t) = 3*(1-X(t)) dt + 0.5 * dW(t), X(0)=5, t in [0,10]
## set the model 1d
f <- expression(3*(1-x));g <- expression(0.5)
mod1d <- snssde1d(drift=f,diffusion=g,x0=5,T=10,M=50)
mc.sde1d = MCM.sde(model=mod1d,statistic=sde.fun1d,R=100,exact=list(Me=1,Mo=1,Va=0.5^2/6),
names=c("Me(10)","Mo(10)","Va(10)"))
mc.sde1d
plot(mc.sde1d,index=1)
plot(mc.sde1d,index=2)
plot(mc.sde1d,index=3)
## Not run:
mod1d <- snssde1d(drift=f,diffusion=g,x0=5,T=10,M=1000)
## On Windows or Unix
mc.sde1d = MCM.sde(model=mod1d,statistic=sde.fun1d,R=1000,exact=list(Me=1,Mo=1,Va=0.5^2/6),
names=c("Me(10)","Mo(10)","Va(10)"),parallel="snow",ncpus=parallel::detectCores())
mc.sde1d
## On Unix only
mc.sde1d = MCM.sde(model=mod1d,statistic=sde.fun1d,R=1000,exact=list(Me=1,Mo=1,Va=0.5^2/6),
names=c("Me(10)","Mo(10)","Va(10)"),parallel="multicore",ncpus=parallel::detectCores())
mc.sde1d
## End(Not run)
## Example 3: (2 dim)
## dX(t) = 1/mu*(theta-X(t)) dt + sqrt(sigma) * dW1(t),
## dY(t) = X(t) dt + 0 * dW2(t)
## Not run:
## Set the model 2d
mu=0.75;sigma=0.1;theta=2
x0=0;y0=0;init=c(x=0,y=0)
f <- expression(1/mu*(theta-x), x)
g <- expression(sqrt(sigma),0)
OUI <- snssde2d(drift=f,diffusion=g,M=1000,Dt=0.01,x0=init)
## at time=5
mc.sde2d_a = MCM.sde(model=OUI,statistic=sde.fun2d,R=100,time=5,
exact=list(m1=E_x(5),m2=E_y(5),S1=V_x(5),S2=V_y(5),C12=cov_xy(5)),
parallel="snow",ncpus=parallel::detectCores())
mc.sde2d_a
plot(mc.sde2d_a,index=1)
plot(mc.sde2d_a,index=2)
## at time=10
38 MEM.sde
mc.sde2d_b = MCM.sde(model=OUI,statistic=sde.fun2d,R=100,time=10,
exact=list(m1=E_x(10),m2=E_y(10),S1=V_x(10),S2=V_y(10),C12=cov_xy(10)),
parallel="snow",ncpus=parallel::detectCores())
mc.sde2d_b
plot(mc.sde2d_b,index=1)
plot(mc.sde2d_b,index=2)
## End(Not run)
## Example 4: (3 dim)
## dX(t) = sigma*(Y(t)-X(t)) dt + 0.1 * dW1(t)
## dY(t) = (rho*X(t)-Y(t)-X(t)*Z(t)) dt + 0.1 * dW2(t)
## dZ(t) = (X(t)*Y(t)-bet*Z(t)) dt + 0.1 * dW3(t)
## W1(t), W2(t) and W3(t) are three correlated Brownian motions with Sigma
## Not run:
## Set the model 3d
sigma=10;rho=28; bet=8/3
f <- expression(sigma*(y-x),rho*x-y-x*z,x*y-bet*z)
g <- expression(0.1,0.1,0.1)
# correlation matrix
Sigma <-matrix(c(1,0.3,0.5,0.3,1,0.2,0.5,0.2,1),nrow=3,ncol=3)
mod3d <- snssde3d(x0=rep(0,3),drift=f,diffusion=g,M=1000,Dt=0.01,corr=Sigma)
## End(Not run)
Description
Calculate and numerical approximation of moment equations (Symbolic ODE’s of means and
variances-covariance) at any time for SDE’s (1,2 and 3 dim) for the two cases Ito and Stratonovich
interpretations.
Usage
MEM.sde(drift, diffusion, ...)
## Default S3 method:
MEM.sde(drift, diffusion, corr = NULL, type = c("ito", "str"), solve = FALSE,
MEM.sde 39
Arguments
drift drift coefficient: an expression 1-dim(t,x), 2-dim(t,x,y) or 3-dim(t,x,y,z).
diffusion diffusion coefficient: an expression 1-dim(t,x), 2-dim(t,x,y) or 3-dim(t,x,y,z).
corr the correlation coefficient ’|corr|<=1’ of W1(t) and W2(t) (2d) must be an ex-
pression length equal 1. And for 3d (W1(t),W2(t),W3(t)) an expressions length
equal 3. See examples.
type type of process "ito" or "Stratonovich"; the default type="ito".
solve if solve=TRUE solves a system of ordinary differential equations.
parms parameters passed to drift and diffusion.
init the initial (state) values for the ODE system. for 1-dim (m=x0,S=0), 2-dim
(m1=x0,m2=y0,S1=0,S2=0,C12=0) and for 3-dim (m1=x0,m2=y0,m3=z0,S1=0,S2=0,S3=0,C12=0,C13=
see examples.
time time sequence (vector) for which output is wanted; the first value of time must
be the initial time.
object, at an object inheriting from class "MEM.sde" and summaries at any time at.
... potentially arguments to be passed to methods, such as ode for solver for ODE’s.
Details
The stochastic transition is approximated by the moment equations, and the numerical treatment is
required to solve these equations from above with given initial conditions.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
Symbolic ODE’s of means and variances-covariance. If solve=TRUE approximate the moment of
SDE’s at any time.
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Rodriguez R, Tuckwell H (2000). A dynamical system for the approximate moments of nonlinear
stochastic models of spiking neurons and networks. Mathematical and Computer Modelling, 31(4),
175–180.
Alibrandi U, Ricciardi G (2012). Stochastic Methods in Nonlinear Structural Dynamics, 3–60.
Springer Vienna, Vienna. ISBN 978-3-7091-1306-6.
40 MEM.sde
See Also
MCM.sde Monte-Carlo methods for SDE’s.
Examples
library(deSolve)
## Example 1: 1-dim
## dX(t) = mu * X(t) * dt + sigma * X(t) * dW(t)
## Symbolic ODE's of mean and variance
f <- expression(mu*x)
g <- expression(sigma*x)
res1 <- MEM.sde(drift=f,diffusion=g,type="ito")
res2 <- MEM.sde(drift=f,diffusion=g,type="str")
res1
res2
## numerical approximation of mean and variance
para <- c(mu=2,sigma=0.5)
t <- seq(0,1,by=0.001)
init <- c(m=1,S=0)
res1 <- MEM.sde(drift=f,diffusion=g,solve=TRUE,init=init,parms=para,time=t)
res1
matplot.0D(res1$sol.ode,main="Mean and Variance of X(t), type Ito")
plot(res1$sol.ode,select=c("m","S"))
## approximation at time = 0.75
summary(res1,at=0.75)
##
res2 <- MEM.sde(drift=f,diffusion=g,solve=TRUE,init=init,parms=para,time=t,type="str")
res2
matplot.0D(res2$sol.ode,main="Mean and Variance of X(t), type Stratonovich")
plot(res2$sol.ode,select=c("m","S"))
## approximation at time = 0.75
summary(res2,at=0.75)
## Comparison:
## Example2: 2-dim
## dX(t) = 1/mu*(theta-X(t)) dt + sqrt(sigma) * dW1(t),
## dY(t) = X(t) dt + 0 * dW2(t)
## Not run:
para=c(mu=0.75,sigma=0.1,theta=2)
init=c(m1=0,m2=0,S1=0,S2=0,C12=0)
t <- seq(0,10,by=0.001)
f <- expression(1/mu*(theta-x), x)
g <- expression(sqrt(sigma),0)
res2d <- MEM.sde(drift=f,diffusion=g,solve=TRUE,init=init,parms=para,time=t)
res2d
MEM.sde 41
## Exact moment
mu=0.75;sigma=0.1;theta=2;x0=0;y0=0
E_x <- function(t) theta+(x0-theta)*exp(-t/mu)
V_x <- function(t) 0.5*sigma*mu *(1-exp(-2*(t/mu)))
E_y <- function(t) y0+theta*t+(x0-theta)*mu*(1-exp(-t/mu))
V_y <- function(t) sigma*mu^3*((t/mu)-2*(1-exp(-t/mu))+0.5*(1-exp(-2*(t/mu))))
cov_xy <- function(t) 0.5*sigma*mu^2 *(1-2*exp(-t/mu)+exp(-2*(t/mu)))
##
summary(res2d,at=5)
E_x(5);E_y(5);V_x(5);V_y(5);cov_xy(5)
matplot.0D(res2d$sol.ode,select=c("m1"))
curve(E_x,add=TRUE,col="red")
## plot
plot(res2d$sol.ode)
matplot.0D(res2d$sol.ode,select=c("S1","S2","C12"))
plot(res2d$sol.ode[,"m1"], res2d$sol.ode[,"m2"], xlab = "m1(t)",
ylab = "m2(t)", type = "l",lwd = 2)
hist(res2d$sol.ode,select=c("m1","m2"), col = c("darkblue", "red", "orange", "black"))
## Numerical approximation
RHO <- expression(0.5)
para=c(mu=1,lambda=3,theta=0.5,sigma=0.1)
ini=c(m1=10,m2=2,S1=0,S2=0,C12=0)
res2d = MEM.sde(drift=f,diffusion=g,solve=TRUE,parms=para,init=ini,time=seq(0,1,by=0.01))
res2d
matplot.0D(res2d$sol.ode,select=c("m1","m2"))
matplot.0D(res2d$sol.ode,select=c("S1","S2","C12"))
## Example4: 3-dim
## dX(t) = sigma*(Y(t)-X(t)) dt + 0.1 * dW1(t)
## dY(t) = (rho*X(t)-Y(t)-X(t)*Z(t)) dt + 0.1 * dW2(t)
## dZ(t) = (X(t)*Y(t)-bet*Z(t)) dt + 0.1 * dW3(t)
## with E(dw1dw2)=rho1, E(dw1dw3)=rho2 and E(dw2dw3)=rho3
42 moment
f <- expression(sigma*(y-x),rho*x-y-x*z,x*y-bet*z)
g <- expression(0.1,0.1,0.1)
RHO <- expression(rho1,rho2,rho3)
## Symbolic moments equations
res3d = MEM.sde(drift=f,diffusion=g,corr=RHO)
res3d
## Numerical approximation
RHO <- expression(0.5,0.2,-0.7)
para=c(sigma=10,rho=28,bet=8/3)
ini=c(m1=1,m2=1,m3=1,S1=0,S2=0,S3=0,C12=0,C13=0,C23=0)
res3d = MEM.sde(drift=f,diffusion=g,solve=T,parms=para,init=ini,time=seq(0,1,by=0.01))
res3d
summary(res3d,at=0.25)
summary(res3d,at=0.50)
summary(res3d,at=0.75)
plot(res3d$sol.ode)
matplot.0D(res3d$sol.ode,select=c("m1","m2","m3"))
matplot.0D(res3d$sol.ode,select=c("S1","S2","S3"))
matplot.0D(res3d$sol.ode,select=c("C12","C13","C23"))
## End(Not run)
Description
Generic function for compute the kurtosis, skewness, median, mode and coefficient of variation
(relative variability), moment and confidence interval of class "sde".
Usage
## Default S3 method:
bconfint(x, level = 0.95, ...)
## Default S3 method:
kurtosis(x, ...)
## Default S3 method:
moment(x, order = 1,center = TRUE, ...)
## Default S3 method:
cv(x, ...)
## Default S3 method:
plot2d 43
skewness(x, ...)
## Default S3 method:
Median(x, ...)
## Default S3 method:
Mode(x, ...)
Arguments
Author(s)
Examples
## Example 1:
## dX(t) = 2*(3-X(t)) *dt + dW(t)
set.seed(1234)
Description
Usage
## Default S3 method:
plot2d(x, ...)
## Default S3 method:
lines2d(x, ...)
## Default S3 method:
points2d(x, ...)
## Default S3 method:
plot3D(x, display = c("persp","rgl"), ...)
Arguments
Details
Author(s)
Examples
## Example 1:
set.seed(1234)
fx <- rep(expression(0),2)
gx <- rep(expression(1),2)
Description
Transition density and random generation for X(t-s) | X(s)=x0 of the 1-dim SDE.
rsde1d 45
Usage
rsde1d(object, ...)
dsde1d(object, ...)
## Default S3 method:
rsde1d(object, at, ...)
## Default S3 method:
dsde1d(object, at, ...)
## S3 method for class 'dsde1d'
plot(x,hist=FALSE, ...)
Arguments
object an object inheriting from class snssde1d and bridgesde1d.
at time between s=t0 and t=T. The default at = T.
x an object inheriting from class dsde1d.
hist if hist=TRUE plot histogram. Based on truehist function.
... potentially arguments to be passed to methods, such as density for kernel den-
sity.
Details
The function rsde1d returns a M random variable xt=at realize at time t = at defined by :
xt=at = {t ≥ 0; x = Xt=at }
And dsde1d returns a transition density approximation for X(t-s) | X(s)=x0. with t = at is a
fixed time between t0 and T.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
dsde1d gives the transition density estimate of X(t-s) | X(s)=x0. rsde1d generates random of
X(t-s) | X(s)=x0.
Author(s)
A.C. Guidoum, K. Boukhetala.
See Also
density Kernel density estimation in "stats" package.
kde Kernel density estimate for 1- to 6-dimensional data in "ks" package.
sm.density Nonparametric density estimation in one, two or three dimensions in "sm" package.
rng random number generators in "yuima" package.
46 rsde1d
Examples
## Example 1:
## dX(t) = (-2*(X(t)<=0)+2*(X(t)>=0)) *dt + 0.5 * dW(t)
set.seed(1234)
f <- expression(-2*(x<=0)+2*(x>=0))
g <- expression(0.5)
res1 <- snssde1d(drift=f,diffusion=g,M=5000)
x <- rsde1d(res1, at = 1)
summary(x)
dens1 <- dsde1d(res1, at = 1)
dens1
plot(dens1,main="Transition density of X(t=1)|X(s=0)=0") # kernel estimated
plot(dens1,hist=TRUE) # histogramme
## Example 2:
## Transition density of standard Brownian motion W(t) at time = 0.5
set.seed(1234)
f <- expression(0)
g <- expression(1)
res2 <- snssde1d(drift=f,diffusion=g,M=5000)
plot(dsde1d(res2, at = 0.5),dens=function(x) dnorm(x,0,sqrt(0.5)))
plot(dsde1d(res2, at = 0.5),dens=function(x) dnorm(x,0,sqrt(0.5)),hist=TRUE)
## Not run:
for (i in seq(res2$t0,res2$T,by=res2$Dt)){
plot(dsde1d(res2, at = i),main=paste0('Transition Density \n t = ',i))
}
## End(Not run)
## Example 4:
## Transition density of bridge Brownian motion W(t) at time = 0.25 and 0.75
set.seed(1234)
## Not run:
f <- expression(0)
g <- expression(1)
Bd <- bridgesde1d(drift=f,diffusion=g,M=5000)
Bd
plot(dsde1d(Bd, at = 0.25)) ## Transition Density at time=0.25
rsde2d 47
## End(Not run)
Description
Transition density and random generation for the joint and marginal of (X(t-s),Y(t-s) | X(s)=x0,Y(s)=y0)
of the SDE’s 2-d.
Usage
rsde2d(object, ...)
dsde2d(object, ...)
## Default S3 method:
rsde2d(object, at, ...)
## Default S3 method:
dsde2d(object, pdf=c("Joint","Marginal"), at, ...)
## S3 method for class 'dsde2d'
plot(x,display=c("persp","rgl","image","contour"),hist=FALSE,...)
Arguments
object an object inheriting from class snssde2d and bridgesde2d.
at time between s=t0 and t=T. The default at = T.
pdf probability density function Joint or Marginal.
x an object inheriting from class dsde2d.
display display plots.
hist if hist=TRUE plot histogram. Based on truehist function.
... potentially potentially arguments to be passed to methods, such as density for
marginal density and kde2d fro joint density.
Details
The function rsde2d returns a M random variable xt=at , yt=at realize at time t = at.
And dsde2d returns a bivariate density approximation for (X(t-s),Y(t-s) | X(s)=x0,Y(s)=y0).
with t = at is a fixed time between t0 and T.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
48 rsde2d
Value
dsde2d gives the bivariate density approximation for (X(t-s),Y(t-s) | X(s)=x0,Y(s)=y0). rsde2d
generates random of the couple (X(t-s),Y(t-s) | X(s)=x0,Y(s)=y0).
Author(s)
A.C. Guidoum, K. Boukhetala.
See Also
kde2d Two-dimensional kernel density estimation in "MASS" package.
kde Kernel density estimate for 1- to 6-dimensional data in "ks" package.
sm.density Nonparametric density estimation in one, two or three dimensions in "sm" package.
rng random number generators in "yuima" package.
BiGQD.density Generate the transition density of a bivariate generalized quadratic diffusion model
(2D GQD) in "DiffusionRgqd" package.
Examples
## Example:1
set.seed(1234)
# SDE's 2d
fx <- expression(3*(2-y),2*x)
gx <- expression(1,y)
mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(1,2),M=1000)
# random
r2d <- rsde2d(mod2d,at=0.5)
summary(r2d)
# Marginal density
# Joint density
denJ <- dsde2d(mod2d,pdf="J",n=200, at= 0.5,lims=c(-3,4,0,6))
denJ
plot(denJ)
plot(denJ,display="contour")
## Not run:
B2d <- snssde2d(drift=rep(expression(0),2),diffusion=rep(expression(1),2),
M=10000)
for (i in seq(B2d$Dt,B2d$T,by=B2d$Dt)){
plot(dsde2d(B2d, at = i,lims=c(-3,3,-3,3),n=100),
rsde2d 49
## End(Not run)
## Example 3:
## Not run:
fx <- expression(4*(-1-x)*y , 4*(1-y)*x )
gx <- expression(0.25*y,0.2*x)
mod2d1 <- snssde2d(drift=fx,diffusion=gx,x0=c(x0=1,y0=-1),
M=5000,type="str")
## End(Not run)
## Not run:
B2d <- bridgesde2d(drift=rep(expression(0),2),
diffusion=rep(expression(1),2),M=5000)
for (i in seq(0.01,0.99,by=B2d$Dt)){
plot(dsde2d(B2d, at = i,lims=c(-3,3,-3,3),
n=100),display="contour",main=
paste0('Transition Density \n t = ',i))
}
## End(Not run)
## End(Not run)
Description
Transition density and random generation for the joint and marginal of (X(t-s),Y(t-s),Z(t-s) |
X(s)=x0,Y(s)=y0,Z(s)=z0) of the SDE’s 3-d.
Usage
rsde3d(object, ...)
dsde3d(object, ...)
## Default S3 method:
rsde3d(object, at, ...)
## Default S3 method:
dsde3d(object, pdf=c("Joint","Marginal"), at, ...)
## S3 method for class 'dsde3d'
plot(x,display="rgl",hist=FALSE,...)
Arguments
object an object inheriting from class snssde3d and bridgesde3d.
at time between s=t0 and t=T. The default at = T.
pdf probability density function Joint or Marginal.
x an object inheriting from class dsde3d.
display display plots.
hist if hist=TRUE plot histogram. Based on truehist function.
... potentially arguments to be passed to methods, such as density for marginal
density and sm.density for joint density.
Details
The function rsde3d returns a M random variable xt=at , yt=at , zt=at realize at time t = at.
And dsde3d returns a trivariate kernel density approximation for (X(t-s),Y(t-s),Z(t-s) | X(s)=x0,Y(s)=y0,Z(s)=z0).
with t = at is a fixed time between t0 and T.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
rsde3d 51
Value
dsde3d gives the trivariate density approximation (X(t-s),Y(t-s),Z(t-s) | X(s)=x0,Y(s)=y0,Z(s)=z0).
rsde3d generates random of the (X(t-s),Y(t-s),Z(t-s) | X(s)=x0,Y(s)=y0,Z(s)=z0).
Author(s)
A.C. Guidoum, K. Boukhetala.
See Also
kde Kernel density estimate for 1- to 6-dimensional data in "ks" package.
sm.density Nonparametric density estimation in one, two or three dimensions in "sm" package.
kde3d Compute a three dimension kernel density estimate in "misc3d" package.
rng random number generators in "yuima" package.
rcBS, rcCIR, rcOU and rsOU in package "sde".
Examples
# random at t= 0.75
r3d1 <- rsde3d(mod3d1,at=0.75)
summary(r3d1)
## End(Not run)
# random
r3d2 <- rsde3d(mod3d2)
summary(r3d2)
## End(Not run)
## Not run:
B3d <- snssde3d(drift=rep(expression(0),3),diffusion=rep(expression(1),3),M=500)
for (i in seq(B3d$Dt,B3d$T,by=B3d$Dt)){
plot(dsde3d(B3d, at = i,pdf="J"),box=F,main=paste0('Transition Density t = ',i))
}
## End(Not run)
Description
The (S3) generic function snssde1d of simulation of solution to 1-dim stochastic differential equa-
tion of Itô or Stratonovich type, with different methods.
Usage
snssde1d(N, ...)
## Default S3 method:
snssde1d 53
Arguments
N number of simulation steps.
M number of trajectories (Monte-Carlo).
x0 initial value of the process at time t0.
t0 initial time.
T ending time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
54 snssde1d
Details
The function snssde1d returns a ts x of length N+1; i.e. solution of the sde of Ito or Stratonovich
types; If Dt is not specified, then the best discretization ∆t = T −t
N .
0
Stratonovich sde :
dX(t) = a(t, X(t))dt + b(t, X(t)) ◦ dW (t)
The methods of approximation are classified according to their different properties. Mainly two
criteria of optimality are used in the literature: the strong and the weak (orders of) convergence.
The method of simulation can be one among: Euler-Maruyama Order 0.5, Milstein Order 1,
Milstein Second-Order, Predictor-Corrector method, Itô-Taylor Order 1.5, Heun Order 2
and Runge-Kutta Order 1,2 and 3.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Value
snssde1d returns an object inheriting from class "snssde1d".
X an invisible ts object.
drift drift coefficient.
diffusion diffusion coefficient.
type type of sde.
method the numerical method used.
Author(s)
A.C. Guidoum, K. Boukhetala.
snssde1d 55
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Friedman, A. (1975). Stochastic differential equations and applications. Volume 1, ACADEMIC
PRESS.
Henderson, D. and Plaschko,P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
Allen, E. (2007). Modeling with Ito stochastic differential equations. Springer-Verlag.
Jedrzejewski, F. (2009). Modeles aleatoires et physique probabiliste. Springer-Verlag.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York.
Kloeden, P.E, and Platen, E. (1989). A survey of numerical methods for stochastic differential
equations. Stochastic Hydrology and Hydraulics, 3, 155–178.
Kloeden, P.E, and Platen, E. (1991a). Relations between multiple ito and stratonovich integrals.
Stochastic Analysis and Applications, 9(3), 311–321.
Kloeden, P.E, and Platen, E. (1991b). Stratonovich and ito stochastic taylor expansions. Mathema-
tische Nachrichten, 151, 33–50.
Kloeden, P.E, and Platen, E. (1995). Numerical Solution of Stochastic Differential Equations.
Springer-Verlag, New York.
Oksendal, B. (2000). Stochastic Differential Equations: An Introduction with Applications. 5th
edn. Springer-Verlag, Berlin.
Platen, E. (1980). Weak convergence of approximations of ito integral equations. Z Angew Math
Mech. 60, 609–614.
Platen, E. and Bruti-Liberati, N. (2010). Numerical Solution of Stochastic Differential Equations
with Jumps in Finance. Springer-Verlag, New York
Saito, Y, and Mitsui, T. (1993). Simulation of Stochastic Differential Equations. The Annals of the
Institute of Statistical Mathematics, 3, 419–432.
See Also
snssde2d and snssde3d for 2 and 3-dim sde.
sde.sim in package "sde".
simulate in package "yuima".
Examples
f <- expression(2*(3-x) )
g <- expression(1)
56 snssde2d
## End(Not run)
## Example 2: Stratonovich sde
## dX(t) = ((2-X(t))/(2-t)) dt + X(t) o dW(t)
set.seed(1234)
f <- expression((2-x)/(2-t))
g <- expression(x)
mod2 <- snssde1d(type="str",drift=f,diffusion=g,M=4000,x0=1, method="milstein")
mod2
summary(mod2,at = 0.25)
summary(mod2,at = 1)
## Not run:
plot(mod2)
lines(time(mod2),apply(mod2$X,1,mean),col=2,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[1,],col=4,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[2,],col=4,lwd=2)
legend("topleft",c("mean path",paste("bound of", 95," percent confidence")),
inset = .01,col=c(2,4),lwd=2,cex=0.8)
## End(Not run)
Description
The (S3) generic function snssde2d of simulation of solutions to 2-dim stochastic differential equa-
tions of Itô or Stratonovich type, with different methods.
Usage
snssde2d(N, ...)
## Default S3 method:
snssde2d(N = 1000, M = 1, x0 = c(0,0),t0 = 0, T = 1, Dt,
drift, diffusion, corr = NULL, type = c("ito", "str"), alpha = 0.5, mu = 0.5,
method = c("euler", "milstein", "predcorr", "smilstein", "taylor",
"heun", "rk1", "rk2","rk3"), ...)
snssde2d 57
Arguments
N number of simulation steps.
M number of trajectories (Monte-Carlo).
x0 initial values x0=(x,y) of the process Xt and Yt at time t0.
t0 initial time.
T ending time.
58 snssde2d
drift drift coefficient: an expression of three variables t, x and y for process Xt and
Yt .
diffusion diffusion coefficient: an expression of three variables t, x and y for process
Xt and Yt .
corr the correlation structure of two Brownian motions W1(t) and W2(t); must be a
real symmetric positive-definite square matrix of dimension 2.
type if type="ito" simulation sde of Itô type, else type="str" simulation sde of
Stratonovich type; the default type="ito".
alpha, mu weight of the predictor-corrector scheme; the default alpha = 0.5 and mu = 0.5.
method numerical methods of simulation, the default method = "euler".
x, object an object inheriting from class "snssde2d".
at time between t0 and T. Monte-Carlo statistics of the solutions (Xt , Yt ) at time
at. The default at = T.
digits integer, used for number formatting.
... potentially further arguments for (non-default) methods.
Details
The function snssde2d returns a mts x of length N+1; i.e. solution of the 2-dim sde (Xt , Yt ) of Ito
or Stratonovich types; If Dt is not specified, then the best discretization ∆t = T −t
N .
0
Value
snssde2d returns an object inheriting from class "snssde2d".
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Friedman, A. (1975). Stochastic differential equations and applications. Volume 1, ACADEMIC
PRESS.
Henderson, D. and Plaschko,P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
Allen, E. (2007). Modeling with Ito stochastic differential equations. Springer-Verlag.
Jedrzejewski, F. (2009). Modeles aleatoires et physique probabiliste. Springer-Verlag.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York.
Kloeden, P.E, and Platen, E. (1989). A survey of numerical methods for stochastic differential
equations. Stochastic Hydrology and Hydraulics, 3, 155–178.
Kloeden, P.E, and Platen, E. (1991a). Relations between multiple ito and stratonovich integrals.
Stochastic Analysis and Applications, 9(3), 311–321.
Kloeden, P.E, and Platen, E. (1991b). Stratonovich and ito stochastic taylor expansions. Mathema-
tische Nachrichten, 151, 33–50.
Kloeden, P.E, and Platen, E. (1995). Numerical Solution of Stochastic Differential Equations.
Springer-Verlag, New York.
Oksendal, B. (2000). Stochastic Differential Equations: An Introduction with Applications. 5th
edn. Springer-Verlag, Berlin.
Platen, E. (1980). Weak convergence of approximations of ito integral equations. Z Angew Math
Mech. 60, 609–614.
Platen, E. and Bruti-Liberati, N. (2010). Numerical Solution of Stochastic Differential Equations
with Jumps in Finance. Springer-Verlag, New York
Saito, Y, and Mitsui, T. (1993). Simulation of Stochastic Differential Equations. The Annals of the
Institute of Statistical Mathematics, 3, 419–432.
60 snssde2d
See Also
snssde3d for 3-dim sde.
simulate in package "yuima".
Examples
set.seed(1234)
Sigma <- matrix(c(0.9,0.3,0.3,0.4),nrow=2,ncol=2) # correlation structure
mod2d1 <- snssde2d(drift=fx,diffusion=gx,corr=Sigma,x0=c(x0=1,y0=-1),M=1000)
mod2d1
summary(mod2d1)
##
dev.new()
plot(mod2d1,type="n")
mx <- apply(mod2d1$X,1,mean)
my <- apply(mod2d1$Y,1,mean)
lines(time(mod2d1),mx,col=1)
lines(time(mod2d1),my,col=2)
legend("topright",c(expression(E(X[t])),expression(E(Y[t]))),lty=1,inset = .01,col=c(1,2),cex=0.95)
##
dev.new()
plot2d(mod2d1) ## in plane (O,X,Y)
lines(my~mx,col=2)
Description
The (S3) generic function snssde3d of simulation of solutions to 3-dim stochastic differential equa-
tions of Itô or Stratonovich type, with different methods.
Usage
snssde3d(N, ...)
## Default S3 method:
snssde3d(N = 1000, M =1, x0=c(0,0,0), t0 = 0, T = 1, Dt,
drift, diffusion, corr = NULL, alpha = 0.5, mu = 0.5, type = c("ito", "str"),
method = c("euler", "milstein","predcorr", "smilstein", "taylor",
"heun", "rk1", "rk2", "rk3"), ...)
Arguments
N number of simulation steps.
M number of trajectories.
x0 initial value of the process Xt , Yt and Zt at time t0.
t0 initial time.
T ending time.
Dt time step of the simulation (discretization). If it is missing a default ∆t =
T −t0
N .
drift drift coefficient: an expression of four variables t, x, y and z for process Xt ,
Yt and Zt .
diffusion diffusion coefficient: an expression of four variables t, x, y and z for process
Xt , Yt and Zt .
corr the correlation structure of three Brownian motions W1(t), W2(t) and W3(t);
must be a real symmetric positive-definite square matrix of dimension 3.
alpha, mu weight of the predictor-corrector scheme; the default alpha = 0.5 and mu = 0.5.
type if type="ito" simulation sde of Itô type, else type="str" simulation sde of
Stratonovich type; the default type="ito".
method numerical methods of simulation, the default method = "euler".
x, object an object inheriting from class "snssde3d".
at time between t0 and T. Monte-Carlo statistics of the solutions (Xt , Yt , Zt ) at
time at. The default at = T.
digits integer, used for number formatting.
display "persp" perspective or "rgl" plots.
... potentially further arguments for (non-default) methods.
snssde3d 63
Details
The function snssde3d returns a mts x of length N+1; i.e. solution of the 3-dim sde (Xt , Yt , Zt ) of
Ito or Stratonovich types; If Dt is not specified, then the best discretization ∆t = T −t
N .
0
dX(t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t))dW1 (t)
dY (t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t))dW2 (t)
dZ(t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t))dW3 (t)
dX(t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t)) ◦ dW1 (t)
dY (t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t)) ◦ dW2 (t)
dZ(t) = a(t, X(t), Y (t), Z(t))dt + b(t, X(t), Y (t), Z(t)) ◦ dW3 (t)
Value
Author(s)
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Friedman, A. (1975). Stochastic differential equations and applications. Volume 1, ACADEMIC
PRESS.
Henderson, D. and Plaschko,P. (2006). Stochastic differential equations in science and engineering.
World Scientific.
Allen, E. (2007). Modeling with Ito stochastic differential equations. Springer-Verlag.
Jedrzejewski, F. (2009). Modeles aleatoires et physique probabiliste. Springer-Verlag.
Iacus, S.M. (2008). Simulation and inference for stochastic differential equations: with R examples.
Springer-Verlag, New York.
Kloeden, P.E, and Platen, E. (1989). A survey of numerical methods for stochastic differential
equations. Stochastic Hydrology and Hydraulics, 3, 155–178.
Kloeden, P.E, and Platen, E. (1991a). Relations between multiple ito and stratonovich integrals.
Stochastic Analysis and Applications, 9(3), 311–321.
Kloeden, P.E, and Platen, E. (1991b). Stratonovich and ito stochastic taylor expansions. Mathema-
tische Nachrichten, 151, 33–50.
Kloeden, P.E, and Platen, E. (1995). Numerical Solution of Stochastic Differential Equations.
Springer-Verlag, New York.
Oksendal, B. (2000). Stochastic Differential Equations: An Introduction with Applications. 5th
edn. Springer-Verlag, Berlin.
Platen, E. (1980). Weak convergence of approximations of ito integral equations. Z Angew Math
Mech. 60, 609–614.
Platen, E. and Bruti-Liberati, N. (2010). Numerical Solution of Stochastic Differential Equations
with Jumps in Finance. Springer-Verlag, New York
Saito, Y, and Mitsui, T. (1993). Simulation of Stochastic Differential Equations. The Annals of the
Institute of Statistical Mathematics, 3, 419–432.
See Also
snssde1d and snssde2d for 1- and 2-dim sde.
sde.sim in package "sde". simulate in package "yuima".
Examples
gx <- rep(expression(0.2),3)
Description
The (S3) generic function st.int of simulation of stochastic integrals of Itô or Stratonovich type.
66 st.int
Usage
st.int(expr, ...)
## Default S3 method:
st.int(expr, lower = 0, upper = 1, M = 1, subdivisions = 1000L,
type = c("ito", "str"), ...)
Arguments
expr an expression of two variables t (time) and w (w: standard Brownian motion).
lower, upper the lower and upper end points of the interval to be integrate.
M number of trajectories (Monte-Carlo).
subdivisions the maximum number of subintervals.
type Itô or Stratonovich integration.
st.int 67
Details
The function st.int returns a ts x of length N+1; i.e. simulation of stochastic integrals of Itô or
Stratonovich type.
The Itô interpretation is:
Z t N
X
f (s)dWs = lim f (ti−1 )(Wti − Wti−1 )
t0 N →∞
i=1
Value
st.int returns an object inheriting from class "st.int".
Author(s)
A.C. Guidoum, K. Boukhetala.
References
Ito, K. (1944). Stochastic integral. Proc. Jap. Acad, Tokyo, 20, 19–529.
Stratonovich RL (1966). New Representation for Stochastic Integrals and Equations. SIAM Journal
on Control, 4(2), 362–371.
Kloeden, P.E, and Platen, E. (1995). Numerical Solution of Stochastic Differential Equations.
Springer-Verlag, New York.
Oksendal, B. (2000). Stochastic Differential Equations: An Introduction with Applications. 5th
edn. Springer-Verlag, Berlin.
68 TEX.sde
See Also
Examples
g <- expression( w )
mod2 <- st.int(expr=g,type="str",M=50,lower=0,upper=1)
mod2
summary(mod2)
## Display
plot(mod2)
lines(time(mod2),apply(mod2$X,1,mean),col=2,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[1,],col=4,lwd=2)
lines(time(mod2),apply(mod2$X,1,bconfint,level=0.95)[2,],col=4,lwd=2)
legend("topleft",c("mean path",paste("bound of", 95," percent confidence")),
inset = .01,col=c(2,4),lwd=2,cex=0.8)
Description
These methods produces the related LaTeX table and mathematic expression for Sim.DiffProc en-
vironment.
TEX.sde 69
Usage
TEX.sde(object, ...)
## Default S3 method:
TEX.sde(object, ...)
Arguments
object an objects from class MCM.sde and MEM.sde. Or an R vector of expression of
SDEs, i.e., drift and diffusion coefficients.
... arguments to be passed to kable function if object from class MCM.sde.
Details
New tools for constructing tables and mathematical expressions with Sim.DiffProc package.
An overview of this package, see browseVignettes('Sim.DiffProc') for more informations.
Author(s)
A.C. Guidoum
References
Guidoum AC, Boukhetala K (2020). "Performing Parallel Monte Carlo and Moment Equations
Methods for Itô and Stratonovich Stochastic Differential Systems: R Package Sim.DiffProc". Jour-
nal of Statistical Software, 96(2), 1–82. doi:10.18637/jss.v096.i02
Xie Y (2015). Dynamic Documents with R and knitr. 2nd edition. Chapman and Hall/CRC, Boca
Raton, Florida. ISBN 978-1498716963, URL https://yihui.org/knitr/.
Wickham H (2015). Advanced R. Chapman & Hall/CRC The R Series. CRC Press. ISBN
9781498759809.
See Also
kable create tables in LaTeX, HTML, Markdown and reStructuredText.
toLatex converting R Objects to BibTeX or LaTeX.
Examples
# Example 1
f <- expression(-mu1 * x)
g <- expression(mu2 * sqrt(x))
TEX.sde(object = c(drift = f, diffusion = g))
# Example 2
70 TEX.sde
f <- expression(mu1*cos(mu2+z),mu1*sin(mu2+z),0)
g <- expression(sigma,sigma,alpha)
TEX.sde(object = c(drift = f, diffusion = g))
# Example 3
# Example 4
## Not run:
mu1=0.25; mu2=3; sigma=0.05; alpha=0.03
mod3d <- snssde3d(drift=f,diffusion=g,x0=c(x=0,y=0,z=0),M=100,T=10)
## End(Not run)
Index
∗ BM bridgesde1d, 8
BM, 6 bridgesde2d, 12
∗ LaTeX bridgesde3d, 15
TEX.sde, 68 fitsde, 18
∗ Monte-Carlo fptsde1d, 21
MCM.sde, 34 fptsde2d, 25
∗ datasets fptsde3d, 28
Irates, 33 HWV, 31
∗ fit MCM.sde, 34
fitsde, 18 MEM.sde, 38
∗ fpt rsde1d, 44
fptsde1d, 21 rsde2d, 47
fptsde2d, 25 rsde3d, 50
fptsde3d, 28 snssde1d, 52
∗ moment equations snssde2d, 56
MEM.sde, 38 snssde3d, 61
∗ mts st.int, 65
bridgesde1d, 8 ∗ transition density
bridgesde2d, 12 rsde1d, 44
bridgesde3d, 15 rsde2d, 47
fptsde2d, 25 rsde3d, 50
fptsde3d, 28 ∗ ts
MCM.sde, 34 BM, 6
rsde1d, 44 bridgesde1d, 8
rsde2d, 47 bridgesde2d, 12
rsde3d, 50 bridgesde3d, 15
snssde1d, 52 fitsde, 18
snssde2d, 56 fptsde1d, 21
snssde3d, 61 fptsde2d, 25
∗ package fptsde3d, 28
Sim.DiffProc-package, 2 HWV, 31
∗ parallel MCM.sde, 34
MCM.sde, 34 rsde1d, 44
∗ random generators rsde2d, 47
rsde1d, 44 rsde3d, 50
rsde2d, 47 snssde1d, 52
rsde3d, 50 snssde2d, 56
∗ sde snssde3d, 61
BM, 6 st.int, 65
71
72 INDEX
rsde1d, 44
rsde2d, 47
rsde3d, 50
Sim.DiffProc (Sim.DiffProc-package), 2
Sim.DiffProc-package, 2
skewness (moment), 42
skewness.bridgesde1d (bridgesde1d), 8
skewness.bridgesde2d (bridgesde2d), 12
skewness.bridgesde3d (bridgesde3d), 15
skewness.fptsde1d (fptsde1d), 21
skewness.fptsde2d (fptsde2d), 25
skewness.fptsde3d (fptsde3d), 28
skewness.snssde1d (snssde1d), 52
skewness.snssde2d (snssde2d), 56
skewness.snssde3d (snssde3d), 61
skewness.st.int (st.int), 65
sm.density, 29, 50
snssde1d, 10, 22, 35, 45, 52, 64, 68
snssde2d, 13, 25, 35, 44, 47, 55, 56, 64, 68
snssde3d, 16, 29, 35, 44, 50, 55, 60, 61, 68
st.int, 65
summary.bridgesde1d (bridgesde1d), 8
summary.bridgesde2d (bridgesde2d), 12