HETEROSCEDASTICIDADE CONDICIONAL

 UNIVERSIDADE FEDERAL DA PARAÍBA

Autores

Prof. Dr. Sinézio Fernandes Maia

Natan Henrique Alves

Data de Publicação

29 de setembro de 2024

Resumo

O mercado financeiro oferece diversas formas de gestão de risco, sendo uma das mais conhecidas e utilizadas as operações de hedge, realizadas por meio do mercado de derivativos. Essas operações permitem que os produtores se protejam contra variações inesperadas nos preços dos ativos negociados no mercado à vista. Considerando o risco que a volatilidade dos preços pode acarretar, este trabalho tem como objetivo estudar a relação entre a volatilidade e a razão ótima de hedge no período de 2019 a 2024. A questão central abordada é: a volatilidade seria responsável pela efetividade e pela determinação da razão ótima de hedge? Para avaliar essa hipótese, serão utilizados modelos pertencentes à família ARCH.

1. Introdução

No estudo do mercado futuro de commodities e cambial, a volatilidade dos preços é um dos principais elementos a serem analisados. No mercado de boi gordo, as flutuações de preços podem ser causadas por diversos choques, sejam eles políticos, econômicos ou sazonais. O risco associado a esses choques pode ter um impacto significativo sobre os ganhos financeiros dos participantes desse mercado. Compreender o comportamento da volatilidade dos preços diante desses choques é essencial para que os agentes de mercado possam minimizar seus riscos. Por meio do mercado futuro, as operações de hedge auxiliam na alocação desse risco, reduzindo a exposição às oscilações de preços dos ativos de interesse.

O mercado futuro brasileiro é atualmente administrado pela B3 (Brasil, Bolsa, Balcão), que oferece a principal plataforma para a negociação de contratos futuros de diversos ativos subjacentes. O mercado futuro faz parte do mercado de derivativos, sendo um dos seus segmentos mais utilizados para hedge de commodities. Esses contratos estabelecem um acordo entre duas partes, uma compradora e outra vendedora, definindo o preço e a data de liquidação. As principais commodities negociadas atualmente incluem café arábica, etanol hidratado, soja, milho e boi gordo.

Os agentes que operam com contratos futuros para fins de hedge geralmente buscam fixar os preços de compra ou venda em um nível que garanta uma margem mínima de lucro. Isso é possível porque os preços do mercado à vista (spot) e do mercado futuro tendem a ser correlacionados, permitindo que os agentes compensem eventuais perdas em um mercado com ganhos no outro. O objetivo deste trabalho é analisar a relação entre a volatilidade e a razão ótima de hedge, tanto para o mercado de boi gordo quanto para o cambial, avaliando a efetividade dessa razão em ambos os mercados. O período de análise abrange de dezembro de 2019 a agosto de 2024. A questão central a ser investigada é: a volatilidade influencia a efetividade da razão ótima de hedge? A volatilidade foi estudada com base nos modelos da família ARCH.

2. Revisão da Literatura

3. Teoria do Portifólio

4. Metodologia

5. Resultados

Espera-se que, no mercado futuro, os agentes que buscam hedge para sua produção encontrem maior estabilidade de preços. Ao analisar a série de retornos do mercado futuro de boi gordo entre 2019 e 2024, observa-se que esses retornos apresentaram menor variância em comparação ao mercado spot. Esse período foi atípico para o mercado de boi gordo, marcado por uma elevação de preços decorrente de uma combinação de fatores, como o aumento da demanda chinesa, a redução no abate de fêmeas e os impactos da pandemia, que afetaram a logística dos frigoríficos e agravaram a escassez de oferta (CONAB, 2021).

Código
g1+g2

As commodities negociadas na B3, em grande parte, são influenciadas pela taxa de câmbio, que mostrou um comportamento mais correlacionado entre os retornos dos mercados spot e futuro, com variâncias semelhantes. O câmbio se destacou pelo forte aumento no início de 2020, o que gerou maior volatilidade no começo da série de retornos.

Código
g3+g4

Foram estimados 12 modelos para cada série, tanto spot quanto futuro totalizando 48 modelos. Esses modelos foram avaliados pelos critérios de Akaike, Schwartz, Bayesiano e Hannan-Quinn, sendo a escolha pautada pela parcimônia de cada modelo. O teste ARCH de Engle (1982) foi aplicado para identificar a presença de heterocedasticidade condicional nas séries analisadas, e constatou-se a presença de efeito ARCH em todas as séries no período considerado.

Os modelos que apresentaram os melhores resultados para o boi gordo no mercado spot e futuro foram o GARCH(1,1) e o GARCH(1,2), respectivamente. O modelo EGARCH(1,1) foi o mais adequado para ambos os mercados, enquanto o TARCH(1,2) se destacou no mercado spot e o TARCH(1,1) no mercado futuro, de acordo com os critérios propostos.

No mercado à vista, a soma dos coeficientes alfa e beta (igual a 1,00) calculada a partir do modelo GARCH indica que os choques ocorridos nesse mercado demoram a se dissipar. Em contraste, no mercado futuro, a soma de alfa e beta (igual a 0,108) revela uma baixa persistência, comportamento oposto ao observado no mercado à vista. Além disso, os modelos EGARCH e TARCH indicam a presença de assimetria positiva em ambos os mercados.

Para o câmbio, os melhores modelos apontados pelos critérios de avaliação para os mercados spot e futuro foram o GARCH(1,1) para ambos. A soma dos parâmetros alfa e beta (0,85) indicou que, no mercado spot, os choques no câmbio têm uma alta reação e persistência ao longo do tempo. No mercado futuro, a soma dos parâmetros foi de 0,98, sugerindo uma baixa reação, mas uma alta persistência.

Os modelos EGARCH(1,1) e TARCH(1,1) foram igualmente selecionados para os mercados spot e futuro. Esses modelos indicaram assimetria negativa no mercado de câmbio, com os coeficientes gama menores que 0.

Histograma dos Preços Boi Gordo

Histograma Dolar

Histograma dos Retornos do Boi Gordo

Histograma dos Retornos do Dolar

Estatísticas do Boi Gordo

Código
# Calcular os retornos logarítmicos
retorno <- preco |> 
  mutate(
    boif = c(NA, diff(log(boi_fut))),
    bois = c(NA, diff(log(boi_spot)))
  ) |> 
  select(Data, bois, boif) |> 
  na.omit()

# Função para calcular estatísticas
estatisticas <- function(retorno) {
  media <- mean(retorno)
  desvio <- sd(retorno)
  Kurtosis <- kurtosis(retorno)
  Skewness <- skewness(retorno)
  return(c(Media = media, Desvio_Padrão = desvio, Curtose = Kurtosis, Assimetria = Skewness))
}

# Calcular estatísticas para Boi Spot e Boi Futuro
{
Estatisticas_bois <- estatisticas(retorno$bois)
Estatisticas_boif <- estatisticas(retorno$boif)

# Criar data frame com os resultados
df2 <- data.frame(
  Estatísticas = names(Estatisticas_bois),
  Boi_Spot = Estatisticas_bois,
  Boi_Futuro = Estatisticas_boif
)

# Exibir a tabela formatada com kable e kableExtra
kable(df2, caption = "Estatísticas Descritivas dos Retornos do Boi", 
      col.names = c("Estatísticas", "Boi Spot", "Boi Futuro")) |> 
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), 
                full_width = F, 
                position = "center")
}
Estatísticas Descritivas dos Retornos do Boi
Estatísticas Boi Spot Boi Futuro
Media Media 0.0002794 0.0002838
Desvio_Padrão Desvio_Padrão 0.0134757 0.0086524
Curtose Curtose 8.5012596 14.8754970
Assimetria Assimetria -0.4551146 0.1209234

