Simulations and models of stochastic differential equations

A.C. Guidoum and K. Boukhetala

2016-11-13

snssde1d()

Assume that we want to describe the following SDE:

Ito form1:

\[\begin{equation}\label{eq:05} dX_{t} = \frac{1}{2}\theta^{2} X_{t} dt + \theta X_{t} dW_{t},\qquad X_{0}=x_{0} > 0 \end{equation}\] Stratonovich form: \[\begin{equation}\label{eq:06} dX_{t} = \frac{1}{2}\theta^{2} X_{t} dt +\theta X_{t} \circ dW_{t},\qquad X_{0}=x_{0} > 0 \end{equation}\]

In the above \(f(t,x)=\frac{1}{2}\theta^{2} x\) and \(g(t,x)= \theta x\) (\(\theta > 0\)), \(W_{t}\) is a standard Wiener process. To simulate this models using snssde1d() function we need to specify:

theta = 0.5
f <- expression( (0.5*theta^2*x) )
g <- expression( theta*x )
mod1 <- snssde1d(drift=f,diffusion=g,x0=10,M=500,type="ito") # Using Ito
mod2 <- snssde1d(drift=f,diffusion=g,x0=10,M=500,type="str") # Using Stratonovich 
mod1
## Ito Sde 1D:
##  | dX(t) = (0.5 * theta^2 * X(t)) * dt + theta * X(t) * dW(t)
## Method:
##  | Euler scheme of order 0.5
## Summary:
##  | Size of process   | N  = 1000.
##  | Number of simulation  | M  = 500.
##  | Initial value     | x0 = 10.
##  | Time of process   | t in [0,1].
##  | Discretization    | Dt = 0.001.
mod2
## Stratonovich Sde 1D:
##  | dX(t) = (0.5 * theta^2 * X(t)) * dt + theta * X(t) o dW(t)
## Method:
##  | Euler scheme of order 0.5
## Summary:
##  | Size of process   | N  = 1000.
##  | Number of simulation  | M  = 500.
##  | Initial value     | x0 = 10.
##  | Time of process   | t in [0,1].
##  | Discretization    | Dt = 0.001.

Using Monte-Carlo simulations, the following statistical measures (S3 method) for class snssde1d() can be approximated for the \(X_{t}\) process at any time \(t\):

The summary of the results of mod1 and mod2 at time \(t=1\) of class snssde1d() is given by:

summary(mod1, at = 1)
## 
##  Monte-Carlo Statistics for X(t) at time t = 1
##                               
## Mean                  10.99598
## Variance              31.52028
## Median                 9.71960
## First quartile         7.01976
## Third quartile        13.57172
## Skewness               1.20481
## Kurtosis               4.47704
## Moment of order 3    213.20873
## Moment of order 4   4448.05997
## Moment of order 5  67075.89171
## Int.conf Inf (95%)     3.54499
## Int.conf Sup (95%)    25.19046
summary(mod2, at = 1)
## 
##  Monte-Carlo Statistics for X(t) at time t = 1
##                                
## Mean                   10.09247
## Variance               27.14782
## Median                  9.22196
## First quartile          6.49679
## Third quartile         12.70541
## Skewness                1.66113
## Kurtosis                7.46548
## Moment of order 3     234.96690
## Moment of order 4    5502.08997
## Moment of order 5  114509.25603
## Int.conf Inf (95%)      3.81760
## Int.conf Sup (95%)     23.35448

Hence we can just make use of the rsde1d() function to build our random number generator for the conditional density of the \(X_{t}|X_{0}\) (\(X_{t}^{\text{mod1}}| X_{0}\) and \(X_{t}^{\text{mod2}}|X_{0}\)) at time \(t = 1\).

