INFORME

library(readxl)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.1.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 4.1.3
#rm(list=ls())
DataSet<-read_excel("C:/Users/FIEECS UNI/Downloads/indice 1.xlsx")
head(DataSet)
## # A tibble: 6 x 7
##   Date                 Open  High   Low Close `Adj Close`      Volume
##   <dttm>              <dbl> <dbl> <dbl> <dbl>       <dbl>       <dbl>
## 1 2014-02-01 00:00:00 4105. 4343. 3968. 4308.       4308. 39978180000
## 2 2014-03-01 00:00:00 4261. 4372. 4132. 4199.       4199. 46796180000
## 3 2014-04-01 00:00:00 4220. 4286. 3946. 4115.       4115. 44391220000
## 4 2014-05-01 00:00:00 4121. 4252. 4021. 4243.       4243. 39290130000
## 5 2014-06-01 00:00:00 4248. 4417. 4208. 4408.       4408. 40249370000
## 6 2014-07-01 00:00:00 4425. 4486. 4351. 4370.       4370. 39536410000
DataSet2<-read_excel("C:/Users/FIEECS UNI/Downloads/indice 2.xlsx")
head(DataSet2)
## # A tibble: 6 x 7
##   Date                  Open   High    Low  Close `Adj Close`      Volume
##   <dttm>               <dbl>  <dbl>  <dbl>  <dbl>       <dbl>       <dbl>
## 1 2014-02-01 00:00:00 21562. 22987. 21198. 22837.      22837. 32344157800
## 2 2014-03-01 00:00:00 22631. 22839. 21138. 22151.      22151. 36242166400
## 3 2014-04-01 00:00:00 22292. 23225. 22097. 22134.      22134. 32007331400
## 4 2014-05-01 00:00:00 22195. 23209. 21680. 23082.      23082. 27871344900
## 5 2014-06-01 00:00:00 23328. 23398. 22802. 23191.      23191. 28091330000
## 6 2014-07-01 00:00:00 23327. 24912. 23127. 24757.      24757. 31713818500

Apreciamos la data

nasdq_Price <- data.frame(DataSet$Date, DataSet$`Adj Close`)
colnames(nasdq_Price)<- c("Date", "nasdq")

hang_Price <- data.frame(DataSet2$Date, DataSet2$`Adj Close`)
colnames(hang_Price)<- c("Date", "hang")

Crypto_prices <- merge(x = nasdq_Price, y = hang_Price,
                       by = "Date", all.x = T)
