Análise Garch
library(lubridate)
library(PerformanceAnalytics)
data_inicio <- ymd("2007-08-28")
data_fim <- ymd("2024-07-15")
futuroT<- read.table("FUTURO-DIARIO.txt", head= T)
futuro<- data.frame(futuroT$FUTURO.GBP)
futuroTS<- ts(futuro,frequency = 365, start =data_inicio )
library(zoo)
n<- nrow(futuroTS)
datas <- seq(from = as.Date(data_inicio), by = "day", length.out = n)
futuroD <- zoo(futuroTS, order.by = datas)
Arima111<-arima(futuroD,order=c(1,1,12),method=c("CSS"))
Arima111
Call:
arima(x = futuroD, order = c(1, 1, 12), method = c("CSS"))
Coefficients:
ar1 ma1 ma2 ma3 ma4 ma5 ma6 ma7
0.2454 -0.1951 -0.0236 0.0753 0.0734 -0.0298 -0.0146 0.0722
s.e. 0.1026 0.1024 0.0158 0.0172 0.0184 0.0186 0.0178 0.0189
ma8 ma9 ma10 ma11 ma12
-0.0191 0.1327 -0.1110 0.0621 0.0700
s.e. 0.0217 0.0180 0.0223 0.0207 0.0212
sigma^2 estimated as 3952: log likelihood = -24108.05, aic = NA
Residuos<-residuals(Arima111)
par(mfrow=c(1,1))
chart.TimeSeries(Residuos)chart.ACF(Residuos)O
library(urca)
options(scipen = 9999)
dfuller2<-ur.df(Residuos, lags = 18, type = "trend", selectlags = "BIC")
summary(dfuller2)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression trend
Call:
lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-1227.67 -17.65 -1.05 16.78 879.76
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.8880565 1.8837413 -1.002 0.316260
z.lag.1 -1.3278719 0.0722600 -18.376 < 0.0000000000000002 ***
tt 0.0015840 0.0007536 2.102 0.035632 *
z.diff.lag1 0.3258593 0.0700932 4.649 0.000003436483987 ***
z.diff.lag2 0.3480228 0.0674821 5.157 0.000000261873118 ***
z.diff.lag3 0.3275138 0.0645001 5.078 0.000000398156924 ***
z.diff.lag4 0.3004596 0.0620128 4.845 0.000001309923105 ***
z.diff.lag5 0.3048154 0.0598735 5.091 0.000000371432869 ***
z.diff.lag6 0.3104979 0.0576245 5.388 0.000000074936886 ***
z.diff.lag7 0.2843201 0.0552202 5.149 0.000000273820347 ***
z.diff.lag8 0.2575810 0.0526611 4.891 0.000001038387476 ***
z.diff.lag9 0.2666548 0.0500475 5.328 0.000000104361988 ***
z.diff.lag10 0.2689231 0.0474550 5.667 0.000000015491581 ***
z.diff.lag11 0.2544464 0.0445496 5.712 0.000000011952232 ***
z.diff.lag12 0.2128699 0.0418111 5.091 0.000000370963742 ***
z.diff.lag13 0.2327394 0.0387809 6.001 0.000000002117530 ***
z.diff.lag14 0.2379510 0.0352156 6.757 0.000000000015976 ***
z.diff.lag15 0.1166081 0.0317324 3.675 0.000241 ***
z.diff.lag16 -0.0095793 0.0273558 -0.350 0.726224
z.diff.lag17 0.0273204 0.0224991 1.214 0.224704
z.diff.lag18 0.1228876 0.0165750 7.414 0.000000000000147 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 61.43 on 4297 degrees of freedom
Multiple R-squared: 0.5164, Adjusted R-squared: 0.5142
F-statistic: 229.4 on 20 and 4297 DF, p-value: < 0.00000000000000022
Value of test-statistic is: -18.3763 112.6055 168.8941
Critical values for test statistics:
1pct 5pct 10pct
tau3 -3.96 -3.41 -3.12
phi2 6.09 4.68 4.03
phi3 8.27 6.25 5.34
O valor da estatística de teste ( -18.3763) é menor do que todos os valores críticos, rejeitamos a hipótese nula de que existe uma raiz unitária.
[1] 0.0005056733
[1] 0.0174966
par(mfrow=c(1,1))
chart.Histogram(diff(log(futuroD))) Index futuroT.FUTURO.GBP
Min. :2007-08-29 Min. :-0.2465425
1st Qu.:2010-08-16 1st Qu.:-0.0082116
Median :2013-08-04 Median : 0.0000000
Mean :2013-08-04 Mean : 0.0005057
3rd Qu.:2016-07-23 3rd Qu.: 0.0091062
Max. :2019-07-12 Max. : 0.1097484
library(fBasics)
StatfuturoD<-basicStats(diff(log(futuroD)));StatfuturoD futuroT.FUTURO.GBP
nobs 4336.000000
NAs 0.000000
Minimum -0.246542
Maximum 0.109748
1. Quartile -0.008212
3. Quartile 0.009106
Mean 0.000506
Median 0.000000
Sum 2.192599
SE Mean 0.000266
LCL Mean -0.000015
UCL Mean 0.001027
Variance 0.000306
Stdev 0.017497
Skewness -0.674363
Kurtosis 13.771957
futuroT.FUTURO.GBP
-0.6745965
kurtosis(data.frame(diff(log(futuroD))))futuroT.FUTURO.GBP
16.7797
jarqueberaTest((diff(log(futuroD))))
Title:
Jarque - Bera Normalality Test
Test Results:
STATISTIC:
X-squared: 34633.8607
P VALUE:
Asymptotic p Value: < 0.00000000000000022
### ESTIMAÇÃO GARCH / RETORNO E VARIÂNCIA
library(fGarch)
Garch11<-garchFit(~ arma(1,1,12) + garch(1,1),
data=diff(log(futuroD)),
include.mean = F,
trace=F)
summary(Garch11)
Title:
GARCH Modelling
Call:
garchFit(formula = ~arma(1, 1, 12) + garch(1, 1), data = diff(log(futuroD)),
include.mean = F, trace = F)
Mean and Variance Equation:
data ~ arma(1, 1, 12) + garch(1, 1)
<environment: 0x000001cd17011db8>
[data = diff(log(futuroD))]
Conditional Distribution:
norm
Coefficient(s):
ar1 omega alpha1 beta1
0.0489122664 0.0000030083 0.0514882921 0.9396038000
Std. Errors:
based on Hessian
Error Analysis:
Estimate Std. Error t value Pr(>|t|)
ar1 0.0489122664 0.0161277347 3.033 0.00242 **
omega 0.0000030083 0.0000009402 3.200 0.00138 **
alpha1 0.0514882921 0.0068730407 7.491 0.0000000000000682 ***
beta1 0.9396038000 0.0090302564 104.051 < 0.0000000000000002 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Log Likelihood:
11849.35 normalized: 2.732785
Description:
Mon Aug 12 22:16:07 2024 by user: marcu
Standardised Residuals Tests:
Statistic p-Value
Jarque-Bera Test R Chi^2 1285.9186288 0.0000000
Shapiro-Wilk Test R W 0.9756782 0.0000000
Ljung-Box Test R Q(10) 9.0405794 0.5282568
Ljung-Box Test R Q(15) 11.9338463 0.6840293
Ljung-Box Test R Q(20) 14.2843075 0.8157932
Ljung-Box Test R^2 Q(10) 13.8706556 0.1789736
Ljung-Box Test R^2 Q(15) 19.0894381 0.2097096
Ljung-Box Test R^2 Q(20) 22.5682168 0.3104897
LM Arch Test R TR^2 14.4759707 0.2713512
Information Criterion Statistics:
AIC BIC SIC HQIC
-5.463724 -5.457844 -5.463726 -5.461648