Estatísticas do Dolar

Código
# Calcular os retornos logarítmicos
retorno1 <- dolar |> 
  mutate(
    dolarf = c(NA, diff(log(dolar_fut))),
    dolars = c(NA, diff(log(dolar_spot)))
  ) |> 
  select(data, dolars, dolarf) |> 
  na.omit()

# Função para calcular estatísticas
estatisticas <- function(retorno1) {
  media <- mean(retorno1)
  desvio <- sd(retorno1)
  Kurtosis <- kurtosis(retorno1)
  Skewness <- skewness(retorno1)
  return(c(Media = media, Desvio_Padrão = desvio, Curtose = Kurtosis, Assimetria = Skewness))
}

# Calcular estatísticas para Boi Spot e Boi Futuro
{
Estatisticas_dolars <- estatisticas(retorno1$dolars)
Estatisticas_dolarf <- estatisticas(retorno1$dolarf)

# Criar data frame com os resultados
df2 <- data.frame(
  Estatísticas = names(Estatisticas_dolars),
  Dolar_Spot = Estatisticas_dolars,
  Dolar_Futuro = Estatisticas_dolarf
)

# Exibir a tabela formatada com kable e kableExtra
kable(df2, caption = "Estatísticas Descritivas dos Retornos do Dolar", 
      col.names = c("Estatísticas", "Dolar Spot", "Dolar Futuro")) |> 
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), 
                full_width = F, 
                position = "center")
}
Estatísticas Descritivas dos Retornos do Dolar
Estatísticas Dolar Spot Dolar Futuro
Media Media 0.0002468 0.0002477
Desvio_Padrão Desvio_Padrão 0.0107566 0.0102802
Curtose Curtose 3.4587218 1.2051048
Assimetria Assimetria 0.1774958 0.1334497

Janela 2019-2024

Normalidade Boi Gordo Janela

estabilidade Spot Boi Gordo Janela

Raiz Unitaria Spot Boi Gordo Janela

estabilidade Futuro Boi Gordo Janela

Raiz Unitaria Futuro Boi Gordo Janela

Estabilidade preços Spot do Dolar

Raiz Unitaria Spot Dolar

Estabilidade Futuro Dolar

Raiz unitaria Futuro Dolar

ARIMA Boi Gordo na Janela 2019-2024

Spot Boi Gordo Janela

Futuro Boi Gordo Janela

Garch, EGARCH e TARCH

Grach Boi Spot

Código
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
                   mean.model = list(armaOrder = c(3, 3), include.mean = TRUE),
                   distribution.model = "norm")


data <- diff(log(Boits))  
garch_fit <- ugarchfit(spec = spec, data = data)
garch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : sGARCH(1,1)
Mean Model  : ARFIMA(3,0,3)
Distribution    : norm 

Optimal Parameters
------------------------------------
        Estimate  Std. Error      t value Pr(>|t|)
mu      0.000381    0.000391      0.97415 0.329982
ar1     1.571576    0.031261     50.27323 0.000000
ar2    -0.582766    0.054577    -10.67793 0.000000
ar3    -0.051762    0.030893     -1.67553 0.093830
ma1    -1.924635    0.000031 -61836.37325 0.000000
ma2     1.164935    0.000592   1969.13547 0.000000
ma3    -0.171595    0.007734    -22.18811 0.000000
omega   0.000000    0.000002      0.21003 0.833642
alpha1  0.046957    0.018563      2.52962 0.011418
beta1   0.952043    0.017548     54.25421 0.000000

Robust Standard Errors:
        Estimate  Std. Error       t value Pr(>|t|)
mu      0.000381    0.000737      0.516925  0.60521
ar1     1.571576    0.091807     17.118297  0.00000
ar2    -0.582766    0.147776     -3.943572  0.00008
ar3    -0.051762    0.070546     -0.733731  0.46311
ma1    -1.924635    0.000030 -64433.886458  0.00000
ma2     1.164935    0.000575   2025.206759  0.00000
ma3    -0.171595    0.007842    -21.881758  0.00000
omega   0.000000    0.000023      0.020013  0.98403
alpha1  0.046957    0.177995      0.263812  0.79192
beta1   0.952043    0.169481      5.617391  0.00000

LogLikelihood : 3282.756 

Information Criteria
------------------------------------
                    
Akaike       -5.6330
Bayes        -5.5894
Shibata      -5.6331
Hannan-Quinn -5.6165

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                       1.959  0.1616
Lag[2*(p+q)+(p+q)-1][17]     5.984  1.0000
Lag[4*(p+q)+(p+q)-1][29]    11.209  0.9157
d.o.f=6
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                      1.439  0.2303
Lag[2*(p+q)+(p+q)-1][5]     2.149  0.5836
Lag[4*(p+q)+(p+q)-1][9]     2.836  0.7858
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]   0.02372 0.500 2.000  0.8776
ARCH Lag[5]   0.39055 1.440 1.667  0.9153
ARCH Lag[7]   0.70782 2.315 1.543  0.9559

Nyblom stability test
------------------------------------
Joint Statistic:  73.3874
Individual Statistics:             
mu     0.3965
ar1    0.1753
ar2    0.1875
ar3    0.1163
ma1    0.2156
ma2    0.1956
ma3    0.1091
omega  9.3589
alpha1 0.2572
beta1  0.2580

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.29 2.54 3.05
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias          0.02121 0.9831    
Negative Sign Bias 1.23250 0.2180    
Positive Sign Bias 0.51549 0.6063    
Joint Effect       1.92759 0.5876    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic  p-value(g-1)
1    20     63.09 0.00000124126
2    30     76.83 0.00000333864
3    40    105.95 0.00000004225
4    50    116.74 0.00000018663


Elapsed time : 1.04118 
Código
coeficientes <- round(coef(garch_fit), 6)
print(coeficientes)
       mu       ar1       ar2       ar3       ma1       ma2       ma3     omega 
 0.000381  1.571576 -0.582766 -0.051762 -1.924635  1.164935 -0.171595  0.000000 
   alpha1     beta1 
 0.046957  0.952043 
Código
vconds1 <- garch_fit@fit$sigma^2

plot.ts(vconds1, type = "l", main = "Variância Condicional GARCH(1,1)",
        xlab = "", ylab = "Variância Condicional")

Código
plot(garch_fit, which = 3)

Código
plot.ts(vconds1)

Código
DP <- sqrt(vconds1)
vol <- DP * sqrt(252)
plot.ts(vol)

Código
mean_vol <- mean(vol) * 100
print(mean_vol)
[1] 24.38569

Egarch e Tarch

Código
spec_egarch <- ugarchspec(
  variance.model = list(model = "eGARCH", garchOrder = c(2, 1)),
  mean.model = list(armaOrder = c(3, 1), include.mean = TRUE),
  distribution.model = "std"  # Distribuição t-student
)


