You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get time, number of observations per day and number of observations
t<- index(data) # time indexp<- round(60*24/as.numeric(diff(t[1:2]))) # number of observations per dayn<- length(t) # number of observations
Marginal modeling
Fit intraday egarch models
# Takes a while, so better to save the models and load them next time... if (file.exists("data/GAM-PCC-intraday-fx-margins.rda")) {
load("data/GAM-PCC-intraday-fx-margins.rda")
} else {
cl<- makeCluster(detectCores()-1)
registerDoParallel(cl)
fits_margins<- as.list(numeric(dim(data)[2]))
time_margins<- system.time(
fits_margins<- foreach(i=1:dim(data)[2],
.packages= c("rugarch", "zoo")) %dopar%
{fitIntradayEGARCH(data[,i],p)}
)[3]
closeAllConnections()
save(fits_margins, time_margins,
file="data/GAM-PCC-intraday-fx-margins.rda")
}
# Takes a while, so better to save the models and load them next time... if (file.exists("data/GAM-PCC-intraday-fx-copula.rda")) {
load("data/GAM-PCC-intraday-fx-copula.rda")
} else {
time_copula<- system.time(
fit_copula<- gamVineStructureSelect(U, lin.covs= as.data.frame(time_of_day),
smooth.covs=data.frame(t=absolute_time),
simplified=TRUE, familycrit="AIC",
method="FS", n.iters=40,
verbose=FALSE, parallel=TRUE)
)[3]
save(fit_copula, time_copula,
file="data/GAM-PCC-intraday-fx-copula.rda")
}
fit_copula
## GAM-Vine matrix:
## [,1] [,2] [,3] [,4]
## [1,] 3 0 0 0
## [2,] 2 1 0 0
## [3,] 4 2 2 0
## [4,] 1 4 4 4
##
## Where
## 1 <-> EURUSD
## 2 <-> USDJPY
## 3 <-> GBPUSD
## 4 <-> USDCHF
##
## Tree 1:
## GBPUSD,EURUSD : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X2 + X3 + X4 + X5 + X6 + X8 + X9 + s(t, k = 40, bs = "cr")
## EURUSD,USDCHF : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + s(t, k = 320,
## bs = "cr")
## USDJPY,USDCHF : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X2 + X3 + X4 + X6 + X7 + X9 + s(t, k = 80, bs = "cr")
##
## Tree 2:
## GBPUSD,USDCHF|EURUSD : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X3 + X4 + s(t, k = 20, bs = "cr")
## EURUSD,USDJPY|USDCHF : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X2 + X3 + X4 + X9 + s(t, k = 40, bs = "cr")
##
## Tree 3:
## GBPUSD,USDJPY|USDCHF,EURUSD : t copula with tau(z) = (exp(z)-1)/(exp(z)+1) where
## z ~ X1 + X2 + X5 + X6 + s(t, k = 40, bs = "cr")
Parametric bootstrap for the confidence intervals
nBoot<-2e2# Number of bootstraped simulations# Takes a while, so better to save the simulations and load them next time... if (file.exists("data/GAM-PCC-intraday-fx-bootstrap.rda")) {
load("data/GAM-PCC-intraday-fx-bootstrap.rda")
} else {
newdata<-data.frame(t=absolute_time, X<-time_of_day)
cl<- makeCluster(detectCores()-1)
registerDoParallel(cl)
val.bs<- as.list(numeric(nBoot))
time_bootstrap<- system.time(
val.bs<- foreach(i=1:nBoot, .packages= c("gamCopula")) %dopar%
{make_sim_model(i, fit_copula, newdata)}
)[3]
save(val.bs, time_bootstrap,
file="data/GAM-PCC-intraday-fx-bootstrap.rda")
closeAllConnections()
}
Results of copula modeling
# Extract mean and confidence intervals for the smooth and parametersconst<-smooth<-param<-list()
for (kin1:length(val.bs[[1]])) {
const[[k]] <- apply(sapply(val.bs, function(x) x[[k]][[1]]), 1,
function(y) c(mean(y), quantile(y, c(0.025,0.975))))
smooth[[k]] <- try(apply(sapply(val.bs, function(x) x[[k]][[2]]), 1,
function(y) c(mean(y), quantile(y, c(0.025,0.975)))))
param[[k]] <- try(apply(sapply(val.bs, function(x) x[[k]][[3]]), 1,
function(y) c(mean(y), quantile(y, c(0.025,0.975)))))
}