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.01040 0.04480 0.06941 0.07772 0.10360 0.19270
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.004457
##
## x f(x)
## Min. :-0.00297228 Min. : 0.001421
## 1st Qu.: 0.04927906 1st Qu.: 2.038952
## Median : 0.10153040 Median : 3.980654
## Mean : 0.10153040 Mean : 4.779871
## 3rd Qu.: 0.15378174 3rd Qu.: 7.471913
## Max. : 0.20603309 Max. :11.435554
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.5278 Min. :0.5039
## 1st Qu.:0.6110 1st Qu.:0.5749
## Median :0.6289 Median :0.5942
## Mean :0.6299 Mean :0.5954
## 3rd Qu.:0.6493 3rd Qu.:0.6146
## Max. :0.7389 Max. :0.6972
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.006424
##
## x f(x)
## Min. :0.5085214 Min. : 0.000706
## 1st Qu.:0.5709316 1st Qu.: 0.141091
## Median :0.6333418 Median : 1.354651
## Mean :0.6333418 Mean : 4.001835
## 3rd Qu.:0.6957519 3rd Qu.: 7.592983
## Max. :0.7581621 Max. :14.125127
##
## 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.006346
##
## y f(y)
## Min. :0.4848679 Min. : 0.000710
## 1st Qu.:0.5427144 1st Qu.: 0.075143
## Median :0.6005608 Median : 1.827204
## Mean :0.6005608 Mean : 4.317556
## 3rd Qu.:0.6584072 3rd Qu.: 8.494397
## Max. :0.7162537 Max. :13.238111
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.5277935 Min. :0.5039071 Min. : 0.00000
## 1st Qu.:0.5805676 1st Qu.:0.5522340 1st Qu.: 0.14470
## Median :0.6333418 Median :0.6005608 Median : 3.25281
## Mean :0.6333418 Mean :0.6005608 Mean : 23.96652
## 3rd Qu.:0.6861159 3rd Qu.:0.6488876 3rd Qu.: 26.20101
## Max. :0.7388900 Max. :0.6972145 Max. :182.97964
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.5457 Min. :0.6987 Min. :0.6990
## 1st Qu.:0.5743 1st Qu.:0.7618 1st Qu.:0.7571
## Median :0.5814 Median :0.7822 Median :0.7699
## Mean :0.5817 Mean :0.7851 Mean :0.7689
## 3rd Qu.:0.5889 3rd Qu.:0.8024 3rd Qu.:0.7807
## Max. :0.6188 Max. :0.9995 Max. :0.8319
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"] (998 obs.); Bandwidth 'bw' = 0.002451
##
## x f(x)
## Min. :0.5383808 Min. : 0.00185
## 1st Qu.:0.5603160 1st Qu.: 0.65974
## Median :0.5822513 Median : 5.78150
## Mean :0.5822513 Mean :11.38601
## 3rd Qu.:0.6041866 3rd Qu.:20.59527
## Max. :0.6261219 Max. :38.19457
##
## Marginal density for the F.P.T of Y(t)
## T(S,Y) = inf{t >= 0 : Y(t) <= -3 + 5 * t}
##
## Data: out[, "y"] (998 obs.); Bandwidth 'bw' = 0.006846
##
## y f(y)
## Min. :0.6781384 Min. : 0.000668
## 1st Qu.:0.7636014 1st Qu.: 0.058404
## Median :0.8490644 Median : 0.428164
## Mean :0.8490644 Mean : 2.922379
## 3rd Qu.:0.9345274 3rd Qu.: 4.834813
## Max. :1.0199904 Max. :13.417336
##
## Marginal density for the F.P.T of Z(t)
## T(S,Z) = inf{t >= 0 : Z(t) <= -3 + 5 * t}
##
## Data: out[, "z"] (998 obs.); Bandwidth 'bw' = 0.003975
##
## z f(z)
## Min. :0.687053 Min. : 0.001140
## 1st Qu.:0.726238 1st Qu.: 0.102364
## Median :0.765423 Median : 1.986895
## Mean :0.765423 Mean : 6.373751
## 3rd Qu.:0.804608 3rd Qu.:12.402919
## Max. :0.843793 Max. :23.329990
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)