A new algorithm based on the Monte Carlo technique to generate the random variable FPT of a time homogeneous diffusion process (1, 2 and 3D) through a time-dependent boundary, order to estimate her probability density function.
Let \(X_t\) be a diffusion process which is the unique solution of the following stochastic differential equation:
\[\begin{equation}\label{eds01} dX_t = \mu(t,X_t) dt + \sigma(t,X_t) dW_t,\quad X_{t_{0}}=x_{0} \end{equation}\]if \(S(t)\) is a time-dependent boundary, we are interested in generating the first passage time (FPT) of the diffusion process through this boundary that is we will study the following random variable:
\[ \tau_{S(t)}= \left\{ \begin{array}{ll} inf \left\{t: X_{t} \geq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \leq S(t_{0}) \\ inf \left\{t: X_{t} \leq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \geq S(t_{0}) \end{array} \right. \]
The main arguments to ‘random’ rfptsdekd()
(where k=1,2,3
) consist:
object
an object inheriting from class snssde1d
, snssde2d
and snssde3d
.boundary
an expression of a constant or time-dependent boundary \(S(t)\).The main arguments to ‘density’ dfptsdekd()
(where k=1,2,3
) consist:
object
an object inheriting from class snssde1d
, snssde2d
and snssde3d
.boundary
an expression of a constant or time-dependent boundary \(S(t)\).pdf
probability density function Joint
or Marginal
.Consider the following SDE and linear boundary:
\[\begin{align*} dX_{t}= & \frac{1}{2} \alpha^2 X_{t} dt + \alpha X_{t} dW_{t},~x_{0} \neq 0.\\ S(t)= & a+bt \end{align*}\]The analytical solution of this model is: \[ X_t = x_{0}\exp\left(\alpha W_{t}\right) \] generating the first passage time (FPT) of this model through this boundary: \[ \tau_{S(t)}= \inf \left\{t: X_{t} \geq S(t) |X_{t_{0}}=x_{0} \right\} ~~ \text{if} \quad x_{0} \leq S(t_{0}) \]
Set the model \(X_t\):
alpha=2
f <- expression( alpha^2 * x )
g <- expression( alpha * x )
mod1d <- snssde1d(drift=f,diffusion=g,x0=0.5,M=1000)
Generate the first-passage-time \(\tau_{S(t)}\), with rfptsde1d()
function:
St <- expression( -5*t+1 )
fpt1d <- rfptsde1d(mod1d, boundary = St)
summary(fpt1d)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.01280 0.04210 0.06811 0.07615 0.10440 0.19110
The kernel density of \(\tau_{S(t)}\) with boundary \(S(t) = -5t+1\), using dfptsde1d()
function, see e.g. Figure 2.
den <- dfptsde1d(mod1d, boundary = St, bw ='ucv')
den
##
## Kernel density for the F.P.T of X(t)
## T(S,X) = inf{t >= 0 : X(t) >= -5 * t + 1}
##
## Data: fpt (1000 obs.); Bandwidth 'bw' = 0.006574
##
## x f(x)
## Min. :-0.00691709 Min. : 0.001816
## 1st Qu.: 0.04752829 1st Qu.: 1.524516
## Median : 0.10197366 Median : 4.234771
## Mean : 0.10197366 Mean : 4.587215
## 3rd Qu.: 0.15641904 3rd Qu.: 7.700497
## Max. : 0.21086441 Max. :11.077398
plot(den)
The following \(2\)-dimensional SDE’s with a vector of drift and a diagonal matrix of diffusion coefficients:
\[\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}\]\(W_{1,t}\) and \(W_{2,t}\) is a two independent standard Wiener process. First passage time (2D) \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})})\) is defined as:
\[ \left\{ \begin{array}{ll} \tau_{S(t),X_{t}}=\inf \left\{t: X_{t} \geq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \leq S(t_{0}) \\ \tau_{S(t),Y_{t}}=\inf \left\{t: Y_{t} \geq S(t)|Y_{t_{0}}=y_{0} \right\} & \hbox{if} \quad y_{0} \leq S(t_{0}) \end{array} \right. \] and \[ \left\{ \begin{array}{ll} \tau_{S(t),X_{t}}= \inf \left\{t: X_{t} \leq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \geq S(t_{0}) \\ \tau_{S(t),Y_{t}}= \inf \left\{t: Y_{t} \leq S(t)|Y_{t_{0}}=y_{0} \right\} & \hbox{if} \quad y_{0} \geq S(t_{0}) \end{array} \right. \]
Assume that we want to describe the following SDE’s (2D):
\[\begin{equation}\label{eq016} \begin{cases} dX_t = 5 (-1-Y_{t}) X_{t} dt + 0.5 dW_{1,t}\\ dY_t = 5 (-1-X_{t}) Y_{t} dt + 0.5 dW_{2,t} \end{cases} \end{equation}\]and \[ S(t)=-3+5t \]
Set the system \((X_t , Y_t)\):
fx <- expression(5*(-1-y)*x , 5*(-1-x)*y)
gx <- rep(expression(0.5),2)
mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(x=2,y=-2),M=1000)
Generate the couple \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})})\), with rfptsde2d()
function::
St <- expression(-3+5*t)
fpt2d <- rfptsde2d(mod2d, boundary = St)
summary(fpt2d)
## x y
## Min. :0.5428 Min. :0.5053
## 1st Qu.:0.6147 1st Qu.:0.5790
## Median :0.6325 Median :0.5969
## Mean :0.6320 Mean :0.5968
## 3rd Qu.:0.6498 3rd Qu.:0.6145
## Max. :0.7306 Max. :0.6952
The marginal density of \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})})\) are reported using dfptsde2d()
function, see e.g. Figure 4.
denM <- dfptsde2d(mod2d, boundary = St, pdf = 'M')
denM
##
## Marginal density for the F.P.T of X(t)
## T(S,X) = inf{t >= 0 : X(t) <= -3 + 5 * t}
##
## Data: out[, "x"] (1000 obs.); Bandwidth 'bw' = 0.005914
##
## x f(x)
## Min. :0.5250838 Min. : 0.000765
## 1st Qu.:0.5809053 1st Qu.: 0.216465
## Median :0.6367267 Median : 2.180507
## Mean :0.6367267 Mean : 4.474177
## 3rd Qu.:0.6925482 3rd Qu.: 8.054656
## Max. :0.7483697 Max. :14.516711
##
## Marginal density for the F.P.T of Y(t)
## T(S,Y) = inf{t >= 0 : Y(t) <= -3 + 5 * t}
##
## Data: out[, "y"] (1000 obs.); Bandwidth 'bw' = 0.005988
##
## y f(y)
## Min. :0.4873646 Min. : 0.000786
## 1st Qu.:0.5438231 1st Qu.: 0.163504
## Median :0.6002817 Median : 1.827234
## Mean :0.6002817 Mean : 4.423691
## 3rd Qu.:0.6567402 3rd Qu.: 8.394179
## Max. :0.7131988 Max. :14.335349
plot(denM)
A contour
and image
plot of density obtained from a realization of system \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})})\).
denJ <- dfptsde2d(mod2d, boundary = St, pdf = 'J')
denJ
##
## Joint density for the F.P.T of (X(t),Y(t))
## T(S,X,Y) = inf{t >= 0 : X(t) <= -3 + 5 * t and Y(t) <= -3 + 5 * t}
##
## Data: (x,y) (2 x 1000 obs.);
##
## x y f(x,y)
## Min. :0.5428270 Min. :0.5053289 Min. : 0.00000
## 1st Qu.:0.5897769 1st Qu.:0.5528053 1st Qu.: 0.35881
## Median :0.6367267 Median :0.6002817 Median : 4.68652
## Mean :0.6367267 Mean :0.6002817 Mean : 27.39715
## 3rd Qu.:0.6836766 3rd Qu.:0.6477581 3rd Qu.: 33.10262
## Max. :0.7306265 Max. :0.6952345 Max. :216.54240
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 Joint density with:
plot(denJ,display="persp",main="Bivariate Density")
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}\]\(W_{1,t}\), \(W_{2,t}\) and \(W_{3,t}\) is a 3 independent standard Wiener process. First passage time (3D) \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})},\tau_{(S(t),Z_{t})})\) is defined as:
\[ \left\{ \begin{array}{ll} \tau_{S(t),X_{t}}=\inf \left\{t: X_{t} \geq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \leq S(t_{0}) \\ \tau_{S(t),Y_{t}}=\inf \left\{t: Y_{t} \geq S(t)|Y_{t_{0}}=y_{0} \right\} & \hbox{if} \quad y_{0} \leq S(t_{0}) \\ \tau_{S(t),Z_{t}}=\inf \left\{t: Z_{t} \geq S(t)|Z_{t_{0}}=z_{0} \right\} & \hbox{if} \quad z_{0} \leq S(t_{0}) \end{array} \right. \] and \[ \left\{ \begin{array}{ll} \tau_{S(t),X_{t}}= \inf \left\{t: X_{t} \leq S(t)|X_{t_{0}}=x_{0} \right\} & \hbox{if} \quad x_{0} \geq S(t_{0}) \\ \tau_{S(t),Y_{t}}= \inf \left\{t: Y_{t} \leq S(t)|Y_{t_{0}}=y_{0} \right\} & \hbox{if} \quad y_{0} \geq S(t_{0}) \\ \tau_{S(t),Z_{t}}= \inf \left\{t: Z_{t} \leq S(t)|Z_{t_{0}}=z_{0} \right\} & \hbox{if} \quad z_{0} \geq S(t_{0}) \\ \end{array} \right. \]
Assume that we want to describe the following SDE’s (3D): \[\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}\]and \[ S(t)=-3+5t \]
Set the system \((X_t , Y_t , Z_t)\):
fx <- expression(4*(-1-x)*y , 4*(1-y)*x , 4*(1-z)*y)
gx <- rep(expression(0.2),3)
mod3d <- snssde3d(drift=fx,diffusion=gx,x0=c(x=2,y=-2,z=0),M=1000)
Generate the triplet \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})},\tau_{(S(t),Z_{t})})\), with rfptsde3d()
function::
St <- expression(-3+5*t)
fpt3d <- rfptsde3d(mod3d, boundary = St)
## missing output are removed
summary(fpt3d)
## x y z
## Min. :0.5448 Min. :0.7067 Min. :0.7058
## 1st Qu.:0.5736 1st Qu.:0.7630 1st Qu.:0.7571
## Median :0.5814 Median :0.7817 Median :0.7688
## Mean :0.5815 Mean :0.7857 Mean :0.7685
## 3rd Qu.:0.5893 3rd Qu.:0.8038 3rd Qu.:0.7808
## Max. :0.6186 Max. :0.9444 Max. :0.8222
The marginal density of \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})},\tau_{(S(t),Z_{t})})\) are reported using dfptsde3d()
function, see e.g. Figure 4.
denM <- dfptsde3d(mod3d, boundary = St)
## missing output are removed
denM
##
## Marginal density for the F.P.T of X(t)
## T(S,X) = inf{t >= 0 : X(t) <= -3 + 5 * t}
##
## Data: out[, "x"] (997 obs.); Bandwidth 'bw' = 0.002612
##
## x f(x)
## Min. :0.5369418 Min. : 0.00178
## 1st Qu.:0.5593266 1st Qu.: 0.96025
## Median :0.5817114 Median : 5.12410
## Mean :0.5817114 Mean :11.15736
## 3rd Qu.:0.6040961 3rd Qu.:21.60855
## Max. :0.6264809 Max. :35.19331
##
## Marginal density for the F.P.T of Y(t)
## T(S,Y) = inf{t >= 0 : Y(t) <= -3 + 5 * t}
##
## Data: out[, "y"] (997 obs.); Bandwidth 'bw' = 0.006893
##
## y f(y)
## Min. :0.6860048 Min. : 0.000949
## 1st Qu.:0.7557690 1st Qu.: 0.200052
## Median :0.8255331 Median : 1.007633
## Mean :0.8255331 Mean : 3.579987
## 3rd Qu.:0.8952973 3rd Qu.: 6.563431
## Max. :0.9650615 Max. :13.702419
##
## Marginal density for the F.P.T of Z(t)
## T(S,Z) = inf{t >= 0 : Z(t) <= -3 + 5 * t}
##
## Data: out[, "z"] (997 obs.); Bandwidth 'bw' = 0.003993
##
## z f(z)
## Min. :0.6937727 Min. : 0.001598
## 1st Qu.:0.7288810 1st Qu.: 0.367224
## Median :0.7639893 Median : 3.281570
## Mean :0.7639893 Mean : 7.113847
## 3rd Qu.:0.7990976 3rd Qu.:13.400432
## Max. :0.8342059 Max. :23.047743
plot(denM)
For Joint density for \((\tau_{(S(t),X_{t})},\tau_{(S(t),Y_{t})},\tau_{(S(t),Z_{t})})\) see package sm or ks.
library(sm)
sm.density(fpt3d,display="rgl")
##
library(ks)
fhat <- kde(x=fpt3d)
plot(fhat, drawpoints=TRUE)