Microsoft <- read.delim("~/catedraeconometria/Microsoft.txt")
View(Microsoft)
library(tseries)
## Warning: package 'tseries' was built under R version 3.2.4
attach(`Microsoft`)
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
plot(LN.Returns, type = "l")

LN.Returns2 <-c(LN.Returns[2:194])
adf.test(LN.Returns2, alternative="stationary", k=0)#Dickey-Fuller Test
## Warning in adf.test(LN.Returns2, alternative = "stationary", k = 0): p-
## value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: LN.Returns2
## Dickey-Fuller = -15.241, Lag order = 0, p-value = 0.01
## alternative hypothesis: stationary
acf(LN.Returns2, lag.max = 25)#Autocorrelation Function Of The Sample

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

Box.test (LN.Returns2, lag = 25, type = "Ljung")# Prueba de significancia conjunta de las correlaciones de los Lags
##
## Box-Ljung test
##
## data: LN.Returns2
## X-squared = 32.282, df = 25, p-value = 0.15
AR1<-arima(LN.Returns, order = c(1,0,0))#AR lag1 process
MA1<-arima(LN.Returns2, order = c(0,0,1))#MA lag1 process
AR4<-arima(LN.Returns2, order = c(4,0,0))#AR lag 4 process
MA4<-arima(LN.Returns2, order = c(0,0,4))#MA lag 4 process
ARMA44<-arima(LN.Returns2, order = c(4,0,4))
## Warning in arima(LN.Returns2, order = c(4, 0, 4)): possible convergence
## problem: optim gave code = 1
AR25<-arima(LN.Returns2, order = c(25,0,0))#AR lag 25 process
MA25<-arima(LN.Returns2, order = c(0,0,25))#MA lag 25 process
AR7<-arima(LN.Returns2, order = c(7,0,0))#AR lag 7 process
MA7<-arima(LN.Returns2, order = c(0,0,7))#MA lag 7 process
AIC(AR1,AR4,AR25,AR7)
## Warning in AIC.default(AR1, AR4, AR25, AR7): models are not all fitted to
## the same number of observations
## df AIC
## AR1 3 -332.4039
## AR4 6 -335.1167
## AR25 27 -313.0093
## AR7 9 -336.9463
AIC(MA1,MA4,MA25,MA7)
## df AIC
## MA1 3 -329.9903
## MA4 6 -337.8972
## MA25 27 -318.1608
## MA7 9 -332.5664
BIC(AR1,AR4,AR25,AR7)
## Warning in BIC.default(AR1, AR4, AR25, AR7): models are not all fitted to
## the same number of observations
## df BIC
## AR1 3 -322.6003
## AR4 6 -315.5406
## AR25 27 -224.9167
## AR7 9 -307.5821
BIC(MA1,MA4,MA25,MA7)
## df BIC
## MA1 3 -320.2023
## MA4 6 -318.3211
## MA25 27 -230.0682
## MA7 9 -303.2022
ARMA74<- arima(LN.Returns2, order = c(7,0,4))
ARMA74p<-arima(LN.Returns2, order = c(7,0,4),fixed = c(0,NA,NA,0,NA,0,NA,0,0,NA,NA,NA)) #ARMA74 "más" parsimonioso
## Warning in arima(LN.Returns2, order = c(7, 0, 4), fixed = c(0, NA, NA, 0, :
## some AR parameters were fixed: setting transform.pars = FALSE
ARMA11<- arima(LN.Returns2, order = c(1,0,1))
AIC(AR7, MA4, ARMA74, ARMA74p)
## df AIC
## AR7 9 -336.9463
## MA4 6 -337.8972
## ARMA74 13 -331.5904
## ARMA74p 8 -337.3917
BIC(AR1, MA1, ARMA11)
## Warning in BIC.default(AR1, MA1, ARMA11): models are not all fitted to the
## same number of observations
## df BIC
## AR1 3 -322.6003
## MA1 3 -320.2023
## ARMA11 4 -316.3856
plot(LN.Returns2)
lines(fitted(ARMA74), col = "Red")
lines(fitted(AR7), col = "Blue")
lines(fitted(MA4), col = "Green")