x1 <- rsde1d(object = mod1, at = 1)  # X(t=1) | X(0)=x0 (Itô SDE)
x2 <- rsde1d(object = mod2, at = 1)  # X(t=1) | X(0)=x0 (Stratonovich SDE)
summary(data.frame(x1,x2))
##        x1               x2        
##  Min.   : 2.368   Min.   : 2.276  
##  1st Qu.: 7.020   1st Qu.: 6.497  
##  Median : 9.720   Median : 9.222  
##  Mean   :10.996   Mean   :10.092  
##  3rd Qu.:13.572   3rd Qu.:12.705  
##  Max.   :34.148   Max.   :37.802

The function dsde1d() can be used to show the kernel density estimation for \(X_{t}|X_{0}\) at time \(t=1\) with log-normal curves:

mu1 = log(10); sigma1= sqrt(theta^2)  # log mean and log variance for mod1 
mu2 = log(10)-0.5*theta^2 ; sigma2 = sqrt(theta^2) # log mean and log variance for mod2
AppdensI <- dsde1d(mod1, at = 1)
AppdensS <- dsde1d(mod2, at = 1)
plot(AppdensI , dens = function(x) dlnorm(x,meanlog=mu1,sdlog = sigma1))
plot(AppdensS , dens = function(x) dlnorm(x,meanlog=mu2,sdlog = sigma2))

In Figure 2, we present the flow of trajectories, the mean path (red lines) of solution of and , with their empirical \(95\%\) confidence bands, that is to say from the \(2.5th\) to the \(97.5th\) percentile for each observation at time \(t\) (blue lines):

plot(mod1,plot.type="single",ylab=expression(X^mod1))
lines(time(mod1),mean(mod1),col=2,lwd=2)
lines(time(mod1),bconfint(mod1,level=0.95)[,1],col=4,lwd=2)
lines(time(mod1),bconfint(mod1,level=0.95)[,2],col=4,lwd=2)
legend("topleft",c("mean path",paste("bound of",95,"% confidence")),col=c(2,4),lwd=2,cex=0.8)
plot(mod2,plot.type="single",ylab=expression(X^mod2))
lines(time(mod2),mean(mod2),col=2,lwd=2)
lines(time(mod2),bconfint(mod2,level=0.95)[,1],col=4,lwd=2)
lines(time(mod2),bconfint(mod2,level=0.95)[,2],col=4,lwd=2)
legend("topleft",c("mean path",paste("bound of",95,"% confidence")),col=c(2,4),lwd=2,cex=0.8)

Return to snssde1d()

snssde2d()

The following \(2\)-dimensional SDE’s with a vector of drift and a diagonal matrix of diffusion coefficients:

Ito form: \[\begin{equation}\label{eq:09} \begin{cases} dX_t = f_{x}(t,X_{t},Y_{t}) dt + g_{x}(t,X_{t},Y_{t}) dW_{1,t}\\ dY_t = f_{y}(t,X_{t},Y_{t}) dt + g_{y}(t,X_{t},Y_{t}) dW_{2,t} \end{cases} \end{equation}\] Stratonovich form: \[\begin{equation}\label{eq:10} \begin{cases} dX_t = f_{x}(t,X_{t},Y_{t}) dt + g_{x}(t,X_{t},Y_{t}) \circ dW_{1,t}\\ dY_t = f_{y}(t,X_{t},Y_{t}) dt + g_{y}(t,X_{t},Y_{t}) \circ dW_{2,t} \end{cases} \end{equation}\]

\(W_{1,t}\) and \(W_{2,t}\) is a two independent standard Wiener process. To simulate \(2d\) models using snssde2d() function we need to specify:

Ornstein-Uhlenbeck process and its integral

