R Under development (unstable) (2024-03-03 r86036 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(Sim.DiffProc) Package 'Sim.DiffProc', version 4.9 browseVignettes('Sim.DiffProc') for more informations. > > > ### 2-dim Ito bridge sde > set.seed(1234) > > fx <- expression(4*(-1-x) , x) > gx <- expression(0.2 , 0) > res <- bridgesde2d(drift=fx,diffusion=gx,Dt=0.005,M=500) > res Itô Bridge Sde 2D: | dX(t) = 4 * (-1 - X(t)) * dt + 0.2 * dW1(t) | dY(t) = X(t) * dt + 0 * dW2(t) Method: | Euler scheme with order 0.5 Summary: | Size of process | N = 1001. | Crossing realized | C = 500 among 500. | Initial values | x0 = (0,0). | Ending values | y = (0,0). | Time of process | t in [0,5]. | Discretization | Dt = 0.005. > summary(res) ## Monte-Carlo statistics at time T/2=2.5 Monte-Carlo Statistics for (X(t),Y(t)) at time t = 2.5 | Crossing realized 500 among 500 X Y Mean -1.0030573 -2.2099784 Variance 0.0045892 0.0034646 Median -1.0031157 -2.2114024 Mode -1.0008840 -2.2128791 First quartile -1.0518003 -2.2487562 Third quartile -0.9587026 -2.1712329 Minimum -1.2027993 -2.3974294 Maximum -0.7814393 -2.0481089 Skewness 0.0711521 0.0360794 Kurtosis 2.8781525 2.9124049 Coef-variation -0.0675372 -0.0266342 3th-order moment 0.0000221 0.0000074 4th-order moment 0.0000606 0.0000350 5th-order moment 0.0000015 -0.0000001 6th-order moment 0.0000013 0.0000006 > summary(res,at=1) ## Monte-Carlo statistics at time 1 Monte-Carlo Statistics for (X(t),Y(t)) at time t = 1 | Crossing realized 500 among 500 X Y Mean -0.9782661 -0.7554881 Variance 0.0055552 0.0015861 Median -0.9780195 -0.7558516 Mode -0.9564967 -0.7555558 First quartile -1.0325486 -0.7813315 Third quartile -0.9258241 -0.7306599 Minimum -1.2036952 -0.8777720 Maximum -0.7686252 -0.6506899 Skewness -0.0168452 -0.0099052 Kurtosis 2.7520245 2.9190313 Coef-variation -0.0761893 -0.0527150 3th-order moment -0.0000070 -0.0000006 4th-order moment 0.0000849 0.0000073 5th-order moment -0.0000003 0.0000000 6th-order moment 0.0000021 0.0000001 > summary(res,at=4) ## Monte-Carlo statistics at time 4 Monte-Carlo Statistics for (X(t),Y(t)) at time t = 4 | Crossing realized 500 among 500 X Y Mean -0.9857418 -0.7527662 Variance 0.0045730 0.0015467 Median -0.9880801 -0.7512646 Mode -0.9863887 -0.7470079 First quartile -1.0290469 -0.7779033 Third quartile -0.9414837 -0.7273119 Minimum -1.1878318 -0.8756237 Maximum -0.7633155 -0.6418674 Skewness 0.0311155 -0.1076027 Kurtosis 2.9955695 3.0991994 Coef-variation -0.0686023 -0.0522441 3th-order moment 0.0000096 -0.0000065 4th-order moment 0.0000626 0.0000074 5th-order moment 0.0000010 -0.0000001 6th-order moment 0.0000014 0.0000001 > ## > 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) > > > ## > > 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 Itô Bridge Sde 2D: | dX(t) = 4 * (-1 - X(t)) * dt + 0.2 * dB1(t) | dY(t) = X(t) * dt + 0 * dB2(t) | Correlation structure: 1.0 0.7 0.7 1.0 Method: | Euler scheme with order 0.5 Summary: | Size of process | N = 1001. | Crossing realized | C = 500 among 500. | Initial values | x0 = (0,0). | Ending values | y = (0,0). | Time of process | t in [0,5]. | Discretization | Dt = 0.005. > > ## 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) > > fx <- expression(4*(-1-x)*y, 4*(1-y)*x, 4*(1-z)*y) > gx <- rep(expression(0.2),3) > # correlation matrix > Sigma <-matrix(c(1,0.3,0.5,0.3,1,0.2,0.5,0.2,1),nrow=3,ncol=3) > > res <- bridgesde3d(x0=c(0,-1,0.5),y=c(0,-2,0.5),drift=fx,diffusion=gx,corr=Sigma,M=200) > res Itô Bridge Sde 3D: | dX(t) = 4 * (-1 - X(t)) * Y(t) * dt + 0.2 * dB1(t) | dY(t) = 4 * (1 - Y(t)) * X(t) * dt + 0.2 * dB2(t) | dZ(t) = 4 * (1 - Z(t)) * Y(t) * dt + 0.2 * dB3(t) | Correlation structure: 1.0 0.3 0.5 0.3 1.0 0.2 0.5 0.2 1.0 Method: | Euler scheme with order 0.5 Summary: | Size of process | N = 1001. | Crossing realized | C = 199 among 200. | Initial values | x0 = (0,-1,0.5). | Ending values | y = (0,-2,0.5). | Time of process | t in [0,1]. | Discretization | Dt = 0.001. > summary(res) ## Monte-Carlo statistics at time T/2=0.5 Monte-Carlo Statistics for (X(t),Y(t),Z(t)) at time t = 0.5 | Crossing realized 199 among 200 X Y Z Mean 0.6764265 0.5060498 0.1278097 Variance 0.0117415 0.0074919 0.0294141 Median 0.6798065 0.5126240 0.1348365 Mode 0.6784697 0.5181950 0.1659863 First quartile 0.6182005 0.4487512 0.0215379 Third quartile 0.7489718 0.5609637 0.2432146 Minimum 0.3053625 0.2798871 -0.6098128 Maximum 0.9583460 0.7946176 0.5085510 Skewness -0.4370167 0.0463749 -0.4678248 Kurtosis 3.7429361 3.2233451 3.9084817 Coef-variation 0.1601923 0.1710418 1.3418808 3th-order moment -0.0005560 0.0000301 -0.0023600 4th-order moment 0.0005160 0.0001809 0.0033816 5th-order moment -0.0000666 0.0000079 -0.0012388 6th-order moment 0.0000393 0.0000075 0.0010249 > summary(res,at=0.25) ## Monte-Carlo statistics at time 0.25 Monte-Carlo Statistics for (X(t),Y(t),Z(t)) at time t = 0.25 | Crossing realized 199 among 200 X Y Z Mean 0.9903957 -0.1654947 0.0045809 Variance 0.0098876 0.0081776 0.0317897 Median 0.9879226 -0.1628644 -0.0081038 Mode 0.9814483 -0.1511598 -0.0318484 First quartile 0.9293625 -0.2243503 -0.1044067 Third quartile 1.0471662 -0.1019929 0.1260630 Minimum 0.7210630 -0.3896680 -0.7189567 Maximum 1.3080265 0.0526330 0.5068231 Skewness 0.1856698 -0.1021267 -0.0951232 Kurtosis 3.4350811 2.6662111 3.8314379 Coef-variation 0.1004008 -0.5464238 38.9215147 3th-order moment 0.0001825 -0.0000755 -0.0005392 4th-order moment 0.0003358 0.0001783 0.0038720 5th-order moment 0.0000174 -0.0000033 -0.0007369 6th-order moment 0.0000180 0.0000056 0.0010499 > summary(res,at=0.75) ## Monte-Carlo statistics at time 0.75 Monte-Carlo Statistics for (X(t),Y(t),Z(t)) at time t = 0.75 | Crossing realized 199 among 200 X Y Z Mean 2.0010387 0.1231822 -0.5046211 Variance 0.0097342 0.0041729 0.0501655 Median 1.9955165 0.1289686 -0.4870370 Mode 1.9808758 0.1356478 -0.4096230 First quartile 1.9323563 0.0806200 -0.6596325 Third quartile 2.0711211 0.1653711 -0.3442381 Minimum 1.7766990 -0.0713646 -1.1414503 Maximum 2.2423345 0.2892217 -0.0188320 Skewness 0.0497121 -0.1117937 -0.2686653 Kurtosis 2.4964785 3.0281126 2.5153648 Coef-variation 0.0493055 0.5244122 -0.4438511 3th-order moment 0.0000477 -0.0000301 -0.0030187 4th-order moment 0.0002366 0.0000527 0.0063301 5th-order moment 0.0000031 -0.0000007 -0.0010159 6th-order moment 0.0000081 0.0000010 0.0012145 > ## > 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) > lines(time(res),apply(res$Z,1,mean),col=5,lwd=2) > legend("topleft",c(expression(E(X[t])),expression(E(Y[t])), + expression(E(Z[t]))),lty=1,inset = .01,col=c(3,4,5)) > ## > plot3D(res,display = "persp",main="3-dim bridge sde") > > proc.time() user system elapsed 3.23 0.56 3.79