R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library(forecast)
## Warning: package 'forecast' was built under R version 3.4.2
library(xts)
## Warning: package 'xts' was built under R version 3.4.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.4.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(tseries)
## Warning: package 'tseries' was built under R version 3.4.3
library(fpp)
## Loading required package: fma
## Loading required package: expsmooth
## Loading required package: lmtest
library(readr)
mydata=read_csv("~/Desktop/monthly-returns-for-att-jan-1961.csv")
## Parsed with column specification:
## cols(
##   Month = col_character(),
##   `Monthly returns for AT&T, Jan 1961 through Dec. 1967` = col_character()
## )
str(mydata)
## Classes 'tbl_df', 'tbl' and 'data.frame':    86 obs. of  2 variables:
##  $ Month                                               : chr  "1961-01" "1961-02" "1961-03" "1961-04" ...
##  $ Monthly returns for AT&T, Jan 1961 through Dec. 1967: chr  "0.074" "0.002" "0.074" "0.017" ...
##  - attr(*, "spec")=List of 2
##   ..$ cols   :List of 2
##   .. ..$ Month                                               : list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   .. ..$ Monthly returns for AT&T, Jan 1961 through Dec. 1967: list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   ..$ default: list()
##   .. ..- attr(*, "class")= chr  "collector_guess" "collector"
##   ..- attr(*, "class")= chr "col_spec"
names(mydata)[2]="Returns"
mydata$Returns=as.numeric(mydata$Returns)
## Warning: NAs introduced by coercion
#Jan 1961 through Dec 1967 (84 periods)
train=mydata[1:72,]
test=mydata[73:84,] #12 months
myts=ts(train$Returns,frequency=12,start=c(1961,1))
test.ts=ts(test$Returns,frequency=12,start=c(1967,4))
plot(myts)

#SES
fit1=ses(myts,alpha=0.5,initial="simple",h=12)
plot(fit1)

plot(residuals(fit1))

hist(residuals(fit1))

forecast1=forecast(fit1,h=12)
accuracy(forecast1,test.ts)
##                         ME       RMSE        MAE       MPE     MAPE
## Training set -0.0010186227 0.02730243 0.02091446      -Inf      Inf
## Test set     -0.0003295839 0.02387229 0.01988764 -54.45663 82.14482
##                   MASE       ACF1 Theil's U
## Training set 0.8559807 -0.3025793        NA
## Test set     0.8139552 -0.3151326 0.5807948
#Holt
fit2=holt(myts,alpha=0.8,beta=0.2,h=12)
plot(fit2)

plot(residuals(fit2))

hist(residuals(fit2))

forecast2=forecast(fit2,h=12)
accuracy(forecast2,test.ts)
##                       ME       RMSE        MAE      MPE     MAPE      MASE
## Training set 0.000389098 0.03385028 0.02577456     -Inf      Inf 1.0548933
## Test set     0.021110541 0.03239854 0.02436931 33.32809 59.79205 0.9973796
##                    ACF1 Theil's U
## Training set -0.4612228        NA
## Test set     -0.2004980 0.9451072

Based on the forecasted data and errors for these two models, I would say that the first model performs better due to a much lower ME and RMSE on the test set. Also, the residual histogram looks much more normal from the first model than from the second. An explanation for this could be due to the higher alpha value used in the second model compared to the first (0.8 vs 0.5).