## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup, echo=FALSE,message=FALSE------------------------------------------
library(QuantileModels)

## ----message=FALSE------------------------------------------------------------
data=dataCAViaR

SAV <- CAViaR(Y=data$GM[1:2892],
model.type = "SAV",p=1,q=1,band.hs = TRUE,quant.type = 7,
tau=0.05,refine.estim = FALSE)

AS <- CAViaR(Y=data$GM[1:2892],
model.type = "AS",p=1,q=1,band.hs = TRUE,quant.type = 7,
tau=0.05,refine.estim = FALSE)

INDGARCH <- CAViaR(Y=data$GM[1:2892],
model.type = "INDGARCH",p=1,q=1,band.hs = TRUE,quant.type = 7,
tau=0.05,refine.estim = FALSE)

I_CAV <- CAViaR(Y=data$GM[1:2892],
model.type = "I-CAV",p=1,q=1,band.hs = TRUE,quant.type = 7,
tau=0.05,refine.estim = FALSE)


## -----------------------------------------------------------------------------
summary(SAV)

## ----fig.width=9, fig.height=5.5, fig.cap= "GM VaR at 5% under different specifications"----
graphic_opts <- par(no.readonly = TRUE)
par(mfrow=c(2,2))

plot(-SAV$VaR,.by="quarter",ylim=c(1.5,10),main="SAV",main.timespan=FALSE)
plot(-AS$VaR,.by="quarter",ylim=c(1.5,10),main="AS",main.timespan=FALSE)
plot(-INDGARCH$VaR,.by="quarter",ylim=c(1.5,10),main="INDGARCH",main.timespan=FALSE)
plot(-I_CAV$VaR,.by="quarter",ylim=c(1.5,10),main="I-CAV",main.timespan=FALSE)
par(graphic_opts)

## ----fig.width=6, fig.height=6------------------------------------------------
plot(SAV,titl="GM Var at 5%")

## ----message=FALSE------------------------------------------------------------
Barclays <- MVMQ_CAViaR(MVMQ[,c(6,1)],tau =c(0.01,0.01),band.hs = TRUE)

Goldman <- MVMQ_CAViaR(MVMQ[,c(7,4)],tau =c(0.01,0.01),band.hs = TRUE)

HSBC <- MVMQ_CAViaR(MVMQ[,c(5,3)],tau =c(0.01,0.01),band.hs = TRUE)

Deutsche <- MVMQ_CAViaR(MVMQ[,c(6,2)],tau =c(0.01,0.01),band.hs = TRUE)

## ----message=FALSE------------------------------------------------------------
summary(Barclays)

summary(Goldman)

## ----fig.width=8, fig.height=5------------------------------------------------
dates <- as.Date(zoo::index(MVMQ))

#Barclays
plot(dates,as.vector(MVMQ[,1]),type = "p",ylim = c(-60,60),cex=0.6,xaxt="n",cex.axis=0.8,col=2,xlab="",ylab = "",main = "Barclays")
lines(dates,Barclays[[5]][,2],type = "l")
axis.Date(side=1,at=seq(dates[1],dates[2765],by="year"),cex.axis=0.8,las=2)
legend("topleft",legend = c("Daily Returns","1% VaR"),col = 2:1,pch = c("o","-"))

#Deutsche
plot(dates,as.vector(MVMQ[,2]),type = "p",ylim = c(-60,60),cex=0.6,xaxt="n",cex.axis=0.8,col=2,xlab="",ylab = "",main = "Deutsche")
lines(dates,Deutsche[[5]][,2],type = "l")
axis.Date(side=1,at=seq(dates[1],dates[2765],by="year"),cex.axis=0.8,las=2)
legend("topleft",legend = c("Daily Returns","1% VaR"),col = 2:1,pch = c("o","-"))

#Goldman
plot(dates,as.vector(MVMQ[,4]),type = "p",ylim = c(-60,60),cex=0.6,xaxt="n",cex.axis=0.8,col=2,xlab="",ylab = "",main = "Goldman")
lines(dates,Goldman[[5]][,2],type = "l")
axis.Date(side=1,at=seq(dates[1],dates[2765],by="year"),cex.axis=0.8,las=2)
legend("topleft",legend = c("Daily Returns","1% VaR"),col = 2:1,pch =c("o","-"))

#HSBC
plot(dates,as.vector(MVMQ[,3]),type = "p",ylim = c(-60,60),cex=0.6,xaxt="n",cex.axis=0.8,col=2,xlab="",ylab = "",main = "HSBC")
lines(dates,HSBC[[5]][,2],type = "l")
axis.Date(side=1,at=seq(dates[1],dates[2765],by="year"),cex.axis=0.8,las=2)
legend("topleft",legend = c("Daily Returns","1% VaR"),col = 2:1,pch = c("o","-"))

## ----fig.width=8, fig.height=5------------------------------------------------
plot(Barclays,rows=2,columns=1)
plot(Goldman,rows=2,columns=1)

