RetornosPfizer <- read.csv("~/catedraeconometria/RetornosPfizer.csv")
View(RetornosPfizer)
library(tseries)
## Warning: package 'tseries' was built under R version 3.2.4
attach(`RetornosPfizer`)
library(tseries)
library(stats)
library(lmtest)
## Warning: package 'lmtest' was built under R version 3.2.3
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(aod)
## Warning: package 'aod' was built under R version 3.2.3
library(forecast)
## Warning: package 'forecast' was built under R version 3.2.3
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.2.3
## This is forecast 6.2
library(stargazer)
## Warning: package 'stargazer' was built under R version 3.2.3
## 
## Please cite as:
##  Hlavac, Marek (2015). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2. http://CRAN.R-project.org/package=stargazer
Close1 <-c(Close[1:80])
LN.Returns2<-c(LN.Returns[2:80])
Close2 <- c(Close[81:125])
plot(Close1, type = "l")

adf.test(Close1, alternative="stationary", k=0)#Dickey-Fuller Test
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Close1
## Dickey-Fuller = -3.9858, Lag order = 0, p-value = 0.01461
## alternative hypothesis: stationary
Close1d<- diff((Close1))
plot(Close1d, type = "l")

plot(LN.Returns2, col="blue", type ="l")

adf.test(diff(Close1d), alternative="stationary", k=0)#Dickey-Fuller Test
## Warning in adf.test(diff(Close1d), alternative = "stationary", k = 0): p-
## value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff(Close1d)
## Dickey-Fuller = -13.871, Lag order = 0, p-value = 0.01
## alternative hypothesis: stationary
acf(Close1d, lag.max = 25)#Autocorrelation Function Of The Sample

pacf(Close1d, lag.max = 25)#Partial Autocorrelation Function of The Sample

Box.test (Close1d, lag = 25, type = "Ljung")
## 
##  Box-Ljung test
## 
## data:  Close1d
## X-squared = 24.303, df = 25, p-value = 0.5019
AR23<-arima(window(Close, end=80), order = c(23,1,0))#AR lag2 process
OutofSampleEstimate <-Arima(window(Close,start=81),model=AR23)
Ingenuo <-naive(window(Close, end = 80))
IngenuoOutofsample <- naive((window(Close, start = 81, model=Ingenuo)))
plot.ts(window(Close, start=81, type="l"))
lines(fitted(OutofSampleEstimate), col="red")
lines(fitted(IngenuoOutofsample), col ="Blue")
abline(h=mean(window(Close, start = 81)), col= "yellow")

accuracy(forecast(AR23, h=80))
##                     ME      RMSE       MAE         MPE      MAPE      MASE
## Training set -0.017897 0.4067109 0.3256707 -0.06520694 0.9912509 0.9113701
##                     ACF1
## Training set 0.008720134
accuracy(forecast(OutofSampleEstimate, h=45))
##                       ME      RMSE       MAE         MPE      MAPE
## Training set -0.01445373 0.3590053 0.2946913 -0.05579035 0.9911435
##                   MASE       ACF1
## Training set 0.9355279 -0.0550554
accuracy(IngenuoOutofsample)
##                       ME      RMSE   MAE         MPE     MAPE MASE
## Training set -0.02000002 0.3758565 0.315 -0.07447867 1.058898    1
##                     ACF1
## Training set -0.09470516
accuracy(meanf(Close2))
##                        ME     RMSE       MAE         MPE     MAPE MASE
## Training set 1.579143e-16 0.453787 0.3703999 -0.02337511 1.246936    1