Sim.DiffProc-package: Simulation of Diffusion Processes
Description
The package Sim.DiffProc is an object created in R environment for simulation and modeling of stochastic differential equations
(SDEs) the type Ito and Stratonovich. This package contains many objects and functions, for example the numerical methods to find the solutions to SDEs (1, 2 and 3-dim),
with a possibility for simulates a flows trajectories,with good accuracy. Many theoretical problems on the SDEs have become the object of
practical research, as statistical analysis and simulation of solution of SDEs, enabled many searchers in different domains to use these
equations to modeling and to analyse practical problems, in financial and actuarial modeling and other areas of application, for example
modelling and simulate of dispersion in shallow water using the attractive center (Boukhetala K, 1996). We hope that the package presented
here and the updated survey on the subject might be of help for practitioners, postgraduate and PhD students, and researchers in the field
who might want to implement new methods.href
- http://CRAN.R-project.org/package=#1
- http://www.usthb.dz/en/
- http://www.r-project.org
pkg
#1Main Features
stochastic integrals:
We consider a simple example to simulation Ito integral, used st.int function:
$$\int_{t_{0}}^{t} W_{s}^{n} dW_{s} = \frac{1}{n+1} \left[W_{t}^{n+1} - W_{t_{0}}^{n+1}\right]- \frac{n}{2} \int_{t_{0}}^{t} W_{s}^{n-1} ds$$
And the Stratonovich integral
$$\int_{t_{0}}^{t} W_{s}^{n} \circ dW_{s} = \frac{1}{n+1} \left[W_{t}^{n+1} - W_{t_{0}}^{n+1}\right]$$
R> fexpr <- expression( w^2 )
R> ito <- st.int(fexpr,type="ito",M=1,lower=0,upper=1)
R> ito
Ito integral:
| X(t) = integral (f(s,w) * dw(s))
| f(t,w) = w^2
Summary:
| Number of subintervals = 1000.
| Number of simulations = 1.
| Limits of integration = [0,1].
| Discretization = 0.001.
R> str <- st.int(fexpr,type="str",M=1,lower=0,upper=1)
R> str
Stratonovich integral:
| X(t) = integral (f(s,w) o dw(s))
| f(t,w) = w^2
Summary:
| Number of subintervals = 1000.
| Number of simulations = 1.
| Limits of integration = [0,1].
| Discretization = 0.001.
SDE's 1,2 and 3-dim:
There are thus two widely used types of stochastic calculus, Stratonovich and Ito, differing in respect of the stochastic integral used. Modelling issues typically dictate which version in appropriate, but once one has been chosen a corresponding equation of the other type with the same solutions can be determined. Thus it is possible to switch between the two stochastic calculi. Specifically, the processes ${ X_{t}, t \geq 0 }$ solution to the Ito SDE:
$$dX_{t} = f(t,X_{t}) dt + g(t,X_{t}) dW_{t}$$
where ${ W_{t}, t \geq 0 }$ is the standard Wiener process or standard Brownian motion, the drift $f(t,X_{t})$ and diffusion $g(t,X_{t})$ are known functions that are assumed to be sufficiently regular (Lipschitz, bounded growth) for existence and uniqueness of solution; has the same solutions as the Stratonovich SDE:
$$dX_{t} = \underline{f}(t,X_{t}) dt + g(t,X_{t}) \circ dW_{t}$$
with the modified drift coefficient
$$\underline{f}(t,X_{t})= f(t,X_{t}) - \frac{1}{2} g(t,X_{t})\frac{\partial g}{\partial x}(t,X_{t})$$
The following examples for different methods of simulation of SDEs (1,2 and 3-dim) use the snssde1d, snssde2d and snssde3d functions.
R> ## 1-dim sde
R> f <- expression(2*(3-x) )
R> g <- expression(2*x)
R> res1 <- snssde1d(drift=f,diffusion=g,M=10,x0=1,N=1000)
R> res1
Ito Sde 1D:
| dx = 2 * (3 - x) * dt + 2 * x * dw
Method:
| Euler scheme of order 0.5
Summary:
| Size of process | N = 1000.
| Number of simulation | M = 10.
| Initial value | x0 = 1.
| Time of process | t in [0,1].
| Discretization | Dt = 0.001.
R> res2 <- snssde1d(drift=f,diffusion=g,M=10,x0=1,N=1000,type="str")
R> res2
Stratonovich Sde 1D:
| dx = 2 * (3 - x) * dt + 2 * x o dw
Method:
| Euler scheme of order 0.5
Summary:
| Size of process | N = 1000.
| Number of simulation | M = 10.
| Initial value | x0 = 1.
| Time of process | t in [0,1].
| Discretization | Dt = 0.001.
R> ## 2-dim sde
R> fx <- expression(x-y)
R> gx <- expression(2*y)
R> fy <- expression(y-x)
R> gy <- expression(2*x)
R> res2d <- snssde2d(driftx=fx,diffx=gx,drifty=fy,diffy=gy,N=1000,x0=1,y0=1)
R> res2d
Ito Sde 2D:
| dx = x - y * dt + 2 * y * dw1
| dy = y - x * dt + 2 * x * dw2
Method:
| Euler scheme of order 0.5
Summary:
| Size of process | N = 1000.
| Initial values | (x0,y0) = (1,1).
| Time of process | t in [0,1].
| Discretization | Dt = 0.001.
R> plot2d(res2d)
R> ## 3-dim sde
R> fx <- expression(y)
R> gx <- expression(z)
R> fy <- expression(0)
R> gy <- expression(1)
R> fz <- expression(0)
R> gz <- expression(1)
R> res3d <- snssde3d(driftx=fx,diffx=gx,drifty=fy,diffy=gy,driftz=fz,
+ diffz=gz,N=1000)
R> res3d
Ito Sde 3D:
| dx = y * dt + z * dw1
| dy = 0 * dt + 1 * dw2
| dz = 0 * dt + 1 * dw3
Method:
| Euler scheme of order 0.5
Summary:
| Size of process | N = 1000.
| Initial values | (x0,y0,z0) = (0,0,0).
| Time of process | t in [0,1].
| Discretization | Dt = 0.001.
R> plot3D(res3d)
Estimate the parameters of 1-dim sde:
Consider a process solution of the general stochastic differential equation:
$$dX_{t} = f(t,X_{t},\underline{\theta}) dt + g(t,X_{t},\underline{\theta}) dW_{t}$$
The package Sim.DiffProc implements the function fitsde of estimate drift and diffusion parameters $\underline{\theta}=(\theta_{1},\theta_{2},\dots,\theta_{p})$
with different methods of maximum pseudo-likelihood of the 1-dim stochastic differential equation.
An example we use a real data, fit with the CKLS model:
$$dX_{t} = (\theta_{1}+\theta_{2} X_{t}) dt + \theta_{3} X^{\theta_{4}}_{t} dW_{t}$$
we estimate the vector of parameters $\underline{\theta}=(\theta_{1},\theta_{2},\theta_{3},\theta_{4})$, using Euler pseudo-likelihood.
R> ## 1-dim fitsde
R> data(Irates)
R> rates <- Irates[,"r1"]
R> rates <- window(rates, start=1964.471, end=1989.333)
R> fx <- expression(theta[1]+theta[2]*x)
R> gx <- expression(theta[3]*x^theta[4])
R> ## theta = (theta1,theta2,theta3,theta4), p=4
R> fitmod <- fitsde(rates,drift=fx,diffusion=gx,pmle="euler",start = list(theta1=1,
theta2=1,theta3=1,theta4=1),optim.method = "L-BFGS-B")
R> fitmod
Call:
fitsde(data = rates, drift = fx, diffusion = gx, pmle = "euler",
start = list(theta1 = 1, theta2 = 1, theta3 = 1, theta4 = 1),
optim.method = "L-BFGS-B")
Coefficients:
theta1 theta2 theta3 theta4
2.0769516 -0.2631871 0.1302158 1.4513173
R> summary(fitmod)
Pseudo maximum likelihood estimation
Method: Euler
Call:
fitsde(data = rates, drift = fx, diffusion = gx, pmle = "euler",
start = list(theta1 = 1, theta2 = 1, theta3 = 1, theta4 = 1),
optim.method = "L-BFGS-B")
Coefficients:
Estimate Std. Error
theta1 2.0769516 0.98838467
theta2 -0.2631871 0.19544290
theta3 0.1302158 0.02523105
theta4 1.4513173 0.10323740
-2 log L: 475.7572
R> coef(fitmod)
theta1 theta2 theta3 theta4
2.0769516 -0.2631871 0.1302158 1.4513173
R> logLik(fitmod)
[1] -237.8786
R> AIC(fitmod)
[1] 483.7572
R> BIC(fitmod)
[1] 487.1514
R> vcov(fitmod)
theta1 theta2 theta3 theta4
theta1 0.9769042534 -1.843596e-01 -2.714334e-04 0.0011374342
theta2 -0.1843595796 3.819793e-02 5.169849e-05 -0.0002165286
theta3 -0.0002714334 5.169849e-05 6.366061e-04 -0.0025457493
theta4 0.0011374342 -2.165286e-04 -2.545749e-03 0.0106579616
R> confint(fitmod,level=0.95)
2.5 % 97.5 %
theta1 0.13975321 4.0141499
theta2 -0.64624812 0.1198740
theta3 0.08076388 0.1796678
theta4 1.24897569 1.6536589
Random number generators (RN's) to generate 1,2 and 3-dim sde:
Simulation M-sample for the random variable $X_{\tau}$ at time $t=\tau$ by a simulated 1, 2 and 3-dim sde, using the functions rsde1d, rsde2d and rsde3d.
R> ## 1-dim rsde
R> f <- expression( 2*(3-x) )
R> g <- expression( 1 )
R> res1d <- rsde1d(drift=f,diffusion=g,M=10,N=1000,tau=0.5412)
R> res1d
$t
[1] 0.5412
$x
[1] 2.411824 2.770963 2.168312 2.164712 1.950571 2.727019 2.179878
[8] 1.655399 2.306720 1.542930
attr(,"class")
[1] "rsde1d"
R> summary(res1d)
Monte-Carlo Statistics for X(t) at t = 0.5412
Mean 2.187832723
Variance 0.161302906
Median 2.174095030
First quartile 2.004106578
Third quartile 2.385547618
Skewness -0.099669829
Kurtosis 1.765543320
Moment of order 2 0.145172615
Moment of order 3 -0.006456944
Moment of order 4 0.045937014
Moment of order 5 -0.004150598
Bound conf Inf (95%) 1.542929743
Bound conf Sup (95%) 2.770962901
R> ## 2 and 3-dim rsde
R> example(rsde2d)
R> example(rsde3d)
First-passage-time (f.p.t) in 1,2 and 3-dim sde
The function fptsde1d (fptsde2d and fptsde3d for 2 and 3-dim) returns a random variable $\tau_{c}$ "first passage time", defined by :
$$\tau_{c} = { t \geq 0 ; X_{t} \geq c },\quad if \quad (x_{0} < c)$$
$$\tau_{c} = { t \geq 0 ; X_{t} \leq c },\quad if \quad (x_{0} > c)$$
with $c$ is a fixed boundary or barrier.
R> data(trimodal)
R> f <- expression( -3*(1+x) )
R> g <- expression( 0.5*x )
R> res1d <- fptsde1d(drift=f,diffusion=g,x0=1,c=0,M=10,N=1000)
R> res1d
$x0
[1] 1
$c
[1] 0
$tau
[1] 0.2167267 0.2503778 0.1886201 0.2351797 0.2119866 0.2139262
[7] 0.2433908 0.2112800 0.2189377 0.2245442
attr(,"class")
[1] "fptsde1d"
R> summary(res)
Monte-Carlo Statistics for tau(c) = inf{t >= 0 : X(t) <= 0="" 2="" 3="" 4="" 5="" }="" mean="" 2.296887e-01="" variance="" 5.289304e-04="" median="" 2.257272e-01="" first="" quartile="" 2.121965e-01="" third="" 2.452968e-01="" skewness="" 6.074848e-01="" kurtosis="" 3.040314e+00="" moment="" of="" order="" 5.236411e-04="" 7.389809e-06="" 8.505806e-07="" 3.289878e-08="" bound="" conf="" inf="" (95%)="" 1.946310e-01="" sup="" 2.846021e-01="" r=""> ## fpt in 2 and 3-dim sde
R> example(fptsde2d)
R> example(fptsde3d)
For other examples see demo(Sim.DiffProc), and for an overview of this package, see vignette("SDEs"), vignette("FitSDE").=>Requirements
Rversion >= 2.15.1Licence
This package and its documentation are usable under the terms of the "GNU
General Public License", a copy of which is distributed with the package.Details
ll{
Package: Sim.DiffProc
Type: Package
Version: 2.6
Date: 2014-05-04
License: GPL (>= 3)
Depends: R (>= 2.15.1)
Suggests: rgl, scatterplot3d
}
There are main types of functions in this package:
- Computing the stochastic integrals of Ito or Stratonovich type.
- Simulation of solutions to 1,2 and 3-dim stochastic differential equations of Ito or Stratonovich type, with different methods.
- Estimate drift and diffusion parameters by the method of maximum pseudo-likelihood of the 1-dim stochastic differential equation.
- Simulation of solutions to 1,2 and 3-dim diffusion bridge of Ito or Stratonovich type, with different methods.
- Random number generators (RN's) to generate 1,2 and 3-dim sde of Ito or Stratonovich type.
- First-passage-time (f.p.t) in 1,2 and 3-dim sde of Ito or Stratonovich type.
- Displaying an object inheriting from class
"sde"(1,2 and 3 dim).
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.
Roman, R.P., Serrano, J. J., Torres, F. (2013).
fptdApprox: Approximation of first-passage-time densities for diffusion processes.
Rpackage version 2.0.
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.
Rpackage version 0.2-5.
Vasicek, O. (1977).
An Equilibrium Characterization of the Term Structure.
Journal of Financial Economics, 5, 177--188.
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.
Iacus, S.M. (2009).
sde: Simulation and Inference for Stochastic Differential Equations.
Rpackage 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).
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.
Mathematische 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.
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.
Sorensen, H. (2000).
Inference for Diffusion Processes and Stochastic Volatility Models.
Ph.D. thesis, Department of Mathematical Sciences, University of Copenhagen.
Sorensen, H. (2002).
Estimation of diffusion parameters for discretely observed diffusion processes.
Bernoulli, 8, 491--508.
Sorensen, H. (2004).
Parametric inference for diffusion processes observed at discrete points in time: a survey.
International Statistical Review, 72, 337--354.
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.
Risken, H. (2001).
The Fokker Planck Equation : Methods of Solutions and Applications.
2nd edition, Springer Series in Synergetics.
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 observation.
Statistics, 21, 99--116.
Protter, P. (2005).
Stochastic Integration and Differential Equations.
2nd edn. Springer-Verlag, New York.
Bladt, M. and Sorensen, M. (2007).
Simple simulation of diffusion bridges with application to likelihood inference for diffusions.
Working Paper, University of Copenhagen.
Available at http://www.math.ku.dk/~michael/diffusionbridgepreprint.pdf
Ozaki, T. (1992).
A bridge between nonlinear time series models and nonlinear stochastic dynamical 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
sde, yumia, fptdApprox, PSM.