Crypto_prices
##          Date   nasdq     hang
## 1  2014-02-01 4308.12 22836.96
## 2  2014-03-01 4198.99 22151.06
## 3  2014-04-01 4114.56 22133.97
## 4  2014-05-01 4242.62 23081.65
## 5  2014-06-01 4408.18 23190.72
## 6  2014-07-01 4369.77 24756.85
## 7  2014-08-01 4580.27 24742.06
## 8  2014-09-01 4493.39 22932.98
## 9  2014-10-01 4630.74 23998.06
## 10 2014-11-01 4791.63 23987.45
## 11 2014-12-01 4736.05 23605.04
## 12 2015-01-01 4635.24 24507.05
## 13 2015-02-01 4963.53 24823.29
## 14 2015-03-01 4900.88 24900.89
## 15 2015-04-01 4941.42 28133.00
## 16 2015-05-01 5070.03 27424.19
## 17 2015-06-01 4986.87 26250.03
## 18 2015-07-01 5128.28 24636.28
## 19 2015-08-01 4776.51 21670.58
## 20 2015-09-01 4620.16 20846.30
## 21 2015-10-01 5053.75 22640.04
## 22 2015-11-01 5108.67 21996.42
## 23 2015-12-01 5007.41 21914.40
## 24 2016-01-01 4613.95 19683.11
## 25 2016-02-01 4557.95 19111.93
## 26 2016-03-01 4869.85 20776.70
## 27 2016-04-01 4775.36 21067.05
## 28 2016-05-01 4948.05 20815.09
## 29 2016-06-01 4842.67 20794.37
## 30 2016-07-01 5162.13 21891.37
## 31 2016-08-01 5213.22 22976.88
## 32 2016-09-01 5312.00 23297.15
## 33 2016-10-01 5189.14 22934.54
## 34 2016-11-01 5323.68 22789.77
## 35 2016-12-01 5383.12 22000.56
## 36 2017-01-01 5614.79 23360.78
## 37 2017-02-01 5825.44 23740.73
## 38 2017-03-01 5911.74 24111.59
## 39 2017-04-01 6047.61 24615.13
## 40 2017-05-01 6198.52 25660.65
## 41 2017-06-01 6140.42 25764.58
## 42 2017-07-01 6348.12 27323.99
## 43 2017-08-01 6428.66 27970.30
## 44 2017-09-01 6495.96 27554.30
## 45 2017-10-01 6727.67 28245.54
## 46 2017-11-01 6873.97 29177.35
## 47 2017-12-01 6903.39 29919.15
## 48 2018-01-01 7411.48 32887.27
## 49 2018-02-01 7273.01 30844.72
## 50 2018-03-01 7063.45 30093.38
## 51 2018-04-01 7066.27 30808.45
## 52 2018-05-01 7442.12 30468.56
## 53 2018-06-01 7510.30 28955.11
## 54 2018-07-01 7671.79 28583.01
## 55 2018-08-01 8109.54 27888.55
## 56 2018-09-01 8046.35 27788.52
## 57 2018-10-01 7305.90 24979.69
## 58 2018-11-01 7330.54 26506.75
## 59 2018-12-01 6635.28 25845.70
## 60 2019-01-01 7281.74 27942.47
## 61 2019-02-01 7532.53 28633.18
## 62 2019-03-01 7729.32 29051.36
## 63 2019-04-01 8095.39 29699.11
## 64 2019-05-01 7453.15 26901.09
## 65 2019-06-01 8006.24 28542.62
## 66 2019-07-01 8175.42 27777.75
## 67 2019-08-01 7962.88 25724.73
## 68 2019-09-01 7999.34 26092.27
## 69 2019-10-01 8292.36 26906.72
## 70 2019-11-01 8665.47 26346.49
## 71 2019-12-01 8972.60 28189.75

Ahora, en el siguiente paso:

nasdq_TS <- ts(Crypto_prices[,2], frequency = 12,
               start = c(2014,1), end = 2019,12)
hang_TS <- ts (Crypto_prices[,3], frequency = 12,
               start = c(2014,1), end = 2019, 12)

Aplicando el Test:

adf.test(nasdq_TS)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  nasdq_TS
## Dickey-Fuller = -1.7942, Lag order = 3, p-value = 0.6581
## alternative hypothesis: stationary
adf.test(hang_TS)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  hang_TS
## Dickey-Fuller = -1.9829, Lag order = 3, p-value = 0.5817
## alternative hypothesis: stationary

Ahora aplicando primera diferencia:

nasdq_TS_diff<-diff(nasdq_TS)

hang_TS_diff<-diff(hang_TS)

Aplicando el test para verificar que el p valor sea menor a 0.05

adf.test(nasdq_TS_diff)
## Warning in adf.test(nasdq_TS_diff): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  nasdq_TS_diff
## Dickey-Fuller = -4.9641, Lag order = 3, p-value = 0.01
## alternative hypothesis: stationary
adf.test(hang_TS_diff)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  hang_TS_diff
## Dickey-Fuller = -3.9056, Lag order = 3, p-value = 0.01983
## alternative hypothesis: stationary

Ploteamos, para tener un mejor campo visual:

##graficando las series
ts.plot(nasdq_TS_diff, hang_TS_diff, main = ("Indices"),
        col=c("red", "blue"))

Creando objeto para Var con las variables estacionarias