The Ornstein-Uhlenbeck (OU) process has a long history in physics. Introduced in essence by Langevin in his famous 1908 paper on Brownian motion, the process received a more thorough mathematical examination several decades later by Uhlenbeck and Ornstein (1930). The OU process is understood here to be the univariate continuous Markov process \(X_t\). In mathematical terms, the equation is written as an Ito equation: \[\begin{equation}\label{eq016} dX_t = -\frac{1}{\mu} X_t dt + \sqrt{\sigma} dW_t,\quad X_{0}=x_{0} \end{equation}\] In these equations, \(\mu\) and \(\sigma\) are positive constants called, respectively, the relaxation time and the diffusion constant. The time integral of the OU process \(X_t\) (or indeed of any process \(X_t\)) is defined to be the process \(Y_t\) that satisfies: \[\begin{equation}\label{eq017} Y_{t} = Y_{0}+\int X_{t} dt \Leftrightarrow dY_t = X_{t} dt ,\quad Y_{0}=y_{0} \end{equation}\] \(Y_t\) is not itself a Markov process; however, \(X_t\) and \(Y_t\) together comprise a bivariate continuous Markov process. We wish to find the solutions \(X_t\) and \(Y_t\) to the coupled time-evolution equations: \[\begin{equation}\label{eq018} \begin{cases} dX_t = -\frac{1}{\mu} X_t dt + \sqrt{\sigma} dW_t\\ dY_t = X_{t} dt \end{cases} \end{equation}\]

We simulate a flow of \(500\) trajectories of \((X_{t},Y_{t})\), with integration step size \(\Delta t = 0.01\), and using second Milstein method.

x=5;y=0
mu=3;sigma=0.5
fx <- expression(-(x/mu),x)  
gx <- expression(sqrt(sigma),0)
mod2d <- snssde2d(drift=fx,diffusion=gx,Dt=0.01,M=500,x0=c(x,y),method="smilstein")
mod2d
## Ito Sde 2D:
##  | dX(t) = -(X(t)/mu) * dt + sqrt(sigma) * dW1(t)
##  | dY(t) = X(t) * dt + 0 * dW2(t)
## Method:
##  | Second Milstein scheme of order 1.5
## Summary:
##  | Size of process   | N  = 1000.
##  | Number of simulation  | M  = 500.
##  | Initial values    | (x0,y0) = (5,0).
##  | Time of process   | t in [0,10].
##  | Discretization    | Dt = 0.01.
summary(mod2d)
## 
##  Monte-Carlo Statistics for (X(t),Y(t)) at time t = 10
##                           X          Y
## Mean                0.21799   14.83489
## Variance            0.71889   20.87251
## Median              0.20895   14.93429
## First quartile     -0.38134   11.63571
## Third quartile      0.75892   18.10022
## Skewness            0.24042    0.03821
## Kurtosis            3.24206    3.04422
## Moment of order 3   0.14654    3.64326
## Moment of order 4   1.67552 1326.24895
## Moment of order 5   1.31262 2100.80674
## Int.conf Inf (95%) -1.38838    6.25775
## Int.conf Sup (95%)  1.95350   23.29807

For plotting (back in time) using the command plot, the results of the simulation are shown in Figure 3.

plot(mod2d)

Take note of the well known result, which can be derived from either this equations. That for any \(t > 0\) the OU process \(X_t\) and its integral \(Y_t\) will be the normal distribution with mean and variance given by: \[ \begin{cases} \text{E}(X_{t}) =x_{0} e^{-t/\mu} &\text{and}\quad\text{Var}(X_{t})=\frac{\sigma \mu}{2} \left (1-e^{-2t/\mu}\right )\\ \text{E}(Y_{t}) = y_{0}+x_{0}\mu \left (1-e^{-t/\mu}\right ) &\text{and}\quad\text{Var}(Y_{t})=\sigma\mu^{3}\left (\frac{t}{\mu}-2\left (1-e^{-t/\mu}\right )+\frac{1}{2}\left (1-e^{-2t/\mu}\right )\right ) \end{cases} \]

Hence we can just make use of the rsde2d() function to build our random number for \((X_{t},Y_{t})\) at time \(t = 10\).

out <- rsde2d(object = mod2d, at = 10) 
summary(out)
##        x                 y          
##  Min.   :-2.0829   Min.   : 0.2984  
##  1st Qu.:-0.3813   1st Qu.:11.6357  
##  Median : 0.2090   Median :14.9343  
##  Mean   : 0.2180   Mean   :14.8349  
##  3rd Qu.: 0.7589   3rd Qu.:18.1002  
##  Max.   : 3.4639   Max.   :31.6856

