Séries Financeiras - Lista 4
Introdução
O documento a seguir refere-se a Lista 4 da discplinia de Séries Financeiras, cadeira ministrada pela Professora Sandra canton.
options("getSymbols.warning4.0"=FALSE)
stockData <- new.env()
startDate = as.Date("2008-08-13")
endDate = as.Date("2019-05-15")
ativos<-c("GOGL")
getSymbols(ativos, src="yahoo",from=startDate,to=endDate)## [1] "GOGL"
ggl=GOGL$GOGL.Close
retorno=diff(log(ggl))
retorno=(na.omit(retorno))
n=length(retorno);n## [1] 2705
1
a)
Para verificar a presença de autocorrelação na série dos retornos, será inspeção gráfico juntando com o teste de Box Pierce, com as seguintes hipóteses:
\(H_0: \rho_1 = \rho_2 = ... = \rho_n =0\)
\(H_0: \rho_i \neq 0\)
Com a seguinte estatística de teste:
\(Q_{BP} = n\sum_{k=1}^{h}\cfrac{\hat{\rho_{k}^{2}}}{n-k}\)
Tem-se que, sob a hipótese nula, a estatística de teste tem assintoticamente uma distribuição qui quadrado com h graus de liberdade. Sendo h o número de lags testados.
acf(retorno)Box.test(retorno)##
## Box-Pierce test
##
## data: retorno
## X-squared = 0.34048, df = 1, p-value = 0.5595
verifica-se, portanto, que não há evidências para afirmar que a série de tornos é autocorrelacionada.
b)
mean(retorno)## [1] -0.001223141
Um dos fatos estilizados é de que a média do retorno é teoricamente zero. Verifica-se empiricamente uma média de -0.001, próxima de zero.
c)
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim N(0,\sigma^2)\)
\(\hat{\sigma}^2_t = 0,0006891 + 0,08124y_{t-1}\)
d)
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim t(n-1;shape=3,856)\)
\(\hat{\sigma}^2_t = 0,0007419 + 0,03182y_{t-1}\)
e)
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim t(n-1;skew=1,024;shape=3,856)\)
\(\hat{\sigma}^2_t = 0,0008717 + 0,03252y_{t-1}\)
A distribuição dos resíduos não é simétrica pois esta não rejeita a hipótese de ruído branco, isto é, o modelo com a distribuição assimétrica foi suficiente para captar a volatilidade.
f)
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim N(0,\sigma^2)\)
\(\hat{\sigma}_t = 0,0006774 + 0,03252\epsilon_{t-1} + 0,9583\hat{\sigma}_{t-1} + 0,4412\epsilon_{t-1}\)
g)
O efeito de alavanca acontece quando os retornos negativos são mais influentes na volatilidade futura do que os retornos postivos.
Como os parâmetros são positivos e significativos, o efeito de alavanagem não ocorre.
h)
Como todos são significativos e tem os resíduos de acordo com o esperado, o melhor modelo será aquele com os menores critério de informação. Portanto, o melhor modelo é o m1.
i)
Não, pois o parâmetro gamma não é significativo
j)
\(\sum_{i=1}^{p}\beta_i + \sum_{i=1}^{p}\alpha_i = 1\)
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim N(0,\sigma^2)\)
\(\hat{\sigma}^2_t = 0,8783y_{t-1}\)
2
Modelo
stockData <- new.env()
startDate = as.Date("2010-02-27")
endDate = as.Date("2019-02-27")
ativos<-c("DV.V")
getSymbols(ativos, src="yahoo",from=startDate,to=endDate)## [1] "DV.V"
DOLLY=DV.V$DV.V.Close
retorno=diff(log(DOLLY))
retorno=(na.omit(retorno))
n=length(retorno)
r=retorno
arch <- garch(r, order = c(0,1))##
## ***** ESTIMATION WITH ANALYTICAL GRADIENT *****
##
##
## I INITIAL X(I) D(I)
##
## 1 4.994654e-03 1.000e+00
## 2 5.000000e-02 1.000e+00
##
## IT NF F RELDF PRELDF RELDX STPPAR D*STEP NPRELDF
## 0 1 -3.780e+03
## 1 6 -3.781e+03 3.22e-04 5.35e-04 2.3e-03 3.8e+07 2.3e-04 1.03e+04
## 2 7 -3.781e+03 2.86e-05 3.00e-05 2.2e-03 2.0e+00 2.3e-04 1.45e+01
## 3 11 -3.788e+03 1.80e-03 2.55e-03 2.3e-01 2.0e+00 2.9e-02 1.42e+01
## 4 13 -3.789e+03 2.70e-04 3.97e-04 7.2e-02 6.9e-01 1.2e-02 5.65e-04
## 5 14 -3.791e+03 4.13e-04 6.31e-04 6.3e-02 1.7e+00 1.2e-02 2.91e-03
## 6 16 -3.792e+03 2.73e-04 3.47e-04 1.1e-01 4.2e-01 2.6e-02 3.86e-04
## 7 17 -3.792e+03 1.33e-05 1.10e-05 1.6e-02 0.0e+00 4.2e-03 1.10e-05
## 8 18 -3.792e+03 8.05e-07 7.69e-07 6.0e-03 0.0e+00 1.6e-03 7.69e-07
## 9 19 -3.792e+03 2.68e-09 2.61e-09 3.9e-04 0.0e+00 1.1e-04 2.61e-09
## 10 20 -3.792e+03 2.93e-12 2.87e-12 9.8e-06 0.0e+00 2.7e-06 2.87e-12
##
## ***** RELATIVE FUNCTION CONVERGENCE *****
##
## FUNCTION -3.791699e+03 RELDX 9.771e-06
## FUNC. EVALS 20 GRAD. EVALS 11
## PRELDF 2.867e-12 NPRELDF 2.867e-12
##
## I FINAL X(I) D(I) G(I)
##
## 1 4.437651e-03 1.000e+00 3.153e-02
## 2 1.359318e-01 1.000e+00 6.060e-05
summary(arch)##
## Call:
## garch(x = r, order = c(0, 1))
##
## Model:
## GARCH(0,1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.8983 -0.4234 0.0000 0.2967 4.9211
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## a0 4.438e-03 8.401e-05 52.822 < 2e-16 ***
## a1 1.359e-01 2.104e-02 6.459 1.05e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Diagnostic Tests:
## Jarque Bera Test
##
## data: Residuals
## X-squared = 1863, df = 2, p-value < 2.2e-16
##
##
## Box-Ljung test
##
## data: Squared.Residuals
## X-squared = 0.3919, df = 1, p-value = 0.5313
a.
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim N(0,\sigma^2)\)
\(\hat{\sigma}^2_t = 0,00008401 + 0,002104y_{t-1} - 0,2755\epsilon_t\)
b.
O modelo final não foi adequado, pois o resíduo dos retornos não aderiram a um processo de ruído branco.
a)
"Igarch" <- function(rtn,include.mean=F,volcnt=F){
# Estimation of a Gaussian IGARCH(1,1) model.
# rtn: return series
# include.mean: flag for the constant in the mean equation.
# volcnt: flag for the constant term of the volatility equation.
#### default is the RiskMetrics model
#
Idata <<- rtn
Flag <<- c(include.mean,volcnt)
#
Mean=mean(Idata); Var = var(Idata); S = 1e-6
if((volcnt)&&(include.mean)){
params=c(mu = Mean,omega=0.1*Var,beta=0.85)
lowerBounds = c(mu = -10*abs(Mean), omega= S^2, beta= S)
upperBounds = c(mu = 10*abs(Mean), omega = 100*Var, beta = 1-S)
}
if((volcnt)&&(!include.mean)){
params=c(omega=0.1*Var, beta=0.85)
lowerBounds=c(omega=S^2,beta=S)
upperBounds=c(omega=100*Var,beta=1-S)
}
#
if((!volcnt)&&(include.mean)){
params=c(mu = Mean, beta= 0.8)
lowerBounds = c(mu = -10*abs(Mean), beta= S)
upperBounds = c(mu = 10*abs(Mean), beta = 1-S)
}
if((!volcnt)&&(!include.mean)){
params=c(beta=0.85)
lowerBounds=c(beta=S)
upperBounds=c(beta=1-S)
}
# Step 3: set conditional distribution function:
igarchDist = function(z,hh){dnorm(x = z/hh)/hh}
# Step 4: Compose log-likelihood function:
igarchLLH = function(parm){
include.mean=Flag[1]
volcnt=Flag[2]
mu=0; omega = 0
if((include.mean)&&(volcnt)){
my=parm[1]; omega=parm[2]; beta=parm[3]}
if((!include.mean)&&(volcnt)){
omega=parm[1];beta=parm[2]}
if((!include.mean)&&(!volcnt))beta=parm[1]
if((include.mean)&&(!volcnt)){mu=parm[1]; beta=parm[2]}
#
z = (Idata - mu); Meanz = mean(z^2)
e= omega + (1-beta)* c(Meanz, z[-length(Idata)]^2)
h = filter(e, beta, "r", init=Meanz)
hh = sqrt(abs(h))
llh = -sum(log(igarchDist(z, hh)))
llh
}
# Step 5: Estimate Parameters and Compute Numerically Hessian:
fit = nlminb(start = params, objective = igarchLLH,
lower = lowerBounds, upper = upperBounds)
##lower = lowerBounds, upper = upperBounds, control = list(trace=3))
epsilon = 0.0001 * fit$par
cat("Estimates: ",fit$par,"\n")
npar=length(params)
Hessian = matrix(0, ncol = npar, nrow = npar)
for (i in 1:npar) {
for (j in 1:npar) {
x1 = x2 = x3 = x4 = fit$par
x1[i] = x1[i] + epsilon[i]; x1[j] = x1[j] + epsilon[j]
x2[i] = x2[i] + epsilon[i]; x2[j] = x2[j] - epsilon[j]
x3[i] = x3[i] - epsilon[i]; x3[j] = x3[j] + epsilon[j]
x4[i] = x4[i] - epsilon[i]; x4[j] = x4[j] - epsilon[j]
Hessian[i, j] = (igarchLLH(x1)-igarchLLH(x2)-igarchLLH(x3)+igarchLLH(x4))/
(4*epsilon[i]*epsilon[j])
}
}
cat("Maximized log-likehood: ",igarchLLH(fit$par),"\n")
# Step 6: Create and Print Summary Report:
se.coef = sqrt(diag(solve(Hessian)))
tval = fit$par/se.coef
matcoef = cbind(fit$par, se.coef, tval, 2*(1-pnorm(abs(tval))))
dimnames(matcoef) = list(names(tval), c(" Estimate",
" Std. Error", " t value", "Pr(>|t|)"))
cat("\nCoefficient(s):\n")
printCoefmat(matcoef, digits = 6, signif.stars = TRUE)
if((include.mean)&&(volcnt)){
mu=fit$par[1]; omega=fit$par[2]; beta = fit$par[3]
}
if((include.mean)&&(!volcnt)){
mu = fit$par[1]; beta = fit$par[2]; omega = 0
}
if((!include.mean)&&(volcnt)){
mu=0; omega=fit$par[1]; beta=fit$par[2]
}
if((!include.mean)&&(!volcnt)){
mu=0; omega=0; beta=fit$par[1]
}
z=Idata-mu; Mz = mean(z^2)
e= omega + (1-beta)*c(Mz,z[-length(z)]^2)
h = filter(e,beta,"r",init=Mz)
vol = sqrt(abs(h))
Igarch <- list(par=fit$par,volatility = vol)
}Igarch(as.numeric(r),include.mean = F,volcnt = F)## Estimates: 0.999999
## Maximized log-likehood: -2126.028
## Warning in sqrt(diag(solve(Hessian))): NaNs produzidos
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## beta 0.999999 NA NA NA
b)
A estimação foi incompatível
c)
"garchM" <- function(rtn,type=1){
# Estimation of a Gaussian GARCH(1,1)-M model.
##### The program uses GARCH(1,1) results as initial values.
# rtn: return series
# type = 1 for Variance-in-mean
# = 2 for volatility-in-mean
# = 3 for log(variance)-in-mean
#
if(is.matrix(rtn))rtn=c(rtn[,1])
garchMdata <<- rtn
# obtain initial estimates
m1=garch11FIT(garchMdata)
est=as.numeric(m1$par); v1=m1$ht ## v1 is sigma.t-square
Mean=est[1]; cc=est[2]; ar=est[3]; ma=est[4]; S=1e-6
if(type==2)v1=sqrt(v1)
if(type==3)v1=log(v1)
#### Obtain initial estimate of the parameters for the mean equation
m2=lm(rtn~v1)
Cnst=as.numeric(m2$coefficients[1])
gam=as.numeric(m2$coefficients[2])
params=c(mu=Cnst,gamma=gam, omega=cc, alpha=ar,beta=ma)
lowBounds=c(mu=-5*abs(Mean),gamma=-20*abs(gam), omega=S, alpha=S, beta=ma*0.6)
uppBounds=c(mu=5*abs(Mean),gamma=100*abs(gam), omega=cc*5 ,alpha=3*ar,beta=1-S)
### Pass model information via defining global variable
Vtmp <<- c(type,v1[1])
#
fit=nlminb(start = params, objective= glkM, lower=lowBounds, upper=uppBounds)
##,control=list(trace=3,rel.tol=1e-5))
epsilon = 0.0001 * fit$par
npar=length(params)
Hessian = matrix(0, ncol = npar, nrow = npar)
for (i in 1:npar) {
for (j in 1:npar) {
x1 = x2 = x3 = x4 = fit$par
x1[i] = x1[i] + epsilon[i]; x1[j] = x1[j] + epsilon[j]
x2[i] = x2[i] + epsilon[i]; x2[j] = x2[j] - epsilon[j]
x3[i] = x3[i] - epsilon[i]; x3[j] = x3[j] + epsilon[j]
x4[i] = x4[i] - epsilon[i]; x4[j] = x4[j] - epsilon[j]
Hessian[i, j] = (glkM(x1)-glkM(x2)-glkM(x3)+glkM(x4))/
(4*epsilon[i]*epsilon[j])
}
}
cat("Maximized log-likehood: ",-glkM(fit$par),"\n")
# Step 6: Create and Print Summary Report:
se.coef = sqrt(diag(solve(Hessian)))
tval = fit$par/se.coef
matcoef = cbind(fit$par, se.coef, tval, 2*(1-pnorm(abs(tval))))
dimnames(matcoef) = list(names(tval), c(" Estimate",
" Std. Error", " t value", "Pr(>|t|)"))
cat("\nCoefficient(s):\n")
printCoefmat(matcoef, digits = 6, signif.stars = TRUE)
m3=ResiVol(fit$par)
garchM <- list(residuals=m3$residuals,sigma.t=m3$sigma.t)
}
glkM = function(pars){
rtn <- garchMdata
mu=pars[1]; gamma=pars[2]; omega=pars[3]; alpha=pars[4]; beta=pars[5]
type=Vtmp[1]
nT=length(rtn)
# use conditional variance
if(type==1){
ht=Vtmp[2]
et=rtn[1]-mu-gamma*ht
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept = rtn[i]-mu-gamma*sig2t
at=c(at,ept)
ht=c(ht,sig2t)
}
}
# use volatility
if(type==2){
ht=Vtmp[2]^2
et=rtn[1]-mu-gamma*Vtmp[2]
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept=rtn[i]-mu-gamma*sqrt(sig2t)
at=c(at,ept)
ht=c(ht,sig2t)
}
}
# use log(variance)
if(type==3){
ht=exp(Vtmp[2])
et=rtn[1]-mu-gamma*Vtmp[2]
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept=rtn[i]-mu-gamma*log(abs(sig2t))
at=c(at,ept)
ht=c(ht,sig2t)
}
}
#
hh=sqrt(abs(ht))
glk=-sum(log(dnorm(x=at/hh)/hh))
glk
}
ResiVol = function(pars){
rtn <- garchMdata
mu=pars[1]; gamma=pars[2]; omega=pars[3]; alpha=pars[4]; beta=pars[5]
type=Vtmp[1]
nT=length(rtn)
# use conditional variance
if(type==1){
ht=Vtmp[2]
et=rtn[1]-mu-gamma*ht
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept = rtn[i]-mu-gamma*sig2t
at=c(at,ept)
ht=c(ht,sig2t)
}
}
# use volatility
if(type==2){
ht=Vtmp[2]^2
et=rtn[1]-mu-gamma*Vtmp[2]
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept=rtn[i]-mu-gamma*sqrt(sig2t)
at=c(at,ept)
ht=c(ht,sig2t)
}
}
# use log(variance)
if(type==3){
ht=exp(Vtmp[2])
et=rtn[1]-mu-gamma*Vtmp[2]
at=c(et)
for (i in 2:nT){
sig2t=omega+alpha*at[i-1]^2+beta*ht[i-1]
ept=rtn[i]-mu-gamma*log(abs(sig2t))
at=c(at,ept)
ht=c(ht,sig2t)
}
}
#
ResiVol <- list(residuals=at,sigma.t=sqrt(ht))
}
garch11FIT = function(x){
# Step 1: Initialize Time Series Globally:
tx <<- x
# Step 2: Initialize Model Parameters and Bounds:
Mean = mean(tx); Var = var(tx); S = 1e-6
params = c(mu = Mean, omega = 0.1*Var, alpha = 0.1, beta = 0.8)
lowerBounds = c(mu = -10*abs(Mean), omega = S^2, alpha = S, beta = S)
upperBounds = c(mu = 10*abs(Mean), omega = 100*Var, alpha = 1-S, beta = 1-S)
# Step 3: Set Conditional Distribution Function:
garchDist = function(z, hh) { dnorm(x = z/hh)/hh }
# Step 4: Compose log-Likelihood Function:
garchLLH = function(parm) {
mu = parm[1]; omega = parm[2]; alpha = parm[3]; beta = parm[4]
z = tx-mu; Mean = mean(z^2)
# Use Filter Representation:
e = omega + alpha * c(Mean, z[-length(tx)]^2)
h = filter(e, beta, "r", init = Mean)
hh = sqrt(abs(h))
llh = -sum(log(garchDist(z, hh)))
llh }
#####print(garchLLH(params))
# Step 5: Estimate Parameters and Compute Numerically Hessian:
fit = nlminb(start = params, objective = garchLLH,
lower = lowerBounds, upper = upperBounds)
#
est=fit$par
# compute the sigma.t^2 series
z=tx-est[1]; Mean=mean(z^2)
e=est[2]+est[3]*c(Mean,z[-length(tx)]^2)
h=filter(e,est[4],"r",init=Mean)
garch11Fit <- list(par=est,ht=h)
}garchM(as.numeric(r)*100)## Warning in nlminb(start = params, objective = glkM, lower = lowBounds,
## upper = uppBounds): NA/NaN function evaluation
## Warning in nlminb(start = params, objective = glkM, lower = lowBounds,
## upper = uppBounds): NA/NaN function evaluation
## Maximized log-likehood: -5885.201
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## mu -0.40309457 0.26938651 -1.49634 0.134564
## gamma 0.00638349 0.00591109 1.07992 0.280179
## omega 0.21582502 0.10817875 1.99508 0.046034 *
## alpha 0.03734509 0.00691012 5.40441 6.5023e-08 ***
## beta 0.95936592 0.00734249 130.65954 < 2.22e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Por gamma não ser significativo, o premio de risco não é estatisticamente significativo.
d)
m4 = garchFit(~garch(1,0),data=r,trace=F,leverage=T)
summary(m4)##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~garch(1, 0), data = r, leverage = T, trace = F)
##
## Mean and Variance Equation:
## data ~ garch(1, 0)
## <environment: 0x0000000026dee7f8>
## [data = r]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu omega alpha1 gamma1
## -0.0025003 0.0044244 0.1380372 0.0153195
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.0025003 0.0016937 -1.476 0.140
## omega 0.0044244 0.0001688 26.215 < 2e-16 ***
## alpha1 0.1380372 0.0244725 5.641 1.7e-08 ***
## gamma1 0.0153195 0.0898244 0.171 0.865
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## 2174.079 normalized: 1.232471
##
## Description:
## Sun May 19 23:39:19 2019 by user: Rafael
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 1872.462 0
## Shapiro-Wilk Test R W 0.9041467 0
## Ljung-Box Test R Q(10) 81.31137 2.776668e-13
## Ljung-Box Test R Q(15) 83.17819 1.823808e-11
## Ljung-Box Test R Q(20) 88.48377 1.36324e-10
## Ljung-Box Test R^2 Q(10) 30.6105 0.0006802087
## Ljung-Box Test R^2 Q(15) 36.97375 0.001276731
## Ljung-Box Test R^2 Q(20) 82.27544 1.607812e-09
## LM Arch Test R TR^2 28.61883 0.00448676
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## -2.460407 -2.447991 -2.460417 -2.455819
\(y_t = x_{t}^{'}b + \epsilon_t\)
\(\epsilon_t|\psi_{t-1} \sim N(0,\sigma^2)\)
\(\hat{\sigma}_t = 0,0044\epsilon_{t-1} + 0,1380\hat{\sigma}_{t-1} + 0,0153\epsilon_{t-1}\)
e)
Não, pois rejeita o LM Arch Test.
f)
Egarch <- function(rtn){
# Estimation of an EGARCH(1,1) model. Assume normal innovations
# rtn: return series
#
write(rtn,file='tmp.txt',ncol=1)
# obtain initial estimates
mu=mean(rtn)
par=c(mu,0.1,0.1,0.1,0.7)
#
#
#mm=optim(par,glk,method="Nelder-Mead",hessian=T)
low=c(-10,-5,0,-1,0)
upp=c(10,5,1,0,1)
mm=optim(par,glk,method="L-BFGS-B",hessian=T,lower=low,upper=upp)
## Print the results
par=mm$par
H=mm$hessian
Hi = solve(H)
cat(" ","\n")
cat("Estimation results of EGARCH(1,1) model:","\n")
cat("estimates: ",par,"\n")
se=sqrt(diag(Hi))
cat("std.errors: ",se,"\n")
tra=par/se
cat("t-ratio: ",tra,"\n")
# compute the volatility series and residuals
ht=var(rtn)
T=length(rtn)
if(T > 40)ht=var(rtn[1:40])
at=rtn-par[1]
for (i in 2:T){
eptm1=at[i-1]/sqrt(ht[i-1])
lnht=par[2]+par[3]*(abs(eptm1)+par[4]*eptm1)+par[5]*log(ht[i-1])
sig2t=exp(lnht)
ht=c(ht,sig2t)
}
sigma.t=sqrt(ht)
Egarch <- list(residuals=at,volatility=sigma.t)
}
glk <- function(par){
rtn=read.table("tmp.txt")[,1]
glk=0
ht=var(rtn)
T=length(rtn)
if(T > 40)ht=var(rtn[1:40])
at=rtn[1]-par[1]
for (i in 2:T){
ept=rtn[i]-par[1]
at=c(at,ept)
eptm1=at[i-1]/sqrt(ht[i-1])
lnht=par[2]+par[3]*(abs(eptm1)+par[4]*eptm1)+par[5]*log(ht[i-1])
sig2t=exp(lnht)
ht=c(ht,sig2t)
glk=glk + 0.5*(lnht + ept^2/sig2t)
}
glk
}
Egarch(r)Erro na otimização
h
De todos os modelos ajustaados, o Garch-M apresentou a maior quantidade de parâmetros significativos. Ao todo, nenhum modelo alcançou adequabilidade dos resíduos.