accuracy(ARMA74)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0004901802 0.09537557 0.06836868 -Inf Inf 0.6730853
## ACF1
## Training set -0.001095189
accuracy(AR7)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0001914016 0.09634012 0.06802371 -Inf Inf 0.6696891
## ACF1
## Training set 0.002107097
accuracy(MA4)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0004211694 0.09766238 0.0674431 -Inf Inf 0.663973
## ACF1
## Training set -0.005770095
accuracy(AR1)
## ME RMSE MAE MPE MAPE MASE
## Training set -3.731485e-05 0.1011518 0.06825879 -Inf Inf 0.6716338
## ACF1
## Training set -0.007324689
accuracy(MA1)
## ME RMSE MAE MPE MAPE MASE
## Training set -3.940142e-05 0.1013267 0.0684601 -Inf Inf 0.6739853
## ACF1
## Training set 0.006313545
accuracy(ARMA11)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0003441003 0.1009413 0.06856091 -Inf Inf 0.6749778
## ACF1
## Training set 0.002123849
forecast(ARMA74)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 194 -0.003170062 -0.1254114 0.1190713 -0.1901221 0.1837820
## 195 -0.014231683 -0.1365103 0.1080469 -0.2012407 0.1727773
## 196 0.016245303 -0.1066428 0.1391334 -0.1716958 0.2041864
## 197 0.009281373 -0.1140448 0.1326076 -0.1793298 0.1978925
## 198 -0.024290469 -0.1515550 0.1029740 -0.2189247 0.1703438
## 199 0.013964522 -0.1137934 0.1417224 -0.1814243 0.2093533
## 200 -0.005134711 -0.1329002 0.1226308 -0.2005352 0.1902658
## 201 -0.015220717 -0.1430619 0.1126204 -0.2107369 0.1802955
## 202 0.003061562 -0.1247870 0.1309102 -0.1924660 0.1985891
## 203 0.002542567 -0.1255684 0.1306535 -0.1933863 0.1984714
forecast(AR7)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 194 -0.008486092 -0.1319509 0.1149787 -0.1973093 0.1803371
## 195 -0.016704067 -0.1402365 0.1068284 -0.2056307 0.1722225
## 196 0.015722720 -0.1088659 0.1403114 -0.1748192 0.2062646
## 197 0.017625659 -0.1077227 0.1429741 -0.1740782 0.2093295
## 198 -0.006837984 -0.1352298 0.1215538 -0.2031963 0.1895203
## 199 0.008417784 -0.1201077 0.1369433 -0.1881450 0.2049806
## 200 -0.017498089 -0.1462545 0.1112583 -0.2144140 0.1794178
## 201 -0.007395716 -0.1367467 0.1219553 -0.2052210 0.1904296
## 202 -0.002403383 -0.1321450 0.1273383 -0.2008261 0.1960193
## 203 -0.006780120 -0.1369205 0.1233602 -0.2058126 0.1922523
forecast(MA4)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 194 -0.003860540 -0.1290199 0.1212988 -0.1952753 0.1875542
## 195 -0.010704901 -0.1359750 0.1145652 -0.2022891 0.1808793
## 196 -0.003863425 -0.1301521 0.1224253 -0.1970053 0.1892785
## 197 0.005615960 -0.1217123 0.1329442 -0.1891158 0.2003477
## 198 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
## 199 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
## 200 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
## 201 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
## 202 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
## 203 -0.003047799 -0.1335630 0.1274674 -0.2026535 0.1965579
forecast(AR1)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 196 -0.006290134 -0.1359214 0.1233411 -0.2045441 0.1919638
## 197 -0.002913669 -0.1330260 0.1271987 -0.2019033 0.1960760
## 198 -0.003204825 -0.1333207 0.1269111 -0.2021999 0.1957903
## 199 -0.003179718 -0.1332957 0.1269362 -0.2021749 0.1958154
## 200 -0.003181883 -0.1332978 0.1269341 -0.2021770 0.1958133
## 201 -0.003181696 -0.1332976 0.1269342 -0.2021769 0.1958135
## 202 -0.003181712 -0.1332976 0.1269342 -0.2021769 0.1958134
## 203 -0.003181711 -0.1332976 0.1269342 -0.2021769 0.1958134
## 204 -0.003181711 -0.1332976 0.1269342 -0.2021769 0.1958134
## 205 -0.003181711 -0.1332976 0.1269342 -0.2021769 0.1958134
forecast(MA1)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 194 0.004257923 -0.1255974 0.1341133 -0.1943387 0.2028546
## 195 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 196 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 197 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 198 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 199 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 200 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 201 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 202 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
## 203 -0.003312639 -0.1338061 0.1271809 -0.2028852 0.1962600
forecast(ARMA11)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 194 -0.002896265 -0.1322577 0.1264652 -0.2007376 0.1949451
## 195 -0.002974839 -0.1329684 0.1270187 -0.2017828 0.1958332
## 196 -0.003024639 -0.1332713 0.1272220 -0.2022196 0.1961704
## 197 -0.003056202 -0.1334043 0.1272919 -0.2024065 0.1962941
## 198 -0.003076207 -0.1334651 0.1273127 -0.2024888 0.1963364
## 199 -0.003088886 -0.1334941 0.1273164 -0.2025265 0.1963487
## 200 -0.003096922 -0.1335087 0.1273149 -0.2025446 0.1963507
## 201 -0.003102015 -0.1335165 0.1273124 -0.2025537 0.1963497
## 202 -0.003105243 -0.1335208 0.1273103 -0.2025586 0.1963481
## 203 -0.003107289 -0.1335232 0.1273087 -0.2025613 0.1963467
plot.forecast(forecast(ARMA74))