Var_nasdq <- ts(nasdq_TS_diff, frequency = 12, start = c(2014,1),
                end = c(2019, 12))
Var_hang <- ts(hang_TS_diff, frequency = 12, start = c(2014,1),
               end = c(2019,12))

Var_total <- cbind(Var_nasdq, Var_hang)

print(Var_total)
##            Var_nasdq    Var_hang
## Jan 2014 -109.129883  -685.90039
## Feb 2014  -84.430175   -17.08984
## Mar 2014  128.060058   947.67969
## Apr 2014  165.560059   109.07031
## May 2014  -38.410156  1566.12891
## Jun 2014  210.500000   -14.78906
## Jul 2014  -86.879883 -1809.08008
## Aug 2014  137.350097  1065.08008
## Sep 2014  160.889649   -10.61133
## Oct 2014  -55.580078  -382.41016
## Nov 2014 -100.809571   902.01172
## Dec 2014  328.289551   316.23828
## Jan 2015  -62.649902    77.60156
## Feb 2015   40.540039  3232.10938
## Mar 2015  128.609863  -708.81055
## Apr 2015  -83.159668 -1174.16016
## May 2015  141.409668 -1613.75000
## Jun 2015 -351.770019 -2965.69922
## Jul 2015 -156.349610  -824.27930
## Aug 2015  433.589844  1793.73828
## Sep 2015   54.919922  -643.61914
## Oct 2015 -101.259766   -82.01953
## Nov 2015 -393.459961 -2231.29102
## Dec 2015  -56.000000  -571.17969
## Jan 2016  311.899903  1664.76953
## Feb 2016  -94.490235   290.35156
## Mar 2016  172.689942  -251.96094
## Apr 2016 -105.379883   -20.72070
## May 2016  319.459961  1097.00000
## Jun 2016   51.090332  1085.51172
## Jul 2016   98.779785   320.26953
## Aug 2016 -122.859863  -362.61133
## Sep 2016  134.540039  -144.76953
## Oct 2016   59.439941  -789.20898
## Nov 2016  231.669922  1360.21875
## Dec 2016  210.649902   379.95117
## Jan 2017   86.300293   370.85938
## Feb 2017  135.869629   503.54102
## Mar 2017  150.910157  1045.51953
## Apr 2017  -58.100098   103.92969
## May 2017  207.700195  1559.41016
## Jun 2017   80.540039   646.31055
## Jul 2017   67.299805  -416.00000
## Aug 2017  231.709961   691.23828
## Sep 2017  146.300293   931.81055
## Oct 2017   29.419922   741.80078
## Nov 2017  508.089843  2968.11914
## Dec 2017 -138.470214 -2042.54883
## Jan 2018 -209.559571  -751.33984
## Feb 2018    2.819825   715.06836
## Mar 2018  375.850097  -339.88867
## Apr 2018   68.179688 -1513.45117
## May 2018  161.490234  -372.09961
## Jun 2018  437.750000  -694.45898
## Jul 2018  -63.189941  -100.03125
## Aug 2018 -740.450196 -2808.83008
## Sep 2018   24.640137  1527.06055
## Oct 2018 -695.260254  -661.05078
## Nov 2018  646.460449  2096.77148
## Dec 2018  250.789551   690.70899
## Jan 2019 -109.129883  -685.90039
## Feb 2019  -84.430175   -17.08984
## Mar 2019  128.060058   947.67969
## Apr 2019  165.560059   109.07031
## May 2019  -38.410156  1566.12891
## Jun 2019  210.500000   -14.78906
## Jul 2019  -86.879883 -1809.08008
## Aug 2019  137.350097  1065.08008
## Sep 2019  160.889649   -10.61133
## Oct 2019  -55.580078  -382.41016
## Nov 2019 -100.809571   902.01172
## Dec 2019  328.289551   316.23828

Finalizaremos con:

