Skip to content

Commit 9345cb4

Browse files
committed
version 4.4
1 parent c06bc71 commit 9345cb4

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

demo/Sim.DiffProc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Wed Oct 17 12:16:40 2018
1+
## Fri Sep 15 23:08:50 2017
22
options(prompt="R> ",scipen=20,digits=5,scientific = 5,width = 70,warning=FALSE, message=FALSE)
33
############################################################################
44
# Demo 1 #

tests/bridgesde.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library(Sim.DiffProc)
2+
3+
4+
### 2-dim Ito bridge sde
5+
set.seed(1234)
6+
7+
fx <- expression(4*(-1-x) , x)
8+
gx <- expression(0.2 , 0)
9+
res <- bridgesde2d(drift=fx,diffusion=gx,Dt=0.005,M=2000)
10+
res
11+
summary(res) ## Monte-Carlo statistics at time T/2=2.5
12+
summary(res,at=1) ## Monte-Carlo statistics at time 1
13+
summary(res,at=4) ## Monte-Carlo statistics at time 4
14+
##
15+
plot(res,type="n")
16+
lines(time(res),apply(res$X,1,mean),col=3,lwd=2)
17+
lines(time(res),apply(res$Y,1,mean),col=4,lwd=2)
18+
legend("topright",c(expression(E(X[t])),expression(E(Y[t]))),lty=1,inset = .7,col=c(3,4))
19+
##
20+
plot2d(res)
21+

tests/fitsde.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library(Sim.DiffProc)
2+
3+
4+
## Application to real data
5+
## CKLS modele vs CIR modele
6+
## CKLS (mod1): dX(t) = (theta1+theta2* X(t))* dt + theta3 * X(t)^theta4 * dW(t)
7+
## CIR (mod2): dX(t) = (theta1+theta2* X(t))* dt + theta3 * sqrt(X(t)) * dW(t)
8+
set.seed(1234)
9+
10+
data(Irates)
11+
rates <- Irates[,"r1"]
12+
rates <- window(rates, start=1964.471, end=1989.333)
13+
14+
fx1 <- expression(theta[1]+theta[2]*x)
15+
gx1 <- expression(theta[3]*x^theta[4])
16+
gx2 <- expression(theta[3]*sqrt(x))
17+
18+
fitmod1 <- fitsde(rates,drift=fx1,diffusion=gx1,pmle="euler",start = list(theta1=1,theta2=1,
19+
theta3=1,theta4=1),optim.method = "L-BFGS-B")
20+
fitmod2 <- fitsde(rates,drift=fx1,diffusion=gx2,pmle="euler",start = list(theta1=1,theta2=1,
21+
theta3=1),optim.method = "L-BFGS-B")
22+
summary(fitmod1)
23+
summary(fitmod2)
24+
coef(fitmod1)
25+
coef(fitmod2)
26+
confint(fitmod1,parm=c('theta2','theta3'))
27+
confint(fitmod2,parm=c('theta2','theta3'))
28+
AIC(fitmod1)
29+
AIC(fitmod2)

tests/fptsde.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library(Sim.DiffProc)
2+
3+
4+
## Example 1:
5+
6+
# SDE's 2d
7+
fx <- expression(5*(-1-y)*x , 5*(-1-x)*y)
8+
gx <- expression(0.5 , 0.5)
9+
mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(2,-2),M=2000)
10+
11+
# boundary
12+
13+
St <- expression(-1+5*t)
14+
15+
# random fpt
16+
17+
out <- fptsde2d(mod2d,boundary=St)
18+
out
19+
summary(out)
20+
21+
# Marginal density
22+
23+
denM <- dfptsde2d(out,pdf="M")
24+
denM
25+
plot(denM)
26+
27+
# Joint density
28+
29+
denJ <- dfptsde2d(out,pdf="J",n=200,lims=c(0.28,0.4,0.04,0.13))
30+
denJ
31+
plot(denJ)
32+
plot(denJ,display="image")
33+
plot(denJ,display="image",drawpoints=TRUE,cex=0.5,pch=19,col.pt='green')
34+
plot(denJ,display="contour")
35+
plot(denJ,display="contour",color.palette=colorRampPalette(c('white','green','blue','red')))

tests/rsde.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library(Sim.DiffProc)
2+
3+
## 2-dim SDE
4+
set.seed(1234)
5+
6+
# SDE's 2d
7+
fx <- expression(3*(2-y),2*x)
8+
gx <- expression(1,y)
9+
mod2d <- snssde2d(drift=fx,diffusion=gx,x0=c(1,2),M=5000)
10+
11+
# random
12+
r2d <- rsde2d(mod2d,at=0.5)
13+
summary(r2d)
14+
15+
# Marginal density
16+
17+
denM <- dsde2d(mod2d,pdf="M", at=0.5)
18+
denM
19+
plot(denM)
20+
21+
# Joint density
22+
denJ <- dsde2d(mod2d,pdf="J", at= 0.5)
23+
denJ
24+
plot(denJ)
25+
plot(denJ,display="contour")

tests/snssde.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library(Sim.DiffProc)
2+
3+
## sde 2-dim
4+
set.seed(1234)
5+
6+
fx <- expression( y , (4*( 1-x^2 )* y - x))
7+
gx <- expression( 0 , 0.2)
8+
9+
mod2d2 <- snssde2d(drift=fx,diffusion=gx,type="str",T=100,N=10000)
10+
mod2d2
11+
plot(mod2d2,pos=2)
12+
dev.new()
13+
plot(mod2d2,union = FALSE)
14+
dev.new()
15+
plot2d(mod2d2,type="n") ## in plane (O,X,Y)
16+
points2d(mod2d2,col=rgb(0,100,0,50,maxColorValue=255), pch=16)
17+
18+

0 commit comments

Comments
 (0)