For each SDE type and for each numerical scheme, the density of \(X_t\) and \(Y_t\) at time \(t=10\) are reported using dsde2d() function, see e.g. Figure 4: the marginal density of \(X_t\) and \(Y_t\) at time \(t=10\).

denM <- dsde2d(mod2d,pdf="M",at =10)
denM
## 
##  Marginal density for the conditional law of X(t)|X(0) at time t = 10
## 
## Data: x (500 obs.);  Bandwidth 'bw' = 0.2202
## 
##        x                  f(x)          
##  Min.   :-2.743438   Min.   :0.0000409  
##  1st Qu.:-1.026477   1st Qu.:0.0053135  
##  Median : 0.690484   Median :0.0736112  
##  Mean   : 0.690484   Mean   :0.1454632  
##  3rd Qu.: 2.407445   3rd Qu.:0.2763057  
##  Max.   : 4.124406   Max.   :0.5007931  
## 
##  Marginal density for the conditional law of Y(t)|Y(0) at time t = 10
## 
## Data: y (500 obs.);  Bandwidth 'bw' = 1.186
## 
##        y                 f(y)           
##  Min.   :-3.26083   Min.   :0.00000763  
##  1st Qu.: 6.36559   1st Qu.:0.00072703  
##  Median :15.99201   Median :0.00975566  
##  Mean   :15.99201   Mean   :0.02594470  
##  3rd Qu.:25.61843   3rd Qu.:0.05366683  
##  Max.   :35.24485   Max.   :0.09078235
plot(denM, main="Marginal Density")

Created using dsde2d() plotted in (x, y)-space with dim = 2. A contour and image plot of density obtained from a realization of system \((X_{t},Y_{t})\) at time t=10.

denJ <- dsde2d(mod2d,pdf="J",at =10)
denJ
## 
##  Joint density for the conditional law of X(t),Y(t)|X(0),Y(0) at time t = 10
## 
## Data: (x,y) (2 x 500 obs.);
## 
##        x                   y                f(x,y)          
##  Min.   :-2.082894   Min.   : 0.29841   Min.   :0.00000000  
##  1st Qu.:-0.696205   1st Qu.: 8.14521   1st Qu.:0.00005552  
##  Median : 0.690484   Median :15.99201   Median :0.00089418  
##  Mean   : 0.690484   Mean   :15.99201   Mean   :0.00560450  
##  3rd Qu.: 2.077173   3rd Qu.:23.83881   3rd Qu.:0.00666960  
##  Max.   : 3.463862   Max.   :31.68561   Max.   :0.04477607
plot(denJ,display="contour",main="Bivariate Density")
plot(denJ,display="image",drawpoints=TRUE,col.pt="green",cex=0.25,pch=19,main="Bivariate Density")

A \(3\)D plot of the density obtained with:

plot(denJ,main="Bivariate Density")

Return to snssde2d()

The stochastic Van-der-Pol equation

