library(quantmod)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following object is masked from 'package:tsibble':
##
## index
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
## Loading required package: TTR
aa <- getSymbols("AAL", auto.assign=FALSE, from="2014-01-01", to="2019-12-31")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
dis <- getSymbols("DIS", auto.assign=FALSE, from="2014-01-01", to="2019-12-31")
#aa<-as.data.frame(aa)
#dis<-as.data.frame(dis)
#month_average_aa<- aa %>% group_by(month=floor_date(as.Date(F_FECHAAVALUO), "month")) #%>%summarize(valor=mean(AREA_PRIVADA_VALM2FINAL))
library(quantmod)
AA_DIS<-data.frame(aa$AAL.Adjusted,dis$DIS.Adjusted)
AA_DIS_TS <-ts(AA_DIS)
AA_DIS_TS %>% autoplot()
### MODEL
library(vars)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following objects are masked from 'package:fma':
##
## cement, housing, petrol
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: strucchange
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
##
## Attaching package: 'vars'
## The following object is masked from 'package:fable':
##
## VAR
VAR <- VAR(AA_DIS_TS)
summary(VAR)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: AAL.Adjusted, DIS.Adjusted
## Deterministic variables: const
## Sample size: 1508
## Log Likelihood: -4396.511
## Roots of the characteristic polynomial:
## 0.9994 0.9872
## Call:
## VAR(y = AA_DIS_TS)
##
##
## Estimation results for equation AAL.Adjusted:
## =============================================
## AAL.Adjusted = AAL.Adjusted.l1 + DIS.Adjusted.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## AAL.Adjusted.l1 0.989023 0.003339 296.227 < 2e-16 ***
## DIS.Adjusted.l1 -0.003730 0.001359 -2.744 0.006147 **
## const 0.811017 0.213164 3.805 0.000148 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.8745 on 1505 degrees of freedom
## Multiple R-Squared: 0.9842, Adjusted R-squared: 0.9842
## F-statistic: 4.689e+04 on 2 and 1505 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation DIS.Adjusted:
## =============================================
## DIS.Adjusted = AAL.Adjusted.l1 + DIS.Adjusted.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## AAL.Adjusted.l1 -0.005087 0.004926 -1.033 0.302
## DIS.Adjusted.l1 0.997572 0.002005 497.428 <2e-16 ***
## const 0.494232 0.314480 1.572 0.116
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.29 on 1505 degrees of freedom
## Multiple R-Squared: 0.9943, Adjusted R-squared: 0.9943
## F-statistic: 1.317e+05 on 2 and 1505 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## AAL.Adjusted DIS.Adjusted
## AAL.Adjusted 0.7648 0.3173
## DIS.Adjusted 0.3173 1.6646
##
## Correlation matrix of residuals:
## AAL.Adjusted DIS.Adjusted
## AAL.Adjusted 1.0000 0.2812
## DIS.Adjusted 0.2812 1.0000
VAR_fc <- VAR %>% forecast(h=120)
VAR_fc %>% autoplot(tsla)