SlideShare a Scribd company logo
1 of 102
Download to read offline
Stochastic Problems in R
Tomas Gonz´alez
February 1, 2018
Contents
0.1 Simulations with yuima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1 Parameter estimation 38
1.1 Generator of moments method . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2 Model Selection 42
2.0.1 LASSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.1 Structural breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.2 Continuous Autoregressive Moving Average (CARMA) . . . . . . . . . . . . . 61
2.3 CO-GARCH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.4 Fractional integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Appendix 81
A Special Functions 82
A.1 Modified Bessel function of the third kind . . . . . . . . . . . . . . . . . . . . 82
A.1.1 Asymptotic relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
B Generalized hyperbolic (GH) distribution 84
B.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
B.2 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
B.3 Expected value and variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
B.4 Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
B.5 Moment generating function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
B.6 Linear transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
B.7 Special cases of the generalized hyperbolic distribution . . . . . . . . . . . . . 87
B.8 Parametrization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
B.8.1 (λ, χ, ψ, µ, Σ, γ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . 87
B.8.2 (λ, α, µ, Σ, γ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . . 88
B.8.3 (λ, α, µ, ∆, δ,βββ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . 89
B.8.4 Switching between different parametrizations . . . . . . . . . . . . . . . 89
B.8.5 Location and scale invariant parametrizations . . . . . . . . . . . . . . 90
B.8.6 Numerical implementation . . . . . . . . . . . . . . . . . . . . . . . . . 90
B.9 Fitting generalized hyperbolic distributions to data . . . . . . . . . . . . . . . 91
B.9.1 EM-Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
B.9.2 MCECM estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
B.10 Generalized inverse Gaussian distribution . . . . . . . . . . . . . . . . . . . . . 92
B.10.1 Gamma distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
1
CONTENTS 2
B.10.2 Inverse gamma distribution . . . . . . . . . . . . . . . . . . . . . . . . 93
B.11 Densities of the special cases of the GH distribution . . . . . . . . . . . . . . . 94
B.11.1 Student-t distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
B.11.2 Variance gamma distribution . . . . . . . . . . . . . . . . . . . . . . . 95
B.12 Conditional density of the mixing variable W . . . . . . . . . . . . . . . . . . 96
B.12.1 Generalized hyperbolic, hyperbolic and NIG distribution . . . . . . . . 96
B.12.2 Student-t distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
B.12.3 Variance gamma distribution . . . . . . . . . . . . . . . . . . . . . . . 97
List of Figures
1 y10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Paths of bilateral gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Paths of variance gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Paths of gamma process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Distribution of x1 and density of Γ(0.7, 1) . . . . . . . . . . . . . . . . . . . . 10
6 Distribution of x1 and density of IG(1, 2) . . . . . . . . . . . . . . . . . . . . 11
7 Paths of IG process (delta=1, gamma=2) . . . . . . . . . . . . . . . . . . . . 11
8 Distribution of x1 and density of IG(1, 2) . . . . . . . . . . . . . . . . . . . . 12
9 Paths of variance gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 14
10 Distribution of x1 and density of NG . . . . . . . . . . . . . . . . . . . . . . . 15
1.1 Market rate (rm) and CAPM stocks . . . . . . . . . . . . . . . . . . . . . . . 39
2.1 DEXUSEU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.2 Gaussian versus NIG for ENI.MI . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.3 US monthly interest rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.4 AAPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.5 log returns of AAPL (top) and change point statistics (bottom) . . . . . . . . 51
2.6 DWJ closings (top) and returns (bottom) with change points . . . . . . . . . 53
2.7 VIX daily log-Returns and ACF . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.8 ACF for inc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.9 Rescaled log-densities for VIX . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.10 Log-returns of NEXT Plc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.11 Simulated CARMA(3,1) process carma.mod. . . . . . . . . . . . . . . . . . . . 62
2.12 Simulated CP CARMA(2,1) process simCP . . . . . . . . . . . . . . . . . . . . 64
2.13 Compound Poisson with normal jump size carmaoptCP . . . . . . . . . . . . . 65
2.14 Simulated VG CARMA(2,1) process modVG . . . . . . . . . . . . . . . . . . . 66
2.15 Variance Gamma increments carmaoptVG . . . . . . . . . . . . . . . . . . . . 67
2.16 Levy noise increments incrLevy . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.17 Simulated NIG CARMA(2,1) process simNIG . . . . . . . . . . . . . . . . . . 69
2.18 Normal Inverse Gaussian carmaoptNIG . . . . . . . . . . . . . . . . . . . . . . 70
2.19 FitInc.NIG.Lev. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
2.20 CP-COGARCH(1,1) with Gaussian noise . . . . . . . . . . . . . . . . . . . . 73
2.21 CP-COGARCH(2,2) with Gaussian noise . . . . . . . . . . . . . . . . . . . . 76
2.22 VG-COGARCH(1,1) model with Euler scheme . . . . . . . . . . . . . . . . . 78
2.23 VG-COGARCH(1,1) model with mixed scheme . . . . . . . . . . . . . . . . . 79
2.24 Simulated VG-COGARCH(1,1) model with mixed scheme simVG . . . . . . . 80
A.1 Modified Bessel function of the third kind with different indices λ . . . . . . . 83
3
LIST OF FIGURES 4
B.1 Fit of Novartis log-returns to t-student and Gaussian distributions . . . . . . 98
B.2 Pairwise plot of three swiss blue chips . . . . . . . . . . . . . . . . . . . . . . 99
B.3 Fit of SMI index to hypergeometric distribution . . . . . . . . . . . . . . . . . 100
List of Tables
2.1 AIC for model selection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.2 Comparison of MLE and LASSO. . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.3 Normal.est. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
B.1 Parameters of the GH distribution . . . . . . . . . . . . . . . . . . . . . . . . 88
5
List of Examples
1.1 Example (Stochastic discount factor (SDF) for a CAPM) . . . . . . . . . . . . 38
1.2 Example (Short interest rates) . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.1 Example (DEXUSEU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.2 Example (Model selection for a stock price with jumps) . . . . . . . . . . . . . 44
2.3 Example (LASSO for US monthly interest rates) . . . . . . . . . . . . . . . . . 48
2.4 Example (Change point for APPL) . . . . . . . . . . . . . . . . . . . . . . . . 49
2.5 Example (Volatility change-point estimator on DWJ returns) . . . . . . . . . . 51
2.6 Example (Fit VIX to a Carma(2,1) process) . . . . . . . . . . . . . . . . . . . 53
2.7 Example (GARCH model for NXT.L) . . . . . . . . . . . . . . . . . . . . . . . 58
B.1 Example (Novartis log returns) . . . . . . . . . . . . . . . . . . . . . . . . . . 97
B.2 Example (Fitting a multivariate NIG distribution to three swiss blue chips) . . 98
B.3 Example (Fit the daily log-returns of the SMI to the hyperbolic distribution) . 99
0.1 Simulations with yuima
Simulation 0.1: Normal jump size.
yuima::simulate the process
set.seed(123)
mu <- 0
sigma <- 1
lambda <- 10
samp <- setSampling(Terminal=10, n=1000)
mod10 <- setPoisson(intensity="lambda", df=list("dnorm(z,mu,sigma)"))
y10 <- yuima::simulate(mod10,sampling=samp,
true.par=list(lambda=lambda,mu=0.1, sigma=2))
6
LIST OF EXAMPLES 7
0 2 4 6 8 10
−10−50510
Figure 1: y10
Simulation 0.2: Bilateral gamma process.
yuima::simulate the process
BGmodel <- setModel(drift="0", xinit="0", jump.coeff="1",
measure.type="code", measure=list(df="rbgamma(z, delta.minus=2,
gamma.minus=0.6, delta.plus=1.4, gamma.plus=0.3)"))
n <- 1000
samp <- setSampling(Terminal=1, n=n)
BGyuima <- setYuima(model=BGmodel, sampling=samp)
LIST OF EXAMPLES 8
0.0 0.2 0.4 0.6 0.8 1.0
−6−4−20246
x
0.0 0.2 0.4 0.6 0.8 1.0
−6−4−20246
x
0.0 0.2 0.4 0.6 0.8 1.0
−6−4−20246
x
0.0 0.2 0.4 0.6 0.8 1.0
−6−4−20246
x
Figure 2: Paths of bilateral gamma process
Simulation 0.3: Variance gamma process.
yuima::simulate the process
VGmodel <- setModel(drift="0", xinit="0", jump.coeff="1",
measure.type="code", measure=list(df="rbgamma(z, delta.minus=2,
gamma.minus=0.6, delta.plus=2, gamma.plus=0.3)"))
VGyuima <- setYuima(model=VGmodel, sampling=samp)
0.0 0.2 0.4 0.6 0.8 1.0
0510
x
0.0 0.2 0.4 0.6 0.8 1.0
0510
x
0.0 0.2 0.4 0.6 0.8 1.0
0510
x
0.0 0.2 0.4 0.6 0.8 1.0
0510
x
0.0 0.2 0.4 0.6 0.8 1.0
0510
x
Figure 3: Paths of variance gamma process
LIST OF EXAMPLES 9
Simulation 0.4: gamma process.
yuima::simulate the process
Gmodel <- setModel(drift="0", xinit="0", jump.coeff="1",
measure.type="code", measure=list(df="rgamma(z,
shape=0.7, scale=1)"))
n <- 10000
samp <- setSampling(Terminal=1, n=n)
Gyuima <- setYuima(model=Gmodel, sampling=samp)
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.01.2
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.01.2
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.01.2
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.01.2
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.01.2
x
Figure 4: Paths of gamma process
Simulation 0.5: gamma process.
yuima::simulate the process
LIST OF EXAMPLES 10
Density
0.0 0.5 1.0 1.5 2.0
0.00.51.01.52.02.53.0
Figure 5: Distribution of x1 and density of Γ(0.7, 1).
Simulation 0.6: inverse gamma process.
yuima::simulate the process
delta <- 1
gamma <- 2
set.seed(127)
x <- rIG(10^4,delta,gamma)
mean(x)
## [1] 0.498
var(x)
## [1] 0.128
LIST OF EXAMPLES 11
Density
0.0 0.5 1.0 1.5 2.0
0.00.51.01.52.0
Figure 6: Distribution of x1 and density of IG(1, 2).
Simulation 0.7: inverse gamma process.
yuima::simulate the process
IGmodel <- setModel(drift=0, xinit=0, jump.coeff=1,
measure.type="code", measure=list(df="rIG(z, delta=1, gamma=2)"))
n <- 1000
samp <- setSampling(Terminal=1, n=n)
IGyuima <- setYuima(model=IGmodel, sampling=samp)
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
x
0.0 0.2 0.4 0.6 0.8 1.0
0.00.20.40.60.81.0
x
Figure 7: Paths of IG process (delta=1, gamma=2).
LIST OF EXAMPLES 12
Simulation 0.8: inverse gamma process.
yuima::simulate the process
Distribution of X1 and Density of IG(1,2)
Density
0.0 0.5 1.0 1.5 2.0
0.00.51.01.52.0
Figure 8: Distribution of x1 and density of IG(1, 2).
Simulation 0.9: process.
yuima::simulate the process
rep <- 3000000
set.seed(129)
X1 <- rpts(rep,0.5,0.2,1)
hist(X1,xlim=c(0,3),ylim=c(0,3),breaks=100,
main=expression(X[1]),probability=TRUE)
LIST OF EXAMPLES 13
X1
X1
Density
0.0 0.5 1.0 1.5 2.0 2.5 3.0
0.00.51.01.52.02.53.0
X05 <- rpts(rep,0.5,0.1,1)
X05.prime <- rpts(rep,0.5,0.1,1)
Xsum <- X05+X05.prime
summary(X1)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.01 0.11 0.21 0.35 0.43 11.72
summary(Xsum)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.01 0.11 0.21 0.35 0.43 10.61
ks.test(X1,Xsum)
LIST OF EXAMPLES 14
##
## Two-sample Kolmogorov-Smirnov test
##
## data: X1 and Xsum
## D = 8e-04, p-value = 0.3
## alternative hypothesis: two-sided
rm(X1)
rm(Xsum)
rm(X05)
rm(X05.prime)
Simulation 0.10: vgamma process.
yuima::simulate the process
lambda <- 2
alpha <- 1.5
beta <- -0.7
mu <- 3
xinit <- 0
gamma <- sqrt(alpha^2-beta^2)
n <- 1000
T <- 1.8
VGPmodel <- setModel(drift=0, jump.coeff=1, measure.type="code",
measure=list(df="rvgamma(z,lambda,alpha,beta,mu)"))
samp <- setSampling(Terminal=T, n=n)
VGPyuima <- setYuima(model=VGPmodel, sampling=samp)
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
0.0 0.5 1.0 1.5
−4−20246
x
Figure 9: Paths of variance gamma process.
LIST OF EXAMPLES 15
n <- 5
samp <- setSampling(Terminal=T, n=n)
VGPyuima <- setYuima(model=VGPmodel, sampling=samp)
VGPsimdata <- NULL
for (i in 1:5000){
result <- yuima::simulate(VGPyuima, xinit=xinit,
true.par=list(lambda=lambda,alpha=alpha,beta=beta,mu=mu))
x1 <- result@data@original.data[n+1,1]
VGPsimdata <- c(VGPsimdata,as.numeric(x1[1]))
}
Density
−5 0 5 10
0.000.050.100.150.20
Figure 10: Distribution of x1 and density of NG.
Simulation 0.11: subordination process.
yuima::simulate the process
delta <- 0.5
alpha <- 1.5
beta <- -0.7
mu <- 3
gamma <- sqrt(alpha^2-beta^2)
n <- 10000
T <- 1.8
set.seed(127)
normal.rn <- rnorm(n,0,1)
iv.rn <- rIG(n,delta*T,gamma)
z <- mu*T+beta*iv.rn+sqrt(iv.rn)*normal.rn
title <- expression(paste(NIG[1.8],
" built by subordination (green) and rNIG (white)"))
LIST OF EXAMPLES 16
nig.rn <- rNIG(n,alpha,beta,delta*T,mu*T)
hist(z,xlim=c(-1,10),ylim=c(0,0.61),breaks=100, freq=FALSE,
col="green", main=title, xlab=expression(X[1.8]) )
curve(dNIG(x,alpha,beta,delta*T,mu*T),add=TRUE,col="red")
par(new=T)
hist(nig.rn,xlim=c(-1,10),ylim=c(0,0.61),breaks=100,
freq=FALSE, main="", xlab="")
NIG1.8 built by subordination (green) and rNIG (white)
X1.8
Density
0 2 4 6 8 10
0.00.10.20.30.40.50.6
Density
0 2 4 6 8 10
0.00.10.20.30.40.50.6
## delta1 <- 0.5
## alpha <- 1.5
## beta <- -0.7
## mu <- 3
LIST OF EXAMPLES 17
## xinit <- 0
## gamma <- sqrt(alpha^2-beta^2)
## n <- 1000
## T <- 1.8
## NIG2model <- setModel(drift=0, jump.coeff=1, measure.type="code",
## measure=list(df="rNIG(z,alpha,beta,delta1,mu)"))
## samp <- setSampling(Terminal=T, n=n)
## NIG2yuima <- setYuima(model=NIG2model, sampling=samp)
## set.seed(127)
## for (i in 1:10) {
## result <- yuima::simulate(NIG2yuima, xinit=xinit,
## true.par=list(delta1=delta1, alpha=alpha, beta=beta,
## mu=mu, gamma=gamma))
## plot(result,xlim=c(0,T),ylim=c(-1,10),col=i,
## main="Paths of NIG process",par(new=T))
## }
Simulation 0.12: inverse gamma process.
yuima::simulate the process
LIST OF EXAMPLES 18
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
0.0 0.5 1.0 1.5
0246810
t
x
Paths of NIG process
Simulation 0.13: inverse gamma process.
yuima::simulate the process
n <- 5
samp <- setSampling(Terminal=T, n=n)
NIG2yuima <- setYuima(model=NIG2model, sampling=samp)
NIG2data <- NULL
for (i in 1:3000){
result <- yuima::simulate(NIG2yuima, xinit=xinit,
true.par=list(delta1=delta1, alpha=alpha, beta=beta,
mu=mu, gamma=gamma))
x1 <- result@data@original.data[n+1,1]
NIG2data <- c(NIG2data,as.numeric(x1[1]))
LIST OF EXAMPLES 19
}
hist(NIG2data,xlim=c(2,8),ylim=c(0,0.8),breaks=100, freq=FALSE,
main=expression(paste("Distribution of ",X[1.8],
" and Density of NIG")))
curve(dNIG(x,alpha,beta,delta*T,mu*T),add=TRUE,col="red")
Distribution of X1.8 and Density of NIG
NIG2data
Density
2 3 4 5 6 7 8
0.00.20.40.60.8
Simulation 0.14: inverse gamma process.
yuima::simulate the process
nrep <- 10^4
alpha <- 0.5
delta <- 0.2
LIST OF EXAMPLES 20
gamma <- 1
beta <- 1
mu <- -0.7
Lambda <- matrix(1,1,1)
t <- 1.5
set.seed(127)
x <- rnts(nrep,alpha,delta*t,gamma,beta,mu*t,Lambda)
s <- rpts(nrep,alpha,delta*t,gamma)
w <- rnorm(nrep,0,1)
y <- rep(mu*t,nrep) + beta*s + sqrt(s)*w
opar<-par(mfrow=c(2,2))
hist(x,xlim=c(-3,3),ylim=c(0,1.2),breaks=200,
main=expression(X[t]),probability=TRUE)
hist(y,xlim=c(-3,3),ylim=c(0,1.2),breaks=200,
main=expression(Y[t]),probability=TRUE,col="red")
LIST OF EXAMPLES 21
Xt
x
Density
−3 −2 −1 0 1 2 3
0.00.40.81.2 Yt
y
Density
−3 −2 −1 0 1 2 3
0.00.40.81.2
Experiment by convolution
nrep <- 3*10^4
X1 <- rnts(nrep,alpha,delta*t,gamma,beta,mu*t,Lambda)
X05 <- rnts(nrep,alpha,delta*t/2,gamma,beta,mu*t/2,Lambda)
X05.prime <- rnts(nrep,alpha,delta*t/2,gamma,beta,mu*t/2,Lambda)
Xsum <- X05+X05.prime
hist(X1,xlim=c(-3,3),ylim=c(0,1.2),breaks=300,
main=expression(X[1]),probability=TRUE)
LIST OF EXAMPLES 22
X1
X1
Density
−3 −2 −1 0 1 2 3
0.00.20.40.60.81.01.2
hist(Xsum,xlim=c(-3,3),ylim=c(0,1.2),breaks=300,
main=expression(paste(X[t/2]+X[t/2],"'")),
probability=TRUE,col="red")
LIST OF EXAMPLES 23
Xt 2 + Xt 2'
Xsum
Density
−3 −2 −1 0 1 2 3
0.00.20.40.60.81.01.2
ks.test(X1,Xsum)
##
## Two-sample Kolmogorov-Smirnov test
##
## data: X1 and Xsum
## D = 0.05, p-value <2e-16
## alternative hypothesis: two-sided
## alpha <- 0.5
## beta <- -0.4
## sigma <- 0.7
## gamma <- 0.5
LIST OF EXAMPLES 24
## n <- 1000
## T <- 1.8
## ASmodel <- setModel(drift=0, jump.coeff=1, measure.type="code",
## measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
## samp <- setSampling(Terminal=T, n=n)
## ASyuima <- setYuima(model=ASmodel, sampling=samp)
## set.seed(129)
## for (i in 1:10) {
## result <- yuima::simulate(ASyuima, true.par=list(alpha=alpha,
## beta=beta,sigma=sigma,gamma=gamma))
## plot(result,xlim=c(0,T),ylim=c(-40,10),col=i,
## main=expression(paste("Paths of stable process (",
## alpha==0.5,",",beta==-0.4,")")),par(new=T))
## }
##
## #param2
## alpha <- 1
## beta <- -0.4
## sigma <- 0.7
## gamma <- 0.5
## AS2model <- setModel(drift=0, jump.coeff=1, measure.type="code",
## measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
## AS2yuima <- setYuima(model=AS2model, sampling=samp)
## for (i in 1:10) {
## result <- yuima::simulate(AS2yuima, true.par=list(alpha=alpha,
## beta=beta,sigma=sigma,gamma=gamma))
## plot(result,xlim=c(0,T),ylim=c(-5,5),col=i,
## main=expression(paste("Paths of stable process (",
## alpha==1,",",beta==-0.4,")")),par(new=T))
## }
##
## #param3
## alpha <- 1
## beta <- 0.4
## sigma <- 0.7
## gamma <- 0.5
## AS3model <- setModel(drift=0, jump.coeff=1, measure.type="code",
## measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
## AS3yuima <- setYuima(model=AS3model, sampling=samp)
## for (i in 1:10) {
## result <- yuima::simulate(AS3yuima, true.par=list(alpha=alpha,
## beta=beta,sigma=sigma,gamma=gamma))
## plot(result,xlim=c(0,T),ylim=c(-5,5),col=i,
## main=expression(paste("Paths of stable process (",
## alpha==1,",",beta==0.4,")")),par(new=T))
## }
LIST OF EXAMPLES 25
##
## #param4
## alpha <- 1.5
## beta <- 0.4
## sigma <- 0.7
## gamma <- 0.5
## AS4model <- setModel(drift=0, jump.coeff=1, measure.type="code",
## measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
## AS4yuima <- setYuima(model=AS4model, sampling=samp)
## for (i in 1:10) {
## result <- yuima::simulate(AS4yuima, true.par=list(alpha=alpha,
## beta=beta, sigma=sigma,gamma=gamma))
## plot(result,xlim=c(0,T),ylim=c(-3,5),col=i,
## main=expression(paste("Paths of stable process (",
## alpha==1.5,",",beta==0.4,")")),par(new=T))
## }
Simulation 0.15:.
opar<-par(mar=c(4,4,2,1))
set.seed(129)
for (i in 1:10) {
result <- yuima::simulate(ASyuima, true.par=list(alpha=alpha,
beta=beta,sigma=sigma,gamma=gamma))
plot(result,xlim=c(0,T),ylim=c(-40,10),col=i,
main=expression(paste("Paths of stable process (",
alpha==0.5,",",beta==-0.4,")")),par(new=T))
}
LIST OF EXAMPLES 26
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
0.0 0.5 1.0 1.5
−40−30−20−10010
t
x
Paths of stable process (α = 0.5,β = −0.4)
par(opar)
Simulation 0.16:.
#param2
alpha <- 1
beta <- -0.4
sigma <- 0.7
gamma <- 0.5
AS2model <- setModel(drift=0, jump.coeff=1, measure.type="code",
measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
AS2yuima <- setYuima(model=AS2model, sampling=samp)
LIST OF EXAMPLES 27
opar<-par(mar=c(4,4,2,1))
for (i in 1:10) {
result <- yuima::simulate(AS2yuima, true.par=list(alpha=alpha,
beta=beta,sigma=sigma,gamma=gamma))
plot(result,xlim=c(0,T),ylim=c(-5,5),col=i,
main=expression(paste("Paths of stable process (",
alpha==1,",",beta==-0.4,")")),par(new=T))
}
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = −0.4)
par(opar)
opar<-par(mar=c(4,4,2,1))
#param3
LIST OF EXAMPLES 28
alpha <- 1
beta <- 0.4
sigma <- 0.7
gamma <- 0.5
AS3model <- setModel(drift=0, jump.coeff=1, measure.type="code",
measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
AS3yuima <- setYuima(model=AS3model, sampling=samp)
for (i in 1:10) {
result <- yuima::simulate(AS3yuima, true.par=list(alpha=alpha,
beta=beta,sigma=sigma,gamma=gamma))
plot(result,xlim=c(0,T),ylim=c(-5,5),col=i,
main=expression(paste("Paths of stable process (",
alpha==1,",",beta==0.4,")")),par(new=T))
}
LIST OF EXAMPLES 29
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
0.0 0.5 1.0 1.5
−4−2024
t
x
Paths of stable process (α = 1,β = 0.4)
par(opar)
#param4
alpha <- 1.5
beta <- 0.4
sigma <- 0.7
gamma <- 0.5
AS4model <- setModel(drift=0, jump.coeff=1, measure.type="code",
measure=list(df="rstable(z,alpha,beta,sigma,gamma)"))
AS4yuima <- setYuima(model=AS4model, sampling=samp)
opar<-par(mar=c(4,4,2,1))
for (i in 1:10) {
LIST OF EXAMPLES 30
result <- yuima::simulate(AS4yuima, true.par=list(alpha=alpha,beta=beta,
sigma=sigma,gamma=gamma))
plot(result,xlim=c(0,T),ylim=c(-3,5),col=i,
main=expression(paste("Paths of stable process (",
alpha==1.5,",",beta==0.4,")")),par(new=T))
}
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
0.0 0.5 1.0 1.5
−2024
t
x
Paths of stable process (α = 1.5,β = 0.4)
par(opar)
Simulation 0.17:.
LIST OF EXAMPLES 31
modJump <- setModel(drift = c("-theta*x"), diffusion = "sigma",
jump.coeff=c("gamma+x/sqrt(1+x^2)"),
measure = list(intensity="lambda",df=list("dnorm(z, -3, 1)")),
measure.type="CP", solve.variable="x")
modJump
##
## Diffusion process with Levy jumps
## Number of equations: 1
## Number of Wiener noises: 1
## Number of Levy noises: 1
## Parametric model with 4 parameters
samp <- setSampling(n=10^4,Terminal=10)
set.seed(125)
X <- yuima::simulate(modJump, xinit=2, sampling=samp,
true.par= list(theta=2, sigma=0.5,gamma=0.3,lambda=0.5))
0 2 4 6 8 10
−1.00.01.02.0
t
x
x0 <- 2
a <- 0.1
c <- -1
model.ig <- setModel(drift="a*x", xinit=x0, jump.coeff=c,
measure.type="code", measure=list(df="rIG(z, delta0, gamma)"))
model.ig
## Levy process
## Number of equations: 1
## Number of Levy noises: 1
## Parametric model with 3 parameters
LIST OF EXAMPLES 32
sampling.ig <- setSampling(Terminal=10, n=10000)
yuima.ig <- setYuima(model=model.ig, sampling=sampling.ig)
set.seed(128)
result.ig <- yuima::simulate(yuima.ig,true.par=list(delta0=0.55,gamma=2))
0 2 4 6 8 10
1.92.02.12.2
t
x
Simulation 0.18:.
x0 <- 2
a <- 0.1
c <- -1
model.nig <- setModel(drift="a*x", xinit=x0, jump.coeff=c,
measure.type="code",measure=list(df="rNIG(z, alpha,
beta, delta0, mu)"))
sampling.nig <- setSampling(Terminal=10, n=10000)
yuima.nig <- setYuima(model=model.nig, sampling=sampling.ig)
set.seed(128)
result.nig <- yuima::simulate(yuima.nig,true.par=list(alpha=2, beta=0,
delta0=0.55, mu=0))
LIST OF EXAMPLES 33
0 2 4 6 8 10
2.03.0
t
x
Simulation 0.19:.
x0 <- 2
a <- 0.1
c <- -1
Lambda <- matrix(1,1,1)
model.nig <- setModel(drift="a*x", xinit=x0, jump.coeff=c,
measure.type="code",measure=list(df="rNIG(z, alpha,
beta, delta0, mu, Lambda)"))
sampling.nig <- setSampling(Terminal=10, n=10000)
yuima.nig <- setYuima(model=model.nig, sampling=sampling.ig)
set.seed(128)
result.nig <- yuima::simulate(yuima.nig,true.par=list(alpha=2,
beta=0, delta0=0.55, mu=0, Lambda=Lambda))
LIST OF EXAMPLES 34
0 2 4 6 8 10
2.03.0
t
x
Simulation 0.20:.
x0 <- c(2,3)
a1 <- function(t,x1,x2){ x1*cos(2*pi*t)-x2*sin(2*pi*t) }
a2 <- function(t,x1,x2){ x1*sin(2*pi*t)+x2*cos(2*pi*t) }
a <- c("a1(t,x1,x2)","a2(t,x1,x2)")
b <- matrix(c("t*x2","1","0","x1"),2,2)
c <- matrix(c("cos(2*pi*t)", "(5-t)*x1","sin(2*pi*t)",1),2,2)
alpha <- 2
beta <- c(0,0)
delta0 <- 0.55
mu <- c(0,0)
Lambda <- matrix(c(1,0,0,1),2,2)
model.mnig <- setModel(drift=a, xinit=x0, diffusion=b,
jump.coeff=c, measure.type="code",
measure=list(df="rNIG(z, alpha, beta, delta0, mu, Lambda)"),
state.variable=c("x1","x2"),solve.variable=c("x1","x2") )
model.mnig
##
## Diffusion process with Levy jumps
## Number of equations: 2
## Number of Wiener noises: 2
## Number of Levy noises: 1
## Parametric model with 7 parameters
sampling.mnig <- setSampling(Terminal=1, n=10000)
yuima.mnig <- setYuima(model=model.mnig, sampling=sampling.mnig)
set.seed(128)
LIST OF EXAMPLES 35
result.mnig <- yuima::simulate(yuima.mnig,true.par=list(alpha=alpha,
beta=beta, delta0=delta0, mu=mu, Lambda=Lambda))
−1.01.5
x1
0.0 0.2 0.4 0.6 0.8 1.0
t
2.04.0
x2
Simulation 0.21:.
mod5 <- setModel(drift = c("-theta*x"), diffusion = "sigma",
jump.coeff=c("gamma+x/sqrt(1+x^2)"),
measure = list(intensity="lambda",df=list("dnorm(z, 2, 0.1)")),
measure.type="CP", solve.variable="x")
theta <- 2
sigma <- 0.5
gamma <- 0.3
lambda <- 2.5
T <- 10
N <- 10000
delta <- T/N
h <- T/N
true <- list(theta=theta, sigma=sigma,gamma=gamma,lambda=lambda)
set.seed(125)
X <- yuima::simulate(mod5, true.p=true,xinit=2,
sampling=setSampling(n=N,Terminal=T))
LIST OF EXAMPLES 36
0 2 4 6 8 10
02468
t
x
r <- h^0.4
est.qmle <- qmle(yuima=X, start=true,
lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1),
upper=list(theta=3,sigma=2,gamma=0.8,lambda=20), method="L-BFGS-B",
threshold=r)
unlist(true)
## theta sigma gamma lambda
## 2.0 0.5 0.3 2.5
summary(est.qmle)
## Quasi-Maximum likelihood estimation
##
## Call:
## qmle(yuima = X, start = true, method = "L-BFGS-B", lower = list(theta = 1,
## sigma = 0, gamma = 0.1, lambda = 0.1), upper = list(theta = 3,
## sigma = 2, gamma = 0.8, lambda = 20), threshold = r)
##
## Coefficients:
## Estimate Std. Error
## sigma 0.501 0.00355
## theta 2.053 0.04959
## lambda 2.500 0.50000
## gamma 0.309 0.00803
##
## -2 log L: -53574
##
##
## Number of estimated jumps: 25
LIST OF EXAMPLES 37
##
## Average inter-arrival times: 0.325708
##
## Average jump size: 2.002308
##
## Standard Dev. of jump size: 0.796882
##
## Jump Threshold: 0.063096
##
## Summary statistics for jump times:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.33 2.72 6.34 5.61 8.11 9.15
##
## Summary statistics for jump size:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.072 1.795 2.335 2.002 2.544 2.742
est.qmle1 <- qmle(yuima=X, start=true,
lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1),
upper=list(theta=3,sigma=2,gamma=0.8,lambda=20), method="L-BFGS-B",
threshold=2) # too large
summary(est.qmle1)@coef
## Estimate Std. Error
## sigma 1.454 0.0103
## theta 1.978 0.1438
## lambda 1.600 0.4000
## gamma 0.295 0.0155
est.qmle2 <- qmle(yuima=X, start=true,
lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1),
upper=list(theta=3,sigma=2,gamma=10,lambda=1000), method="L-BFGS-B",
threshold=0.03) ## too low
summary(est.qmle2)@coef
## Estimate Std. Error
## sigma 0.427 0.003188
## theta 1.460 0.045165
## lambda 77.852 2.799724
## gamma 0.111 0.000103
Chapter 1
Parameter estimation
1.1 Generator of moments method
Example 1.1: Stochastic discount factor (SDF) for a CAPM.
The general theory in Jagannathan and Skoulakis [2002] implies that E(DtRi,t) = 1 for all
stocks i = 1, . . . , N, where Dt is the SDF and Ri,t the gross return 1 + ri,t. It can be shown
that if the CAPM holds, Dt = θ0 + θ1Rm,t where Rm,t the gross return of the market, which
implies the following moment conditions:
E [Ri,t(θ0 + θ1Rm,t) − 1] = 0 for i = 1, . . . , N
which can be tested as follows:
g <- function(theta, x) {
ret <- (theta[1] + theta[2] * (1 + c(x[, 1]))) * (1 + x[, -1]) - 1
return(ret)
}
Dataset Finance in package gmm Chausse [2017] contains daily returns on selected stocks, the
market portfolio and factors of Fama and French1
from 1993-01-05 to 2009-01-30.
library(gmm)
data("Finance")
x <- Finance[, c("rm", "UIS","ORB","MAT","ABAX","T")]
1
http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html
38
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R
Stochastic Processes in R

More Related Content

What's hot

MR Neurography
MR NeurographyMR Neurography
MR Neurographyswalih121
 
U-Net: Convolutional Networks for Biomedical Image Segmentation
U-Net: Convolutional Networks for Biomedical Image SegmentationU-Net: Convolutional Networks for Biomedical Image Segmentation
U-Net: Convolutional Networks for Biomedical Image Segmentationfake can
 
CT perfusion physics and its application in Neuroimaging
CT perfusion physics and its application in NeuroimagingCT perfusion physics and its application in Neuroimaging
CT perfusion physics and its application in NeuroimagingDr.Suhas Basavaiah
 
PHU LUC BANG TINH.pdf
PHU LUC BANG TINH.pdfPHU LUC BANG TINH.pdf
PHU LUC BANG TINH.pdfKhai Truong
 
Radiological Evaluation of CNS Tumors
Radiological Evaluation of CNS TumorsRadiological Evaluation of CNS Tumors
Radiological Evaluation of CNS TumorsSubhash Thakur
 
Image segmentation with deep learning
Image segmentation with deep learningImage segmentation with deep learning
Image segmentation with deep learningAntonio Rueda-Toicen
 
은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)찬희 이
 
Breeding Management Software | Phenome Networks
Breeding Management Software | Phenome NetworksBreeding Management Software | Phenome Networks
Breeding Management Software | Phenome NetworksPhenome Networks
 
내가 이해하는 SVM(왜, 어떻게를 중심으로)
내가 이해하는 SVM(왜, 어떻게를 중심으로)내가 이해하는 SVM(왜, 어떻게를 중심으로)
내가 이해하는 SVM(왜, 어떻게를 중심으로)SANG WON PARK
 
머신러닝의 자연어 처리기술(I)
머신러닝의 자연어 처리기술(I)머신러닝의 자연어 처리기술(I)
머신러닝의 자연어 처리기술(I)홍배 김
 
Spinal trauma IMAGING
Spinal trauma  IMAGINGSpinal trauma  IMAGING
Spinal trauma IMAGINGSanal Kumar
 

What's hot (12)

MR Neurography
MR NeurographyMR Neurography
MR Neurography
 
U-Net: Convolutional Networks for Biomedical Image Segmentation
U-Net: Convolutional Networks for Biomedical Image SegmentationU-Net: Convolutional Networks for Biomedical Image Segmentation
U-Net: Convolutional Networks for Biomedical Image Segmentation
 
CT perfusion physics and its application in Neuroimaging
CT perfusion physics and its application in NeuroimagingCT perfusion physics and its application in Neuroimaging
CT perfusion physics and its application in Neuroimaging
 
PHU LUC BANG TINH.pdf
PHU LUC BANG TINH.pdfPHU LUC BANG TINH.pdf
PHU LUC BANG TINH.pdf
 
Radiological Evaluation of CNS Tumors
Radiological Evaluation of CNS TumorsRadiological Evaluation of CNS Tumors
Radiological Evaluation of CNS Tumors
 
Image segmentation with deep learning
Image segmentation with deep learningImage segmentation with deep learning
Image segmentation with deep learning
 
은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)
 
Breeding Management Software | Phenome Networks
Breeding Management Software | Phenome NetworksBreeding Management Software | Phenome Networks
Breeding Management Software | Phenome Networks
 
내가 이해하는 SVM(왜, 어떻게를 중심으로)
내가 이해하는 SVM(왜, 어떻게를 중심으로)내가 이해하는 SVM(왜, 어떻게를 중심으로)
내가 이해하는 SVM(왜, 어떻게를 중심으로)
 
Kalman Filter
 Kalman Filter    Kalman Filter
Kalman Filter
 
머신러닝의 자연어 처리기술(I)
머신러닝의 자연어 처리기술(I)머신러닝의 자연어 처리기술(I)
머신러닝의 자연어 처리기술(I)
 
Spinal trauma IMAGING
Spinal trauma  IMAGINGSpinal trauma  IMAGING
Spinal trauma IMAGING
 

Similar to Stochastic Processes in R

Morton john canty image analysis and pattern recognition for remote sensing...
Morton john canty   image analysis and pattern recognition for remote sensing...Morton john canty   image analysis and pattern recognition for remote sensing...
Morton john canty image analysis and pattern recognition for remote sensing...Kevin Peña Ramos
 
Donhauser - 2012 - Jump Variation From High-Frequency Asset Returns
Donhauser - 2012 - Jump Variation From High-Frequency Asset ReturnsDonhauser - 2012 - Jump Variation From High-Frequency Asset Returns
Donhauser - 2012 - Jump Variation From High-Frequency Asset ReturnsBrian Donhauser
 
Methods for Applied Macroeconomic Research.pdf
Methods for Applied Macroeconomic Research.pdfMethods for Applied Macroeconomic Research.pdf
Methods for Applied Macroeconomic Research.pdfComrade15
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFaniruddh Tyagi
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFAniruddh Tyagi
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFaniruddh Tyagi
 
Memoire antoine pissoort_aout2017
Memoire antoine pissoort_aout2017Memoire antoine pissoort_aout2017
Memoire antoine pissoort_aout2017Antoine Pissoort
 
Lower Bound methods for the Shakedown problem of WC-Co composites
Lower Bound methods for the Shakedown problem of WC-Co compositesLower Bound methods for the Shakedown problem of WC-Co composites
Lower Bound methods for the Shakedown problem of WC-Co compositesBasavaRaju Akula
 
Lecture notes on planetary sciences and orbit determination
Lecture notes on planetary sciences and orbit determinationLecture notes on planetary sciences and orbit determination
Lecture notes on planetary sciences and orbit determinationErnst Schrama
 

Similar to Stochastic Processes in R (20)

Morton john canty image analysis and pattern recognition for remote sensing...
Morton john canty   image analysis and pattern recognition for remote sensing...Morton john canty   image analysis and pattern recognition for remote sensing...
Morton john canty image analysis and pattern recognition for remote sensing...
 
Donhauser - 2012 - Jump Variation From High-Frequency Asset Returns
Donhauser - 2012 - Jump Variation From High-Frequency Asset ReturnsDonhauser - 2012 - Jump Variation From High-Frequency Asset Returns
Donhauser - 2012 - Jump Variation From High-Frequency Asset Returns
 
Manual Gstat
Manual GstatManual Gstat
Manual Gstat
 
mchr dissertation2
mchr dissertation2mchr dissertation2
mchr dissertation2
 
Methods for Applied Macroeconomic Research.pdf
Methods for Applied Macroeconomic Research.pdfMethods for Applied Macroeconomic Research.pdf
Methods for Applied Macroeconomic Research.pdf
 
Diederik Fokkema - Thesis
Diederik Fokkema - ThesisDiederik Fokkema - Thesis
Diederik Fokkema - Thesis
 
t
tt
t
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDF
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDF
 
Michael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDFMichael_Lavrentiev_Trans trating.PDF
Michael_Lavrentiev_Trans trating.PDF
 
Erlangga
ErlanggaErlangga
Erlangga
 
Memoire antoine pissoort_aout2017
Memoire antoine pissoort_aout2017Memoire antoine pissoort_aout2017
Memoire antoine pissoort_aout2017
 
Mat power manual
Mat power manualMat power manual
Mat power manual
 
Thesis lebanon
Thesis lebanonThesis lebanon
Thesis lebanon
 
Lower Bound methods for the Shakedown problem of WC-Co composites
Lower Bound methods for the Shakedown problem of WC-Co compositesLower Bound methods for the Shakedown problem of WC-Co composites
Lower Bound methods for the Shakedown problem of WC-Co composites
 
Lecture notes on planetary sciences and orbit determination
Lecture notes on planetary sciences and orbit determinationLecture notes on planetary sciences and orbit determination
Lecture notes on planetary sciences and orbit determination
 
BenThesis
BenThesisBenThesis
BenThesis
 
time_series.pdf
time_series.pdftime_series.pdf
time_series.pdf
 
D-STG-SG02.16.1-2001-PDF-E.pdf
D-STG-SG02.16.1-2001-PDF-E.pdfD-STG-SG02.16.1-2001-PDF-E.pdf
D-STG-SG02.16.1-2001-PDF-E.pdf
 
lapointe_thesis
lapointe_thesislapointe_thesis
lapointe_thesis
 

Recently uploaded

VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 

Recently uploaded (20)

VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 

Stochastic Processes in R

  • 1. Stochastic Problems in R Tomas Gonz´alez February 1, 2018
  • 2. Contents 0.1 Simulations with yuima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1 Parameter estimation 38 1.1 Generator of moments method . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 2 Model Selection 42 2.0.1 LASSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.1 Structural breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.2 Continuous Autoregressive Moving Average (CARMA) . . . . . . . . . . . . . 61 2.3 CO-GARCH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 2.4 Fractional integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Appendix 81 A Special Functions 82 A.1 Modified Bessel function of the third kind . . . . . . . . . . . . . . . . . . . . 82 A.1.1 Asymptotic relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 B Generalized hyperbolic (GH) distribution 84 B.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 B.2 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 B.3 Expected value and variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 B.4 Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 B.5 Moment generating function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 B.6 Linear transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 B.7 Special cases of the generalized hyperbolic distribution . . . . . . . . . . . . . 87 B.8 Parametrization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 B.8.1 (λ, χ, ψ, µ, Σ, γ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . 87 B.8.2 (λ, α, µ, Σ, γ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . . 88 B.8.3 (λ, α, µ, ∆, δ,βββ)-Parametrization . . . . . . . . . . . . . . . . . . . . . . 89 B.8.4 Switching between different parametrizations . . . . . . . . . . . . . . . 89 B.8.5 Location and scale invariant parametrizations . . . . . . . . . . . . . . 90 B.8.6 Numerical implementation . . . . . . . . . . . . . . . . . . . . . . . . . 90 B.9 Fitting generalized hyperbolic distributions to data . . . . . . . . . . . . . . . 91 B.9.1 EM-Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 B.9.2 MCECM estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 B.10 Generalized inverse Gaussian distribution . . . . . . . . . . . . . . . . . . . . . 92 B.10.1 Gamma distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 1
  • 3. CONTENTS 2 B.10.2 Inverse gamma distribution . . . . . . . . . . . . . . . . . . . . . . . . 93 B.11 Densities of the special cases of the GH distribution . . . . . . . . . . . . . . . 94 B.11.1 Student-t distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 B.11.2 Variance gamma distribution . . . . . . . . . . . . . . . . . . . . . . . 95 B.12 Conditional density of the mixing variable W . . . . . . . . . . . . . . . . . . 96 B.12.1 Generalized hyperbolic, hyperbolic and NIG distribution . . . . . . . . 96 B.12.2 Student-t distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 B.12.3 Variance gamma distribution . . . . . . . . . . . . . . . . . . . . . . . 97
  • 4. List of Figures 1 y10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2 Paths of bilateral gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 8 3 Paths of variance gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 8 4 Paths of gamma process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5 Distribution of x1 and density of Γ(0.7, 1) . . . . . . . . . . . . . . . . . . . . 10 6 Distribution of x1 and density of IG(1, 2) . . . . . . . . . . . . . . . . . . . . 11 7 Paths of IG process (delta=1, gamma=2) . . . . . . . . . . . . . . . . . . . . 11 8 Distribution of x1 and density of IG(1, 2) . . . . . . . . . . . . . . . . . . . . 12 9 Paths of variance gamma process . . . . . . . . . . . . . . . . . . . . . . . . . 14 10 Distribution of x1 and density of NG . . . . . . . . . . . . . . . . . . . . . . . 15 1.1 Market rate (rm) and CAPM stocks . . . . . . . . . . . . . . . . . . . . . . . 39 2.1 DEXUSEU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.2 Gaussian versus NIG for ENI.MI . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.3 US monthly interest rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.4 AAPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.5 log returns of AAPL (top) and change point statistics (bottom) . . . . . . . . 51 2.6 DWJ closings (top) and returns (bottom) with change points . . . . . . . . . 53 2.7 VIX daily log-Returns and ACF . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.8 ACF for inc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2.9 Rescaled log-densities for VIX . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 2.10 Log-returns of NEXT Plc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.11 Simulated CARMA(3,1) process carma.mod. . . . . . . . . . . . . . . . . . . . 62 2.12 Simulated CP CARMA(2,1) process simCP . . . . . . . . . . . . . . . . . . . . 64 2.13 Compound Poisson with normal jump size carmaoptCP . . . . . . . . . . . . . 65 2.14 Simulated VG CARMA(2,1) process modVG . . . . . . . . . . . . . . . . . . . 66 2.15 Variance Gamma increments carmaoptVG . . . . . . . . . . . . . . . . . . . . 67 2.16 Levy noise increments incrLevy . . . . . . . . . . . . . . . . . . . . . . . . . 68 2.17 Simulated NIG CARMA(2,1) process simNIG . . . . . . . . . . . . . . . . . . 69 2.18 Normal Inverse Gaussian carmaoptNIG . . . . . . . . . . . . . . . . . . . . . . 70 2.19 FitInc.NIG.Lev. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 2.20 CP-COGARCH(1,1) with Gaussian noise . . . . . . . . . . . . . . . . . . . . 73 2.21 CP-COGARCH(2,2) with Gaussian noise . . . . . . . . . . . . . . . . . . . . 76 2.22 VG-COGARCH(1,1) model with Euler scheme . . . . . . . . . . . . . . . . . 78 2.23 VG-COGARCH(1,1) model with mixed scheme . . . . . . . . . . . . . . . . . 79 2.24 Simulated VG-COGARCH(1,1) model with mixed scheme simVG . . . . . . . 80 A.1 Modified Bessel function of the third kind with different indices λ . . . . . . . 83 3
  • 5. LIST OF FIGURES 4 B.1 Fit of Novartis log-returns to t-student and Gaussian distributions . . . . . . 98 B.2 Pairwise plot of three swiss blue chips . . . . . . . . . . . . . . . . . . . . . . 99 B.3 Fit of SMI index to hypergeometric distribution . . . . . . . . . . . . . . . . . 100
  • 6. List of Tables 2.1 AIC for model selection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.2 Comparison of MLE and LASSO. . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.3 Normal.est. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 B.1 Parameters of the GH distribution . . . . . . . . . . . . . . . . . . . . . . . . 88 5
  • 7. List of Examples 1.1 Example (Stochastic discount factor (SDF) for a CAPM) . . . . . . . . . . . . 38 1.2 Example (Short interest rates) . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.1 Example (DEXUSEU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.2 Example (Model selection for a stock price with jumps) . . . . . . . . . . . . . 44 2.3 Example (LASSO for US monthly interest rates) . . . . . . . . . . . . . . . . . 48 2.4 Example (Change point for APPL) . . . . . . . . . . . . . . . . . . . . . . . . 49 2.5 Example (Volatility change-point estimator on DWJ returns) . . . . . . . . . . 51 2.6 Example (Fit VIX to a Carma(2,1) process) . . . . . . . . . . . . . . . . . . . 53 2.7 Example (GARCH model for NXT.L) . . . . . . . . . . . . . . . . . . . . . . . 58 B.1 Example (Novartis log returns) . . . . . . . . . . . . . . . . . . . . . . . . . . 97 B.2 Example (Fitting a multivariate NIG distribution to three swiss blue chips) . . 98 B.3 Example (Fit the daily log-returns of the SMI to the hyperbolic distribution) . 99 0.1 Simulations with yuima Simulation 0.1: Normal jump size. yuima::simulate the process set.seed(123) mu <- 0 sigma <- 1 lambda <- 10 samp <- setSampling(Terminal=10, n=1000) mod10 <- setPoisson(intensity="lambda", df=list("dnorm(z,mu,sigma)")) y10 <- yuima::simulate(mod10,sampling=samp, true.par=list(lambda=lambda,mu=0.1, sigma=2)) 6
  • 8. LIST OF EXAMPLES 7 0 2 4 6 8 10 −10−50510 Figure 1: y10 Simulation 0.2: Bilateral gamma process. yuima::simulate the process BGmodel <- setModel(drift="0", xinit="0", jump.coeff="1", measure.type="code", measure=list(df="rbgamma(z, delta.minus=2, gamma.minus=0.6, delta.plus=1.4, gamma.plus=0.3)")) n <- 1000 samp <- setSampling(Terminal=1, n=n) BGyuima <- setYuima(model=BGmodel, sampling=samp)
  • 9. LIST OF EXAMPLES 8 0.0 0.2 0.4 0.6 0.8 1.0 −6−4−20246 x 0.0 0.2 0.4 0.6 0.8 1.0 −6−4−20246 x 0.0 0.2 0.4 0.6 0.8 1.0 −6−4−20246 x 0.0 0.2 0.4 0.6 0.8 1.0 −6−4−20246 x Figure 2: Paths of bilateral gamma process Simulation 0.3: Variance gamma process. yuima::simulate the process VGmodel <- setModel(drift="0", xinit="0", jump.coeff="1", measure.type="code", measure=list(df="rbgamma(z, delta.minus=2, gamma.minus=0.6, delta.plus=2, gamma.plus=0.3)")) VGyuima <- setYuima(model=VGmodel, sampling=samp) 0.0 0.2 0.4 0.6 0.8 1.0 0510 x 0.0 0.2 0.4 0.6 0.8 1.0 0510 x 0.0 0.2 0.4 0.6 0.8 1.0 0510 x 0.0 0.2 0.4 0.6 0.8 1.0 0510 x 0.0 0.2 0.4 0.6 0.8 1.0 0510 x Figure 3: Paths of variance gamma process
  • 10. LIST OF EXAMPLES 9 Simulation 0.4: gamma process. yuima::simulate the process Gmodel <- setModel(drift="0", xinit="0", jump.coeff="1", measure.type="code", measure=list(df="rgamma(z, shape=0.7, scale=1)")) n <- 10000 samp <- setSampling(Terminal=1, n=n) Gyuima <- setYuima(model=Gmodel, sampling=samp) 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.01.2 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.01.2 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.01.2 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.01.2 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.01.2 x Figure 4: Paths of gamma process Simulation 0.5: gamma process. yuima::simulate the process
  • 11. LIST OF EXAMPLES 10 Density 0.0 0.5 1.0 1.5 2.0 0.00.51.01.52.02.53.0 Figure 5: Distribution of x1 and density of Γ(0.7, 1). Simulation 0.6: inverse gamma process. yuima::simulate the process delta <- 1 gamma <- 2 set.seed(127) x <- rIG(10^4,delta,gamma) mean(x) ## [1] 0.498 var(x) ## [1] 0.128
  • 12. LIST OF EXAMPLES 11 Density 0.0 0.5 1.0 1.5 2.0 0.00.51.01.52.0 Figure 6: Distribution of x1 and density of IG(1, 2). Simulation 0.7: inverse gamma process. yuima::simulate the process IGmodel <- setModel(drift=0, xinit=0, jump.coeff=1, measure.type="code", measure=list(df="rIG(z, delta=1, gamma=2)")) n <- 1000 samp <- setSampling(Terminal=1, n=n) IGyuima <- setYuima(model=IGmodel, sampling=samp) 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 x 0.0 0.2 0.4 0.6 0.8 1.0 0.00.20.40.60.81.0 x Figure 7: Paths of IG process (delta=1, gamma=2).
  • 13. LIST OF EXAMPLES 12 Simulation 0.8: inverse gamma process. yuima::simulate the process Distribution of X1 and Density of IG(1,2) Density 0.0 0.5 1.0 1.5 2.0 0.00.51.01.52.0 Figure 8: Distribution of x1 and density of IG(1, 2). Simulation 0.9: process. yuima::simulate the process rep <- 3000000 set.seed(129) X1 <- rpts(rep,0.5,0.2,1) hist(X1,xlim=c(0,3),ylim=c(0,3),breaks=100, main=expression(X[1]),probability=TRUE)
  • 14. LIST OF EXAMPLES 13 X1 X1 Density 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0.00.51.01.52.02.53.0 X05 <- rpts(rep,0.5,0.1,1) X05.prime <- rpts(rep,0.5,0.1,1) Xsum <- X05+X05.prime summary(X1) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 0.01 0.11 0.21 0.35 0.43 11.72 summary(Xsum) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 0.01 0.11 0.21 0.35 0.43 10.61 ks.test(X1,Xsum)
  • 15. LIST OF EXAMPLES 14 ## ## Two-sample Kolmogorov-Smirnov test ## ## data: X1 and Xsum ## D = 8e-04, p-value = 0.3 ## alternative hypothesis: two-sided rm(X1) rm(Xsum) rm(X05) rm(X05.prime) Simulation 0.10: vgamma process. yuima::simulate the process lambda <- 2 alpha <- 1.5 beta <- -0.7 mu <- 3 xinit <- 0 gamma <- sqrt(alpha^2-beta^2) n <- 1000 T <- 1.8 VGPmodel <- setModel(drift=0, jump.coeff=1, measure.type="code", measure=list(df="rvgamma(z,lambda,alpha,beta,mu)")) samp <- setSampling(Terminal=T, n=n) VGPyuima <- setYuima(model=VGPmodel, sampling=samp) 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x 0.0 0.5 1.0 1.5 −4−20246 x Figure 9: Paths of variance gamma process.
  • 16. LIST OF EXAMPLES 15 n <- 5 samp <- setSampling(Terminal=T, n=n) VGPyuima <- setYuima(model=VGPmodel, sampling=samp) VGPsimdata <- NULL for (i in 1:5000){ result <- yuima::simulate(VGPyuima, xinit=xinit, true.par=list(lambda=lambda,alpha=alpha,beta=beta,mu=mu)) x1 <- result@data@original.data[n+1,1] VGPsimdata <- c(VGPsimdata,as.numeric(x1[1])) } Density −5 0 5 10 0.000.050.100.150.20 Figure 10: Distribution of x1 and density of NG. Simulation 0.11: subordination process. yuima::simulate the process delta <- 0.5 alpha <- 1.5 beta <- -0.7 mu <- 3 gamma <- sqrt(alpha^2-beta^2) n <- 10000 T <- 1.8 set.seed(127) normal.rn <- rnorm(n,0,1) iv.rn <- rIG(n,delta*T,gamma) z <- mu*T+beta*iv.rn+sqrt(iv.rn)*normal.rn title <- expression(paste(NIG[1.8], " built by subordination (green) and rNIG (white)"))
  • 17. LIST OF EXAMPLES 16 nig.rn <- rNIG(n,alpha,beta,delta*T,mu*T) hist(z,xlim=c(-1,10),ylim=c(0,0.61),breaks=100, freq=FALSE, col="green", main=title, xlab=expression(X[1.8]) ) curve(dNIG(x,alpha,beta,delta*T,mu*T),add=TRUE,col="red") par(new=T) hist(nig.rn,xlim=c(-1,10),ylim=c(0,0.61),breaks=100, freq=FALSE, main="", xlab="") NIG1.8 built by subordination (green) and rNIG (white) X1.8 Density 0 2 4 6 8 10 0.00.10.20.30.40.50.6 Density 0 2 4 6 8 10 0.00.10.20.30.40.50.6 ## delta1 <- 0.5 ## alpha <- 1.5 ## beta <- -0.7 ## mu <- 3
  • 18. LIST OF EXAMPLES 17 ## xinit <- 0 ## gamma <- sqrt(alpha^2-beta^2) ## n <- 1000 ## T <- 1.8 ## NIG2model <- setModel(drift=0, jump.coeff=1, measure.type="code", ## measure=list(df="rNIG(z,alpha,beta,delta1,mu)")) ## samp <- setSampling(Terminal=T, n=n) ## NIG2yuima <- setYuima(model=NIG2model, sampling=samp) ## set.seed(127) ## for (i in 1:10) { ## result <- yuima::simulate(NIG2yuima, xinit=xinit, ## true.par=list(delta1=delta1, alpha=alpha, beta=beta, ## mu=mu, gamma=gamma)) ## plot(result,xlim=c(0,T),ylim=c(-1,10),col=i, ## main="Paths of NIG process",par(new=T)) ## } Simulation 0.12: inverse gamma process. yuima::simulate the process
  • 19. LIST OF EXAMPLES 18 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process 0.0 0.5 1.0 1.5 0246810 t x Paths of NIG process Simulation 0.13: inverse gamma process. yuima::simulate the process n <- 5 samp <- setSampling(Terminal=T, n=n) NIG2yuima <- setYuima(model=NIG2model, sampling=samp) NIG2data <- NULL for (i in 1:3000){ result <- yuima::simulate(NIG2yuima, xinit=xinit, true.par=list(delta1=delta1, alpha=alpha, beta=beta, mu=mu, gamma=gamma)) x1 <- result@data@original.data[n+1,1] NIG2data <- c(NIG2data,as.numeric(x1[1]))
  • 20. LIST OF EXAMPLES 19 } hist(NIG2data,xlim=c(2,8),ylim=c(0,0.8),breaks=100, freq=FALSE, main=expression(paste("Distribution of ",X[1.8], " and Density of NIG"))) curve(dNIG(x,alpha,beta,delta*T,mu*T),add=TRUE,col="red") Distribution of X1.8 and Density of NIG NIG2data Density 2 3 4 5 6 7 8 0.00.20.40.60.8 Simulation 0.14: inverse gamma process. yuima::simulate the process nrep <- 10^4 alpha <- 0.5 delta <- 0.2
  • 21. LIST OF EXAMPLES 20 gamma <- 1 beta <- 1 mu <- -0.7 Lambda <- matrix(1,1,1) t <- 1.5 set.seed(127) x <- rnts(nrep,alpha,delta*t,gamma,beta,mu*t,Lambda) s <- rpts(nrep,alpha,delta*t,gamma) w <- rnorm(nrep,0,1) y <- rep(mu*t,nrep) + beta*s + sqrt(s)*w opar<-par(mfrow=c(2,2)) hist(x,xlim=c(-3,3),ylim=c(0,1.2),breaks=200, main=expression(X[t]),probability=TRUE) hist(y,xlim=c(-3,3),ylim=c(0,1.2),breaks=200, main=expression(Y[t]),probability=TRUE,col="red")
  • 22. LIST OF EXAMPLES 21 Xt x Density −3 −2 −1 0 1 2 3 0.00.40.81.2 Yt y Density −3 −2 −1 0 1 2 3 0.00.40.81.2 Experiment by convolution nrep <- 3*10^4 X1 <- rnts(nrep,alpha,delta*t,gamma,beta,mu*t,Lambda) X05 <- rnts(nrep,alpha,delta*t/2,gamma,beta,mu*t/2,Lambda) X05.prime <- rnts(nrep,alpha,delta*t/2,gamma,beta,mu*t/2,Lambda) Xsum <- X05+X05.prime hist(X1,xlim=c(-3,3),ylim=c(0,1.2),breaks=300, main=expression(X[1]),probability=TRUE)
  • 23. LIST OF EXAMPLES 22 X1 X1 Density −3 −2 −1 0 1 2 3 0.00.20.40.60.81.01.2 hist(Xsum,xlim=c(-3,3),ylim=c(0,1.2),breaks=300, main=expression(paste(X[t/2]+X[t/2],"'")), probability=TRUE,col="red")
  • 24. LIST OF EXAMPLES 23 Xt 2 + Xt 2' Xsum Density −3 −2 −1 0 1 2 3 0.00.20.40.60.81.01.2 ks.test(X1,Xsum) ## ## Two-sample Kolmogorov-Smirnov test ## ## data: X1 and Xsum ## D = 0.05, p-value <2e-16 ## alternative hypothesis: two-sided ## alpha <- 0.5 ## beta <- -0.4 ## sigma <- 0.7 ## gamma <- 0.5
  • 25. LIST OF EXAMPLES 24 ## n <- 1000 ## T <- 1.8 ## ASmodel <- setModel(drift=0, jump.coeff=1, measure.type="code", ## measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) ## samp <- setSampling(Terminal=T, n=n) ## ASyuima <- setYuima(model=ASmodel, sampling=samp) ## set.seed(129) ## for (i in 1:10) { ## result <- yuima::simulate(ASyuima, true.par=list(alpha=alpha, ## beta=beta,sigma=sigma,gamma=gamma)) ## plot(result,xlim=c(0,T),ylim=c(-40,10),col=i, ## main=expression(paste("Paths of stable process (", ## alpha==0.5,",",beta==-0.4,")")),par(new=T)) ## } ## ## #param2 ## alpha <- 1 ## beta <- -0.4 ## sigma <- 0.7 ## gamma <- 0.5 ## AS2model <- setModel(drift=0, jump.coeff=1, measure.type="code", ## measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) ## AS2yuima <- setYuima(model=AS2model, sampling=samp) ## for (i in 1:10) { ## result <- yuima::simulate(AS2yuima, true.par=list(alpha=alpha, ## beta=beta,sigma=sigma,gamma=gamma)) ## plot(result,xlim=c(0,T),ylim=c(-5,5),col=i, ## main=expression(paste("Paths of stable process (", ## alpha==1,",",beta==-0.4,")")),par(new=T)) ## } ## ## #param3 ## alpha <- 1 ## beta <- 0.4 ## sigma <- 0.7 ## gamma <- 0.5 ## AS3model <- setModel(drift=0, jump.coeff=1, measure.type="code", ## measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) ## AS3yuima <- setYuima(model=AS3model, sampling=samp) ## for (i in 1:10) { ## result <- yuima::simulate(AS3yuima, true.par=list(alpha=alpha, ## beta=beta,sigma=sigma,gamma=gamma)) ## plot(result,xlim=c(0,T),ylim=c(-5,5),col=i, ## main=expression(paste("Paths of stable process (", ## alpha==1,",",beta==0.4,")")),par(new=T)) ## }
  • 26. LIST OF EXAMPLES 25 ## ## #param4 ## alpha <- 1.5 ## beta <- 0.4 ## sigma <- 0.7 ## gamma <- 0.5 ## AS4model <- setModel(drift=0, jump.coeff=1, measure.type="code", ## measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) ## AS4yuima <- setYuima(model=AS4model, sampling=samp) ## for (i in 1:10) { ## result <- yuima::simulate(AS4yuima, true.par=list(alpha=alpha, ## beta=beta, sigma=sigma,gamma=gamma)) ## plot(result,xlim=c(0,T),ylim=c(-3,5),col=i, ## main=expression(paste("Paths of stable process (", ## alpha==1.5,",",beta==0.4,")")),par(new=T)) ## } Simulation 0.15:. opar<-par(mar=c(4,4,2,1)) set.seed(129) for (i in 1:10) { result <- yuima::simulate(ASyuima, true.par=list(alpha=alpha, beta=beta,sigma=sigma,gamma=gamma)) plot(result,xlim=c(0,T),ylim=c(-40,10),col=i, main=expression(paste("Paths of stable process (", alpha==0.5,",",beta==-0.4,")")),par(new=T)) }
  • 27. LIST OF EXAMPLES 26 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) 0.0 0.5 1.0 1.5 −40−30−20−10010 t x Paths of stable process (α = 0.5,β = −0.4) par(opar) Simulation 0.16:. #param2 alpha <- 1 beta <- -0.4 sigma <- 0.7 gamma <- 0.5 AS2model <- setModel(drift=0, jump.coeff=1, measure.type="code", measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) AS2yuima <- setYuima(model=AS2model, sampling=samp)
  • 28. LIST OF EXAMPLES 27 opar<-par(mar=c(4,4,2,1)) for (i in 1:10) { result <- yuima::simulate(AS2yuima, true.par=list(alpha=alpha, beta=beta,sigma=sigma,gamma=gamma)) plot(result,xlim=c(0,T),ylim=c(-5,5),col=i, main=expression(paste("Paths of stable process (", alpha==1,",",beta==-0.4,")")),par(new=T)) } 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = −0.4) par(opar) opar<-par(mar=c(4,4,2,1)) #param3
  • 29. LIST OF EXAMPLES 28 alpha <- 1 beta <- 0.4 sigma <- 0.7 gamma <- 0.5 AS3model <- setModel(drift=0, jump.coeff=1, measure.type="code", measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) AS3yuima <- setYuima(model=AS3model, sampling=samp) for (i in 1:10) { result <- yuima::simulate(AS3yuima, true.par=list(alpha=alpha, beta=beta,sigma=sigma,gamma=gamma)) plot(result,xlim=c(0,T),ylim=c(-5,5),col=i, main=expression(paste("Paths of stable process (", alpha==1,",",beta==0.4,")")),par(new=T)) }
  • 30. LIST OF EXAMPLES 29 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) 0.0 0.5 1.0 1.5 −4−2024 t x Paths of stable process (α = 1,β = 0.4) par(opar) #param4 alpha <- 1.5 beta <- 0.4 sigma <- 0.7 gamma <- 0.5 AS4model <- setModel(drift=0, jump.coeff=1, measure.type="code", measure=list(df="rstable(z,alpha,beta,sigma,gamma)")) AS4yuima <- setYuima(model=AS4model, sampling=samp) opar<-par(mar=c(4,4,2,1)) for (i in 1:10) {
  • 31. LIST OF EXAMPLES 30 result <- yuima::simulate(AS4yuima, true.par=list(alpha=alpha,beta=beta, sigma=sigma,gamma=gamma)) plot(result,xlim=c(0,T),ylim=c(-3,5),col=i, main=expression(paste("Paths of stable process (", alpha==1.5,",",beta==0.4,")")),par(new=T)) } 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) 0.0 0.5 1.0 1.5 −2024 t x Paths of stable process (α = 1.5,β = 0.4) par(opar) Simulation 0.17:.
  • 32. LIST OF EXAMPLES 31 modJump <- setModel(drift = c("-theta*x"), diffusion = "sigma", jump.coeff=c("gamma+x/sqrt(1+x^2)"), measure = list(intensity="lambda",df=list("dnorm(z, -3, 1)")), measure.type="CP", solve.variable="x") modJump ## ## Diffusion process with Levy jumps ## Number of equations: 1 ## Number of Wiener noises: 1 ## Number of Levy noises: 1 ## Parametric model with 4 parameters samp <- setSampling(n=10^4,Terminal=10) set.seed(125) X <- yuima::simulate(modJump, xinit=2, sampling=samp, true.par= list(theta=2, sigma=0.5,gamma=0.3,lambda=0.5)) 0 2 4 6 8 10 −1.00.01.02.0 t x x0 <- 2 a <- 0.1 c <- -1 model.ig <- setModel(drift="a*x", xinit=x0, jump.coeff=c, measure.type="code", measure=list(df="rIG(z, delta0, gamma)")) model.ig ## Levy process ## Number of equations: 1 ## Number of Levy noises: 1 ## Parametric model with 3 parameters
  • 33. LIST OF EXAMPLES 32 sampling.ig <- setSampling(Terminal=10, n=10000) yuima.ig <- setYuima(model=model.ig, sampling=sampling.ig) set.seed(128) result.ig <- yuima::simulate(yuima.ig,true.par=list(delta0=0.55,gamma=2)) 0 2 4 6 8 10 1.92.02.12.2 t x Simulation 0.18:. x0 <- 2 a <- 0.1 c <- -1 model.nig <- setModel(drift="a*x", xinit=x0, jump.coeff=c, measure.type="code",measure=list(df="rNIG(z, alpha, beta, delta0, mu)")) sampling.nig <- setSampling(Terminal=10, n=10000) yuima.nig <- setYuima(model=model.nig, sampling=sampling.ig) set.seed(128) result.nig <- yuima::simulate(yuima.nig,true.par=list(alpha=2, beta=0, delta0=0.55, mu=0))
  • 34. LIST OF EXAMPLES 33 0 2 4 6 8 10 2.03.0 t x Simulation 0.19:. x0 <- 2 a <- 0.1 c <- -1 Lambda <- matrix(1,1,1) model.nig <- setModel(drift="a*x", xinit=x0, jump.coeff=c, measure.type="code",measure=list(df="rNIG(z, alpha, beta, delta0, mu, Lambda)")) sampling.nig <- setSampling(Terminal=10, n=10000) yuima.nig <- setYuima(model=model.nig, sampling=sampling.ig) set.seed(128) result.nig <- yuima::simulate(yuima.nig,true.par=list(alpha=2, beta=0, delta0=0.55, mu=0, Lambda=Lambda))
  • 35. LIST OF EXAMPLES 34 0 2 4 6 8 10 2.03.0 t x Simulation 0.20:. x0 <- c(2,3) a1 <- function(t,x1,x2){ x1*cos(2*pi*t)-x2*sin(2*pi*t) } a2 <- function(t,x1,x2){ x1*sin(2*pi*t)+x2*cos(2*pi*t) } a <- c("a1(t,x1,x2)","a2(t,x1,x2)") b <- matrix(c("t*x2","1","0","x1"),2,2) c <- matrix(c("cos(2*pi*t)", "(5-t)*x1","sin(2*pi*t)",1),2,2) alpha <- 2 beta <- c(0,0) delta0 <- 0.55 mu <- c(0,0) Lambda <- matrix(c(1,0,0,1),2,2) model.mnig <- setModel(drift=a, xinit=x0, diffusion=b, jump.coeff=c, measure.type="code", measure=list(df="rNIG(z, alpha, beta, delta0, mu, Lambda)"), state.variable=c("x1","x2"),solve.variable=c("x1","x2") ) model.mnig ## ## Diffusion process with Levy jumps ## Number of equations: 2 ## Number of Wiener noises: 2 ## Number of Levy noises: 1 ## Parametric model with 7 parameters sampling.mnig <- setSampling(Terminal=1, n=10000) yuima.mnig <- setYuima(model=model.mnig, sampling=sampling.mnig) set.seed(128)
  • 36. LIST OF EXAMPLES 35 result.mnig <- yuima::simulate(yuima.mnig,true.par=list(alpha=alpha, beta=beta, delta0=delta0, mu=mu, Lambda=Lambda)) −1.01.5 x1 0.0 0.2 0.4 0.6 0.8 1.0 t 2.04.0 x2 Simulation 0.21:. mod5 <- setModel(drift = c("-theta*x"), diffusion = "sigma", jump.coeff=c("gamma+x/sqrt(1+x^2)"), measure = list(intensity="lambda",df=list("dnorm(z, 2, 0.1)")), measure.type="CP", solve.variable="x") theta <- 2 sigma <- 0.5 gamma <- 0.3 lambda <- 2.5 T <- 10 N <- 10000 delta <- T/N h <- T/N true <- list(theta=theta, sigma=sigma,gamma=gamma,lambda=lambda) set.seed(125) X <- yuima::simulate(mod5, true.p=true,xinit=2, sampling=setSampling(n=N,Terminal=T))
  • 37. LIST OF EXAMPLES 36 0 2 4 6 8 10 02468 t x r <- h^0.4 est.qmle <- qmle(yuima=X, start=true, lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1), upper=list(theta=3,sigma=2,gamma=0.8,lambda=20), method="L-BFGS-B", threshold=r) unlist(true) ## theta sigma gamma lambda ## 2.0 0.5 0.3 2.5 summary(est.qmle) ## Quasi-Maximum likelihood estimation ## ## Call: ## qmle(yuima = X, start = true, method = "L-BFGS-B", lower = list(theta = 1, ## sigma = 0, gamma = 0.1, lambda = 0.1), upper = list(theta = 3, ## sigma = 2, gamma = 0.8, lambda = 20), threshold = r) ## ## Coefficients: ## Estimate Std. Error ## sigma 0.501 0.00355 ## theta 2.053 0.04959 ## lambda 2.500 0.50000 ## gamma 0.309 0.00803 ## ## -2 log L: -53574 ## ## ## Number of estimated jumps: 25
  • 38. LIST OF EXAMPLES 37 ## ## Average inter-arrival times: 0.325708 ## ## Average jump size: 2.002308 ## ## Standard Dev. of jump size: 0.796882 ## ## Jump Threshold: 0.063096 ## ## Summary statistics for jump times: ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 1.33 2.72 6.34 5.61 8.11 9.15 ## ## Summary statistics for jump size: ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -0.072 1.795 2.335 2.002 2.544 2.742 est.qmle1 <- qmle(yuima=X, start=true, lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1), upper=list(theta=3,sigma=2,gamma=0.8,lambda=20), method="L-BFGS-B", threshold=2) # too large summary(est.qmle1)@coef ## Estimate Std. Error ## sigma 1.454 0.0103 ## theta 1.978 0.1438 ## lambda 1.600 0.4000 ## gamma 0.295 0.0155 est.qmle2 <- qmle(yuima=X, start=true, lower=list(theta=1,sigma=0,gamma=0.1,lambda=0.1), upper=list(theta=3,sigma=2,gamma=10,lambda=1000), method="L-BFGS-B", threshold=0.03) ## too low summary(est.qmle2)@coef ## Estimate Std. Error ## sigma 0.427 0.003188 ## theta 1.460 0.045165 ## lambda 77.852 2.799724 ## gamma 0.111 0.000103
  • 39. Chapter 1 Parameter estimation 1.1 Generator of moments method Example 1.1: Stochastic discount factor (SDF) for a CAPM. The general theory in Jagannathan and Skoulakis [2002] implies that E(DtRi,t) = 1 for all stocks i = 1, . . . , N, where Dt is the SDF and Ri,t the gross return 1 + ri,t. It can be shown that if the CAPM holds, Dt = θ0 + θ1Rm,t where Rm,t the gross return of the market, which implies the following moment conditions: E [Ri,t(θ0 + θ1Rm,t) − 1] = 0 for i = 1, . . . , N which can be tested as follows: g <- function(theta, x) { ret <- (theta[1] + theta[2] * (1 + c(x[, 1]))) * (1 + x[, -1]) - 1 return(ret) } Dataset Finance in package gmm Chausse [2017] contains daily returns on selected stocks, the market portfolio and factors of Fama and French1 from 1993-01-05 to 2009-01-30. library(gmm) data("Finance") x <- Finance[, c("rm", "UIS","ORB","MAT","ABAX","T")] 1 http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html 38