The Van der Pol (1922) equation is an ordinary differential equation that can be derived from the Rayleigh differential equation by differentiating and setting \(\dot{x}=y\), see Naess and Hegstad (1994); Leung (1995) and for more complex dynamics in Van-der-Pol equation see Jing et al. (2006). It is an equation describing self-sustaining oscillations in which energy is fed into small oscillations and removed from large oscillations. This equation arises in the study of circuits containing vacuum tubes and is given by: \[\begin{equation}\label{eq:12} \ddot{X}-\mu (1-X^{2}) \dot{X} + X = 0 \end{equation}\] where \(x\) is the position coordinate (which is a function of the time \(t\)), and \(\mu\) is a scalar parameter indicating the nonlinearity and the strength of the damping, to simulate the deterministic equation see Grayling (2014) for more details. Consider stochastic perturbations of the Van-der-Pol equation, and random excitation force of such systems by White noise \(\xi_{t}\), with delta-type correlation function \(\text{E}(\xi_{t}\xi_{t+h})=2\sigma \delta (h)\) \[\begin{equation}\label{eq:13} \ddot{X}-\mu (1-X^{2}) \dot{X} + X = \xi_{t}, \end{equation}\] where \(\mu > 0\) . It’s solution cannot be obtained in terms of elementary functions, even in the phase plane. The White noise \(\xi_{t}\) is formally derivative of the Wiener process \(W_{t}\). The representation of a system of two first order equations follows the same idea as in the deterministic case by letting \(\dot{x}=y\), from physical equation we get the above system: \[\begin{equation}\label{eq:14} \begin{cases} \dot{X} = Y \\ \dot{Y} = \mu \left(1-X^{2}\right) Y - X + \xi_{t} \end{cases} \end{equation}\] The system can mathematically explain by a Stratonovitch equations: \[\begin{equation}\label{eq:15} \begin{cases} dX_{t} = Y_{t} dt \\ dY_{t} = \left(\mu (1-X^{2}_{t}) Y_{t} - X_{t}\right) dt + 2 \sigma \circ dW_{2,t} \end{cases} \end{equation}\]

Implemente in R as follows, with integration step size \(\Delta t = 0.01\) and using stochastic Runge-Kutta methods 1-stage.

mu = 4; sigma=0.1
fx <- expression( y ,  (mu*( 1-x^2 )* y - x)) 
gx <- expression( 0 ,2*sigma)
mod2d <- snssde2d(drift=fx,diffusion=gx,N=10000,Dt=0.01,type="str",method="rk1")
mod2d
## Stratonovich Sde 2D:
##  | dX(t) = Y(t) * dt + 0 o dW1(t)
##  | dY(t) = (mu * (1 - X(t)^2) * Y(t) - X(t)) * dt + 2 * sigma o dW2(t)
## Method:
##  | Runge-Kutta method of order 1
## Summary:
##  | Size of process   | N  = 10000.
##  | Number of simulation  | M  = 1.
##  | Initial values    | (x0,y0) = (0,0).
##  | Time of process   | t in [0,100].
##  | Discretization    | Dt = 0.01.
plot2d(mod2d) ## in plane (O,X,Y)
plot(mod2d)   ## back in time

Return to snssde2d()

snssde3d()

The following \(3\)-dimensional SDE’s with a vector of drift and a diagonal matrix of diffusion coefficients:

Ito form: \[\begin{equation}\label{eq17} \begin{cases} dX_t = f_{x}(t,X_{t},Y_{t},Z_{t}) dt + g_{x}(t,X_{t},Y_{t},Z_{t}) dW_{1,t}\\ dY_t = f_{y}(t,X_{t},Y_{t},Z_{t}) dt + g_{y}(t,X_{t},Y_{t},Z_{t}) dW_{2,t}\\ dZ_t = f_{z}(t,X_{t},Y_{t},Z_{t}) dt + g_{z}(t,X_{t},Y_{t},Z_{t}) dW_{3,t} \end{cases} \end{equation}\] Stratonovich form: \[\begin{equation}\label{eq18} \begin{cases} dX_t = f_{x}(t,X_{t},Y_{t},Z_{t}) dt + g_{x}(t,X_{t},Y_{t},Z_{t}) \circ dW_{1,t}\\ dY_t = f_{y}(t,X_{t},Y_{t},Z_{t}) dt + g_{y}(t,X_{t},Y_{t},Z_{t}) \circ dW_{2,t}\\ dZ_t = f_{z}(t,X_{t},Y_{t},Z_{t}) dt + g_{z}(t,X_{t},Y_{t},Z_{t}) \circ dW_{3,t} \end{cases} \end{equation}\]

\(W_{1,t}\), \(W_{2,t}\) and \(W_{3,t}\) is a 3 independent standard Wiener process. To simulate this system using snssde3d() function we need to specify:

Basic example

