## [1] "BTC-USD"
\(-\infty,<z,<\infty\)
BTCSP <- read.csv("C:/Users/Personal/Desktop/BTCSP.csv", sep=";")
precio<-BTCSP
library(zoo)
precio.zoo=zoo(precio[,-1], order.by=as.Date(strptime(as.character(precio[,1]), "%d.%m.%Y")))
library(rmgarch)
library(PerformanceAnalytics)
model<- window(precio.zoo [,"BTC.Close"], start="2014-01-01")
model<- na.approx(na.trim(CalculateReturns(model), side="both"))
spec = ugarchspec()
print(spec)
##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : sGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(1,0,1)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.002540 0.001101 2.3077 0.021014
## ar1 0.814833 0.382341 2.1312 0.033075
## ma1 -0.791863 0.402468 -1.9675 0.049124
## omega 0.000125 0.000026 4.7669 0.000002
## alpha1 0.122571 0.020129 6.0893 0.000000
## beta1 0.825323 0.024812 33.2629 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.002540 0.001164 2.1824 0.029081
## ar1 0.814833 0.541378 1.5051 0.132296
## ma1 -0.791863 0.565336 -1.4007 0.161305
## omega 0.000125 0.000074 1.6862 0.091765
## alpha1 0.122571 0.033899 3.6158 0.000299
## beta1 0.825323 0.052460 15.7325 0.000000
##
## LogLikelihood : 2788.191
##
## Information Criteria
## ------------------------------------
##
## Akaike -3.4712
## Bayes -3.4511
## Shibata -3.4713
## Hannan-Quinn -3.4638
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1034 0.7478
## Lag[2*(p+q)+(p+q)-1][5] 1.3352 0.9995
## Lag[4*(p+q)+(p+q)-1][9] 4.7756 0.5055
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3453 0.5568
## Lag[2*(p+q)+(p+q)-1][5] 1.0215 0.8548
## Lag[4*(p+q)+(p+q)-1][9] 1.3170 0.9692
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.2712 0.500 2.000 0.6025
## ARCH Lag[5] 0.3865 1.440 1.667 0.9165
## ARCH Lag[7] 0.4865 2.315 1.543 0.9796
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.3331
## Individual Statistics:
## mu 0.32344
## ar1 0.03306
## ma1 0.03301
## omega 0.10592
## alpha1 0.07153
## beta1 0.10984
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.49 1.68 2.12
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 1.0648 0.2871
## Negative Sign Bias 1.1088 0.2677
## Positive Sign Bias 0.7929 0.4279
## Joint Effect 1.9171 0.5898
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 286.9 9.624e-50
## 2 30 299.4 1.056e-46
## 3 40 316.5 3.768e-45
## 4 50 329.7 3.034e-43
##
##
## Elapsed time : 5.006171
garch112e2.2.2.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)),
variance.model = list(garchOrder = c(2,1),
model = "eGARCH"), distribution.model = "std")
garch.fit112e2.2.2= ugarchfit(garch112e2.2.2.spec, data = model, fit.control=list(scale=TRUE))
print(garch.fit112e2.2.2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : eGARCH(2,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001261 0.000528 2.3895 0.016871
## omega -0.098617 0.052158 -1.8908 0.058657
## alpha1 -0.091854 0.062178 -1.4773 0.139602
## alpha2 0.112060 0.062577 1.7908 0.073330
## beta1 0.983072 0.008942 109.9359 0.000000
## gamma1 0.451433 0.099049 4.5577 0.000005
## gamma2 -0.137387 0.080693 -1.7026 0.088644
## shape 2.550534 0.186797 13.6540 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001261 0.000509 2.4788 0.013183
## omega -0.098617 0.070233 -1.4041 0.160275
## alpha1 -0.091854 0.065685 -1.3984 0.161993
## alpha2 0.112060 0.064881 1.7272 0.084139
## beta1 0.983072 0.012533 78.4368 0.000000
## gamma1 0.451433 0.107693 4.1918 0.000028
## gamma2 -0.137387 0.085209 -1.6124 0.106885
## shape 2.550534 0.197290 12.9278 0.000000
##
## LogLikelihood : 3036.887
##
## Information Criteria
## ------------------------------------
##
## Akaike -3.7790
## Bayes -3.7522
## Shibata -3.7791
## Hannan-Quinn -3.7691
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 3.322 0.06836
## Lag[2*(p+q)+(p+q)-1][2] 4.493 0.05561
## Lag[4*(p+q)+(p+q)-1][5] 7.590 0.03721
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1405 0.7078
## Lag[2*(p+q)+(p+q)-1][8] 0.7473 0.9883
## Lag[4*(p+q)+(p+q)-1][14] 1.9573 0.9920
## d.o.f=3
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[4] 0.01235 0.500 2.000 0.9115
## ARCH Lag[6] 0.38116 1.461 1.711 0.9244
## ARCH Lag[8] 0.58042 2.368 1.583 0.9750
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.4443
## Individual Statistics:
## mu 0.51929
## omega 0.17655
## alpha1 0.40823
## alpha2 0.42594
## beta1 0.14497
## gamma1 0.09465
## gamma2 0.09181
## shape 0.13315
##
## 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 1.0846 0.2783
## Negative Sign Bias 0.4547 0.6494
## Positive Sign Bias 1.4585 0.1449
## Joint Effect 3.0063 0.3907
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 38.41 0.005261
## 2 30 38.43 0.113098
## 3 40 53.32 0.062957
## 4 50 50.24 0.423920
##
##
## Elapsed time : 7.888568
garch.fit = ugarchfit(garch112e2.2.2.spec, data = model, fit.control=list(scale=TRUE))
plot(garch.fit, which=3)
##
## please wait...calculating quantiles...
garchroll <- ugarchroll(garch112e2.2.2.spec, data = model, n.start =500,
refit.window = "moving"
, refit.every = 100)
garchVaR <- quantile(garchroll, probs=0.01)
actual <- xts(as.data.frame(garchroll)$Realized, time(garchVaR))
mean(actual < garchVaR)
## [1] 0.008159565
## VaR Backtest Report
## ===========================================
## Model: eGARCH-std
## Backtest Length: 1103
## Data:
##
## ==========================================
## alpha: 1%
## Expected Exceed: 11
## Actual VaR Exceed: 9
## Actual %: 0.8%
##
## Unconditional Coverage (Kupiec)
## Null-Hypothesis: Correct Exceedances
## LR.uc Statistic: 0.403
## LR.uc Critical: 6.635
## LR.uc p-value: 0.526
## Reject Null: NO
##
## Conditional Coverage (Christoffersen)
## Null-Hypothesis: Correct Exceedances and
## Independence of Failures
## LR.cc Statistic: 0.551
## LR.cc Critical: 9.21
## LR.cc p-value: 0.759
## Reject Null: NO
##
## please wait...calculating quantiles...
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: eGARCH
## Horizon: 3
## Roll Steps: 0
## Out of Sample: 0
##
## 0-roll forecast [T0=2020-01-30]:
## Series Sigma
## T+1 0.001261 0.04461
## T+2 0.001261 0.04622
## T+3 0.001261 0.04635
modelfit=ugarchfit(garch112e2.2.2.spec,data=model, solver="hybrid", out.sample=20)
modelforecast<-ugarchforecast(modelfit, data = NULL, n.ahead = 30, n.roll = 20, external.forecasts = list(mregfor = NULL, vregfor = NULL))
modelforecast
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: eGARCH
## Horizon: 30
## Roll Steps: 20
## Out of Sample: 20
##
## 0-roll forecast [T0=2020-01-06]:
## Series Sigma
## T+1 0.001214 0.04605
## T+2 0.001214 0.04710
## T+3 0.001214 0.04722
## T+4 0.001214 0.04734
## T+5 0.001214 0.04746
## T+6 0.001214 0.04758
## T+7 0.001214 0.04770
## T+8 0.001214 0.04781
## T+9 0.001214 0.04793
## T+10 0.001214 0.04804
## T+11 0.001214 0.04815
## T+12 0.001214 0.04826
## T+13 0.001214 0.04836
## T+14 0.001214 0.04847
## T+15 0.001214 0.04857
## T+16 0.001214 0.04867
## T+17 0.001214 0.04877
## T+18 0.001214 0.04887
## T+19 0.001214 0.04897
## T+20 0.001214 0.04907
## T+21 0.001214 0.04916
## T+22 0.001214 0.04926
## T+23 0.001214 0.04935
## T+24 0.001214 0.04944
## T+25 0.001214 0.04953
## T+26 0.001214 0.04962
## T+27 0.001214 0.04970
## T+28 0.001214 0.04979
## T+29 0.001214 0.04987
## T+30 0.001214 0.04995
##
## GARCH Roll Mean Forecast Performance Measures
## ---------------------------------------------
## Model : eGARCH
## No.Refits : 12
## No.Forecasts: 1103
##
## Stats
## MSE 0.00209
## MAE 0.03024
## DAC 0.52400
##
## GARCH Roll Mean Forecast Performance Measures
## ---------------------------------------------
## Model : sGARCH
## No.Refits : 12
## No.Forecasts: 1103
##
## Stats
## MSE 0.002107
## MAE 0.030420
## DAC 0.520400
bootp=ugarchboot(garch.fit,method=c("Partial","Full")[1],n.ahead = 12,n.bootpred=1000,n.bootfit=1000)
bootp
##
## *-----------------------------------*
## * GARCH Bootstrap Forecast *
## *-----------------------------------*
## Model : eGARCH
## n.ahead : 12
## Bootstrap method: partial
## Date (T[0]): 2020-01-30
##
## Series (summary):
## min q.25 mean q.75 max forecast[analytic]
## t+1 -0.34122 -0.012918 0.003356 0.017043 0.31886 0.001261
## t+2 -0.20763 -0.012533 0.006871 0.022018 0.34953 0.001261
## t+3 -0.20595 -0.013358 0.001464 0.016831 0.17488 0.001261
## t+4 -0.19842 -0.014634 0.002776 0.018565 0.31764 0.001261
## t+5 -0.20414 -0.016399 0.000498 0.016992 0.21584 0.001261
## t+6 -0.49729 -0.014409 0.000358 0.017074 0.27964 0.001261
## t+7 -0.29973 -0.012481 0.005515 0.020261 0.52718 0.001261
## t+8 -0.18334 -0.016198 0.002855 0.017824 0.30386 0.001261
## t+9 -0.36912 -0.016468 0.001129 0.016847 0.51179 0.001261
## t+10 -0.38256 -0.014856 0.001165 0.015573 0.33576 0.001261
## .....................
##
## Sigma (summary):
## min q0.25 mean q0.75 max forecast[analytic]
## t+1 0.044608 0.044608 0.044608 0.044608 0.044608 0.044608
## t+2 0.040791 0.042135 0.047028 0.047516 0.328326 0.046223
## t+3 0.037867 0.041156 0.047299 0.049411 0.159514 0.046350
## t+4 0.035179 0.040211 0.047443 0.050768 0.170167 0.046474
## t+5 0.032965 0.040053 0.047745 0.051209 0.156046 0.046597
## t+6 0.031812 0.039500 0.048474 0.053011 0.151017 0.046718
## t+7 0.029778 0.039090 0.049993 0.053324 0.473618 0.046838
## t+8 0.028666 0.038618 0.049374 0.053551 0.237884 0.046955
## t+9 0.027220 0.038243 0.050007 0.055505 0.197381 0.047071
## t+10 0.027007 0.038073 0.051173 0.056056 0.345446 0.047186
## .....................