Skip to content

Commit e2c5303

Browse files
committed
Version 4.7
1 parent be0974d commit e2c5303

File tree

5 files changed

+231
-441
lines changed

5 files changed

+231
-441
lines changed

inst/doc/bridgesde.R

Lines changed: 39 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -8,141 +8,59 @@ options(prompt="R> ",scipen=16,digits=5,warning=FALSE, message=FALSE,
88
## -------------------------------------------------------------------
99
f <- expression((1-x)/(1-t))
1010
g <- expression(x)
11-
mod <- bridgesde1d(drift=f,diffusion=g,x0=3,y=1,M=1000,method="milstein")
11+
mod <- bridgesde1d(drift=f,diffusion=g,x0=3,y=1,M=1000)
1212
mod
13-
summary(mod) ## default: summary at time = (T-t0)/2
1413

1514
## ----01,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE-----
1615
# plot(mod,ylab=expression(X[t]))
1716
# lines(time(mod),apply(mod$X,1,mean),col=2,lwd=2)
1817
# legend("topleft","mean path",inset = .01,col=2,lwd=2,cex=0.8,bty="n")
1918

20-
## ----33, echo=FALSE, fig.cap=' Bridge sde 1D ', fig.env='figure*',fig.width=7,fig.height=7----
21-
knitr::include_graphics("Figures/fig03.png")
22-
23-
## ----02, fig.cap=' ', fig.env='figure*'----------------------------
24-
m <- apply(mod$X,1,mean)
25-
S <- apply(mod$X,1,var)
26-
out <- data.frame(m,S)
27-
matplot(time(mod), out, type = "l", xlab = "time", ylab = "", col=2:3,lwd=2,lty=2:3,las=1)
28-
legend("topright",c(expression(m(t),S(t))),col=2:3,lty=2:3,lwd=2,bty="n")
29-
3019
## -------------------------------------------------------------------
31-
s = 0.55
32-
mean(mod, at = s)
33-
moment(mod, at = s , center = TRUE , order = 2) ## variance
34-
Median(mod, at = s)
35-
Mode(mod, at = s)
36-
quantile(mod , at = s)
37-
kurtosis(mod , at = s)
38-
skewness(mod , at = s)
39-
cv(mod , at = s )
40-
min(mod , at = s)
41-
max(mod , at = s)
42-
moment(mod, at = s , center= TRUE , order = 4)
43-
moment(mod, at = s , center= FALSE , order = 4)
20+
x <- rsde1d(object = mod, at = 0.55)
21+
head(x, n = 3)
4422

45-
## -------------------------------------------------------------------
46-
summary(mod, at = 0.55)
23+
## ----04,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE----
24+
# dens <- dsde1d(mod, at = 0.55)
25+
# plot(dens,hist=TRUE) ## histgramme
26+
# plot(dens,add=TRUE) ## kernel density
4727

48-
## -------------------------------------------------------------------
49-
x <- rsde1d(object = mod, at = s)
50-
head(x, n = 10)
51-
summary(x)
52-
53-
## ----03 ,fig.env='figure*', fig.cap=' '----------------------------
54-
plot(time(mod),mod$X[,1],type="l",ylab="X(t)",xlab="time",axes=F,lty=3)
55-
points(s,x[1],pch=19,col=2,cex=0.5)
56-
lines(c(s,s),c(0,x[1]),lty=2,col=2)
57-
lines(c(0,s),c(x[1],x[1]),lty=2,col=2)
58-
axis(1, s, bquote(at==.(s)),col=2,col.ticks=2)
59-
axis(2, x[1], bquote(X[t==.(s)]),col=2,col.ticks=2)
60-
legend('topright',col=2,pch=19,legend=bquote(X[t==.(s)]==.(x[1])),bty = 'n')
61-
box()
62-
63-
## ----04,fig.env='figure*', fig.cap=' '-----------------------------
64-
dens <- dsde1d(mod, at = s)
65-
dens
66-
plot(dens,hist=TRUE) ## histgramme
67-
plot(dens,add=TRUE) ## kernel density
68-
69-
## ----05,fig.env='figure*', fig.cap=' Transitional densitie at time $t-s = 0.25,0.75$ '----
70-
plot(dsde1d(mod,at=0.75))
71-
plot(dsde1d(mod,at=0.25),add=TRUE)
72-
legend('topright',col=c('#0000FF4B','#FF00004B'),pch=15,legend=c("t-s=0.25","t-s=0.75"),bty = 'n')
28+
## ----33, echo=FALSE, fig.cap='Bridge sde 1D. Histgramme and kernel density estimation for $X_{t}|X_{0}=3,X_{T}=1$', fig.env='figure*',fig.width=7,fig.height=7----
29+
knitr::include_graphics(c("Figures/fig03.png","Figures/fig1008.png"))
7330

7431
## -------------------------------------------------------------------
7532
fx <- expression(-(1+y)*x , -(1+x)*y)
7633
gx <- expression(0.2*(1-y),0.1*(1-x))
77-
mod2 <- bridgesde2d(drift=fx,diffusion=gx,x0=c(1,-0.5),y=c(1,0.5),Dt=0.01,M=1000,type="str",method="rk1")
34+
Sigma <-matrix(c(1,0.3,0.3,1),nrow=2,ncol=2)
35+
mod2 <- bridgesde2d(drift=fx,diffusion=gx,x0=c(1,-0.5),y=c(1,0.5),Dt=0.01,M=1000,type="str",corr=Sigma)
7836
mod2
79-
summary(mod2) ## default: summary at time = (T-t0)/2
8037

8138
## ----06,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE-----
8239
# plot(mod2,col=c('#FF00004B','#0000FF82'))
8340

84-
## ----333, echo=FALSE, fig.cap=' Bridge sde 2D ', fig.env='figure*',fig.width=7,fig.height=7----
41+
## ----333, echo=FALSE, fig.cap=' Bridge sde 2D ', fig.env='figure*',fig.width=5,fig.height=5----
8542
knitr::include_graphics("Figures/fig04.png")
8643

87-
## ----07, fig.cap=' ', fig.env='figure*'----------------------------
88-
m1 <- apply(mod2$X,1,mean)
89-
m2 <- apply(mod2$Y,1,mean)
90-
S1 <- apply(mod2$X,1,var)
91-
S2 <- apply(mod2$Y,1,var)
92-
C12 <- sapply(1:dim(mod2$X)[1],function(i) cov(mod2$X[i,],mod2$Y[i,]))
93-
out2 <- data.frame(m1,m2,S1,S2,C12)
94-
matplot(time(mod2), out2, type = "l", xlab = "time", ylab = "", col=2:6,lwd=2,lty=2:6,las=1)
95-
legend("top",c(expression(m[1](t),m[2](t),S[1](t),S[2](t),C[12](t))),col=2:6,lty=2:6,lwd=2,bty="n")
96-
9744
## -------------------------------------------------------------------
98-
s = 6.75
99-
mean(mod2, at = s)
100-
moment(mod2, at = s , center = TRUE , order = 2) ## variance
101-
Median(mod2, at = s)
102-
Mode(mod2, at = s)
103-
quantile(mod2 , at = s)
104-
kurtosis(mod2 , at = s)
105-
skewness(mod2 , at = s)
106-
cv(mod2 , at = s )
107-
min(mod2 , at = s)
108-
max(mod2 , at = s)
109-
moment(mod2 , at = s , center= TRUE , order = 4)
110-
moment(mod2 , at = s , center= FALSE , order = 4)
45+
x2 <- rsde2d(object = mod2, at = 5)
46+
head(x2, n = 3)
11147

112-
## -------------------------------------------------------------------
113-
summary(mod2, at = 6.75)
48+
## ----09,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE----
49+
# ## Marginal
50+
# denM <- dsde2d(mod2,pdf="M",at = 5)
51+
# plot(denM, main="Marginal Density")
52+
# ## Joint
53+
# denJ <- dsde2d(mod2, pdf="J", n=100,at = 5)
54+
# plot(denJ,display="contour",main="Bivariate Transition Density at time t=5")
11455

115-
## -------------------------------------------------------------------
116-
x2 <- rsde2d(object = mod2, at = s)
117-
head(x2, n = 10)
118-
summary(x2)
119-
120-
## ----08,fig.env='figure*', fig.cap=' '------------------------------
121-
plot(ts.union(mod2$X[,1],mod2$Y[,1]),col=1:2,lty=3,plot.type="single",type="l",ylab= "",xlab="time",axes=F)
122-
points(s,x2$x[1],pch=19,col=3,cex=0.8)
123-
points(s,x2$y[1],pch=19,col=4,cex=0.8)
124-
lines(c(s,s),c(-10,x2$x[1]),lty=2,col=6)
125-
lines(c(0,s),c(x2$x[1],x2$x[1]),lty=2,col=3)
126-
lines(c(0,s),c(x2$y[1],x2$y[1]),lty=2,col=4)
127-
axis(1, s, bquote(at==.(s)),col=6,col.ticks=6)
128-
axis(2, x2$x[1], bquote(X[t==.(s)]),col=3,col.ticks=3)
129-
axis(2, x2$y[1], bquote(Y[t==.(s)]),col=4,col.ticks=4)
130-
legend('topright',legend=bquote(c(X[t==.(s)]==.(x2$x[1]),Y[t==.(s)]==.(x2$y[1]))),bty = 'n')
131-
box()
132-
133-
## ----09,fig.env='figure*', fig.cap=' '-----------------------------
134-
denM <- dsde2d(mod2,pdf="M",at =s)
135-
denM
136-
plot(denM, main="Marginal Density")
137-
138-
## ----10,fig.env='figure*', fig.cap=' '-----------------------------
139-
denJ <- dsde2d(mod2, pdf="J", n=100,at =s)
140-
denJ
141-
plot(denJ,display="contour",main="Bivariate Transition Density at time t=6.755")
142-
plot(denJ,display="image",main="Bivariate Transition Density at time t=6.755")
143-
144-
## ----11,fig.env='figure*', fig.cap=' '-----------------------------
145-
plot(denJ,main="Bivariate Transition Density at time t=6.75")
56+
## ----103, echo=FALSE, fig.cap='The marginal and joint density of $X_{t}|X_{0}=1,X_{T}=1$ and $Y_{t}|Y_{0}=-0.5,Y_{T}=0.5$ at time $t=5$', fig.env='figure*',fig.width=7,fig.height=7----
57+
knitr::include_graphics(c("Figures/fig1009.png","Figures/fig1010.png"))
58+
59+
## ----11,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE----
60+
# plot(denJ,main="Bivariate Transition Density at time t=5")
61+
62+
## ----33303, echo=FALSE, fig.cap='$3$D plot of the transition density of $X_{t}|X_{0}=1,X_{T}=1$ and $Y_{t}|Y_{0}=-0.5,Y_{T}=0.5$ at time $t=5$ ', fig.env='figure*',fig.width=5,fig.height=5----
63+
knitr::include_graphics("Figures/fig1011.png")
14664

14765
## ----eval=FALSE, include=TRUE---------------------------------------
14866
# for (i in seq(1,9,by=0.005)){
@@ -154,74 +72,23 @@ fx <- expression(-4*(1+x)*y, 4*(1-y)*x, 4*(1-z)*y)
15472
gx <- rep(expression(0.2),3)
15573
mod3 <- bridgesde3d(x0=c(0,-1,0.5),y=c(0,-2,0.5),drift=fx,diffusion=gx,M=1000)
15674
mod3
157-
summary(mod3) ## default: summary at time = (T-t0)/2
15875

15976
## ----12,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE-----
16077
# plot(mod3) ## in time
16178
# plot3D(mod3,display = "persp",main="3D Bridge SDE's") ## in space
16279

163-
## ----3333, echo=FALSE, fig.cap=' ', fig.env='figure*',fig.width=7,fig.height=7----
164-
knitr::include_graphics("Figures/fig05.png")
165-
166-
## ----33333, echo=FALSE, fig.cap=' Bridge sde 3D ', fig.env='figure*',fig.width=7,fig.height=7----
167-
knitr::include_graphics("Figures/fig06.png")
168-
169-
## ----13, fig.cap=' ', fig.env='figure*'----------------------------
170-
m1 <- apply(mod3$X,1,mean)
171-
m2 <- apply(mod3$Y,1,mean)
172-
m3 <- apply(mod3$Z,1,mean)
173-
S1 <- apply(mod3$X,1,var)
174-
S2 <- apply(mod3$Y,1,var)
175-
S3 <- apply(mod3$Z,1,var)
176-
out3 <- data.frame(m1,m2,m3,S1,S2,S3)
177-
matplot(time(mod3), out3, type = "l", xlab = "time", ylab = "", col=2:7,lwd=2,lty=2:7,las=1)
178-
legend("bottom",c(expression(m[1](t),m[2](t),m[3](t),S[1](t),S[2](t),S[3](t))),col=2:7,lty=2:7,lwd=2,bty="n")
179-
180-
## -------------------------------------------------------------------
181-
s = 0.75
182-
mean(mod3, at = s)
183-
moment(mod3, at = s , center = TRUE , order = 2) ## variance
184-
Median(mod3, at = s)
185-
Mode(mod3, at = s)
186-
quantile(mod3 , at = s)
187-
kurtosis(mod3 , at = s)
188-
skewness(mod3 , at = s)
189-
cv(mod3 , at = s )
190-
min(mod3 , at = s)
191-
max(mod3 , at = s)
192-
moment(mod3 , at = s , center= TRUE , order = 4)
193-
moment(mod3 , at = s , center= FALSE , order = 4)
194-
195-
## -------------------------------------------------------------------
196-
summary(mod3, at = 0.75)
80+
## ----3333, echo=FALSE, fig.cap=' Bridge sde 3D ', fig.env='figure*',fig.width=7,fig.height=7----
81+
knitr::include_graphics(c("Figures/fig05.png","Figures/fig06.png"))
19782

19883
## -------------------------------------------------------------------
199-
x3 <- rsde3d(object = mod3, at = s)
200-
head(x3, n = 10)
201-
summary(x3)
202-
203-
## ----14,fig.env='figure*', fig.cap=' '------------------------------
204-
plot(ts.union(mod3$X[,1],mod3$Y[,1],mod3$Z[,1]),col=1:3,lty=3,plot.type="single",type="l",ylab= "",xlab="time",axes=F)
205-
points(s,x3$x[1],pch=19,col=4,cex=0.8)
206-
points(s,x3$y[1],pch=19,col=5,cex=0.8)
207-
points(s,x3$z[1],pch=19,col=6,cex=0.8)
208-
lines(c(s,s),c(-10,x3$x[1]),lty=2,col=7)
209-
lines(c(0,s),c(x3$x[1],x3$x[1]),lty=2,col=4)
210-
lines(c(0,s),c(x3$y[1],x3$y[1]),lty=2,col=5)
211-
lines(c(0,s),c(x3$z[1],x3$z[1]),lty=2,col=6)
212-
axis(1, s, bquote(at==.(s)),col=7,col.ticks=7)
213-
axis(2, x3$x[1], bquote(X[t==.(s)]),col=4,col.ticks=4)
214-
axis(2, x3$y[1], bquote(Y[t==.(s)]),col=5,col.ticks=5)
215-
axis(2, x3$z[1], bquote(Z[t==.(s)]),col=6,col.ticks=6)
216-
legend("bottomleft",legend=bquote(c(X[t==.(s)]==.(x3$x[1]),Y[t==.(s)]==.(x3$y[1]),Z[t==.(s)]==.(x3$z[1]))),bty = 'n',cex=0.75)
217-
box()
218-
219-
## ----15,fig.env='figure*', fig.cap=' '-----------------------------
220-
denM <- dsde3d(mod3,pdf="M",at =s)
221-
denM
222-
plot(denM, main="Marginal Density")
223-
224-
## ----111,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE----
84+
x3 <- rsde3d(object = mod3, at = 0.75)
85+
head(x3, n = 3)
86+
87+
## ----15,fig.env='figure*', fig.cap=' ',eval=FALSE, include=TRUE----
88+
# ## Marginal
89+
# denM <- dsde3d(mod3,pdf="M",at =0.75)
90+
# plot(denM, main="Marginal Density")
91+
# ## Joint
22592
# denJ <- dsde3d(mod3,pdf="J",at=0.75)
22693
# plot(denJ,display="rgl")
22794

inst/doc/fitsde.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Parms <- data.frame(Theta1,Theta2,Theta3,Theta4,row.names = c("True mod",
114114
"Comp mod1","Comp mod2","Comp mod3"))
115115
Parms
116116

117-
## ----01,fig.env='figure*', fig.cap=' '-----------------------------
117+
## ----01,fig.env='figure*', fig.cap=' The U.S. Interest Rates monthly form $06/1964$ to $12/1989$ ',fig.width=6,fig.height=4----
118118
data(Irates)
119119
rates <- Irates[, "r1"]
120120
X <- window(rates, start = 1964.471, end = 1989.333)
@@ -136,7 +136,7 @@ names(Info) <- c("logLik","AIC","BIC")
136136
Coef
137137
Info
138138

139-
## ----02,fig.env='figure*', fig.cap=' '-----------------------------
139+
## ----02,fig.env='figure*', fig.cap='The path mean of the solution of the CKLS model with the estimated parameters and real data ',fig.width=6,fig.height=4----
140140
f <- expression( (2.076-0.263*x) )
141141
g <- expression( 0.130*x^1.451 )
142142
mod <- snssde1d(drift=f,diffusion=g,x0=X[1],M=500, N=length(X),t0=1964.471, T=1989.333)

0 commit comments

Comments
 (0)