Assume that we want to describe the following SDE’s (3D) in Ito form: \[\begin{equation}\label{eq0166} \begin{cases} dX_t = 4 (-1-X_{t}) Y_{t} dt + 0.2 dW_{1,t}\\ dY_t = 4 (1-Y_{t}) X_{t} dt + 0.2 dW_{2,t}\\ dZ_t = 4 (1-Z_{t}) Y_{t} dt + 0.2 dW_{3,t} \end{cases} \end{equation}\]

We simulate a flow of 500 trajectories, with integration step size \(\Delta t = 0.001\).

fx <- expression(4*(-1-x)*y , 4*(1-y)*x , 4*(1-z)*y) 
gx <- rep(expression(0.2),3)
mod3d <- snssde3d(x0=c(x=2,y=-2,z=-2),drift=fx,diffusion=gx,N=1000,M=500)
mod3d
## Ito Sde 3D:
##  | dX(t) = 4 * (-1 - X(t)) * Y(t) * dt + 0.2 * dW1(t)
##  | dY(t) = 4 * (1 - Y(t)) * X(t) * dt + 0.2 * dW2(t)
##  | dZ(t) = 4 * (1 - Z(t)) * Y(t) * dt + 0.2 * dW3(t)
## Method:
##  | Euler scheme of order 0.5
## Summary:
##  | Size of process   | N  = 1000.
##  | Number of simulation  | M  = 500.
##  | Initial values    | (x0,y0,z0) = (2,-2,-2).
##  | Time of process   | t in [0,1].
##  | Discretization    | Dt = 0.001.
summary(mod3d)
## 
##   Monte-Carlo Statistics for (X(t),Y(t),Z(t)) at time t = 1
##                           X       Y        Z
## Mean               -0.78788 0.87272  0.78982
## Variance            0.01014 0.10102  0.01012
## Median             -0.79794 0.85339  0.79719
## First quartile     -0.85617 0.67141  0.72217
## Third quartile     -0.73330 1.06789  0.85607
## Skewness            0.70273 0.37686 -0.48184
## Kurtosis            4.13518 3.47136  3.36557
## Moment of order 3   0.00072 0.01210 -0.00049
## Moment of order 4   0.00043 0.03543  0.00034
## Moment of order 5   0.00009 0.01364 -0.00005
## Int.conf Inf (95%) -0.96890 0.25598  0.58101
## Int.conf Sup (95%) -0.57456 1.58272  0.96022
plot(mod3d,union = TRUE)         ## back in time
plot3D(mod3d,display="persp")    ## in space (O,X,Y,Z)

For each SDE type and for each numerical scheme, the marginal density of \(X_t\), \(Y_t\) and \(Z_t\) at time \(t=1\) are reported using dsde3d() function, see e.g. Figure 8.

den <- dsde3d(mod3d,at =1)
den
## 
##  Marginal density for the conditional law of X(t)|X(0) at time t = 1
## 
## Data: x (500 obs.);  Bandwidth 'bw' = 0.02381
## 
##        x                   f(x)         
##  Min.   :-1.1152504   Min.   :0.000388  
##  1st Qu.:-0.9119133   1st Qu.:0.075024  
##  Median :-0.7085761   Median :0.476136  
##  Mean   :-0.7085761   Mean   :1.228278  
##  3rd Qu.:-0.5052390   3rd Qu.:2.216015  
##  Max.   :-0.3019018   Max.   :4.196779  
## 
##  Marginal density for the conditional law of Y(t)|Y(0) at time t = 1
## 
## Data: y (500 obs.);  Bandwidth 'bw' = 0.07684
## 
##        y                   f(y)          
##  Min.   :-0.1396524   Min.   :0.0001174  
##  1st Qu.: 0.4713330   1st Qu.:0.0273182  
##  Median : 1.0823185   Median :0.2032677  
##  Mean   : 1.0823185   Mean   :0.4087731  
##  3rd Qu.: 1.6933039   3rd Qu.:0.7411125  
##  Max.   : 2.3042894   Max.   :1.3366929  
## 
##  Marginal density for the conditional law of Z(t)|Z(0) at time t = 1
## 
## Data: z (500 obs.);  Bandwidth 'bw' = 0.02595
## 
##        z                  f(z)         
##  Min.   :0.3019458   Min.   :0.000348  
##  1st Qu.:0.5014142   1st Qu.:0.047529  
##  Median :0.7008826   Median :0.561927  
##  Mean   :0.7008826   Mean   :1.252100  
##  3rd Qu.:0.9003510   3rd Qu.:2.393278  
##  Max.   :1.0998194   Max.   :4.295844
plot(den, main="Marginal Density") 

