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

## -----------------------------------------------------------------------------
library(tsgarch)
suppressMessages(library(xts))
data(nikkei)
nikkei <- xts(nikkei$value, as.Date(nikkei$index))
monday <- xts(as.numeric(weekdays(index(nikkei)) == "Monday"), index(nikkei))
colnames(monday) <- "monday"
spec_x <- garch_modelspec(nikkei, arma = c(1,1), xreg = monday,
                          xreg_type = "arma_errors", model = 'garch',
                          constant = TRUE, init = 'unconditional',
                          distribution = 'jsu')
mod_x <- estimate(spec_x)
coef(mod_x)["tau1"]

## -----------------------------------------------------------------------------
newx <- xts(matrix(as.numeric(weekdays(index(nikkei)[NROW(nikkei)] + 1:10) == "Monday"),
                   ncol = 1), index(nikkei)[NROW(nikkei)] + 1:10)
colnames(newx) <- "monday"
predict(mod_x, h = 10, newxreg = newx)$mean

## -----------------------------------------------------------------------------
library(tsgarch)
suppressMessages(library(data.table))
suppressMessages(library(xts))
data(nikkei)
nikkei <- xts(nikkei$value, as.Date(nikkei$index))
spec <- garch_modelspec(nikkei, arma = c(1,1), model = 'garch', constant = TRUE, 
                        init = 'unconditional', distribution = 'jsu')
mod <- estimate(spec)
as_flextable(summary(mod))

## -----------------------------------------------------------------------------
arma_coefficients(mod)
arma_inverse_roots(mod)
arma_near_cancellation(arma_inverse_roots(mod), tol = 0.1)

## ----fig.width=7,fig.height=6-------------------------------------------------
plot(mod)

## ----fig.width=7,fig.height=6-------------------------------------------------
plot(mod, type = "arma", which = NULL, envelope = "parametric")