data <- diff(log(Boits))  # Supondo que 'dolars' seja a série de preços
egarch_fit <- ugarchfit(spec = spec_egarch, data = data)
egarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : eGARCH(2,1)
Mean Model  : ARFIMA(3,0,1)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error   t value Pr(>|t|)
mu      0.000530    0.000169   3.14218 0.001677
ar1    -0.976565    0.062368 -15.65800 0.000000
ar2    -0.304584    0.022828 -13.34242 0.000000
ar3    -0.057443    0.015194  -3.78059 0.000156
ma1     0.614033    0.062396   9.84084 0.000000
omega  -0.078868    0.009464  -8.33335 0.000000
alpha1 -0.042667    0.053820  -0.79278 0.427909
alpha2 -0.005825    0.051616  -0.11286 0.910142
beta1   0.991127    0.001262 785.09225 0.000000
gamma1  0.374762    0.073131   5.12450 0.000000
gamma2 -0.231619    0.083193  -2.78411 0.005368
shape   5.055374    0.747308   6.76478 0.000000

Robust Standard Errors:
        Estimate  Std. Error   t value Pr(>|t|)
mu      0.000530    0.000164   3.23217 0.001229
ar1    -0.976565    0.030240 -32.29333 0.000000
ar2    -0.304584    0.035023  -8.69663 0.000000
ar3    -0.057443    0.010177  -5.64442 0.000000
ma1     0.614033    0.029044  21.14125 0.000000
omega  -0.078868    0.012275  -6.42505 0.000000
alpha1 -0.042667    0.057229  -0.74555 0.455936
alpha2 -0.005825    0.054767  -0.10637 0.915293
beta1   0.991127    0.001504 659.10404 0.000000
gamma1  0.374762    0.076965   4.86928 0.000001
gamma2 -0.231619    0.079716  -2.90555 0.003666
shape   5.055374    0.713346   7.08685 0.000000

LogLikelihood : 3328.71 

Information Criteria
------------------------------------
                    
Akaike       -5.7086
Bayes        -5.6564
Shibata      -5.7088
Hannan-Quinn -5.6889

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic    p-value
Lag[1]                       0.587 0.44358227
Lag[2*(p+q)+(p+q)-1][11]    14.520 0.00000000
Lag[4*(p+q)+(p+q)-1][19]    22.102 0.00004719
d.o.f=4
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.2807  0.5962
Lag[2*(p+q)+(p+q)-1][8]     1.1515  0.9625
Lag[4*(p+q)+(p+q)-1][14]    2.0866  0.9894
d.o.f=3

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[4]    0.5631 0.500 2.000  0.4530
ARCH Lag[6]    0.7131 1.461 1.711  0.8310
ARCH Lag[8]    1.0266 2.368 1.583  0.9204

Nyblom stability test
------------------------------------
Joint Statistic:  5.0808
Individual Statistics:             
mu     1.9290
ar1    0.4970
ar2    0.1104
ar3    0.1320
ma1    0.7268
omega  0.3552
alpha1 0.2097
alpha2 0.1612
beta1  0.4170
gamma1 0.1958
gamma2 0.1815
shape  0.1014

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.69 2.96 3.51
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           0.7437 0.4572    
Negative Sign Bias  0.3285 0.7426    
Positive Sign Bias  0.8855 0.3761    
Joint Effect        1.2519 0.7406    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     14.63       0.7460
2    30     26.74       0.5855
3    40     36.07       0.6042
4    50     61.49       0.1085


