FROM DISCRETE
TO CONTINUOUS:
GARCH VOLATILITY MODELLING WITH R
Yakup ARI, PhD
Department of Economics
Alanya
Alaaddin Keykubat University, Turkey
https://orcid.org/0000-0002-5666-5365
yakup.ari@alanya.edu.tr
Abstract
The aim of this
study is to arrange the R codes that facilitate the comparison of
the simple GARCH model and its extensions. The outputs of each
discrete GARCH model are prepared as matrices. In addition,
continuous GARCH model codes are also given. For this purpose, data
of the platinium prices were used.The Platinium prices (PL=F) data is downloaded from
“finance.yahoo.com” via “quantmod” package (Ryan et al., 2018) in R.
The discrete GARCH family models and COGARCH model are fitted to
returns of the PL=F using the “rugarch” package (Ghalanos,
2020a, 2020b) and later a COGARCH(1,1) by R package “yuima” by Iacus
et al. (2017, 2018).
Keywords: GARCH
Comparison, COGARCH, R Project, rugarch, yuima
Some References
Ghalanos A.
(2020a). rugarch:Univariate GARCH models.R package version 1.4-2.
Available at:
https://cran.r-project.org/web/packages/rugarch/rugarch.pdf
Ghalanos A.
(2020b). Introduction to the rugarch package.Technical Report
Available at:
https://cran.r-project.org/web/packages/rugarch/vignettes/
Introduction_to_the_rugarch_package. pdf
Ryan, J.A. and
Ulrich, J. M. (2018). quantmod: Quantitative Financial Modelling
Framework.
R package version
0.4-13.https://CRAN.R-project.org/package=quantmod
Iacus SM, Mercuri
L, Rroji E (2017). “COGARCH$(p, q)$: Simulation and Inference with
the yuima Package.” Journal of Statistical Software,80(4), 1–49.
doi: 10.18637/jss.v080.i04.
Iacus S. M.
&Yoshida N. (2018). “Simulation and Inference for Stochastic
Processes with YUIMA: A Comprehensive R Framework for SDEs and other
Stochastic Processes”, Springer International Publishing, pp.
254-256.
##################### PART 1- LIBRARIES ####################
library(MCMCpack); library(rugarch); library(fGarch);
library(tseries); library(aTSA); library(yuima);
library(quantmod);
######################################################
##################### PART 2 - DATA ####################
#part 2.1 upload
data by quantmod from yahoo-finance
getSymbols("PL=F", from="2018-01-01", to="2020-05-01")
S<-`PL=F`$`PL=F.Close`
X<- dailyReturn(`PL=F`)
# part 2.2 merging and
omitting the na values
md<-merge(S,X)
na.md<-na.omit(md)
# part 2.3
descriptive stats and plots
stat.desc(S);
describe(S); stat.desc(X); describe(X); length(X)
#Set your
language
Sys.setlocale("LC_TIME", "English")
par(mfrow=c(2,1))
plot(X,
main="Returns of PL=F")
plot(S, main="PL=F " )
##############################################################
############ PART
3 - STATIONARITY and ARCH EFFECT ###############
#unit root tests
ADF and PP
adft.out =
adf.test(X)
ppt.out =
pp.test(X)
kpss.out =
kpss.out(X)
mod<-estimate(X,p=0)
mod<-arima(X)
arch.test.out<-arch.test(mod)
arch.test.out
ljung.box.test.out<-Box.test (X, lag = 12, type = "Ljung")
ljung.box.test.out
garch.data = X
########################################################
########################################################
#COMPARING GARCH - FAMILY MODELS
#VIA INFORMATION CRITERIA AND
LOGLIKELIHOOD
########################################################
########################################################
getSymbols("PL=F", from="2018-01-01", to="2020-05-01")
S<-`PL=F`$`PL=F.Close`
X<- dailyReturn(`PL=F`)
garch.data<-X
# Define a function for GARCH model specification and fitting
fit_garch_model <- function(model_type, garch_order, submodel,
distribution, data) {
spec <- ugarchspec(mean.model = list(armaOrder = c(0,0),
include.mean = FALSE),
variance.model = list(model = model_type, garchOrder = garch_order,
submodel = submodel),
distribution.model = distribution)
return(ugarchfit(spec, data = data))
}
# Define the model types, orders, submodels, and distributions
model_types <- c("fGARCH", "eGARCH", "iGARCH") # Add other models as
needed
garch_orders <- list(c(1, 1))
submodels <- c("GARCH", "AVGARCH", "GJRGARCH", "APARCH", "ALLGARCH",
"NGARCH", "NAGARCH", "mcsGARCH") # Add others as needed
distributions <- c("norm", "snorm", "std", "sstd", "ged", "sged",
"nig", "jsu")
# Loop over model types, orders, submodels, and distributions
results <- list()
for (model_type in model_types) {
for (order in garch_orders) {
for (submodel in submodels) {
for (distribution in distributions) {
model_name <- paste(model_type, submodel, distribution, sep = "_")
results[[model_name]] <- fit_garch_model(model_type, order,
submodel, distribution, garch.data)
}
}
}
}
# Extract information criteria and likelihood
info_criteria <- lapply(results, infocriteria)
likelihoods <- lapply(results, likelihood)
########################################################
########################################################
#COMPARING GARCH MODEL WITH VARIOUS
DISTRIBUTIONS
#VIA INFORMATION CRITERIA AND
LOGLIKELIHOOD
# VIA
MSE, RMSE, MAD
########################################################
########################################################
# Define a function to create GARCH
specifications
create_garch_spec <- function(distribution) {
ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model = "fGARCH", garchOrder = c(1, 1),
submodel = "GARCH"),
distribution.model = distribution)
}
# List of distributions
distributions <- c("norm", "snorm", "std", "sstd", "ged", "sged",
"nig", "jsu")
# Initialize lists to store results
specs <- list()
fits <- list()
info_criteria <- list()
likelihoods <- list()
# Loop over distributions
for (dist in distributions) {
spec_name <- paste("spec.garch", dist, "11", sep = ".")
fit_name <- paste("fit.garch", dist, "11", sep = ".")
specs[[spec_name]] <- create_garch_spec(dist)
fits[[fit_name]] <- ugarchfit(specs[[spec_name]], data = garch.data)
info_criteria[[fit_name]] <- infocriteria(fits[[fit_name]])
likelihoods[[fit_name]] <- likelihood(fits[[fit_name]])
}
# Create matrix for GARCH11 results
matrix.garch11 <- matrix(0, length(distributions), 5,
dimnames = list(paste(distributions, "GARCH11", sep = " "),
c("Akaike", "Bayes", "Shibata", "Hannan-Quinn", "Likelihood")))
# Populate the matrix
for (i in 1:length(distributions)) {
fit_name <- paste("fit.garch", distributions[i], "11", sep = ".")
matrix.garch11[i, 1:4] <- info_criteria[[fit_name]][1, ]
matrix.garch11[i, 5] <- likelihoods[[fit_name]]
}
# Assuming you have already fitted the GARCH models as per the
previous code
# Function to calculate forecast metrics
calculate_forecast_metrics <- function(actual, forecast) {
mse <- mean((actual - forecast)^2)
rmse <- sqrt(mse)
mad <- mean(abs(actual - forecast))
return(c(MSE = mse, RMSE = rmse, MAD = mad))
}
# Number of periods to forecast
n_forecast <- 10 # Adjust as needed
# Initialize lists to store forecasts and metrics
forecasts <- list()
forecast_metrics <- list()
# Loop over the fitted models to perform forecasting and calculate
metrics
for (dist in distributions) {
fit_name <- paste("fit.garch", dist, "11", sep = ".")
# Forecasting
forecast <- ugarchforecast(fits[[fit_name]], n.ahead = n_forecast)
forecasts[[fit_name]] <- forecast
# Assuming 'garch.data' is the actual data and 'n_forecast' is the
number of periods you want to forecast
# You need to adjust the actual data extraction based on your data
structure
actual_data <- tail(garch.data, n_forecast)
forecasted_data <- as.numeric(forecast@forecast$seriesFor)
# Calculate metrics
forecast_metrics[[fit_name]] <-
calculate_forecast_metrics(actual_data, forecasted_data)
}
# Display forecast metrics for each model
forecast_metrics
# Continuing from the previous code
# Initialize a matrix to store forecast metrics for each model
metrics_matrix <- matrix(0, length(distributions), 3,
dimnames = list(paste(distributions, "GARCH11", sep = " "),
c("MSE", "RMSE", "MAD")))
# Populate the matrix with forecast metrics
for (i in 1:length(distributions)) {
fit_name <- paste("fit.garch", distributions[i], "11", sep = ".")
metrics_matrix[i, ] <- forecast_metrics[[fit_name]]
}
# Display the matrix
metrics_matrix
# Function to calculate forecast metrics with heteroskedasticity
adjustments
calculate_forecast_metrics <- function(actual, forecast,
conditional_variance) {
errors <- actual - forecast
standardized_errors <- errors / sqrt(conditional_variance)
mse <- mean(errors^2)
rmse <- sqrt(mse)
mad <- mean(abs(errors))
# Heteroskedastic-adjusted metrics
hrmse <- sqrt(mean(standardized_errors^2))
hmae <- mean(abs(standardized_errors))
return(c(MSE = mse, RMSE = rmse, MAD = mad, HRMSE = hrmse, HMAE =
hmae))
}
# Initialize a matrix to store forecast metrics for each model
metrics_matrix <- matrix(0, length(distributions), 5,
dimnames = list(paste(distributions, "GARCH11", sep = " "),
c("MSE", "RMSE", "MAD", "HRMSE", "HMAE")))
# Populate the matrix with forecast metrics
for (i in 1:length(distributions)) {
fit_name <- paste("fit.garch", distributions[i], "11", sep = ".")
# Extract conditional variance from the fitted model
conditional_variance <- sigma(fits[[fit_name]])^2
# Adjust the length of conditional variance to match the forecast
length
conditional_variance <- tail(conditional_variance, n_forecast)
# Calculate metrics
forecast_metrics[[fit_name]] <-
calculate_forecast_metrics(actual_data,
forecasts[[fit_name]]@forecast$seriesFor, conditional_variance)
# Populate the matrix
metrics_matrix[i, ] <- forecast_metrics[[fit_name]]
}
# Display the matrix
metrics_matrix
########################################################
########################################################
#COMPARING GARCH MODEL WITH VARIOUS
DISTRIBUTIONS
# VIA
MSE, RMSE, MAD, HRMSE,
HMAE
########################################################
########################################################
# Load necessary library
library(rugarch)
# Function to create GARCH specifications
create_garch_spec <- function(distribution) {
ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model = "fGARCH", garchOrder = c(1, 1),
submodel = "GARCH"),
distribution.model = distribution)
}
# Function to calculate forecast metrics with heteroskedasticity
adjustments
calculate_forecast_metrics <- function(actual, forecast,
conditional_variance) {
errors <- actual - forecast
standardized_errors <- errors / sqrt(conditional_variance)
mse <- mean(errors^2)
rmse <- sqrt(mse)
mad <- mean(abs(errors))
# Heteroskedastic-adjusted metrics
hrmse <- sqrt(mean(standardized_errors^2))
hmae <- mean(abs(standardized_errors))
return(c(MSE = mse, RMSE = rmse, MAD = mad, HRMSE = hrmse, HMAE =
hmae))
}
# List of distributions
distributions <- c("norm", "snorm", "std", "sstd", "ged", "sged",
"nig", "jsu")
# Initialize lists to store results
specs <- list()
fits <- list()
forecasts <- list()
forecast_metrics <- list()
# Loop over distributions
for (dist in distributions) {
spec_name <- paste("spec.garch", dist, "11", sep = ".")
fit_name <- paste("fit.garch", dist, "11", sep = ".")
# Create and fit GARCH model
specs[[spec_name]] <- create_garch_spec(dist)
fits[[fit_name]] <- ugarchfit(specs[[spec_name]], data = garch.data)
# Forecasting
forecasts[[fit_name]] <- ugarchforecast(fits[[fit_name]], n.ahead =
10) # Adjust n.ahead as needed
# Calculate metrics
actual_data <- tail(garch.data, 10) # Adjust to match forecast
length
forecasted_data <-
as.numeric(forecasts[[fit_name]]@forecast$seriesFor)
conditional_variance <- tail(sigma(fits[[fit_name]])^2, 10) # Adjust
to match forecast length
forecast_metrics[[fit_name]] <-
calculate_forecast_metrics(actual_data, forecasted_data,
conditional_variance)
}
# Initialize a matrix to store forecast metrics for each model
metrics_matrix <- matrix(0, length(distributions), 5,
dimnames = list(paste(distributions, "GARCH11", sep = " "),
c("MSE", "RMSE", "MAD", "HRMSE", "HMAE")))
# Populate the matrix with forecast metrics
for (i in 1:length(distributions)) {
fit_name <- paste("fit.garch", distributions[i], "11", sep = ".")
metrics_matrix[i, ] <- forecast_metrics[[fit_name]]
}
# Display the matrix
metrics_matrix
########################################################
########################################################
#COMPARING STANDART GARCH MODEL
#VIA INFORMATION CRITERIA AND
LOGLIKELIHOOD
########################################################
########################################################
##################### GARCH ################
# norm 1GARCH
spec.garch.norm.11 = ugarchspec(mean.model = list(armaOrder =
c(0,0), include.mean = FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "norm")
fit.garch.norm.11
= ugarchfit(spec.garch.norm.11, data = garch.data)
# snorm 1GARCH
spec.garch.snorm.11 = ugarchspec(mean.model = list(armaOrder =
c(0,0), include.mean = FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "snorm")
fit.garch.snorm.11 = ugarchfit(spec.garch.snorm.11, data =
garch.data)
# std 1GARCH
spec.garch.std.11
= ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "std")
fit.garch.std.11
= ugarchfit(spec.garch.std.11, data = garch.data)
# sstd 1GARCH
spec.garch.sstd.11 = ugarchspec(mean.model = list(armaOrder =
c(0,0), include.mean = FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "sstd")
fit.garch.sstd.11
= ugarchfit(spec.garch.sstd.11, data = garch.data)
# ged 1GARCH
spec.garch.ged.11
= ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "ged")
fit.garch.ged.11
= ugarchfit(spec.garch.ged.11, data = garch.data)
# sged 1GARCH
spec.garch.sged.11 = ugarchspec(mean.model = list(armaOrder =
c(0,0), include.mean = FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "sged")
fit.garch.sged.11
= ugarchfit(spec.garch.sged.11, data = garch.data)
# nig 1GARCH
spec.garch.nig.11
= ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "nig")
fit.garch.nig.11
= ugarchfit(spec.garch.nig.11, data = garch.data)
# jsu 1GARCH
spec.garch.jsu.11
= ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean =
FALSE),
variance.model = list(model =
"fGARCH",garchOrder = c(1, 1),submodel = "GARCH"),
distribution.model = "jsu")
fit.garch.jsu.11
= ugarchfit(spec.garch.jsu.11, data = garch.data)
##### ### PART 5
INFOTMATION CRITERIA & LIKELIHOOD FOR MODEL 11 ########
##### ### PART
5.1 - OUTPUT
GARCH (simple GARCH -SGARCH) ##### ###
normgarch11<-infocriteria(fit.garch.norm.11)
snormgarch11<-infocriteria(fit.garch.snorm.11)
stdgarch11<-infocriteria(fit.garch.std.11)
sstdgarch11<-infocriteria(fit.garch.std.11)
gedgarch11<-infocriteria(fit.garch.ged.11)
sgedgarch11<-infocriteria(fit.garch.sged.11)
niggarch11<-infocriteria(fit.garch.nig.11)
jsugarch11<-infocriteria(fit.garch.jsu.11)
normgarchlike11<-likelihood(fit.garch.norm.11)
snormgarchlike11<-likelihood(fit.garch.snorm.11)
stdgarchlike11<-likelihood(fit.garch.std.11)
sstdgarchlike11<-likelihood(fit.garch.std.11)
gedgarchlike11<-likelihood(fit.garch.ged.11)
sgedgarchlike11<-likelihood(fit.garch.sged.11)
niggarchlike11<-likelihood(fit.garch.nig.11)
jsugarchlike11<-likelihood(fit.garch.jsu.11)
##### ### PART
6 GARCH11 RESULT MATRIX ########
##### PART 6.1
"garch11" MATRIX ####
matrix.garch11<-matrix(0,8,5,dimnames=list(NULL))
{
matrix.garch11
[1,1]<-normgarch11[1,1]
matrix.garch11
[1,2]<-normgarch11[2,1]
matrix.garch11
[1,3]<-normgarch11[3,1]
matrix.garch11
[1,4]<-normgarch11[4,1]
matrix.garch11
[1,5]<-normgarchlike11[1]
matrix.garch11
[2,1]<-snormgarch11[1,1]
matrix.garch11
[2,2]<-snormgarch11[2,1]
matrix.garch11
[2,3]<-snormgarch11[3,1]
matrix.garch11
[2,4]<-snormgarch11[4,1]
matrix.garch11
[2,5]<-snormgarchlike11[1]
matrix.garch11
[3,1]<-stdgarch11[1,1]
matrix.garch11
[3,2]<-stdgarch11[2,1]
matrix.garch11
[3,3]<-stdgarch11[3,1]
matrix.garch11
[3,4]<-stdgarch11[4,1]
matrix.garch11
[3,5]<-stdgarchlike11[1]
matrix.garch11
[4,1]<-sstdgarch11[1,1]
matrix.garch11
[4,2]<-sstdgarch11[2,1]
matrix.garch11
[4,3]<-sstdgarch11[3,1]
matrix.garch11
[4,4]<-sstdgarch11[4,1]
matrix.garch11
[4,5]<-sstdgarchlike11[1]
matrix.garch11
[5,1]<-gedgarch11[1,1]
matrix.garch11
[5,2]<-gedgarch11[2,1]
matrix.garch11
[5,3]<-gedgarch11[3,1]
matrix.garch11
[5,4]<-gedgarch11[4,1]
matrix.garch11
[5,5]<-gedgarchlike11[1]
matrix.garch11
[6,1]<-sgedgarch11[1,1]
matrix.garch11
[6,2]<-sgedgarch11[2,1]
matrix.garch11
[6,3]<-sgedgarch11[3,1]
matrix.garch11
[6,4]<-sgedgarch11[4,1]
matrix.garch11
[6,5]<-sgedgarchlike11[1]
matrix.garch11
[7,1]<-niggarch11[1,1]
matrix.garch11
[7,2]<-niggarch11[2,1]
matrix.garch11
[7,3]<-niggarch11[3,1]
matrix.garch11
[7,4]<-niggarch11[4,1]
matrix.garch11
[7,5]<-niggarchlike11[1]
matrix.garch11
[8,1]<-jsugarch11[1,1]
matrix.garch11
[8,2]<-jsugarch11[2,1]
matrix.garch11
[8,3]<-jsugarch11[3,1]
matrix.garch11
[8,4]<-jsugarch11[4,1]
matrix.garch11
[8,5]<-jsugarchlike11[1]
}
colnames(matrix.garch11) <-c("Akaike",
"Bayes","Shibata","Hannan-Quinn","Likelihood")
rownames(matrix.garch11) <-c("norm GARCH11","snorm GARCH11","std
GARCH11","sstd GARCH11",
"ged GARCH11","sged GARCH11","nig
GARCH11","jsu GARCH11")
##################PART 7 - COGARCH ##################
#An
example, adapted from Bianchi et al. (2016), where this relationship
#is also checked
on the estimates from data for these two models.
#a GARCH(1,1)
using the rugarch package (Ghalanos 2015) and later a COGARCH(1,1)
by yuima.
#GARCH and
COGARCH MODELS
X=garch.data
spec <-
ugarchspec(variance.model =
list(model = "sGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(0, 0),
include.mean = FALSE))
fitGARCH <-
ugarchfit(data = X, spec = spec)
GARCH11param <-
coef(fitGARCH)
GARCH11param
vol.garch<-sigma(fitGARCH)
names(fitGARCH@fit)
plot(fitGARCH,
which="all")
#Now, we
construct a function to convert the parameters from a GARCH(1,1) to
a
#COGARCH(1,1)
model according to formula (7.17). This function is similar to the
#implementation
in the package COGARCH.rm (Bianchi et al. 2017).
#delta<-1/frequency of data
Delta <- 1/10
ParGarToCog<-
function(GARCH11param, dt, names=NULL){
if(is.null(names))
names <-
names(GARCH11param)
my.omega <-
GARCH11param["omega"]
my.alpha <-
GARCH11param["alpha1"]
my.beta <-
GARCH11param["beta1"]
a1 <-
my.alpha/dt
b1 <-
-log(my.beta)/dt
a0 <-
my.omega/(b1*dt^2)
qmleparInGARCH
<- c(a0, a1, b1)
names(qmleparInGARCH) <- c("a0", "a1", "b1")
return(qmleparInGARCH)
}
#Now, we use the
converted values as initial point of the qmle optimizer
ParGarToCog(GARCH11param, Delta)
start <-
as.list(ParGarToCog(GARCH11param, Delta))
cp.modCog11 <-
setCogarch(p=1, q=1, measure =
list(intensity="1",
df=list("dnorm(z, 0, 1)")), measure.type="CP")
vg.modCog11 <-
setCogarch(p=1, q=1, measure =
list(intensity="1",
df=list("dnorm(z, 0, 1)")), measure.type="VG")
volatility.data
<- setData(cumsum(X), delta = Delta)
Cog11.cp <-
setYuima(data = volatility.data, model = cp.modCog11)
Cog11.fit <-
qmle(yuima = Cog11, grideq=TRUE,
start = c(start, y1 = 0.1),
aggregation = FALSE, method = "Nelder-Mead",Est.Incr = "Incr")
v=simulate(Cog11.fit)
vol.cogarch<-v@data@zoo.data$`Series 2`
plotdata<-merge(data2,
v@data@zoo.data$`Series 1`,
v@data@zoo.data$`Series 2`,
v@data@zoo.data$`Series 3`)
par(mfrow=c(3,1))
plot(plotdata[,2],
main="CP-COGARCH Sample Path",xlab="",ylab="G",col="red")
plot(plotdata[,3],
main="CP-COGARCH Volatility",ylab="V",col="blue")
plot(plotdata[,4],
main="CP-COGARCH Observations", ylab="Y1",col="red")
COGARCH11par <-
coef(Cog11.fit)
COGARCH11par
summary(Cog11.fit)
#diagnostics
check11<-Diagnostic.Cogarch(Cog11, param=COGARCH11par)
str(check11)
slotNames(Cog11.fit)
Cog11.fit@vcov
Cog11.fit@min
Cog11.fit@minuslogl
Cog11.fit@details
details(Cog11.fit)
#we apply the
reverse transform from COGARCH(1,1) to GARCH(1,1)
ParCogToGar<-
function(COGARCH11param, dt, names=NULL){
a0 <-
COGARCH11param["a0"]
a1 <-
COGARCH11param["a1"]
b1 <-
COGARCH11param["b1"]
my.omega <-
a0*b1*dt^2
my.alpha <-
a1*dt
my.beta <-
exp(-b1*dt)
qmleparInGARCH
<- c(my.omega, my.alpha, my.beta)
names(qmleparInGARCH) <- c("omega", "alpha1", "beta1")
return(qmleparInGARCH)
}
contodiscrete<-ParCogToGar(COGARCH11par, Delta)
###################### PART 8 MODEL CHECK and DIAGNOSTICS
###################
#Set your
language
Sys.setlocale("LC_TIME", "English")
vol.garch.family<-sigma(fit.allgarch.jsu.11)
data1.garch<-vol.garch.family
adf.test(vol.garch.family)
pp.test(vol.garch.family)
pp.test(data2)
persistence(fit.allgarch.jsu.11)
halflife(fit.allgarch.jsu.11)
convergence(fit.allgarch.jsu.11)
uncvariance(fit.allgarch.jsu.11)
uncmean(fit.allgarch.jsu.11)
gof(fit.allgarch.jsu.11)
pit(fit.allgarch.jsu.11)
plot(fit.allgarch.jsu.11)
specf =
getspec(fit.allgarch.jsu.11)
setfixed.specf <-
as.list(coef(fit.allgarch.jsu.11))
filt1 =
ugarchfilter(specf, X[1:1200, ], n.old = 1000)
filt2 =
ugarchfilter(specf, X[1001:1200, ])
quantile(fit.allgarch.jsu.11)
show(fit.allgarch.jsu.11)
gd =
ugarchdistribution(fit.allgarch.jsu.11, n.sim = 100, recursive =
TRUE,
recursive.length = 1800, recursive.window = 500,
m.sim = 100,
solver = 'hybrid')
show(gd)
plot(gd, which =
1, window = 12)
plot(gd, which =
2, window = 12)
plot(gd, which =
3, window = 12)
plot(gd, which =
4, window = 12)
write.csv(mgarch.data, file = "mgarchdata.csv")
plot.ts(vol.garch.family, xlab="GARCH Volatility",ylab="sigma",
col="blue")
plot(vol.garch.family, main="GARCH(1,1) Volatility",ylab="sigma",
col="blue")
plot(fit.avgarch.ged.11, which="all")
plot(X,
main="Returns of PL=F")
par(mfrow=c(3,1))
plot(X,
main="Returns of PL=F",ylab="returns", col="red")
plot(vol.garch.family,main="JSU-ALLGARCH Volatility of PL=F"
,ylab="Volatility", col="green")
plot(vol.cogarch, main="CP-COGARCH Volatility of PL=F",
col="blue")
|