For Joint density for \((X_t,Y_t,Z_t)\) see package sm or ks.

out <- rsde3d(mod3d,at =1)
library(sm)
sm.density(out,display="rgl")

##

library(ks)
fhat <- kde(x=out)
plot(fhat, drawpoints=TRUE)

Return to snssde3d()

Attractive model for 3D diffusion processes

If we assume that \(U_w( x , y , z , t )\), \(V_w( x , y , z , t )\) and \(S_w( x , y , z , t )\) are neglected and the dispersion coefficient \(D( x , y , z )\) is constant. A system becomes (see Boukhetala,1996): \[\begin{eqnarray}\label{eq19} % \nonumber to remove numbering (before each equation) \begin{cases} dX_t = \left(\frac{-K X_{t}}{\sqrt{X^{2}_{t} + Y^{2}_{t} + Z^{2}_{t}}}\right) dt + \sigma dW_{1,t} \nonumber\\ dY_t = \left(\frac{-K Y_{t}}{\sqrt{X^{2}_{t} + Y^{2}_{t} + Z^{2}_{t}}}\right) dt + \sigma dW_{2,t} \\ dZ_t = \left(\frac{-K Z_{t}}{\sqrt{X^{2}_{t} + Y^{2}_{t} + Z^{2}_{t}}}\right) dt + \sigma dW_{3,t} \nonumber \end{cases} \end{eqnarray}\]

with initial conditions \((X_{0},Y_{0},Z_{0})=(1,1,1)\), by specifying the drift and diffusion coefficients of three processes \(X_{t}\), \(Y_{t}\) and \(Z_{t}\) as R expressions which depends on the three state variables (x,y,z) and time variable t, with integration step size Dt=0.0001.

K = 4; s = 1; sigma = 0.2
fx <- expression( (-K*x/sqrt(x^2+y^2+z^2)) , (-K*y/sqrt(x^2+y^2+z^2)) , (-K*z/sqrt(x^2+y^2+z^2)) ) 
gx <- rep(expression(sigma),3)
mod3d <- snssde3d(drift=fx,diffusion=gx,N=10000,x0=c(x=1,y=1,z=1))
mod3d
## Ito Sde 3D:
##  | dX(t) = (-K * X(t)/sqrt(X(t)^2 + Y(t)^2 + Z(t)^2)) * dt + sigma * dW1(t)
##  | dY(t) = (-K * Y(t)/sqrt(X(t)^2 + Y(t)^2 + Z(t)^2)) * dt + sigma * dW2(t)
##  | dZ(t) = (-K * Z(t)/sqrt(X(t)^2 + Y(t)^2 + Z(t)^2)) * dt + sigma * dW3(t)
## Method:
##  | Euler scheme of order 0.5
## Summary:
##  | Size of process   | N  = 10000.
##  | Number of simulation  | M  = 1.
##  | Initial values    | (x0,y0,z0) = (1,1,1).
##  | Time of process   | t in [0,1].
##  | Discretization    | Dt = 1e-04.

The results of simulation are shown:

plot3D(mod3d,display="persp",col="blue")

Return to snssde3d()

Transformation of an SDE one-dimensional