Elapsed time : 1.680138 
Código
coeficientes_egarch <- round(coef(egarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1     omega    alpha1    alpha2 
 0.000530 -0.976565 -0.304584 -0.057443  0.614033 -0.078868 -0.042667 -0.005825 
    beta1    gamma1    gamma2     shape 
 0.991127  0.374762 -0.231619  5.055374 
Código
#-------------------------------------------------------------#

spec_tgarch <- ugarchspec(
  variance.model = list(model = "fGARCH", submodel = "TGARCH", garchOrder = c(1, 2)),
  mean.model = list(armaOrder = c(3, 3), include.mean = TRUE),
  distribution.model = "std"  
)


data <- diff(log(Boits))  
tgarch_fit <- ugarchfit(spec = spec_tgarch, data = data)
tgarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : fGARCH(1,2)
fGARCH Sub-Model    : TGARCH
Mean Model  : ARFIMA(3,0,3)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error    t value Pr(>|t|)
mu      0.000345    0.000300     1.1478 0.251038
ar1     1.331058    0.015829    84.0881 0.000000
ar2    -0.346351    0.012187   -28.4208 0.000000
ar3    -0.065160    0.023952    -2.7205 0.006519
ma1    -1.709182    0.000273 -6270.3959 0.000000
ma2     0.896025    0.024546    36.5039 0.000000
ma3    -0.099635    0.035377    -2.8164 0.004857
omega   0.000247    0.000123     2.0093 0.044503
alpha1  0.138525    0.028547     4.8525 0.000001
beta1   0.363810    0.145390     2.5023 0.012339
beta2   0.518059    0.139282     3.7195 0.000200
eta11   0.536428    0.144363     3.7158 0.000203
shape   4.940837    0.714760     6.9126 0.000000

Robust Standard Errors:
        Estimate  Std. Error    t value Pr(>|t|)
mu      0.000345    0.000278     1.2393 0.215239
ar1     1.331058    0.035839    37.1396 0.000000
ar2    -0.346351    0.026702   -12.9708 0.000000
ar3    -0.065160    0.023557    -2.7661 0.005673
ma1    -1.709182    0.000319 -5362.5253 0.000000
ma2     0.896025    0.031896    28.0919 0.000000
ma3    -0.099635    0.045955    -2.1681 0.030150
omega   0.000247    0.000122     2.0289 0.042467
alpha1  0.138525    0.030861     4.4886 0.000007
beta1   0.363810    0.109790     3.3137 0.000921
beta2   0.518059    0.108918     4.7564 0.000002
eta11   0.536428    0.151618     3.5380 0.000403
shape   4.940837    0.700107     7.0573 0.000000

LogLikelihood : 3348.03 

Information Criteria
------------------------------------
                    
Akaike       -5.7402
Bayes        -5.6836
Shibata      -5.7404
Hannan-Quinn -5.7188

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.5562  0.4558
Lag[2*(p+q)+(p+q)-1][17]    4.0965  1.0000
Lag[4*(p+q)+(p+q)-1][29]    9.6166  0.9814
d.o.f=6
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                         statistic p-value
Lag[1]                     0.09214  0.7615
Lag[2*(p+q)+(p+q)-1][8]    1.51830  0.9251
Lag[4*(p+q)+(p+q)-1][14]   2.87912  0.9619
d.o.f=3

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[4]    0.4247 0.500 2.000  0.5146
ARCH Lag[6]    1.0934 1.461 1.711  0.7211
ARCH Lag[8]    1.7746 2.368 1.583  0.7867

Nyblom stability test
------------------------------------
Joint Statistic:  4.3429
Individual Statistics:             
mu     0.9883
ar1    0.2167
ar2    0.2146
ar3    0.1320
ma1    0.1994
ma2    0.1867
ma3    0.1085
omega  0.5428
alpha1 0.3003
beta1  0.2836
beta2  0.2832
eta11  0.3342
shape  0.2257

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.89 3.15 3.69
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias          0.51591 0.6060    
Negative Sign Bias 0.10984 0.9126    
Positive Sign Bias 0.08653 0.9311    
Joint Effect       0.76525 0.8578    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     19.17       0.4460
2    30     31.55       0.3402
3    40     42.06       0.3398
4    50     61.58       0.1071


Elapsed time : 1.455682 
Código
coeficientes_egarch <- round(coef(tgarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1       ma2       ma3     omega 
 0.000345  1.331058 -0.346351 -0.065160 -1.709182  0.896025 -0.099635  0.000247 
   alpha1     beta1     beta2     eta11     shape 
 0.138525  0.363810  0.518059  0.536428  4.940837 

Grach Boi Futuro

Código
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(2, 1)),
                   mean.model = list(armaOrder = c(3, 3), include.mean = TRUE),
                   distribution.model = "norm")


data <- diff(log(Boitsf))
garch_fit <- ugarchfit(spec = spec, data = data)
garch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : sGARCH(2,1)
Mean Model  : ARFIMA(3,0,3)
Distribution    : norm 

Optimal Parameters
------------------------------------
        Estimate  Std. Error      t value Pr(>|t|)
mu      0.000277    0.000139       1.9966 0.045868
ar1     1.701947    0.000450    3783.7444 0.000000
ar2    -0.446779    0.000486    -918.9660 0.000000
ar3    -0.277237    0.000487    -569.5437 0.000000
ma1    -1.692860    0.000003 -532694.4769 0.000000
ma2     0.434840    0.000069    6343.7500 0.000000
ma3     0.281451    0.000070    4020.0625 0.000000
omega   0.000000    0.000000       1.3625 0.173051
alpha1  0.000000    0.007234       0.0000 1.000000
alpha2  0.032989    0.007746       4.2587 0.000021
beta1   0.961239    0.002133     450.7300 0.000000

Robust Standard Errors:
        Estimate  Std. Error        t value Pr(>|t|)
mu      0.000277    0.000151       1.839247 0.065879
ar1     1.701947    0.002779     612.358836 0.000000
ar2    -0.446779    0.001061    -421.061670 0.000000
ar3    -0.277237    0.000708    -391.625837 0.000000
ma1    -1.692860    0.000005 -329708.990741 0.000000
ma2     0.434840    0.000021   20375.205478 0.000000
ma3     0.281451    0.000111    2528.406967 0.000000
omega   0.000000    0.000009       0.055844 0.955466
alpha1  0.000000    0.007210       0.000000 1.000000
alpha2  0.032989    0.022072       1.494563 0.135028
beta1   0.961239    0.026469      36.315462 0.000000

LogLikelihood : 9137.658 

Information Criteria
------------------------------------
                    
Akaike       -6.9299
Bayes        -6.9053
Shibata      -6.9299
Hannan-Quinn -6.9210

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic     p-value
Lag[1]                      0.3646 0.545940902
Lag[2*(p+q)+(p+q)-1][17]   11.8029 0.000007694
Lag[4*(p+q)+(p+q)-1][29]   22.4844 0.010289006
d.o.f=6
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                         statistic p-value
Lag[1]                     0.07579  0.7831
Lag[2*(p+q)+(p+q)-1][8]    1.48950  0.9285
Lag[4*(p+q)+(p+q)-1][14]   2.01176  0.9910
d.o.f=3

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[4]    0.2317 0.500 2.000  0.6303
ARCH Lag[6]    0.7021 1.461 1.711  0.8342
ARCH Lag[8]    0.8395 2.368 1.583  0.9465

Nyblom stability test
------------------------------------
Joint Statistic:  175.2951
Individual Statistics:                
mu      0.095511
ar1     0.032277
ar2     0.046845
ar3     0.065101
ma1     0.009987
ma2     0.011102
ma3     0.013675
omega  26.017588
alpha1  0.352820
alpha2  0.306871
beta1   0.293987

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.49 2.75 3.27
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           1.4948 0.1351    
Negative Sign Bias  0.4544 0.6496    
Positive Sign Bias  0.5656 0.5717    
Joint Effect        2.2694 0.5184    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic
1    20     637.8
2    30     665.4
3    40     687.3
4    50     702.9
                                                                                                                     p-value(g-1)
1 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000513
2 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016607
3 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001815342
4 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001331084376


Elapsed time : 1.268119 
Código
coeficientes <- round(coef(garch_fit), 6)
print(coeficientes)
       mu       ar1       ar2       ar3       ma1       ma2       ma3     omega 
 0.000277  1.701947 -0.446779 -0.277237 -1.692860  0.434840  0.281451  0.000000 
   alpha1    alpha2     beta1 
 0.000000  0.032989  0.961239 
Código
vconds1 <- garch_fit@fit$sigma^2

plot.ts(vconds1, type = "l", main = "Variância Condicional GARCH(1,1)",
        xlab = "", ylab = "Variância Condicional")

Código
plot(garch_fit, which = 3)

Código
plot.ts(vconds1)

Código
DP <- sqrt(vconds1)
vol <- DP * sqrt(252)
plot.ts(vol)

Código
mean_vol <- mean(vol) * 100
print(mean_vol)
[1] 12.85705

Egarch e Tarch

Código
spec_egarch <- ugarchspec(
  variance.model = list(model = "eGARCH", garchOrder = c(1, 1)),
  mean.model = list(armaOrder = c(3, 3), include.mean = TRUE),
  distribution.model = "std" 
)


data <- diff(log(Boitsf))  
egarch_fit <- ugarchfit(spec = spec_egarch, data = data)
egarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : eGARCH(1,1)
Mean Model  : ARFIMA(3,0,3)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error     t value Pr(>|t|)
mu     -0.000246    0.000166     -1.4879  0.13678
ar1     0.593737    0.002486    238.7906  0.00000
ar2    -0.600089    0.000857   -700.5396  0.00000
ar3     0.993882    0.001799    552.3557  0.00000
ma1    -0.585493    0.000336  -1743.0050  0.00000
ma2     0.599756    0.000050  11909.7242  0.00000
ma3    -0.987528    0.000020 -49022.3057  0.00000
omega  -0.093217    0.005167    -18.0412  0.00000
alpha1 -0.025134    0.015968     -1.5740  0.11548
beta1   0.989863    0.000312   3168.4657  0.00000
gamma1  0.220281    0.019284     11.4230  0.00000
shape   2.316484    0.098551     23.5055  0.00000

Robust Standard Errors:
        Estimate  Std. Error    t value Pr(>|t|)
mu     -0.000246    0.000158    -1.5581  0.11921
ar1     0.593737    0.003922   151.3851  0.00000
ar2    -0.600089    0.000992  -605.0559  0.00000
ar3     0.993882    0.002589   383.8927  0.00000
ma1    -0.585493    0.000587  -996.8594  0.00000
ma2     0.599756    0.000159  3765.4777  0.00000
ma3    -0.987528    0.000103 -9627.3292  0.00000
omega  -0.093217    0.004801   -19.4173  0.00000
alpha1 -0.025134    0.022045    -1.1402  0.25422
beta1   0.989863    0.000383  2583.8680  0.00000
gamma1  0.220281    0.015594    14.1257  0.00000
shape   2.316484    0.090594    25.5700  0.00000

LogLikelihood : 9877.047 

Information Criteria
------------------------------------
                    
Akaike       -7.4905
Bayes        -7.4638
Shibata      -7.4906
Hannan-Quinn -7.4809

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.1629  0.6865
Lag[2*(p+q)+(p+q)-1][17]    9.6553  0.1358
Lag[4*(p+q)+(p+q)-1][29]   18.2431  0.1327
d.o.f=6
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                      1.216  0.2701
Lag[2*(p+q)+(p+q)-1][5]     2.283  0.5533
Lag[4*(p+q)+(p+q)-1][9]     3.364  0.6977
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]  0.003006 0.500 2.000  0.9563
ARCH Lag[5]  0.665867 1.440 1.667  0.8338
ARCH Lag[7]  1.508969 2.315 1.543  0.8196

Nyblom stability test
------------------------------------
Joint Statistic:  3.4171
Individual Statistics:              
mu     0.11189
ar1    0.11877
ar2    0.05810
ar3    0.08550
ma1    0.09683
ma2    0.07901
ma3    0.06120
omega  0.59336
alpha1 1.06918
beta1  0.58317
gamma1 0.16207
shape  0.96066

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.69 2.96 3.51
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           1.5256 0.1272    
Negative Sign Bias  0.6728 0.5012    
Positive Sign Bias  1.4942 0.1352    
Joint Effect        4.7256 0.1930    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     33.09      0.02346
2    30     41.03      0.06839
3    40     56.90      0.03192
4    50     64.33      0.06982


Elapsed time : 3.154566 
Código
coeficientes_egarch <- round(coef(egarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1       ma2       ma3     omega 
-0.000246  0.593737 -0.600089  0.993882 -0.585493  0.599756 -0.987528 -0.093217 
   alpha1     beta1    gamma1     shape 
-0.025134  0.989863  0.220281  2.316484 
Código
#-------------------------------------------------------------#

spec_tgarch <- ugarchspec(
  variance.model = list(model = "fGARCH", submodel = "TGARCH", garchOrder = c(1, 1)),
  mean.model = list(armaOrder = c(3, 3), include.mean = TRUE),
  distribution.model = "std" 
)


data <- diff(log(Boitsf))  
tgarch_fit <- ugarchfit(spec = spec_tgarch, data = data)
tgarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : fGARCH(1,1)
fGARCH Sub-Model    : TGARCH
Mean Model  : ARFIMA(3,0,3)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error     t value Pr(>|t|)
mu     -0.000214    0.000197     -1.0883 0.276467
ar1     0.593430    0.002738    216.7138 0.000000
ar2    -0.600126    0.000916   -654.8942 0.000000
ar3     0.993485    0.002004    495.7062 0.000000
ma1    -0.585129    0.000388  -1509.9266 0.000000
ma2     0.599770    0.000036  16564.0231 0.000000
ma3    -0.987068    0.000021 -46871.3244 0.000000
omega   0.000105    0.000040      2.6115 0.009013
alpha1  0.120051    0.023232      5.1675 0.000000
beta1   0.929336    0.011541     80.5214 0.000000
eta11   0.085722    0.079558      1.0775 0.281269
shape   2.393808    0.111681     21.4344 0.000000

Robust Standard Errors:
        Estimate  Std. Error     t value Pr(>|t|)
mu     -0.000214    0.000226    -0.94639 0.343952
ar1     0.593430    0.004180   141.98314 0.000000
ar2    -0.600126    0.001098  -546.68440 0.000000
ar3     0.993485    0.002868   346.42836 0.000000
ma1    -0.585129    0.000648  -903.03763 0.000000
ma2     0.599770    0.000169  3556.32188 0.000000
ma3    -0.987068    0.000100 -9830.83384 0.000000
omega   0.000105    0.000047     2.25480 0.024146
alpha1  0.120051    0.032802     3.65992 0.000252
beta1   0.929336    0.017189    54.06571 0.000000
eta11   0.085722    0.114742     0.74708 0.455014
shape   2.393808    0.106763    22.42174 0.000000

LogLikelihood : 9876.859 

Information Criteria
------------------------------------
                    
Akaike       -7.4904
Bayes        -7.4636
Shibata      -7.4904
Hannan-Quinn -7.4807

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.1426  0.7057
Lag[2*(p+q)+(p+q)-1][17]    9.4568  0.2182
Lag[4*(p+q)+(p+q)-1][29]   17.6811  0.1733
d.o.f=6
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                      1.320  0.2506
Lag[2*(p+q)+(p+q)-1][5]     2.415  0.5242
Lag[4*(p+q)+(p+q)-1][9]     3.557  0.6646
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]  0.001126 0.500 2.000  0.9732
ARCH Lag[5]  0.742545 1.440 1.667  0.8105
ARCH Lag[7]  1.593942 2.315 1.543  0.8023

Nyblom stability test
------------------------------------
Joint Statistic:  3.5369
Individual Statistics:              
mu     0.12707
ar1    0.12117
ar2    0.06056
ar3    0.08391
ma1    0.10216
ma2    0.08490
ma3    0.06127
omega  0.53090
alpha1 0.74193
beta1  0.61902
eta11  1.22876
shape  0.73013

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.69 2.96 3.51
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           1.2800 0.2006    
Negative Sign Bias  0.8226 0.4108    
Positive Sign Bias  1.5207 0.1284    
Joint Effect        4.4054 0.2209    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     31.94      0.03176
2    30     49.05      0.01140
3    40     54.78      0.04811
4    50     58.14      0.17414


Elapsed time : 5.953805 
Código
coeficientes_egarch <- round(coef(tgarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1       ma2       ma3     omega 
-0.000214  0.593430 -0.600126  0.993485 -0.585129  0.599770 -0.987068  0.000105 
   alpha1     beta1     eta11     shape 
 0.120051  0.929336  0.085722  2.393808 

Grach Dolar Spot

Código
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
                   mean.model = list(armaOrder = c(3, 1), include.mean = TRUE),
                   distribution.model = "norm")


data <- diff(log(dolars))  
garch_fit <- ugarchfit(spec = spec, data = data)
garch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : sGARCH(1,1)
Mean Model  : ARFIMA(3,0,1)
Distribution    : norm 

Optimal Parameters
------------------------------------
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.000368    0.000285  1.28926  0.19731
ar1    -0.425010    0.396034 -1.07316  0.28320
ar2     0.011323    0.042278  0.26782  0.78884
ar3    -0.035589    0.031616 -1.12567  0.26031
ma1     0.485071    0.394720  1.22890  0.21911
omega   0.000017    0.000002  9.63793  0.00000
alpha1  0.152313    0.025004  6.09162  0.00000
beta1   0.698443    0.032036 21.80155  0.00000

Robust Standard Errors:
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.000368    0.000304   1.2082 0.226977
ar1    -0.425010    0.218299  -1.9469 0.051545
ar2     0.011323    0.035889   0.3155 0.752381
ar3    -0.035589    0.029550  -1.2044 0.228442
ma1     0.485071    0.207986   2.3322 0.019689
omega   0.000017    0.000001  12.1383 0.000000
alpha1  0.152313    0.033440   4.5547 0.000005
beta1   0.698443    0.041566  16.8032 0.000000

LogLikelihood : 3755.011 

Information Criteria
------------------------------------
                    
Akaike       -6.3455
Bayes        -6.3111
Shibata      -6.3456
Hannan-Quinn -6.3325

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.8179  0.3658
Lag[2*(p+q)+(p+q)-1][11]    1.8031  1.0000
Lag[4*(p+q)+(p+q)-1][19]    5.9476  0.9728
d.o.f=4
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                      1.706  0.1914
Lag[2*(p+q)+(p+q)-1][5]     2.895  0.4266
Lag[4*(p+q)+(p+q)-1][9]     4.349  0.5307
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]     1.104 0.500 2.000  0.2934
ARCH Lag[5]     1.491 1.440 1.667  0.5947
ARCH Lag[7]     2.608 2.315 1.543  0.5904

Nyblom stability test
------------------------------------
Joint Statistic:  6.2254
Individual Statistics:              
mu     0.12109
ar1    0.51072
ar2    0.06938
ar3    0.18503
ma1    0.46399
omega  0.86984
alpha1 0.38675
beta1  0.44032

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         1.89 2.11 2.59
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           0.5305 0.5959    
Negative Sign Bias  0.1293 0.8971    
Positive Sign Bias  0.2591 0.7956    
Joint Effect        1.1110 0.7744    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic   p-value(g-1)
1    20     77.34 0.000000005320
2    30     96.55 0.000000003457
3    40    104.05 0.000000079012
4    50    120.48 0.000000059243


Elapsed time : 0.4038219 
Código
coeficientes <- round(coef(garch_fit), 6)
print(coeficientes)
       mu       ar1       ar2       ar3       ma1     omega    alpha1     beta1 
 0.000368 -0.425010  0.011323 -0.035589  0.485071  0.000017  0.152313  0.698443 
Código
vconds1 <- garch_fit@fit$sigma^2

plot.ts(vconds1, type = "l", main = "Variância Condicional GARCH(1,1)",
        xlab = "", ylab = "Variância Condicional")

Código
plot(garch_fit, which = 3)

Código
plot.ts(vconds1)

Código
DP <- sqrt(vconds1)
vol <- DP * sqrt(252)
plot.ts(vol)

Código
mean_vol <- mean(vol) * 100
print(mean_vol)
[1] 16.4485

Egarch e Tarch

Código
spec_egarch <- ugarchspec(
  variance.model = list(model = "eGARCH", garchOrder = c(1, 1)),
  mean.model = list(armaOrder = c(3, 1), include.mean = TRUE),
  distribution.model = "std" 
)


data <- diff(log(dolars)) 
egarch_fit <- ugarchfit(spec = spec_egarch, data = data)
egarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : eGARCH(1,1)
Mean Model  : ARFIMA(3,0,1)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.000116    0.000204  0.56813 0.569943
ar1    -0.302235    0.172394 -1.75316 0.079574
ar2    -0.008102    0.022204 -0.36491 0.715180
ar3    -0.029344    0.024343 -1.20543 0.228036
ma1     0.382775    0.176719  2.16600 0.030311
omega  -0.941551    0.250336 -3.76115 0.000169
alpha1  0.075575    0.032492  2.32595 0.020021
beta1   0.897241    0.027240 32.93832 0.000000
gamma1  0.313448    0.055962  5.60108 0.000000
shape   4.347830    0.606057  7.17396 0.000000

Robust Standard Errors:
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.000116    0.000178  0.65159 0.514667
ar1    -0.302235    0.145141 -2.08235 0.037311
ar2    -0.008102    0.026533 -0.30538 0.760078
ar3    -0.029344    0.024380 -1.20363 0.228733
ma1     0.382775    0.145168  2.63678 0.008370
omega  -0.941551    0.278203 -3.38440 0.000713
alpha1  0.075575    0.032240  2.34412 0.019072
beta1   0.897241    0.030464 29.45291 0.000000
gamma1  0.313448    0.072026  4.35188 0.000013
shape   4.347830    0.687824  6.32113 0.000000

LogLikelihood : 3818.117 

Information Criteria
------------------------------------
                    
Akaike       -6.4490
Bayes        -6.4060
Shibata      -6.4491
Hannan-Quinn -6.4328

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                       2.527  0.1119
Lag[2*(p+q)+(p+q)-1][11]     5.217  0.9075
Lag[4*(p+q)+(p+q)-1][19]     8.840  0.6651
d.o.f=4
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                     0.8746  0.3497
Lag[2*(p+q)+(p+q)-1][5]    1.8220  0.6610
Lag[4*(p+q)+(p+q)-1][9]    2.7498  0.7995
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]     1.101 0.500 2.000  0.2941
ARCH Lag[5]     1.338 1.440 1.667  0.6359
ARCH Lag[7]     1.834 2.315 1.543  0.7524

Nyblom stability test
------------------------------------
Joint Statistic:  3.4928
Individual Statistics:              
mu     0.22198
ar1    0.35109
ar2    0.06736
ar3    0.08982
ma1    0.33052
omega  0.88356
alpha1 0.18020
beta1  0.81893
gamma1 0.34384
shape  0.63853

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.29 2.54 3.05
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value    prob sig
Sign Bias           1.6534 0.09852   *
Negative Sign Bias  0.6653 0.50601    
Positive Sign Bias  1.0425 0.29738    
Joint Effect        2.8195 0.42030    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     24.50      0.17753
2    30     44.28      0.03455
3    40     48.77      0.13575
4    50     59.94      0.13602


Elapsed time : 1.822367 
Código
coeficientes_egarch <- round(coef(egarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1     omega    alpha1     beta1 
 0.000116 -0.302235 -0.008102 -0.029344  0.382775 -0.941551  0.075575  0.897241 
   gamma1     shape 
 0.313448  4.347830 
Código
#-------------------------------------------------------------#

spec_tgarch <- ugarchspec(
  variance.model = list(model = "fGARCH", submodel = "TGARCH", garchOrder = c(2, 2)),
  mean.model = list(armaOrder = c(3, 1), include.mean = TRUE),
  distribution.model = "std"  
)


data <- diff(log(dolars)) 
tgarch_fit <- ugarchfit(spec = spec_tgarch, data = data)
tgarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : fGARCH(2,2)
fGARCH Sub-Model    : TGARCH
Mean Model  : ARFIMA(3,0,1)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error   t value Pr(>|t|)
mu      0.000104    0.000236  0.440701 0.659430
ar1    -0.313716    0.085744 -3.658731 0.000253
ar2    -0.007994    0.031745 -0.251807 0.801190
ar3    -0.025419    0.027805 -0.914193 0.360615
ma1     0.384027    0.085848  4.473337 0.000008
omega   0.000765    0.000355  2.157778 0.030945
alpha1  0.148473    0.040304  3.683865 0.000230
alpha2  0.000000    0.000007  0.000000 1.000000
beta1   0.703746    0.214507  3.280764 0.001035
beta2   0.118406    0.199791  0.592652 0.553414
eta11  -0.310870    0.139845 -2.222957 0.026219
eta12  -0.020391    1.299748 -0.015689 0.987483
shape   4.267956    0.575623  7.414497 0.000000

Robust Standard Errors:
        Estimate  Std. Error    t value Pr(>|t|)
mu      0.000104    0.000249   0.418512 0.675573
ar1    -0.313716    0.016640 -18.853276 0.000000
ar2    -0.007994    0.031739  -0.251854 0.801154
ar3    -0.025419    0.027276  -0.931925 0.351375
ma1     0.384027    0.016079  23.884039 0.000000
omega   0.000765    0.000613   1.248405 0.211883
alpha1  0.148473    0.062968   2.357928 0.018377
alpha2  0.000000    0.000000   0.000003 0.999998
beta1   0.703746    0.184865   3.806803 0.000141
beta2   0.118406    0.194844   0.607699 0.543387
eta11  -0.310870    0.156621  -1.984862 0.047160
eta12  -0.020391    2.254406  -0.009045 0.992783
shape   4.267956    0.672303   6.348259 0.000000

LogLikelihood : 3817.102 

Information Criteria
------------------------------------
                    
Akaike       -6.4422
Bayes        -6.3863
Shibata      -6.4424
Hannan-Quinn -6.4211

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                       3.838 0.05011
Lag[2*(p+q)+(p+q)-1][11]     6.534 0.18582
Lag[4*(p+q)+(p+q)-1][19]    10.195 0.43621
d.o.f=4
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                         statistic p-value
Lag[1]                       6.497 0.01081
Lag[2*(p+q)+(p+q)-1][11]    10.866 0.06425
Lag[4*(p+q)+(p+q)-1][19]    13.296 0.17642
d.o.f=4

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[5]  0.003223 0.500 2.000  0.9547
ARCH Lag[7]  0.858883 1.473 1.746  0.7971
ARCH Lag[9]  2.093008 2.402 1.619  0.7404

Nyblom stability test
------------------------------------
Joint Statistic:  4.6427
Individual Statistics:              
mu     0.23336
ar1    0.47149
ar2    0.07347
ar3    0.10528
ma1    0.45242
omega  0.59751
alpha1 0.53120
alpha2 0.83561
beta1  0.81714
beta2  0.82418
eta11  0.21907
eta12  0.43000
shape  0.89965

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.89 3.15 3.69
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias          1.45855 0.1450    
Negative Sign Bias 1.05376 0.2922    
Positive Sign Bias 0.09579 0.9237    
Joint Effect       2.63862 0.4508    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     25.45      0.14619
2    30     39.14      0.09894
3    40     41.32      0.36962
4    50     46.14      0.58986


Elapsed time : 2.010629 
Código
coeficientes_egarch <- round(coef(tgarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1     omega    alpha1    alpha2 
 0.000104 -0.313716 -0.007994 -0.025419  0.384027  0.000765  0.148473  0.000000 
    beta1     beta2     eta11     eta12     shape 
 0.703746  0.118406 -0.310870 -0.020391  4.267956 

Grach Dolar Futuro

Código
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(2, 1)),
                   mean.model = list(armaOrder = c(3, 2), include.mean = TRUE),
                   distribution.model = "norm")

data <- diff(log(dolarf))  
garch_fit <- ugarchfit(spec = spec, data = data)



coeficientes <- round(coef(garch_fit), 6)
print(coeficientes)
       mu       ar1       ar2       ar3       ma1       ma2     omega    alpha1 
 0.000889  0.638625  0.402435 -0.044760 -0.629054 -0.379367  0.000001  0.054721 
   alpha2     beta1 
 0.000367  0.931797 
Código
vconds1 <- garch_fit@fit$sigma^2

plot.ts(vconds1, type = "l", main = "Variância Condicional GARCH(1,1)",
        xlab = "", ylab = "Variância Condicional")

Código
plot(garch_fit, which = 3)

Código
plot.ts(vconds1)

Código
DP <- sqrt(vconds1)
vol <- DP * sqrt(252)
plot.ts(vol)

Código
mean_vol <- mean(vol) * 100
print(mean_vol)
[1] 15.83595

Egarch e Tarch

Código
spec_egarch <- ugarchspec(
  variance.model = list(model = "eGARCH", garchOrder = c(1, 1)),
  mean.model = list(armaOrder = c(3, 2), include.mean = TRUE),
  distribution.model = "std"  
)


data <- diff(log(dolarf))  
egarch_fit <- ugarchfit(spec = spec_egarch, data = data)
egarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : eGARCH(1,1)
Mean Model  : ARFIMA(3,0,2)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error    t value Pr(>|t|)
mu      0.000265    0.000263    1.00791 0.313497
ar1    -1.239422    0.063345  -19.56638 0.000000
ar2    -0.975150    0.089340  -10.91511 0.000000
ar3    -0.009241    0.073024   -0.12654 0.899301
ma1     1.233865    0.007246  170.27572 0.000000
ma2     0.981341    0.000323 3040.44779 0.000000
omega  -0.101676    0.002108  -48.23064 0.000000
alpha1  0.042940    0.013056    3.28885 0.001006
beta1   0.988976    0.000165 5987.70796 0.000000
gamma1  0.097574    0.007003   13.93321 0.000000
shape  14.371668    4.954976    2.90045 0.003726

Robust Standard Errors:
        Estimate  Std. Error     t value Pr(>|t|)
mu      0.000265    0.000264    1.005104 0.314847
ar1    -1.239422    0.148731   -8.333298 0.000000
ar2    -0.975150    0.211526   -4.610074 0.000004
ar3    -0.009241    0.172482   -0.053576 0.957273
ma1     1.233865    0.014141   87.251649 0.000000
ma2     0.981341    0.000438 2239.048841 0.000000
omega  -0.101676    0.002956  -34.400269 0.000000
alpha1  0.042940    0.016978    2.529082 0.011436
beta1   0.988976    0.000203 4862.658448 0.000000
gamma1  0.097574    0.014377    6.786786 0.000000
shape  14.371668    5.033311    2.855311 0.004299

LogLikelihood : 3803.036 

Information Criteria
------------------------------------
                    
Akaike       -6.4217
Bayes        -6.3745
Shibata      -6.4219
Hannan-Quinn -6.4039

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.0586  0.8087
Lag[2*(p+q)+(p+q)-1][14]    3.3797  1.0000
Lag[4*(p+q)+(p+q)-1][24]    7.1666  0.9901
d.o.f=5
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                    0.01836  0.8922
Lag[2*(p+q)+(p+q)-1][5]   1.60161  0.7149
Lag[4*(p+q)+(p+q)-1][9]   7.26095  0.1783
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]    0.4006 0.500 2.000 0.52677
ARCH Lag[5]    0.5565 1.440 1.667 0.86681
ARCH Lag[7]    7.4237 2.315 1.543 0.07029

Nyblom stability test
------------------------------------
Joint Statistic:  2.6946
Individual Statistics:              
mu     0.18021
ar1    0.70797
ar2    0.20502
ar3    0.21081
ma1    0.73939
ma2    0.27754
omega  0.16901
alpha1 0.27563
beta1  0.18108
gamma1 0.31670
shape  0.05701

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.49 2.75 3.27
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           0.4484 0.6539    
Negative Sign Bias  0.4264 0.6699    
Positive Sign Bias  0.4824 0.6296    
Joint Effect        2.4962 0.4760    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     23.08       0.2338
2    30     37.42       0.1359
3    40     44.50       0.2512
4    50     60.62       0.1234


Elapsed time : 1.613489 
Código
coeficientes_egarch <- round(coef(egarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1       ma2     omega    alpha1 
 0.000265 -1.239422 -0.975150 -0.009241  1.233865  0.981341 -0.101676  0.042940 
    beta1    gamma1     shape 
 0.988976  0.097574 14.371668 
Código
#-------------------------------------------------------------#

spec_tgarch <- ugarchspec(
  variance.model = list(model = "fGARCH", submodel = "TGARCH", garchOrder = c(1, 1)),
  mean.model = list(armaOrder = c(3, 2), include.mean = TRUE),
  distribution.model = "std"  
)


data <- diff(log(dolarf))  
tgarch_fit <- ugarchfit(spec = spec_tgarch, data = data)
tgarch_fit

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : fGARCH(1,1)
fGARCH Sub-Model    : TGARCH
Mean Model  : ARFIMA(3,0,2)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error    t value Pr(>|t|)
mu      0.000879    0.000001   925.6568 0.000000
ar1     0.453628    0.000150  3026.8812 0.000000
ar2     0.572829    0.000231  2484.1964 0.000000
ar3    -0.031747    0.000641   -49.4901 0.000000
ma1    -0.459131    0.000081 -5692.8370 0.000000
ma2    -0.549286    0.000096 -5719.0879 0.000000
omega   0.000151    0.000053     2.8324 0.004620
alpha1  0.043428    0.007596     5.7170 0.000000
beta1   0.949947    0.008508   111.6560 0.000000
eta11  -0.619491    0.041029   -15.0987 0.000000
shape  13.126229    3.901120     3.3647 0.000766

Robust Standard Errors:
        Estimate  Std. Error   t value Pr(>|t|)
mu      0.000879    0.000001 1693.7514 0.000000
ar1     0.453628    0.000353 1283.8091 0.000000
ar2     0.572829    0.000482 1188.6369 0.000000
ar3    -0.031747    0.001831  -17.3413 0.000000
ma1    -0.459131    0.000588 -780.3429 0.000000
ma2    -0.549286    0.000810 -678.2415 0.000000
omega   0.000151    0.000099    1.5324 0.125435
alpha1  0.043428    0.018392    2.3613 0.018213
beta1   0.949947    0.025310   37.5326 0.000000
eta11  -0.619491    0.319943   -1.9363 0.052836
shape  13.126229    4.738741    2.7700 0.005606

LogLikelihood : 3807.912 

Information Criteria
------------------------------------
                    
Akaike       -6.4300
Bayes        -6.3827
Shibata      -6.4302
Hannan-Quinn -6.4122

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                         statistic p-value
Lag[1]                      0.1131  0.7367
Lag[2*(p+q)+(p+q)-1][14]    3.5019  1.0000
Lag[4*(p+q)+(p+q)-1][24]    8.0445  0.9689
d.o.f=5
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                    0.05199  0.8196
Lag[2*(p+q)+(p+q)-1][5]   2.00088  0.6182
Lag[4*(p+q)+(p+q)-1][9]  10.07684  0.0483
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]    0.9627 0.500 2.000 0.32650
ARCH Lag[5]    1.0346 1.440 1.667 0.72269
ARCH Lag[7]   10.8693 2.315 1.543 0.01152

Nyblom stability test
------------------------------------
Joint Statistic:  2.5376
Individual Statistics:               
mu     0.008509
ar1    0.009570
ar2    0.010594
ar3    0.015189
ma1    0.008655
ma2    0.008698
omega  0.188110
alpha1 0.215821
beta1  0.156124
eta11  0.346915
shape  0.094173

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         2.49 2.75 3.27
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias          0.07185 0.9427    
Negative Sign Bias 0.76779 0.4428    
Positive Sign Bias 0.64770 0.5173    
Joint Effect       2.71065 0.4384    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     18.51      0.48872
2    30     35.08      0.20194
3    40     52.56      0.07206
4    50     59.69      0.14098


Elapsed time : 1.457531 
Código
coeficientes_egarch <- round(coef(tgarch_fit), 6)
print(coeficientes_egarch)
       mu       ar1       ar2       ar3       ma1       ma2     omega    alpha1 
 0.000879  0.453628  0.572829 -0.031747 -0.459131 -0.549286  0.000151  0.043428 
    beta1     eta11     shape 
 0.949947 -0.619491 13.126229 

ANEXO

Comparação de Modelos GARCH

Modelo 1.1 1.2 2.1 2.2
GARCH Dolar
AIC -6.3455 -6.3436 -6.3438 -6.3429
BIC -6.3111 -6.3049 -6.3052 -6.2999
SIC -6.3456 -6.3437 -6.3439 -6.3430
HQIC -6.3325 -6.3290 -6.3292 -6.3267
GARCH Boi
AIC -5.6330 -5.6328 -5.6312 -5.6310
BIC -5.5894 -5.5849 -5.5834 -5.5788
SIC -5.6331 -5.6329 -5.6314 -5.6312
HQIC -5.6165 -5.6147 -5.6132 -5.6113
GARCH Dolar fut
AIC -6.3455 -6.3436 -6.3438 -6.3429
BIC -6.3111 -6.3049 -6.3052 -6.2999
SIC -6.3456 -6.3437 -6.3439 -6.3430
HQIC -6.3325 -6.3290 -6.3292 -6.3267
GARCH Boi fut
AIC -6.9299 -6.9274 -6.9265
BIC -6.9053 -6.9029 -6.8997
SIC -6.9299 -6.9275 -6.9266
HQIC -6.9210 -6.9185 -6.9168

Comparação de Modelos EGARCH

Modelo 1.1 1.2 2.1 2.2
EGARCH Dolar
AIC -6.4490 -6.4477 -6.4464 -6.4449
BIC -6.4060 -6.4005 -6.3948 -6.3890
SIC -6.4491 -6.4479 -6.4466 -6.4451
HQIC -6.4328 -6.4299 -6.4269 -6.4238
EGARCH Boi
AIC -5.7048 -5.7080 -5.7086 -5.7069
BIC -5.6613 -5.6601 -5.6564 -5.6503
SIC -5.7050 -5.7082 -5.7088 -5.7072
HQIC -5.6884 -5.6899 -5.6889 -5.6856
EGARCH Boi fut
AIC -7.4905 -7.4887 -7.4882 -7.4887
BIC -7.4638 -7.4597 -7.4570 -7.4553
SIC -7.4906 -7.4887 -7.4882 -7.4888
HQIC -7.4809 -7.4782 -7.4769 -7.4766
EGARCH Dolar fut
AIC -6.4217 -6.4153 -6.4201 -6.4241
BIC -6.3745 -6.3637 -6.3643 -6.3640
SIC -6.4219 -6.4155 -6.4204 -6.4244
HQIC -6.4039 -6.3958 -6.3991 -6.4014

Comparação de Modelos TARCH

Modelo 1.1 1.2 2.1 2.2
TARCH Boi
AIC -5.7383 -5.7402 -5.7353 -5.7383
BIC -5.6861 -5.6836 -5.6743 -5.6730
SIC -5.7385 -5.7404 -5.7355 -5.7386
HQIC -5.7186 -5.7188 -5.7123 -5.7136
TARCH Boi Fut
AIC -7.4904 -7.4881 -7.4871 -7.4864
BIC -7.4636 -7.4591 -7.4559 -7.4529
SIC -7.4904 -7.4881 -7.4872 -7.4865
HQIC -7.4807 -7.4776 -7.4758 -7.4743
TARCH Dolar
AIC -6.4470 -6.4456 -6.4436 -6.4422
BIC -6.4040 -6.3983 -6.3920 -6.3863
SIC -6.4471 -6.4457 -6.4438 -6.4424
HQIC -6.4308 -6.4277 -6.4241 -6.4211
TARCH Dolar Fut
AIC -6.4300 -6.4245 -6.4192
BIC -6.3827 -6.3643 -6.3676
SIC -6.4302 -6.4248 -6.4194
HQIC -6.4122 -6.4018 -6.3997
Código
grafb/grafd

Janela Boi Gordo 2019 a 2024
Código
graf1/graf2

?garchFit