#Selecionando el VAR
VARselect(Var_total, lag.max = 4, type = c("const", "trend", "both", "none"))
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1 
## 
## $criteria
##                   1            2            3            4
## AIC(n) 2.472223e+01 2.483506e+01 2.490965e+01 2.483093e+01
## HQ(n)  2.479983e+01 2.496438e+01 2.509071e+01 2.506372e+01
## SC(n)  2.491807e+01 2.516145e+01 2.536661e+01 2.541844e+01
## FPE(n) 5.454785e+10 6.108839e+10 6.588082e+10 6.099466e+10
###Revisando

Var_final <- VAR(Var_total, p = 1, type = c("const", "trend", "both", "none"))
Var_final
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation Var_nasdq: 
## ============================================== 
## Call:
## Var_nasdq = Var_nasdq.l1 + Var_hang.l1 + const 
## 
## Var_nasdq.l1  Var_hang.l1        const 
##  -0.29481118   0.05226949  65.43267286 
## 
## 
## Estimated coefficients for equation Var_hang: 
## ============================================= 
## Call:
## Var_hang = Var_nasdq.l1 + Var_hang.l1 + const 
## 
## Var_nasdq.l1  Var_hang.l1        const 
##   -1.8775385    0.1951219  192.6724032
summary(Var_final)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Var_nasdq, Var_hang 
## Deterministic variables: const 
## Sample size: 71 
## Log Likelihood: -1070.314 
## Roots of the characteristic polynomial:
## 0.2015 0.2015
## Call:
## VAR(y = Var_total, p = 1, type = c("const", "trend", "both", 
##     "none"))
## 
## 
## Estimation results for equation Var_nasdq: 
## ========================================== 
## Var_nasdq = Var_nasdq.l1 + Var_hang.l1 + const 
## 
##              Estimate Std. Error t value Pr(>|t|)  
## Var_nasdq.l1 -0.29481    0.14440  -2.042   0.0451 *
## Var_hang.l1   0.05227    0.02770   1.887   0.0634 .
## const        65.43267   27.28004   2.399   0.0192 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 224.2 on 68 degrees of freedom
## Multiple R-Squared: 0.06749, Adjusted R-squared: 0.04006 
## F-statistic: 2.461 on 2 and 68 DF,  p-value: 0.09295 
## 
## 
## Estimation results for equation Var_hang: 
## ========================================= 
## Var_hang = Var_nasdq.l1 + Var_hang.l1 + const 
## 
##              Estimate Std. Error t value Pr(>|t|)  
## Var_nasdq.l1  -1.8775     0.7377  -2.545   0.0132 *
## Var_hang.l1    0.1951     0.1415   1.379   0.1724  
## const        192.6724   139.3563   1.383   0.1713  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1145 on 68 degrees of freedom
## Multiple R-Squared: 0.08713, Adjusted R-squared: 0.06028 
## F-statistic: 3.245 on 2 and 68 DF,  p-value: 0.04507 
## 
## 
## 
## Covariance matrix of residuals:
##           Var_nasdq Var_hang
## Var_nasdq     50256   139721
## Var_hang     139721  1311457
## 
## Correlation matrix of residuals:
##           Var_nasdq Var_hang
## Var_nasdq    1.0000   0.5442
## Var_hang     0.5442   1.0000
plot(Var_final)

##revisando coef
coef(Var_final)
## $Var_nasdq
##                 Estimate  Std. Error   t value   Pr(>|t|)
## Var_nasdq.l1 -0.29481118  0.14440240 -2.041595 0.04507398
## Var_hang.l1   0.05226949  0.02769504  1.887323 0.06338565
## const        65.43267286 27.28004099  2.398555 0.01920857
## 
## $Var_hang
##                 Estimate  Std. Error   t value   Pr(>|t|)
## Var_nasdq.l1  -1.8775385   0.7376597 -2.545264 0.01319272
## Var_hang.l1    0.1951219   0.1414763  1.379185 0.17235726
## const        192.6724032 139.3563200  1.382588 0.17131514