#garchSim()和garchFit()
#omega - the constant coefficient of the variance equation, by default 1e-6;
#alpha - the value or vector of autoregressive coefficients, by default 0.1, specifying a model of order 1;
#beta - the value or vector of variance coefficients, by default 0.8, specifying a model of order 1;
#The optional values for the linear part are:
#mu - the intercept value, by default 0 (it implies that the mean = mu/(1-sum(ar)));
#ar - the autoregressive ARMA coefficients, by default 0;
#ma - the moving average ARMA coefficients, by default 0.
getwd()
source("Igarch.R")
source("GarchM.R")
mm=Igarch(x$log.return,include.mean=F,volcnt=F)
sresi=x$log.return/mm$volatility
pacf(sresi)
pacf(sresi**2)
mm1=garchM(x$log.return,type=2)
mm=garchM(sp5,type=2)
#------------------------------------------------------------------------#
library(rugarch)
?rugarch
?ugarchspec
?ugarchfit
#-------------------------------------------------------------------------#
myspec=ugarchspec(variance.model = list(model = "fGARCH",
garchOrder = c(1,1), submodel = "GARCH", external.regressors = NULL,
variance.targeting =FALSE),
mean.model = list(armaOrder = c(2,2), include.mean = TRUE, archm = FALSE,
archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE),
distribution.model = "ged")
myfit=ugarchfit(myspec,data=x$log.return,solver="solnp")
myfit
res=residuals(myfit)
sigma=sigma(myfit)
fit=fitted(myfit)
sres=residuals(myfit,standardize=T)#or sres=res/sigma
for(ii in 1:15) print(Box.test(sres**2,ii,"Ljung"))
ArchTest(sres)
pred3=ugarchforecast(myfit,n.ahead=100)
plot(fitted(pred3),type="l")
plot(myfit)
#------------------------------------------------------------------------#
myspec=ugarchspec(variance.model = list(model = "iGARCH",
garchOrder = c(1,1), submodel = NULL, external.regressors = NULL,
variance.targeting = 0),
mean.model = list(armaOrder = c(3,3), include.mean =FALSE , archm = FALSE,
archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE),
distribution.model = "ged")
myfit1=ugarchfit(myspec,data=x$log.return,solver="solnp")
myfit1
sres1=residuals(myfit1,standardize=T)
for(ii in 1:30) print(Box.test(sres1,ii,"Ljung"))
#-------------------------------------------------------------------------#
myspec=ugarchspec(variance.model = list(model = "fGARCH",
garchOrder = c(1,1), submodel = "GARCH", external.regressors = NULL,
variance.targeting =0),
mean.model = list(armaOrder = c(3,3), include.mean =TRUE , archm = TRUE,
archpow = 2, arfima = FALSE, external.regressors = NULL, archex = FALSE),
distribution.model = "ged")
##archm Whether to include ARCH volatility in the mean regression.
##archpow Indicates whether to use st.deviation (1) or variance (2) in the ARCH in mean regression.
myfit2=ugarchfit(myspec,data=x$log.return,solver="solnp")
myfit2
sres2=residuals(myfit2,standardize=T)
for(ii in 1:30) print(Box.test(sres2,ii,"Ljung"))
#-------------------------------------------------------------------------#
myspec=ugarchspec(variance.model = list(model = "eGARCH",
garchOrder = c(1,1), submodel = NULL, external.regressors = NULL,
variance.targeting = FALSE),
mean.model = list(armaOrder = c(0,0), include.mean = TRUE, archm = FALSE,
archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE),
distribution.model = "ged")
myfit3=ugarchfit(myspec,data=x$log.return,solver="solnp")
myfit3
sres3=residuals(myfit3,standardize=T)
for(ii in 1:30) print(Box.test(sres3,ii,"Ljung"))
##LOG(GARCH) = -0.1623325008 + 0.1310836286*ABS(RESID(-1)/@SQRT(GARCH(-1)))
- 0.0001938796244*RESID(-1)/@SQRT(GARCH(-1)) + 0.9920272489*LOG(GARCH(-1))
##R中默认的egarch模型的形式是什么???
#--------------------------------------------------------------------------#
myspec=ugarchspec(variance.model = list(model = "fGARCH",
garchOrder = c(1,1), submodel = "TGARCH", external.regressors = NULL,
variance.targeting = FALSE),
mean.model = list(armaOrder = c(3,3), include.mean = TRUE, archm =FALSE,
archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE),
distribution.model = "std")
myfit4=ugarchfit(myspec,data=x$log.return,solver="solnp")
myfit4
sres4=residuals(myfit4,standardize=T)
for(ii in 1:30) print(Box.test(sres4,ii,"Ljung"))