Next is an example of one-dimensional SDE driven by three independent Brownian motions (\(W_{1,t}\),\(W_{2,t}\),\(W_{3,t}\)), as follows: \[\begin{equation}\label{eq20} dX_{t} = \mu W_{1,t} dt + \sigma W_{2,t} dW_{3,t} \end{equation}\] To simulate the solution of the process \(X_t\), we make a transformation to a system of three equations as follows: \[\begin{eqnarray}\label{eq21} \begin{cases} % \nonumber to remove numbering (before each equation) dX_t = \mu Y_{t} dt + \sigma Z_{t} dW_{3,t} \nonumber\\ dY_t = dW_{1,t} \\ dZ_t = dW_{2,t} \nonumber \end{cases} \end{eqnarray}\]

run by calling the function snssde3d() to produce a simulation of the solution, with \(\mu = 1\) and \(\sigma = 1\).

fx <- expression(y,0,0) 
gx <- expression(z,1,1)
modtra <- snssde3d(drift=fx,diffusion=gx,M=500)
modtra
## Ito Sde 3D:
##  | dX(t) = Y(t) * dt + Z(t) * dW1(t)
##  | dY(t) = 0 * dt + 1 * dW2(t)
##  | dZ(t) = 0 * dt + 1 * dW3(t)
## Method:
##  | Euler scheme of order 0.5
## Summary:
##  | Size of process   | N  = 1000.
##  | Number of simulation  | M  = 500.
##  | Initial values    | (x0,y0,z0) = (0,0,0).
##  | Time of process   | t in [0,1].
##  | Discretization    | Dt = 0.001.
summary(modtra)
## 
##   Monte-Carlo Statistics for (X(t),Y(t),Z(t)) at time t = 1
##                           X        Y        Z
## Mean                0.02038 -0.00022 -0.04226
## Variance            0.75673  0.98774  0.93418
## Median              0.00419 -0.03371 -0.05310
## First quartile     -0.50761 -0.68390 -0.72646
## Third quartile      0.56291  0.69763  0.63591
## Skewness           -0.25218  0.07301  0.01379
## Kurtosis            4.04460  2.66176  2.79796
## Moment of order 3  -0.16600  0.07167  0.01245
## Moment of order 4   2.31607  2.59691  2.44178
## Moment of order 5  -2.88379  0.38041  0.00787
## Int.conf Inf (95%) -1.97639 -1.90679 -1.91798
## Int.conf Sup (95%)  1.75167  1.93111  1.78561

the following code produces the result in Figure 9.

plot(modtra$X,plot.type="single",ylab="X")
lines(time(modtra),mean(modtra)$X,col=2,lwd=2)
lines(time(modtra),bconfint(modtra,level=0.95)$X[,1],col=4,lwd=2)
lines(time(modtra),bconfint(modtra,level=0.95)$X[,2],col=4,lwd=2)
legend("topleft",c("mean path",paste("bound of",95,"% confidence")),col=c(2,4),lwd=2,cex=0.8)

The histogram and kernel density of \(X_t\) at time \(t=1\) are reported using dsde3d() function, see e.g. Figure 10.

den <- dsde3d(modtra,at=1)
den$resx
## 
## Call:
##  density.default(x = x, na.rm = TRUE)
## 
## Data: x (500 obs.);  Bandwidth 'bw' = 0.2075
## 
##        x                 y            
##  Min.   :-4.7641   Min.   :0.0000021  
##  1st Qu.:-2.8019   1st Qu.:0.0026348  
##  Median :-0.8396   Median :0.0396680  
##  Mean   :-0.8396   Mean   :0.1272792  
##  3rd Qu.: 1.1226   3rd Qu.:0.2325336  
##  Max.   : 3.0849   Max.   :0.4738560
MASS::truehist(den$ech$x,xlab = expression(X[t==1]));box()
lines(den$resx,col="red",lwd=2)
legend("topleft",c("Distribution histogram","Kernel Density"),inset =.01,pch=c(15,NA),lty=c(NA,1),col=c("cyan","red"),lwd=2,cex=0.8)

Return to snssde3d()


  1. The equivalently of \(X_{t}^{\text{mod1}}\) the following Stratonovich SDE: \(dX_{t} = \theta X_{t} \circ dW_{t}\).