For this assignment, I picked data from the company, “ROKU” Source: https://finance.yahoo.com/quote/ROKU/history?period1=1562603344&period2=1594225744&interval=1mo&filter=history&frequency=1mo

#Reading our dataset

#Create our time series

roku_ts = ts(roku$Adj.Close, frequency = 12, start = c(2017,9))
roku_ts
##         Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct
## 2017                                                          26.54  20.38
## 2018  40.62  40.77  31.10  32.54  37.46  42.62  45.42  59.49  73.03  55.60
## 2019  44.95  66.29  64.51  63.59  90.40  90.58 103.33 151.36 101.76 147.20
## 2020 120.95 113.67  87.48 121.23 109.51 116.53 130.42                     
##         Nov    Dec
## 2017  43.90  51.78
## 2018  40.75  30.64
## 2019 160.37 133.90
## 2020
#Using the column "Adj.Close" to create our time series.

#Additive Decomposition: trend-cycle and seasonality

roku_ts_AD = decompose(roku_ts, type = "additive")
plot(roku_ts_AD)

#Multiplicative Decomopsition: trend-cycle and seasonality

roku_ts_MD = decompose(roku_ts, type = "multiplicative")
plot(roku_ts_MD)

According to Hyndman, “decomposition methods seek to break up a time series to isolate overall trends, seasonality, and some remainder component.”

Based on our results, from a visual standpoint, additive and multiplicative decompositions produce very similar results. Therefore, we will need further information to determine, which decomposition method is the best.

#Determining the best decomposition method

eval_stats <- function(fit, ts.obj){
  error<-as.vector(
    na.omit(
      fit$random
      )  #generate residuals without NA
    )
  datavector<-ts.obj[1]  #la
  abserror<-abs(error)
  sqerror<-error^2
  pererror<-(abserror/datavector)*100
  me <- round(mean(error),2)
  mae <- round(mean(abserror),2)
  mse <- round(mean(sqerror),2)
  rmse <- round(sqrt(mse),2)
  mape <- round(mean(pererror),2)
  return(data.frame(
    values = c(me, mae, mse, rmse, mape),
    metrics = c('Mean Error','Mean Absolute Error','Mean Squared Error',
                'Root Mean Squared Error','Mean Absolute Percent Error')
    )
  )
}
inner_join(
  eval_stats(roku_ts_AD, roku)%>%dplyr::select(Additive = values, metrics),  #la
  eval_stats(roku_ts_MD, roku)%>%dplyr::select(Multiplicative = values, metrics) #la
  )%>%
  dplyr::select(Metric = metrics, Additive, Multiplicative)%>%
  knitr::kable()
## Warning in Ops.factor(left, right): '/' not meaningful for factors
## Warning in mean.default(pererror): argument is not numeric or logical: returning
## NA
## Warning in Ops.factor(left, right): '/' not meaningful for factors
## Warning in mean.default(pererror): argument is not numeric or logical: returning
## NA
## Joining, by = "metrics"
Metric Additive Multiplicative
Mean Error 1.20 0.99
Mean Absolute Error 9.78 0.99
Mean Squared Error 170.08 1.00
Root Mean Squared Error 13.04 1.00
Mean Absolute Percent Error NA NA

As our results show, the multiplicative decomposition method is the best one.

It does make sense because the additive decomposition method is essentially used for additive models meaning that the seasonal variations of the models are constant as the time series value increase.Obviously, when we are talking about stocks, rarely do they stay constant overtime, which explains such a difference in our results.

For forecasting, if we are unsure about which composition method to use, it would be wise to pay close attention to the multiplicative one because in terms of dataset, it seems that there are more inconsistant data than consistant data.