#Libraries Required
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.5.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.3
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.5.2
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.5.2
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.5.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.1
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.5.1
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(readr)
## Warning: package 'readr' was built under R version 3.5.1
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 3.5.3
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
#Data Preparation
raw.data<- read.csv("C:\\Users\\nidhi\\Downloads\\all_SPstocks_5yr.csv")
str(raw.data)
## 'data.frame': 619040 obs. of 7 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 15.1 14.9 14.4 14.3 14.9 ...
## $ high : num 15.1 15 14.5 14.9 15 ...
## $ low : num 14.6 14.3 14.1 14.2 13.2 ...
## $ close : num 14.8 14.5 14.3 14.7 14 ...
## $ volume: int 8407500 8882000 8126000 10259500 31879900 15628000 11354400 14725200 11922100 6071400 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 2 2 2 2 2 2 2 2 2 2 ...
summary(raw.data)
## date open high low
## 2017-12-05: 505 Min. : 1.62 Min. : 1.69 Min. : 1.50
## 2017-12-06: 505 1st Qu.: 40.22 1st Qu.: 40.62 1st Qu.: 39.83
## 2017-12-07: 505 Median : 62.59 Median : 63.15 Median : 62.02
## 2017-12-08: 505 Mean : 83.02 Mean : 83.78 Mean : 82.26
## 2017-12-11: 505 3rd Qu.: 94.37 3rd Qu.: 95.18 3rd Qu.: 93.54
## 2017-12-12: 505 Max. :2044.00 Max. :2067.99 Max. :2035.11
## (Other) :616010 NA's :11 NA's :8 NA's :8
## close volume Name
## Min. : 1.59 Min. : 0 A : 1259
## 1st Qu.: 40.24 1st Qu.: 1070320 AAL : 1259
## Median : 62.62 Median : 2082094 AAP : 1259
## Mean : 83.04 Mean : 4321823 AAPL : 1259
## 3rd Qu.: 94.41 3rd Qu.: 4284509 ABBV : 1259
## Max. :2049.00 Max. :618237630 ABC : 1259
## (Other):611486
head(raw.data)
## date open high low close volume Name
## 1 2013-02-08 15.07 15.12 14.63 14.75 8407500 AAL
## 2 2013-02-11 14.89 15.01 14.26 14.46 8882000 AAL
## 3 2013-02-12 14.45 14.51 14.10 14.27 8126000 AAL
## 4 2013-02-13 14.30 14.94 14.25 14.66 10259500 AAL
## 5 2013-02-14 14.94 14.96 13.16 13.99 31879900 AAL
## 6 2013-02-15 13.93 14.61 13.93 14.50 15628000 AAL
raw.data<- raw.data %>% mutate(year=year(raw.data$date))
## Warning: package 'bindrcpp' was built under R version 3.5.1
#Checking NA's
subset(raw.data,is.na(raw.data$open))
## date open high low close volume Name year
## 82950 2017-07-26 NA NA NA 69.0842 3 BHF 2017
## 165735 2015-07-17 NA 88.76 88.24 88.7200 2056819 DHR 2015
## 165858 2016-01-12 NA NA NA 88.5500 0 DHR 2016
## 205077 2015-07-17 NA 48.49 47.85 47.9200 1246786 ES 2015
## 239833 2016-07-01 NA NA NA 49.5400 0 FTV 2016
## 434380 2015-07-17 NA 47.31 46.83 46.9900 1229513 O 2015
## 434503 2016-01-12 NA NA NA 52.4300 0 O 2016
## 478595 2015-06-09 NA NA NA 526.0900 12135 REGN 2015
## 558214 2016-04-07 NA NA NA 41.5600 0 UA 2016
## 581907 2015-05-12 NA NA NA 124.0800 569747 VRTX 2015
## 598237 2015-06-26 NA NA NA 61.9000 100 WRK 2015
subset(raw.data,is.na(raw.data$low))
## date open high low close volume Name year
## 82950 2017-07-26 NA NA NA 69.0842 3 BHF 2017
## 165858 2016-01-12 NA NA NA 88.5500 0 DHR 2016
## 239833 2016-07-01 NA NA NA 49.5400 0 FTV 2016
## 434503 2016-01-12 NA NA NA 52.4300 0 O 2016
## 478595 2015-06-09 NA NA NA 526.0900 12135 REGN 2015
## 558214 2016-04-07 NA NA NA 41.5600 0 UA 2016
## 581907 2015-05-12 NA NA NA 124.0800 569747 VRTX 2015
## 598237 2015-06-26 NA NA NA 61.9000 100 WRK 2015
subset(raw.data,is.na(raw.data$high))
## date open high low close volume Name year
## 82950 2017-07-26 NA NA NA 69.0842 3 BHF 2017
## 165858 2016-01-12 NA NA NA 88.5500 0 DHR 2016
## 239833 2016-07-01 NA NA NA 49.5400 0 FTV 2016
## 434503 2016-01-12 NA NA NA 52.4300 0 O 2016
## 478595 2015-06-09 NA NA NA 526.0900 12135 REGN 2015
## 558214 2016-04-07 NA NA NA 41.5600 0 UA 2016
## 581907 2015-05-12 NA NA NA 124.0800 569747 VRTX 2015
## 598237 2015-06-26 NA NA NA 61.9000 100 WRK 2015
sum(is.na(raw.data))
## [1] 27
#Top 10 Holdings
Top10Holding<- raw.data %>%
group_by(Name) %>%
summarise(close=mean(close),volume=mean(volume)) %>%
mutate(asset= close*volume) %>%
arrange(desc(asset)) %>%
top_n(10)
## Selecting by asset
str(Top10Holding)
## Classes 'tbl_df', 'tbl' and 'data.frame': 10 obs. of 4 variables:
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 4 181 39 323 208 61 335 207 264 201
## $ close : num 109.1 96.5 576.9 51.1 682.2 ...
## $ volume: num 54047900 34359265 3730465 33869463 2457501 ...
## $ asset : num 5.89e+09 3.31e+09 2.15e+09 1.73e+09 1.68e+09 ...
options(scipen=10000)
# Plot Asset by Top 10 Company
ggplot(Top10Holding, aes(x=reorder(Name,-asset), y=paste(format(round(asset / 1e9, 1), trim = TRUE), "B"))) +
geom_bar(stat="identity", width=.5, fill="tomato3") +
labs(title="Top 10 Stocks by Asset",
subtitle="Top Holding vs Asset",
caption="Company:Asset",
y="Total Asset",
x="Company") +
theme(axis.text.x = element_text(angle=65, vjust=0.6))

#Which company is holding more Asset
#Top10Holding %>%
# arrange(desc(asset)) %>%
# mutate(percentage = percent(asset / sum(asset))) -> Top10Holding
ggplot(Top10Holding, aes('', asset, fill = Name)) +
geom_col(position = 'fill') +
geom_label(aes(label = paste(format(round( (asset/sum(asset))*100, 2), nsmall = 2),"%")), position = position_fill(vjust = 0.6)) +
coord_polar(theta = 'y')+
labs(x = NULL, y = NULL, fill = "Company", title = "Assets Distribution in Top 10 Companies")

#Asset by Year
#head(raw.data)
#year(raw.data$date)
#quarter(raw.data$date, with_year = TRUE)
Assetby.year<- raw.data %>%
select(year,Name,close,volume) %>%
filter(Name %in% c("AAPL","FB","AMZN","MSFT","GOOGL","BAC","NFLX","GOOG","JPM","GE")) %>%
group_by(year,Name) %>%
summarise(close=mean(close),volume=mean(volume)) %>%
mutate(asset= close*volume) %>%
arrange(desc(asset))
ggplot() + geom_bar(aes(x=reorder(Name,-asset), y=asset ,fill=year), data = Assetby.year,
stat="identity")+
labs(title="Top 10 Stocks Performance Over year",
subtitle="Assets vs Year",
caption="Company:Asset",
y="Total Asset",
x="Company")

#Subsetting the Required Dataset
Req.data<- raw.data %>%
filter(Name %in% c("AAPL","FB","AMZN","MSFT","GOOGL","BAC","NFLX","GOOG","JPM","GE"))
dim(Req.data)
## [1] 12306 8
str(Req.data)
## 'data.frame': 12306 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 67.7 68.1 68.5 66.7 66.4 ...
## $ high : num 68.4 69.3 68.9 67.7 67.4 ...
## $ low : num 66.9 67.6 66.8 66.2 66.3 ...
## $ close : num 67.9 68.6 66.8 66.7 66.7 ...
## $ volume: int 158168416 129029425 151829363 118721995 88809154 97924631 108854046 118891367 111596821 82583823 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 4 4 4 4 4 4 4 4 4 4 ...
## $ year : num 2013 2013 2013 2013 2013 ...
#Apple Data Analysis
#Subsetting the Apple dataset
Apple.df<- subset(raw.data,Name=="AAPL" ,stringsAsFactors =FALSE )
str(Apple.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 67.7 68.1 68.5 66.7 66.4 ...
## $ high : num 68.4 69.3 68.9 67.7 67.4 ...
## $ low : num 66.9 67.6 66.8 66.2 66.3 ...
## $ close : num 67.9 68.6 66.8 66.7 66.7 ...
## $ volume: int 158168416 129029425 151829363 118721995 88809154 97924631 108854046 118891367 111596821 82583823 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 4 4 4 4 4 4 4 4 4 4 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(Apple.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
Apple.close<-Apple.df[,5]
#Creating the time series
Apple.close.full.ts <- ts(Apple.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
Apple.close.ts <- ts(Apple.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
Apple.test.close.ts <- ts(Apple.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(Apple.close.full.ts)+
ggtitle("Apple stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(Apple.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(Apple.close.ts)

length(Apple.close.ts)
## [1] 1005
# Calculating autocorrelation for various lags in series
gglagplot(Apple.close.full.ts)

acf.apple.close.ts <- acf(Apple.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.apple.close.ts, type="o",main="Correlogram for Apple stock closing price")

#Decomposition of time series components
stl.apple.close.ts <- stl(Apple.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.apple.close.ts) +
ggtitle("Apple stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(Apple.close.full.ts, series="Data") +
autolayer(trendcycle(stl.apple.close.ts), series="Trend") +
autolayer(seasadj(stl.apple.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("New orders index") +
ggtitle("STL Decomposition of Apple stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.apple.train <- stlf(Apple.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.apple.train <- stlf(Apple.close.full.ts, h = length(Apple.test.close.ts) , lambda = BoxCox.lambda(Apple.close.full.ts))
snaive.apple.train <- snaive(Apple.close.full.ts, h = length(Apple.test.close.ts))
ets.stlf.apple.train <- stlf(Apple.close.full.ts, t.window = 13, s.window = "periodic", h = length(Apple.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(Apple.close.full.ts))
fct.ets.apple.train <- forecast(ets.apple.train, h = 252)
fct.stlf.apple.train <- forecast(stlf.apple.train, h = 252)
fct.snaive.apple.train <- forecast(snaive.apple.train, h = 252)
fct.ets.stlf.apple.train <- forecast(ets.stlf.apple.train, h = 252)
accuracy(fct.ets.apple.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.08672064 1.627873 1.150422 0.07590505 1.106518 0.03829627
## ACF1
## Training set -0.003141442
accuracy(fct.stlf.apple.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.07670016 1.374168 0.9951217 0.0609277 0.939138 0.03312651
## ACF1
## Training set -0.001294875
accuracy(fct.snaive.apple.train)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 21.79366 34.41926 30.04004 16.188 24.49376 1 0.9962405
accuracy(fct.ets.stlf.apple.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.07548631 1.541295 1.0592 0.06013289 0.9938344 0.03525961
## ACF1
## Training set -0.007582153
autoplot(Apple.close.full.ts) +
autolayer(ets.apple.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.apple.train,series="STLF method", PI=FALSE) +
autolayer(snaive.apple.train,series="snaive method", PI=FALSE) +
autolayer(ets.stlf.apple.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("Apple Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.apple.train %>% forecast(h=252) %>%
autoplot() +
autolayer(Apple.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

ets.apple.train[["model"]]
## ETS(A,Ad,N)
##
## Call:
## ets(y = x, model = etsmodel, damped = TRUE, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9632
## beta = 0.0001
## phi = 0.8082
##
## Initial states:
## l = 72.5221
## b = -3.5179
##
## sigma: 1.6311
##
## AIC AICc BIC
## 10198.46 10198.52 10229.27
summary(fct.stlf.apple.train)
##
## Forecast method: STL + ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 13.9546
##
## sigma: 0.1201
##
## AIC AICc BIC
## 3642.978 3642.997 3658.385
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.07670016 1.374168 0.9951217 0.0609277 0.939138 0.03312651
## ACF1
## Training set -0.001294875
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 164.1064 161.9604 166.2670 160.8302 167.4167
## 2018.012 164.7572 161.7205 167.8232 160.1247 169.4581
## 2018.016 165.2433 161.5225 169.0080 159.5705 171.0187
## 2018.020 165.7805 161.4807 170.1388 159.2282 172.4696
## 2018.024 165.5985 160.7978 170.4723 158.2861 173.0819
## 2018.028 166.8308 161.5554 172.1939 158.7983 175.0685
## 2018.032 167.0719 161.3734 172.8728 158.3982 175.9851
## 2018.036 166.1230 160.0528 172.3101 156.8868 175.6327
## 2018.040 166.0886 159.6547 172.6540 156.3020 176.1829
## 2018.044 166.9805 160.1834 173.9239 156.6443 177.6588
## 2018.048 166.2592 159.1502 173.5291 155.4519 177.4427
## 2018.052 165.5048 158.1010 173.0840 154.2525 177.1673
## 2018.056 166.1540 158.4358 174.0622 154.4268 178.3256
## 2018.060 165.2013 157.2195 173.3876 153.0769 177.8042
## 2018.064 164.9497 156.6981 173.4205 152.4185 177.9936
## 2018.068 166.5946 158.0317 175.3914 153.5933 180.1430
## 2018.072 166.9021 158.0708 175.9819 153.4963 180.8893
## 2018.076 166.4087 157.3392 175.7413 152.6444 180.7884
## 2018.080 167.0228 157.6905 176.6330 152.8625 181.8329
## 2018.084 166.8656 157.2992 176.7243 152.3533 182.0618
## 2018.088 165.7982 156.0322 175.8711 150.9865 181.3279
## 2018.092 165.0448 155.0766 175.3345 149.9296 180.9120
## 2018.096 165.3300 155.1322 175.8640 149.8696 181.5766
## 2018.100 165.5873 155.1653 176.3600 149.7900 182.2050
## 2018.104 166.4132 155.7522 177.4397 150.2563 183.4250
## 2018.108 167.5057 156.5998 178.7918 150.9802 184.9205
## 2018.112 168.4158 157.2742 179.9524 151.5356 186.2196
## 2018.116 167.9951 156.6676 179.7321 150.8365 186.1113
## 2018.120 167.8548 156.3355 179.7981 150.4088 186.2925
## 2018.124 168.7532 157.0077 180.9374 150.9673 187.5653
## 2018.127 168.5058 156.5791 180.8859 150.4486 187.6235
## 2018.131 167.2769 155.2096 179.8120 149.0105 186.6376
## 2018.135 166.7143 154.4853 179.4258 148.2065 186.3505
## 2018.139 165.6517 153.2842 178.5161 146.9380 185.5278
## 2018.143 167.1087 154.5063 180.2228 148.0417 187.3726
## 2018.147 168.0410 155.2259 181.3824 148.6547 188.6585
## 2018.151 167.6981 154.7240 181.2133 148.0744 188.5873
## 2018.155 167.7797 154.6317 181.4834 147.8960 188.9631
## 2018.159 168.2535 154.9174 182.1598 148.0881 189.7528
## 2018.163 167.1556 153.6999 181.1961 146.8131 188.8660
## 2018.167 167.8424 154.1937 182.0906 147.2107 189.8764
## 2018.171 167.3628 153.5732 181.7664 146.5214 189.6405
## 2018.175 166.8992 152.9705 181.4566 145.8510 189.4179
## 2018.179 166.2409 152.1843 180.9408 145.0028 188.9834
## 2018.183 166.6725 152.4411 181.5616 145.1731 189.7105
## 2018.187 165.7451 151.4025 180.7600 144.0815 188.9813
## 2018.191 165.1956 150.7271 180.3510 143.3452 188.6526
## 2018.195 164.1369 149.5686 179.4066 142.1397 187.7746
## 2018.199 164.8270 150.0786 180.2914 142.5604 188.7684
## 2018.203 164.5446 149.6637 180.1562 142.0812 188.7170
## 2018.207 164.4871 149.4645 180.2548 141.8129 188.9043
## 2018.211 166.5758 151.3087 182.6030 143.5337 191.3959
## 2018.215 166.9866 151.5570 183.1911 143.7019 192.0838
## 2018.219 168.9561 153.2883 185.4137 145.3131 194.4464
## 2018.223 168.7395 152.9417 185.3417 144.9036 194.4569
## 2018.227 165.8675 150.0746 182.4788 142.0448 191.6046
## 2018.231 164.3320 148.4807 181.0162 140.4258 190.1863
## 2018.235 165.0137 148.9926 181.8825 140.8536 191.1564
## 2018.239 166.2320 150.0139 183.3126 141.7766 192.7046
## 2018.243 165.7928 149.4644 182.9982 141.1746 192.4622
## 2018.247 165.2089 148.7794 182.5299 140.4420 192.0610
## 2018.251 164.3643 147.8493 181.7852 139.4724 191.3751
## 2018.255 165.0490 148.3682 182.6504 139.9095 192.3418
## 2018.259 165.9578 149.0998 183.7513 140.5532 193.5504
## 2018.263 165.8172 148.8393 183.7451 140.2352 193.6214
## 2018.267 164.7815 147.7340 182.7935 139.0987 192.7201
## 2018.271 164.9131 147.7333 183.0720 139.0339 193.0824
## 2018.275 165.6075 148.2650 183.9440 139.4855 194.0542
## 2018.279 167.3887 149.8233 185.9630 140.9317 196.2053
## 2018.283 166.9763 149.3109 185.6652 140.3723 195.9740
## 2018.287 166.0925 148.3550 184.8678 139.3841 195.2282
## 2018.291 166.8106 148.9113 185.7624 139.8607 196.2224
## 2018.295 167.7831 149.7079 186.9258 140.5701 197.4928
## 2018.299 167.8565 149.6573 187.1378 140.4598 197.7841
## 2018.303 168.8004 150.4277 188.2701 141.1442 199.0222
## 2018.307 169.6970 151.1536 189.3521 141.7859 200.2083
## 2018.311 169.4323 150.7865 189.2044 141.3704 200.1285
## 2018.315 169.1871 150.4388 189.0764 140.9742 200.0685
## 2018.319 169.1021 150.2427 189.1171 140.7252 200.1816
## 2018.323 168.5399 149.5987 188.6511 140.0438 199.7725
## 2018.327 167.9932 148.9705 188.2003 139.3783 199.3783
## 2018.331 168.3633 149.2048 188.7210 139.5467 199.9847
## 2018.335 168.1858 148.9253 188.6601 139.2191 199.9914
## 2018.339 168.3270 148.9459 188.9366 139.1816 200.3456
## 2018.343 168.4808 148.9788 189.2258 139.1564 200.7125
## 2018.347 168.1587 148.5660 189.0091 138.7015 200.5574
## 2018.351 165.5868 146.0453 186.3999 136.2135 197.9342
## 2018.355 164.4536 144.8756 185.3176 135.0302 196.8846
## 2018.359 164.7948 145.0877 185.8025 135.1800 197.4516
## 2018.363 163.9009 144.1444 184.9723 134.2163 196.6610
## 2018.367 163.5506 143.7110 184.7197 133.7447 196.4661
## 2018.371 161.6479 141.8273 182.8120 131.8768 194.5614
## 2018.375 162.2747 142.3091 183.5985 132.2878 195.4385
## 2018.378 161.8150 141.7764 183.2264 131.7222 195.1186
## 2018.382 161.9238 141.7754 183.4597 131.6689 195.4238
## 2018.386 161.7572 141.5178 183.3987 131.3690 195.4245
## 2018.390 161.2115 140.9072 182.9321 130.7299 195.0059
## 2018.394 160.7621 140.3875 182.5675 130.1788 194.6920
## 2018.398 161.3233 140.8105 183.2817 130.5346 195.4932
## 2018.402 162.3144 141.6343 184.4550 131.2759 196.7689
## 2018.406 162.0443 141.2832 184.2804 130.8878 196.6509
## 2018.410 162.4133 141.5280 184.7884 131.0727 197.2385
## 2018.414 161.9673 141.0143 184.4245 130.5290 196.9239
## 2018.418 161.3635 140.3547 183.8910 129.8456 196.4334
## 2018.422 160.5959 139.5437 183.1811 129.0174 195.7599
## 2018.426 161.8766 140.6380 184.6632 130.0191 197.3547
## 2018.430 163.0058 141.5915 185.9832 130.8856 198.7818
## 2018.434 162.9390 141.4332 186.0224 130.6847 198.8831
## 2018.438 162.8828 141.2853 186.0725 130.4942 198.9954
## 2018.442 163.8438 142.0827 187.2120 131.2110 200.2355
## 2018.446 164.3967 142.5012 187.9142 131.5642 201.0227
## 2018.450 165.2264 143.1768 188.9128 132.1643 202.1168
## 2018.454 164.8679 142.7495 188.6377 131.7064 201.8918
## 2018.458 165.0488 142.8233 188.9403 131.7294 202.2648
## 2018.462 164.5023 142.2228 188.4623 131.1061 201.8289
## 2018.466 164.2401 141.8867 188.2885 130.7367 201.7078
## 2018.470 164.3184 141.8667 188.4796 130.6707 201.9646
## 2018.474 164.3507 141.8045 188.6210 130.5643 202.1697
## 2018.478 166.0417 143.2794 190.5434 131.9309 204.2208
## 2018.482 164.9982 142.2212 189.5289 130.8706 203.2274
## 2018.486 164.6726 141.8287 189.2846 130.4486 203.0321
## 2018.490 164.2804 141.3752 188.9681 129.9685 202.7616
## 2018.494 164.7868 141.7536 189.6173 130.2850 203.4924
## 2018.498 164.8600 141.7315 189.8005 130.2184 203.7397
## 2018.502 164.0863 140.9269 189.0720 129.4032 203.0411
## 2018.506 164.5540 141.2703 189.6789 129.6867 203.7276
## 2018.510 167.0820 143.5179 192.5029 131.7921 206.7146
## 2018.514 166.5350 142.9235 192.0177 131.1784 206.2680
## 2018.518 167.4981 143.7247 193.1575 131.9000 207.5076
## 2018.522 166.0706 142.3183 191.7232 130.5103 206.0753
## 2018.526 167.0056 143.0938 192.8326 131.2075 207.2832
## 2018.530 168.5874 144.4665 194.6388 132.4756 209.2143
## 2018.534 168.8002 144.5754 194.9703 132.5354 209.6146
## 2018.538 168.1630 143.9002 194.3853 131.8459 209.0632
## 2018.542 166.7118 142.4753 192.9219 130.4405 207.5990
## 2018.546 164.8889 140.7096 191.0556 128.7107 205.7154
## 2018.550 163.8828 139.6980 190.0691 127.7019 204.7451
## 2018.554 163.9845 139.7072 190.2780 127.6680 205.0167
## 2018.558 165.6632 141.1681 192.1900 129.0198 207.0583
## 2018.562 166.1657 141.5462 192.8315 129.3380 207.7796
## 2018.566 166.0204 141.3284 192.7733 129.0877 207.7734
## 2018.570 166.3447 141.5429 193.2221 129.2501 208.2941
## 2018.574 164.2697 139.5518 191.0771 127.3088 206.1176
## 2018.578 165.1947 140.3192 192.1747 127.9987 207.3127
## 2018.582 165.2095 140.2502 192.2878 127.8913 207.4839
## 2018.586 165.2188 140.1765 192.3949 127.7795 207.6486
## 2018.590 164.9910 139.8853 192.2449 127.4607 207.5457
## 2018.594 164.3065 139.1755 191.6001 126.7432 206.9277
## 2018.598 164.1766 138.9752 191.5551 126.5115 206.9337
## 2018.602 163.0241 137.8376 190.4018 125.3874 205.7857
## 2018.606 163.9740 138.6282 191.5261 126.0997 207.0083
## 2018.610 164.6536 139.1710 192.3573 126.5761 207.9260
## 2018.614 165.8464 140.1842 193.7448 127.5003 209.4227
## 2018.618 166.1166 140.3518 194.1324 127.6195 209.8785
## 2018.622 165.6999 139.8902 193.7751 127.1399 209.5585
## 2018.625 166.2137 140.2812 194.4264 127.4720 210.2887
## 2018.629 165.9763 139.9846 194.2629 127.1498 210.1702
## 2018.633 165.0141 139.0249 193.3124 126.1971 209.2316
## 2018.637 163.9470 137.9702 192.2469 125.1547 208.1727
## 2018.641 163.4929 137.4772 191.8462 124.6467 207.8061
## 2018.645 162.1742 136.1945 190.5052 123.3888 206.4592
## 2018.649 162.3699 136.2963 190.8095 123.4468 206.8269
## 2018.653 162.7334 136.5516 191.2961 123.6507 207.3846
## 2018.657 161.7129 135.5435 190.2772 122.6548 206.3724
## 2018.661 162.1559 135.8717 190.8499 122.9282 207.0197
## 2018.665 162.0920 135.7375 190.8708 122.7627 207.0915
## 2018.669 161.9611 135.5425 190.8186 122.5396 207.0868
## 2018.673 162.1850 135.6714 191.1523 122.6240 207.4847
## 2018.677 162.5580 135.9362 191.6482 122.8376 208.0517
## 2018.681 163.1883 136.4357 192.4243 123.2738 208.9110
## 2018.685 163.4777 136.6245 192.8290 123.4153 209.3828
## 2018.689 163.3214 136.4074 192.7481 123.1718 209.3478
## 2018.693 163.0003 136.0405 192.4873 122.7864 209.1247
## 2018.697 162.8876 135.8636 192.4532 122.5815 209.1381
## 2018.701 163.4528 136.3042 193.1579 122.9622 209.9229
## 2018.705 165.0787 137.7105 195.0190 124.2584 211.9147
## 2018.709 166.2257 138.6807 196.3580 125.1411 213.3615
## 2018.713 166.1449 138.5331 196.3585 124.9640 213.4111
## 2018.717 166.2655 138.5691 196.5786 124.9611 213.6897
## 2018.721 166.9149 139.0863 197.3750 125.4144 214.5701
## 2018.725 166.1947 138.3576 196.6775 124.6869 213.8904
## 2018.729 166.2355 138.3216 196.8097 124.6160 214.0771
## 2018.733 166.8772 138.8321 197.5977 125.0631 214.9485
## 2018.737 166.8618 138.7452 197.6684 124.9443 215.0707
## 2018.741 167.7333 139.4646 198.7071 125.5892 216.2041
## 2018.745 169.3859 140.8940 200.5984 126.9067 218.2280
## 2018.749 169.3527 140.7909 200.6496 126.7726 218.3299
## 2018.753 168.5586 139.9969 199.8697 125.9842 217.5633
## 2018.757 167.6498 139.0994 198.9637 125.0984 216.6646
## 2018.761 168.6155 139.9043 200.1053 125.8243 217.9055
## 2018.765 169.1125 140.2837 200.7349 126.1474 218.6113
## 2018.769 168.5715 139.7210 200.2299 125.5789 218.1312
## 2018.773 168.9429 139.9866 200.7220 125.7945 218.6932
## 2018.777 168.4002 139.4230 200.2144 125.2257 218.2101
## 2018.781 167.5299 138.5631 199.3479 124.3769 217.3513
## 2018.785 166.7265 137.7646 198.5537 123.5866 216.5679
## 2018.789 166.6708 137.6440 198.5775 123.4375 216.6397
## 2018.793 167.4516 138.2812 199.5170 124.0047 217.6693
## 2018.797 168.7350 139.3735 201.0067 125.0022 219.2745
## 2018.801 168.5634 139.1482 200.9035 124.7541 219.2135
## 2018.805 169.0988 139.5631 201.5743 125.1113 219.9620
## 2018.809 170.0764 140.3785 202.7294 125.8470 221.2172
## 2018.813 170.7146 140.8865 203.5127 126.2921 222.0835
## 2018.817 171.0074 141.0819 203.9179 126.4418 222.5541
## 2018.821 169.7175 139.8450 202.5887 125.2385 221.2098
## 2018.825 169.4743 139.5559 202.4059 124.9310 221.0649
## 2018.829 168.2883 138.4149 201.1889 123.8193 219.8371
## 2018.833 168.1245 138.1984 201.0922 123.5808 219.7820
## 2018.837 168.5727 138.5352 201.6668 123.8645 220.4296
## 2018.841 167.3656 137.3769 200.4247 122.7377 219.1746
## 2018.845 167.8094 137.7099 200.9943 123.0180 219.8168
## 2018.849 166.5464 136.5025 199.6894 121.8456 218.4954
## 2018.853 166.8390 136.6993 200.0925 121.9976 218.9631
## 2018.857 165.8246 135.7176 199.0594 121.0387 217.9258
## 2018.861 165.8204 135.6472 199.1360 120.9392 218.0512
## 2018.865 165.0429 134.8802 198.3621 120.1834 217.2849
## 2018.869 165.7678 135.4671 199.2402 120.7033 218.2502
## 2018.873 165.7398 135.3757 199.2900 120.5843 218.3473
## 2018.876 165.1945 134.8189 198.7705 120.0270 217.8473
## 2018.880 167.0624 136.4349 200.9063 121.5161 220.1311
## 2018.884 166.4173 135.7883 200.2768 120.8743 219.5159
## 2018.888 166.4099 135.7160 200.3489 120.7737 219.6359
## 2018.892 166.4242 135.6635 200.4447 120.6916 219.7808
## 2018.896 165.8587 135.0897 199.9018 120.1190 219.2557
## 2018.900 165.3667 134.5824 199.4393 119.6094 218.8147
## 2018.904 164.0093 133.2980 198.0225 118.3691 217.3720
## 2018.908 162.8211 132.1669 196.7910 117.2738 216.1233
## 2018.912 161.4607 130.8824 195.3683 116.0349 214.6732
## 2018.916 161.2709 130.6488 195.2368 115.7839 214.5784
## 2018.920 161.0249 130.3652 195.0429 115.4861 214.4181
## 2018.924 160.8079 130.1077 194.8807 115.2130 214.2908
## 2018.928 161.5110 130.6750 195.7347 115.7145 215.2309
## 2018.932 161.4191 130.5300 195.7106 115.5471 215.2485
## 2018.936 162.2811 131.2396 196.7401 116.1822 216.3730
## 2018.940 161.8550 130.7953 196.3465 115.7340 216.0023
## 2018.944 161.6133 130.5165 196.1563 115.4414 215.8454
## 2018.948 160.5485 129.5014 195.0557 114.4581 214.7314
## 2018.952 161.2576 130.0740 195.9164 114.9646 215.6785
## 2018.956 162.0607 130.7308 196.8811 115.5500 216.7350
## 2018.960 162.5880 131.1407 197.5407 115.9037 217.4707
## 2018.964 163.5882 131.9738 198.7234 116.6545 218.7562
## 2018.968 162.7986 131.2056 197.9264 115.9033 217.9611
## 2018.972 160.4970 129.0868 195.4549 113.8864 215.4050
## 2018.976 159.6722 128.2892 194.6169 113.1088 214.5656
## 2018.980 159.8598 128.3961 194.8999 113.1788 214.9052
## 2018.984 160.3750 128.7955 195.5459 113.5229 215.6265
## 2018.988 159.5101 127.9632 194.6624 112.7134 214.7389
## 2018.992 158.8010 127.2705 193.9508 112.0351 214.0317
## 2018.996 161.5008 129.6190 197.0186 114.2044 217.3011
## 2019.000 161.5552 129.6072 197.1539 114.1635 217.4852
## 2019.004 160.5006 128.6064 196.0593 113.1966 216.3750
## 2019.008 164.1064 131.7633 200.1314 116.1230 220.7010
checkresiduals(fct.stlf.apple.train)
## Warning in checkresiduals(fct.stlf.apple.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,N,N)
## Q* = 389.78, df = 249.2, p-value = 0.00000002919
##
## Model df: 2. Total lags used: 251.2
#FB Data Analysis
#Subsetting the FB dataset
FB.df<- subset(raw.data,Name=="FB" ,stringsAsFactors =FALSE )
str(FB.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 28.9 28.6 27.7 27.4 28 ...
## $ high : num 29.2 28.7 28.2 28.3 28.6 ...
## $ low : num 28.5 28 27.1 27.3 28 ...
## $ close : num 28.5 28.3 27.4 27.9 28.5 ...
## $ volume: int 37662614 36979533 93417215 50100805 35581045 33061895 49356691 42046417 49593513 36299386 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 181 181 181 181 181 181 181 181 181 181 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(FB.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
FB.close<-FB.df[,5]
#Creating the time series
FB.close.full.ts <- ts(FB.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
FB.close.ts <- ts(FB.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
FB.test.close.ts <- ts(FB.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(FB.close.full.ts)+
ggtitle("FB stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(FB.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(FB.close.full.ts)

length(FB.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(FB.close.full.ts)

acf.FB.close.ts <- acf(FB.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.FB.close.ts, type="o",main="Correlogram for FB stock closing price")

#Decomposition of time series components
stl.FB.close.ts <- stl(FB.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.FB.close.ts) +
ggtitle("FB stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(FB.close.full.ts, series="Data") +
autolayer(trendcycle(stl.FB.close.ts), series="Trend") +
autolayer(seasadj(stl.FB.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("New orders index") +
ggtitle("STL Decomposition of FB stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.FB.train <- stlf(FB.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.FB.train <- stlf(FB.close.full.ts, h = length(FB.close.full.ts) , lambda = BoxCox.lambda(FB.close.full.ts))
naive.FB.train <- rwf(FB.close.full.ts,h = length(FB.close.full.ts))
ets.stlf.FB.train <- stlf(FB.close.full.ts, t.window = 13, s.window = "periodic", h = length(FB.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(FB.close.full.ts))
fct.ets.FB.train <- forecast(ets.FB.train, h = 252)
fct.stlf.FB.train <- forecast(stlf.FB.train, h = 252)
fct.naive.FB.train <- forecast(naive.FB.train, h = 252)
fct.ets.stlf.FB.train <- forecast(ets.stlf.FB.train, h = 252)
accuracy(fct.ets.FB.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1401989 1.627623 1.139146 0.1490151 1.448798 0.03689144
## ACF1
## Training set -0.003429169
accuracy(fct.stlf.FB.train)
## ME RMSE MAE MPE MAPE
## Training set 0.003218355 1.364835 0.9965791 -0.02954566 1.213399
## MASE ACF1
## Training set 0.03227438 0.009384538
accuracy(fct.naive.FB.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1288725 1.60261 1.100046 0.1322852 1.293029 0.03562516
## ACF1
## Training set 0.008105657
accuracy(fct.ets.stlf.FB.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1113795 1.923596 1.184022 0.08394754 1.445014 0.03834476
## ACF1
## Training set -0.01535867
autoplot(FB.close.full.ts) +
autolayer(ets.FB.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.FB.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.FB.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.FB.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("FB Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.FB.train %>% forecast(h=252) %>%
autoplot() +
autolayer(FB.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.FB.train[["model"]]
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9763
## beta = 0.0001
##
## Initial states:
## l = 18.9878
## b = 0.0649
##
## sigma: 0.6889
##
## AIC AICc BIC
## 8032.415 8032.463 8058.093
summary(fct.stlf.FB.train)
##
## Forecast method: STL + ETS(A,A,N)
##
## Model Information:
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9763
## beta = 0.0001
##
## Initial states:
## l = 18.9878
## b = 0.0649
##
## sigma: 0.6889
##
## AIC AICc BIC
## 8032.415 8032.463 8058.093
##
## Error measures:
## ME RMSE MAE MPE MAPE
## Training set 0.003218355 1.364835 0.9965791 -0.02954566 1.213399
## MASE ACF1
## Training set 0.03227438 0.009384538
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 187.3705 185.4450 189.2990 184.4269 190.3210
## 2018.012 187.5634 184.8726 190.2599 183.4505 191.6897
## 2018.016 188.8160 185.5310 192.1095 183.7956 193.8564
## 2018.020 189.7139 185.9263 193.5129 183.9259 195.5285
## 2018.024 189.5401 185.3116 193.7827 183.0790 196.0342
## 2018.028 189.5421 184.9143 194.1868 182.4714 196.6523
## 2018.032 190.7159 185.7161 195.7355 183.0774 198.4005
## 2018.036 190.9752 185.6317 196.3410 182.8123 199.1904
## 2018.040 191.1961 185.5299 196.8874 182.5408 199.9103
## 2018.044 192.0121 186.0377 198.0145 182.8865 201.2030
## 2018.048 191.3714 185.1103 197.6632 181.8085 201.0061
## 2018.052 192.3221 185.7793 198.8983 182.3295 202.3928
## 2018.056 192.6479 185.8376 199.4944 182.2474 203.1330
## 2018.060 192.2835 185.2194 199.3865 181.4960 203.1620
## 2018.064 192.2166 184.9062 199.5687 181.0535 203.4772
## 2018.068 192.9492 185.3958 200.5470 181.4156 204.5865
## 2018.072 194.3413 186.5479 202.1815 182.4418 206.3505
## 2018.076 194.2390 186.2213 202.3064 181.9976 206.5967
## 2018.080 193.4027 185.1716 201.6865 180.8361 206.0924
## 2018.084 193.2087 184.7658 201.7070 180.3195 206.2275
## 2018.088 192.2821 183.6379 200.9848 179.0861 205.6147
## 2018.092 192.7986 183.9480 201.7102 179.2882 206.4518
## 2018.096 192.7520 183.7036 201.8643 178.9402 206.7132
## 2018.100 192.8541 183.6110 202.1639 178.7457 207.1184
## 2018.104 193.3678 183.9309 202.8740 178.9641 207.9335
## 2018.108 193.9258 184.2983 203.6251 179.2318 208.7879
## 2018.112 194.4176 184.6035 204.3062 179.4393 209.5702
## 2018.116 194.3473 184.3542 204.4177 179.0964 209.7790
## 2018.120 194.7337 184.5611 204.9862 179.2094 210.4449
## 2018.124 194.1873 183.8457 204.6118 178.4059 210.1626
## 2018.127 194.3574 183.8439 204.9565 178.3142 210.6008
## 2018.131 193.2737 182.6015 204.0345 176.9891 209.7657
## 2018.135 193.4385 182.5998 204.3685 176.9005 210.1903
## 2018.139 193.6309 182.6280 204.7279 176.8428 210.6391
## 2018.143 194.2250 183.0566 205.4901 177.1849 211.4912
## 2018.147 194.6900 183.3594 206.1199 177.4030 212.2093
## 2018.151 194.8142 183.3265 206.4038 177.2881 212.5789
## 2018.155 194.5413 182.9023 206.2853 176.7849 212.5431
## 2018.159 193.0990 181.3215 204.9846 175.1323 211.3188
## 2018.163 193.0430 181.1163 205.0806 174.8493 211.4963
## 2018.167 193.7471 181.6658 205.9419 175.3181 212.4417
## 2018.171 194.7835 182.5461 207.1369 176.1166 213.7215
## 2018.175 193.0120 180.6472 205.4960 174.1520 212.1512
## 2018.179 192.4423 179.9405 205.0664 173.3740 211.7970
## 2018.183 193.1835 180.5332 205.9586 173.8892 212.7699
## 2018.187 192.6900 179.9052 205.6027 173.1913 212.4880
## 2018.191 192.5519 179.6305 205.6040 172.8455 212.5643
## 2018.195 191.6798 178.6309 204.8625 171.7798 211.8931
## 2018.199 193.4861 180.2833 206.8248 173.3514 213.9388
## 2018.203 194.3605 181.0145 207.8446 174.0079 215.0365
## 2018.207 194.6036 181.1224 208.2257 174.0454 215.4915
## 2018.211 194.5763 180.9640 208.3322 173.8187 215.6700
## 2018.215 193.0754 179.3493 206.9486 172.1454 214.3499
## 2018.219 193.1528 179.2971 207.1584 172.0258 214.6307
## 2018.223 193.3948 179.4088 207.5333 172.0697 215.0770
## 2018.227 193.7029 179.5871 207.9740 172.1803 215.5889
## 2018.231 196.0770 181.8090 210.5016 174.3223 218.1984
## 2018.235 196.6496 182.2506 211.2077 174.6956 218.9760
## 2018.239 197.3892 182.8583 212.0815 175.2345 219.9218
## 2018.243 196.1431 181.5040 210.9472 173.8243 218.8479
## 2018.247 195.9932 181.2344 210.9198 173.4926 218.8865
## 2018.251 195.6394 180.7643 210.6853 172.9623 218.7162
## 2018.255 195.9661 180.9676 211.1378 173.1015 219.2363
## 2018.259 196.6009 181.4764 211.9011 173.5445 220.0685
## 2018.263 196.6949 181.4516 212.1165 173.4580 220.3493
## 2018.267 196.4365 181.0795 211.9747 173.0270 220.2703
## 2018.271 196.8935 181.4151 212.5556 173.2994 220.9178
## 2018.275 196.6759 181.0851 212.4534 172.9111 220.8776
## 2018.279 196.6654 180.9605 212.5597 172.7274 221.0469
## 2018.283 196.0356 180.2251 212.0387 171.9375 220.5847
## 2018.287 195.2852 179.3717 211.3947 171.0309 219.9983
## 2018.291 195.7220 179.6912 211.9512 171.2894 220.6190
## 2018.295 196.0074 179.8620 212.3538 171.4007 221.0846
## 2018.299 195.8726 179.6187 212.3303 171.1012 221.1212
## 2018.303 196.4039 180.0337 212.9804 171.4556 221.8351
## 2018.307 197.1470 180.6583 213.8442 172.0185 222.7636
## 2018.311 197.5915 180.9888 214.4051 172.2898 223.3870
## 2018.315 197.7383 181.0262 214.6640 172.2704 223.7062
## 2018.319 197.5949 180.7778 214.6284 171.9676 223.7288
## 2018.323 197.8497 180.9230 214.9953 172.0560 224.1560
## 2018.327 197.7992 180.7677 215.0525 171.8463 224.2713
## 2018.331 198.1182 180.9775 215.4832 171.9995 224.7621
## 2018.335 198.1531 180.9076 215.6256 171.8753 224.9623
## 2018.339 198.3157 180.9643 215.8967 171.8772 225.2919
## 2018.343 198.8639 181.4019 216.5578 172.2572 226.0136
## 2018.347 198.8629 181.2985 216.6621 172.1007 226.1747
## 2018.351 197.1715 179.5285 215.0534 170.2910 224.6114
## 2018.355 196.0799 178.3509 214.0514 169.0696 223.6582
## 2018.359 197.0231 179.1803 215.1105 169.8395 224.7793
## 2018.363 197.3196 179.3725 215.5138 169.9776 225.2401
## 2018.367 197.0799 179.0366 215.3732 169.5922 225.1531
## 2018.371 197.0247 178.8832 215.4191 169.3880 225.2536
## 2018.375 198.2544 179.9968 216.7666 170.4408 226.6640
## 2018.378 199.2716 180.9013 217.8983 171.2865 227.8570
## 2018.382 200.1627 181.6820 218.9017 172.0096 228.9207
## 2018.386 200.1629 181.5849 219.0018 171.8623 229.0748
## 2018.390 199.9975 181.3253 218.9337 171.5540 229.0591
## 2018.394 198.2952 179.5518 217.3070 169.7447 227.4741
## 2018.398 198.5961 179.7526 217.7104 169.8937 227.9327
## 2018.402 199.5235 180.5712 218.7485 170.6554 229.0301
## 2018.406 199.0750 180.0346 218.3912 170.0736 228.7223
## 2018.410 198.9595 179.8266 218.3712 169.8180 228.7538
## 2018.414 197.8373 178.6275 217.3297 168.5799 227.7565
## 2018.418 199.1294 179.8068 218.7361 169.7002 229.2240
## 2018.422 198.6164 179.2088 218.3115 169.0585 228.8474
## 2018.426 200.4246 180.8969 220.2406 170.6836 230.8408
## 2018.430 202.0113 182.3674 221.9447 172.0930 232.6075
## 2018.434 202.1894 182.4510 222.2199 172.1276 232.9350
## 2018.438 202.9619 183.1203 223.0975 172.7432 233.8691
## 2018.442 203.0642 183.1299 223.2950 172.7049 234.1180
## 2018.446 204.5130 184.4659 224.8579 173.9816 235.7418
## 2018.450 206.0281 185.8674 226.4878 175.3236 237.4328
## 2018.454 207.1660 186.8978 227.7346 176.2977 238.7379
## 2018.458 207.9943 187.6238 228.6673 176.9702 239.7265
## 2018.462 209.7851 189.2978 230.5757 178.5827 241.6976
## 2018.466 210.2059 189.6229 231.0943 178.8583 242.2688
## 2018.470 210.2830 189.6100 231.2640 178.7988 242.4885
## 2018.474 210.4548 189.6906 231.5294 178.8323 242.8044
## 2018.478 211.5151 190.6465 232.6958 179.7336 244.0275
## 2018.482 212.2988 191.3302 233.5812 180.3652 244.9675
## 2018.486 212.2725 191.2168 233.6447 180.2069 245.0795
## 2018.490 212.1396 190.9988 233.5998 179.9451 245.0821
## 2018.494 211.6707 190.4505 233.2135 179.3560 244.7408
## 2018.498 211.9959 190.6841 233.6326 179.5423 245.2104
## 2018.502 212.0625 190.6636 233.7889 179.4767 245.4152
## 2018.506 212.2712 190.7831 234.0891 179.5502 245.7647
## 2018.510 212.8474 191.2647 234.7619 179.9826 246.4894
## 2018.514 212.1385 190.4820 234.1304 179.1623 245.9001
## 2018.518 212.3684 190.6234 234.4512 179.2579 246.2699
## 2018.522 211.4238 189.6095 233.5796 178.2090 245.4384
## 2018.526 211.7773 189.8731 234.0252 178.4260 245.9336
## 2018.530 212.4056 190.4074 234.7495 178.9114 246.7094
## 2018.534 212.8985 190.8087 235.3359 179.2651 247.3462
## 2018.538 212.8440 190.6718 235.3666 179.0859 247.4229
## 2018.542 210.8711 188.6483 233.4493 177.0378 245.5368
## 2018.546 210.2029 187.9087 232.8561 176.2619 244.9846
## 2018.550 209.7219 187.3534 232.4526 175.6689 244.6232
## 2018.554 210.3226 187.8622 233.1471 176.1298 245.3683
## 2018.558 210.8084 188.2582 233.7248 176.4792 245.9953
## 2018.562 211.2797 188.6402 234.2875 176.8148 246.6072
## 2018.566 211.7475 189.0190 234.8464 177.1474 247.2150
## 2018.570 212.4924 189.6704 235.6864 177.7502 248.1061
## 2018.574 211.7829 188.8923 235.0491 176.9373 247.5084
## 2018.578 213.1348 190.1410 236.5053 178.1318 249.0201
## 2018.582 213.7436 190.6593 237.2064 178.6030 249.7708
## 2018.586 214.0303 190.8612 237.5802 178.7610 250.1915
## 2018.590 214.4683 191.2121 238.1074 179.0668 250.7668
## 2018.594 215.7750 192.4172 239.5167 180.2185 252.2308
## 2018.598 216.2846 192.8389 240.1162 180.5945 252.8787
## 2018.602 214.8457 191.3455 238.7363 179.0744 251.5315
## 2018.606 214.9024 191.3226 238.8752 179.0104 251.7149
## 2018.610 215.3888 191.7221 239.4504 179.3649 252.3379
## 2018.614 215.7915 192.0397 239.9404 179.6384 252.8749
## 2018.618 215.9367 192.1044 240.1685 179.6615 253.1478
## 2018.622 216.7743 192.8497 241.1000 180.3587 254.1295
## 2018.625 216.2765 192.2830 240.6743 179.7569 253.7432
## 2018.629 216.8030 192.7231 241.2892 180.1521 254.4057
## 2018.633 217.5301 193.3604 242.1078 180.7426 255.2733
## 2018.637 217.3143 193.0714 241.9679 180.4163 255.1747
## 2018.641 216.7893 192.4791 241.5138 179.7898 254.7592
## 2018.645 213.8515 189.5171 238.6069 176.8180 251.8711
## 2018.649 213.9280 189.5162 238.7632 176.7773 252.0706
## 2018.653 215.0824 190.5742 240.0151 177.7847 253.3746
## 2018.657 215.2281 190.6417 240.2415 177.8119 253.6445
## 2018.661 216.4734 191.7892 241.5854 178.9081 255.0410
## 2018.665 216.6742 191.9112 241.8674 178.9893 255.3668
## 2018.669 215.4509 190.6350 240.7015 177.6871 254.2328
## 2018.673 215.2751 190.3876 240.6000 177.4032 254.1719
## 2018.677 216.0893 191.1125 241.5050 178.0814 255.1255
## 2018.681 215.9150 190.8670 241.4048 177.7996 255.0656
## 2018.685 216.6249 191.4898 242.2034 178.3770 255.9117
## 2018.689 216.1936 190.9925 241.8415 177.8462 255.5877
## 2018.693 216.7150 191.4306 242.4480 178.2411 256.2400
## 2018.697 216.9077 191.5462 242.7202 178.3169 256.5551
## 2018.701 218.6984 193.2306 244.6171 179.9451 258.5083
## 2018.705 219.1815 193.6317 245.1843 180.3035 259.1207
## 2018.709 219.6190 193.9881 245.7049 180.6179 259.6860
## 2018.713 219.7895 194.0825 245.9537 180.6731 259.9772
## 2018.717 220.5167 194.7236 246.7686 181.2693 260.8391
## 2018.721 221.7700 195.8813 248.1182 182.3767 262.2400
## 2018.725 221.1757 195.2255 247.5889 181.6900 261.7464
## 2018.729 221.0025 194.9834 247.4876 181.4126 261.6841
## 2018.733 219.3865 193.3255 245.9185 179.7348 260.1417
## 2018.737 219.0698 192.9430 245.6707 179.3189 259.9315
## 2018.741 220.5568 194.3305 247.2574 180.6539 261.5712
## 2018.745 220.7352 194.4342 247.5130 180.7191 261.8685
## 2018.749 221.0246 194.6469 247.8812 180.8922 262.2792
## 2018.753 220.9996 194.5513 247.9295 180.7604 262.3672
## 2018.757 219.3533 192.8653 246.3281 179.0559 260.7914
## 2018.761 219.2158 192.6598 246.2614 178.8157 260.7633
## 2018.765 219.3205 192.6921 246.4410 178.8107 260.9834
## 2018.769 220.1729 193.4579 247.3812 179.5312 261.9706
## 2018.773 220.4486 193.6582 247.7346 179.6926 262.3659
## 2018.777 219.5226 192.6801 246.8648 178.6887 261.5274
## 2018.781 218.0717 191.1875 245.4605 177.1764 260.1495
## 2018.785 216.4617 189.5394 243.8938 175.5107 258.6076
## 2018.789 217.1997 190.1937 244.7170 176.1213 259.4764
## 2018.793 217.3761 190.2976 244.9684 176.1878 259.7684
## 2018.797 217.8607 190.7036 245.5333 176.5531 260.3764
## 2018.801 217.7330 190.5097 245.4748 176.3254 260.3556
## 2018.805 218.5344 191.2266 246.3619 176.9981 261.2886
## 2018.809 219.4591 192.0645 247.3744 177.7906 262.3481
## 2018.813 219.5575 192.0926 247.5457 177.7826 262.5588
## 2018.817 220.0126 192.4705 248.0799 178.1204 263.1356
## 2018.821 219.2212 191.6266 247.3448 177.2506 262.4318
## 2018.825 219.8983 192.2223 248.1048 177.8039 263.2362
## 2018.829 217.5988 189.9011 245.8337 175.4742 260.9824
## 2018.833 216.8893 189.1384 245.1813 174.6851 260.3616
## 2018.837 217.0864 189.2641 245.4520 174.7742 260.6721
## 2018.841 216.8125 188.9287 245.2429 174.4076 260.4985
## 2018.845 217.6430 189.6752 246.1584 175.1102 261.4595
## 2018.849 217.7902 189.7525 246.3779 175.1516 261.7181
## 2018.853 219.9647 191.8161 248.6622 177.1559 264.0601
## 2018.857 219.4020 191.1981 248.1584 176.5103 263.5888
## 2018.861 219.4579 191.1864 248.2845 176.4638 263.7530
## 2018.865 219.2505 190.9168 248.1423 176.1628 263.6464
## 2018.869 220.5157 192.0900 249.5000 177.2873 265.0532
## 2018.873 220.9010 192.4012 249.9612 177.5602 265.5554
## 2018.876 220.9637 192.3966 250.0937 177.5211 265.7257
## 2018.880 221.9653 193.3118 251.1825 178.3909 266.8610
## 2018.884 221.6507 192.9379 250.9305 177.9871 266.6433
## 2018.888 221.0462 192.2802 250.3830 177.3030 266.1272
## 2018.892 220.2156 191.4013 249.6048 176.4004 265.3783
## 2018.896 219.8547 190.9826 249.3050 175.9527 265.1120
## 2018.900 220.0665 191.1249 249.5886 176.0592 265.4345
## 2018.904 219.6731 190.6746 249.2553 175.5804 265.1342
## 2018.908 219.2968 190.2414 248.9393 175.1186 264.8513
## 2018.912 218.2632 189.1649 247.9533 174.0215 263.8921
## 2018.916 219.8706 190.6739 249.6587 175.4782 265.6493
## 2018.920 221.1781 191.8894 251.0583 176.6451 267.0977
## 2018.924 220.6340 191.2924 250.5708 176.0217 266.6415
## 2018.928 221.7704 192.3407 251.7959 177.0235 267.9137
## 2018.932 221.9019 192.4053 251.9966 177.0537 268.1520
## 2018.936 222.3971 192.8260 252.5680 177.4358 268.7643
## 2018.940 221.7979 192.1755 252.0237 176.7600 268.2506
## 2018.944 222.0424 192.3511 252.3393 176.9000 268.6046
## 2018.948 219.7854 190.0786 250.1049 174.6227 266.3845
## 2018.952 220.1494 190.3714 250.5421 174.8787 266.8611
## 2018.956 219.6793 189.8481 250.1287 174.3289 266.4791
## 2018.960 220.0850 190.1819 250.6082 174.6255 266.9982
## 2018.964 220.8495 190.8669 251.4533 175.2689 267.8865
## 2018.968 221.7717 191.7063 252.4591 176.0648 268.9370
## 2018.972 222.7752 192.6254 253.5477 176.9394 270.0709
## 2018.976 221.7398 191.5494 252.5575 175.8442 269.1061
## 2018.980 227.5634 197.1859 258.5595 181.3772 275.1997
## 2018.984 228.5332 198.0724 259.6133 182.2199 276.2983
## 2018.988 227.5878 197.0844 258.7150 181.2114 275.4265
## 2018.992 227.8941 197.3216 259.0924 181.4130 275.8422
## 2018.996 228.0320 197.3942 259.2980 181.4520 276.0844
## 2019.000 228.3431 197.6362 259.6799 181.6585 276.5047
## 2019.004 226.4450 195.7166 257.8097 179.7305 274.6514
## 2019.008 223.4386 192.7135 254.8088 176.7332 271.6563
checkresiduals(fct.stlf.FB.train)
## Warning in checkresiduals(fct.stlf.FB.train): The fitted degrees of freedom
## is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,A,N)
## Q* = 360.01, df = 247.2, p-value = 0.000003604
##
## Model df: 4. Total lags used: 251.2
#AMZN Data Analysis
#Subsetting the AMZN dataset
AMZN.df<- subset(raw.data,Name=="AMZN" ,stringsAsFactors =FALSE )
str(AMZN.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 261 263 259 262 267 ...
## $ high : num 265 263 260 270 271 ...
## $ low : num 261 257 257 260 265 ...
## $ close : num 262 257 259 269 269 ...
## $ volume: int 3879078 3403403 2938660 5292996 3462780 3979832 2853752 3528862 3637396 3123402 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 39 39 39 39 39 39 39 39 39 39 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(AMZN.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
AMZN.close<-AMZN.df[,5]
#Creating the time series
AMZN.close.full.ts <- ts(AMZN.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
AMZN.close.ts <- ts(AMZN.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
AMZN.test.close.ts <- ts(AMZN.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(AMZN.close.full.ts)+
ggtitle("AMZN stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(AMZN.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(AMZN.close.full.ts)

length(AMZN.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(AMZN.close.full.ts)

acf.AMZN.close.ts <- acf(AMZN.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.AMZN.close.ts, type="o",main="Correlogram for AMZN stock closing price")

#Decomposition of time series components
stl.AMZN.close.ts <- stl(AMZN.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.AMZN.close.ts) +
ggtitle("AMZN stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(AMZN.close.full.ts, series="Data") +
autolayer(trendcycle(stl.AMZN.close.ts), series="Trend") +
autolayer(seasadj(stl.AMZN.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("New orders index") +
ggtitle("STL Decomposition of AMZN stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.AMZN.train <- stlf(AMZN.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.AMZN.train <- stlf(AMZN.close.full.ts, h = length(AMZN.close.full.ts) , lambda = BoxCox.lambda(AMZN.close.full.ts))
naive.AMZN.train <- rwf(AMZN.close.full.ts,h = length(AMZN.close.full.ts))
ets.stlf.AMZN.train <- stlf(AMZN.close.full.ts, t.window = 13, s.window = "periodic", h = length(AMZN.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(AMZN.close.full.ts))
fct.ets.AMZN.train <- forecast(ets.AMZN.train, h = 252)
fct.stlf.AMZN.train <- forecast(stlf.AMZN.train, h = 252)
fct.naive.AMZN.train <- forecast(naive.AMZN.train, h = 252)
fct.ets.stlf.AMZN.train <- forecast(ets.stlf.AMZN.train, h = 252)
accuracy(fct.ets.AMZN.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.9433174 19.0802 9.564551 0.1038093 1.835943 0.0514047
## ACF1
## Training set -0.009004313
accuracy(fct.stlf.AMZN.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.2757324 9.51264 5.9275 0.01059696 1.088995 0.03185736
## ACF1
## Training set -0.02274692
accuracy(fct.naive.AMZN.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.9306773 10.29015 6.516864 0.11884 1.207084 0.0350249
## ACF1
## Training set 0.02999666
accuracy(fct.ets.stlf.AMZN.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.618843 11.20188 6.664894 0.06421528 1.240161 0.03582048
## ACF1
## Training set -0.007927371
autoplot(AMZN.close.full.ts) +
autolayer(ets.AMZN.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.AMZN.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.AMZN.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.AMZN.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("AMZN Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.AMZN.train %>% forecast(h=252) %>%
autoplot() +
autolayer(AMZN.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.AMZN.train[["model"]]
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 0.0006
##
## Initial states:
## l = 6.2849
## b = 0.0014
##
## sigma: 0.0215
##
## AIC AICc BIC
## -680.1879 -680.1399 -654.5095
summary(fct.stlf.AMZN.train)
##
## Forecast method: STL + ETS(A,A,N)
##
## Model Information:
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 0.0006
##
## Initial states:
## l = 6.2849
## b = 0.0014
##
## sigma: 0.0215
##
## AIC AICc BIC
## -680.1879 -680.1399 -654.5095
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.2757324 9.51264 5.9275 0.01059696 1.088995 0.03185736
## ACF1
## Training set -0.02274692
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 1334.569 1307.672 1361.997 1293.644 1376.733
## 2018.012 1336.415 1298.469 1375.423 1278.801 1396.511
## 2018.016 1344.829 1298.205 1393.056 1274.154 1419.252
## 2018.020 1360.129 1305.829 1416.588 1277.931 1447.378
## 2018.024 1364.910 1304.117 1428.413 1272.994 1463.165
## 2018.028 1372.422 1305.593 1442.522 1271.490 1481.006
## 2018.032 1371.442 1299.423 1447.277 1262.780 1489.032
## 2018.036 1374.466 1297.424 1455.880 1258.333 1500.828
## 2018.040 1381.639 1299.626 1468.598 1258.120 1516.730
## 2018.044 1392.500 1305.508 1485.029 1261.591 1536.367
## 2018.048 1396.429 1305.054 1493.917 1259.030 1548.130
## 2018.052 1405.995 1310.037 1508.667 1261.813 1565.888
## 2018.056 1406.221 1306.435 1513.286 1256.395 1573.081
## 2018.060 1403.053 1299.829 1514.105 1248.172 1576.253
## 2018.064 1410.794 1303.484 1526.538 1249.890 1591.438
## 2018.068 1427.774 1315.769 1548.882 1259.936 1616.916
## 2018.072 1434.680 1318.794 1560.286 1261.135 1630.975
## 2018.076 1435.599 1316.382 1565.121 1257.174 1638.145
## 2018.080 1429.168 1307.311 1561.865 1246.899 1636.810
## 2018.084 1417.126 1293.213 1552.369 1231.890 1628.883
## 2018.088 1409.692 1283.455 1547.777 1221.089 1626.028
## 2018.092 1410.656 1281.459 1552.280 1217.736 1632.667
## 2018.096 1411.327 1279.261 1556.400 1214.229 1638.873
## 2018.100 1412.880 1277.925 1561.430 1211.576 1646.011
## 2018.104 1415.911 1277.982 1568.037 1210.276 1654.786
## 2018.108 1417.617 1276.887 1573.139 1207.911 1661.955
## 2018.112 1415.942 1272.785 1574.453 1202.726 1665.109
## 2018.116 1401.109 1256.882 1561.117 1186.405 1652.763
## 2018.120 1398.521 1252.091 1561.280 1180.641 1654.633
## 2018.124 1391.460 1243.336 1556.407 1171.165 1651.149
## 2018.127 1394.741 1243.915 1563.001 1170.530 1659.777
## 2018.131 1394.822 1241.660 1565.993 1167.243 1664.575
## 2018.135 1396.241 1240.638 1570.445 1165.138 1670.906
## 2018.139 1392.986 1235.482 1569.627 1159.162 1671.627
## 2018.143 1403.733 1242.830 1584.488 1164.965 1688.995
## 2018.147 1409.554 1245.803 1593.815 1166.663 1700.483
## 2018.151 1411.661 1245.496 1598.948 1165.293 1707.502
## 2018.155 1407.639 1239.788 1597.141 1158.875 1707.116
## 2018.159 1406.916 1237.037 1599.020 1155.250 1710.641
## 2018.163 1400.856 1229.606 1594.826 1147.264 1707.669
## 2018.167 1429.734 1253.007 1630.205 1168.129 1746.959
## 2018.171 1434.620 1255.245 1638.409 1169.199 1757.234
## 2018.175 1422.685 1242.718 1627.473 1156.497 1747.023
## 2018.179 1414.106 1233.193 1620.293 1146.623 1740.802
## 2018.183 1431.110 1246.119 1642.252 1157.699 1765.791
## 2018.187 1430.844 1243.921 1644.511 1154.683 1769.669
## 2018.191 1433.877 1244.628 1650.524 1154.383 1777.568
## 2018.195 1426.305 1236.101 1644.372 1145.507 1772.392
## 2018.199 1455.109 1259.285 1679.921 1166.112 1812.034
## 2018.203 1456.434 1258.527 1683.965 1164.469 1817.820
## 2018.207 1452.809 1253.488 1682.297 1158.865 1817.450
## 2018.211 1467.718 1264.546 1701.959 1168.197 1840.051
## 2018.215 1458.206 1254.444 1693.467 1157.924 1832.311
## 2018.219 1449.874 1245.404 1686.290 1148.656 1825.965
## 2018.223 1445.933 1240.192 1684.151 1142.950 1825.039
## 2018.227 1440.423 1233.655 1680.166 1136.035 1822.103
## 2018.231 1443.009 1234.117 1685.542 1135.598 1829.276
## 2018.235 1479.536 1263.770 1730.348 1162.104 1879.122
## 2018.239 1499.521 1279.154 1756.004 1175.422 1908.283
## 2018.243 1482.674 1262.922 1738.800 1159.592 1891.027
## 2018.247 1475.847 1255.325 1733.217 1151.743 1886.337
## 2018.251 1472.014 1250.320 1731.096 1146.295 1885.388
## 2018.255 1489.285 1263.363 1753.630 1157.456 1911.201
## 2018.259 1507.168 1276.906 1776.920 1169.067 1937.858
## 2018.263 1523.167 1288.819 1798.038 1179.170 1962.179
## 2018.267 1516.198 1281.165 1792.231 1171.309 1957.226
## 2018.271 1517.961 1280.962 1796.652 1170.295 1963.393
## 2018.275 1521.819 1282.547 1803.533 1170.927 1972.238
## 2018.279 1518.154 1277.758 1801.548 1165.725 1971.420
## 2018.283 1516.579 1274.759 1802.007 1162.173 1973.256
## 2018.287 1510.821 1268.239 1797.509 1155.410 1969.676
## 2018.291 1521.013 1275.215 1811.844 1160.995 1986.653
## 2018.295 1527.349 1278.929 1821.632 1163.598 1998.672
## 2018.299 1530.270 1279.764 1827.380 1163.574 2006.280
## 2018.303 1536.744 1283.594 1837.340 1166.286 2018.498
## 2018.307 1542.791 1287.065 1846.802 1168.671 2030.176
## 2018.311 1553.470 1294.423 1861.780 1174.599 2047.905
## 2018.315 1549.456 1289.449 1859.279 1169.294 2046.486
## 2018.319 1552.645 1290.527 1865.347 1169.507 2054.455
## 2018.323 1555.607 1291.420 1871.142 1169.555 2062.128
## 2018.327 1571.629 1303.232 1892.540 1179.530 2086.938
## 2018.331 1584.143 1312.095 1909.777 1186.819 2107.195
## 2018.335 1585.510 1311.648 1913.687 1185.651 2112.818
## 2018.339 1582.269 1307.372 1912.070 1181.013 2112.358
## 2018.343 1590.243 1312.442 1923.895 1184.858 2126.687
## 2018.347 1588.153 1309.142 1923.639 1181.118 2127.720
## 2018.351 1569.394 1292.021 1903.318 1164.870 2106.633
## 2018.355 1563.480 1285.594 1898.408 1158.323 2102.507
## 2018.359 1575.220 1293.806 1914.757 1165.027 2121.829
## 2018.363 1576.695 1293.515 1918.741 1164.040 2127.514
## 2018.367 1572.694 1288.704 1916.103 1158.974 2125.884
## 2018.371 1570.353 1285.281 1915.456 1155.170 2126.446
## 2018.375 1578.339 1290.384 1927.301 1159.066 2140.816
## 2018.378 1584.181 1293.714 1936.559 1161.362 2152.334
## 2018.382 1588.881 1296.103 1944.439 1162.809 2162.333
## 2018.386 1592.277 1297.421 1950.741 1163.293 2170.589
## 2018.390 1580.006 1285.878 1937.991 1152.202 2157.732
## 2018.394 1570.822 1276.897 1928.961 1143.431 2148.979
## 2018.398 1584.030 1286.282 1947.190 1151.186 2170.457
## 2018.402 1595.882 1294.542 1963.790 1157.924 2190.145
## 2018.406 1596.748 1293.809 1966.999 1156.579 2194.973
## 2018.410 1598.117 1293.492 1970.818 1155.613 2200.479
## 2018.414 1587.228 1283.181 1959.633 1145.684 2189.300
## 2018.418 1599.214 1291.536 1976.437 1152.504 2209.244
## 2018.422 1604.100 1294.097 1984.557 1154.128 2219.538
## 2018.426 1642.201 1323.672 2033.450 1179.946 2275.245
## 2018.430 1668.780 1343.831 2068.270 1197.312 2315.322
## 2018.434 1672.395 1345.312 2074.915 1197.949 2324.026
## 2018.438 1673.962 1345.133 2079.040 1197.102 2329.923
## 2018.442 1675.377 1344.836 2082.977 1196.152 2335.611
## 2018.446 1684.746 1350.980 2096.721 1200.961 2352.250
## 2018.450 1691.553 1355.045 2107.319 1203.909 2365.385
## 2018.454 1697.990 1358.806 2117.470 1206.585 2378.030
## 2018.458 1698.267 1357.592 2120.013 1204.824 2382.175
## 2018.462 1698.216 1356.120 2122.145 1202.836 2385.859
## 2018.466 1705.872 1360.861 2133.822 1206.388 2400.225
## 2018.470 1701.793 1356.155 2130.955 1201.525 2398.315
## 2018.474 1693.695 1348.233 2123.085 1193.807 2390.790
## 2018.478 1702.528 1353.923 2136.231 1198.208 2406.814
## 2018.482 1707.683 1356.654 2144.818 1199.975 2417.735
## 2018.486 1694.431 1344.634 2130.490 1188.635 2402.948
## 2018.490 1690.248 1339.901 2127.431 1183.780 2400.792
## 2018.494 1685.376 1334.629 2123.496 1178.454 2397.645
## 2018.498 1685.962 1333.732 2126.361 1177.016 2402.135
## 2018.502 1677.790 1325.849 2118.274 1169.387 2394.307
## 2018.506 1682.666 1328.387 2126.491 1171.003 2404.811
## 2018.510 1686.909 1330.420 2133.923 1172.172 2414.436
## 2018.514 1688.183 1330.089 2137.637 1171.248 2419.881
## 2018.518 1689.035 1329.425 2140.820 1170.032 2424.727
## 2018.522 1685.864 1325.571 2138.947 1165.997 2423.875
## 2018.526 1691.293 1328.550 2147.876 1168.009 2435.200
## 2018.530 1699.346 1333.607 2160.115 1171.856 2450.266
## 2018.534 1699.017 1332.019 2161.811 1169.831 2453.441
## 2018.538 1695.056 1327.562 2158.923 1165.280 2451.437
## 2018.542 1679.045 1313.591 2140.814 1152.341 2432.227
## 2018.546 1659.944 1297.210 2118.757 1137.294 2408.529
## 2018.550 1636.567 1277.492 2091.241 1119.323 2378.626
## 2018.554 1647.840 1285.118 2107.528 1125.453 2398.268
## 2018.558 1667.814 1299.585 2134.860 1137.599 2430.431
## 2018.562 1677.739 1306.122 2149.490 1142.759 2448.230
## 2018.566 1676.163 1303.611 2149.544 1139.957 2449.522
## 2018.570 1683.650 1308.222 2161.102 1143.420 2463.856
## 2018.574 1675.048 1300.206 2152.220 1135.788 2455.011
## 2018.578 1697.234 1316.339 2182.492 1149.369 2490.592
## 2018.582 1700.991 1318.012 2189.338 1150.248 2499.604
## 2018.586 1696.823 1313.483 2186.087 1145.686 2497.151
## 2018.590 1701.614 1315.968 2194.254 1147.279 2507.667
## 2018.594 1701.256 1314.430 2195.855 1145.347 2510.724
## 2018.598 1708.006 1318.442 2206.534 1148.280 2524.107
## 2018.602 1696.337 1308.090 2193.664 1138.634 2510.699
## 2018.606 1693.107 1304.332 2191.568 1134.769 2509.542
## 2018.610 1700.725 1309.024 2203.365 1138.300 2524.205
## 2018.614 1713.317 1317.578 2221.556 1145.206 2546.166
## 2018.618 1723.402 1324.170 2236.552 1150.392 2564.499
## 2018.622 1735.922 1332.644 2254.696 1157.217 2586.436
## 2018.625 1724.804 1322.771 2242.469 1148.020 2573.734
## 2018.629 1720.575 1318.257 2239.081 1143.509 2571.106
## 2018.633 1728.290 1322.999 2251.065 1147.076 2586.031
## 2018.637 1728.952 1322.278 2253.971 1145.879 2590.592
## 2018.641 1719.281 1313.577 2243.542 1137.729 2579.909
## 2018.645 1693.046 1292.106 2211.690 1118.468 2544.710
## 2018.649 1701.829 1297.684 2225.050 1122.771 2561.211
## 2018.653 1718.446 1309.290 2248.562 1132.317 2589.345
## 2018.657 1723.578 1312.035 2257.234 1134.149 2600.505
## 2018.661 1744.842 1327.189 2286.821 1146.767 2635.634
## 2018.665 1743.851 1325.210 2287.587 1144.488 2637.756
## 2018.669 1727.643 1311.550 2268.594 1132.066 2617.218
## 2018.673 1740.204 1319.991 2286.940 1138.843 2639.496
## 2018.677 1738.011 1317.106 2286.126 1135.787 2639.799
## 2018.681 1745.631 1321.746 2298.076 1139.261 2654.755
## 2018.685 1749.153 1323.243 2304.703 1140.008 2663.607
## 2018.689 1740.789 1315.649 2295.839 1132.878 2654.660
## 2018.693 1743.691 1316.678 2301.654 1133.223 2662.580
## 2018.697 1752.431 1322.162 2315.096 1137.427 2679.277
## 2018.701 1770.607 1334.838 2340.884 1147.851 2710.191
## 2018.705 1769.790 1333.017 2341.870 1145.727 2712.577
## 2018.709 1779.331 1339.089 2356.408 1150.430 2730.569
## 2018.713 1764.945 1326.946 2339.621 1139.388 2712.483
## 2018.717 1767.256 1327.518 2344.692 1139.340 2719.572
## 2018.721 1786.802 1341.184 2372.380 1150.599 2752.746
## 2018.725 1794.439 1345.789 2384.467 1154.028 2767.947
## 2018.729 1807.757 1354.697 2404.035 1161.167 2791.791
## 2018.733 1801.642 1348.864 2398.071 1155.590 2786.175
## 2018.737 1812.493 1355.889 2414.422 1161.101 2806.326
## 2018.741 1844.304 1378.765 2458.401 1180.265 2858.413
## 2018.745 1856.408 1386.705 2476.466 1186.550 2880.584
## 2018.749 1847.412 1378.691 2466.722 1179.097 2870.614
## 2018.753 1837.339 1369.881 2455.533 1170.966 2858.962
## 2018.757 1834.123 1366.257 2453.381 1167.303 2857.755
## 2018.761 1845.012 1373.270 2469.873 1172.789 2878.132
## 2018.765 1870.335 1391.142 2505.486 1187.602 2920.671
## 2018.769 1879.039 1396.482 2519.139 1191.639 2937.794
## 2018.773 1886.783 1401.093 2531.537 1195.047 2953.474
## 2018.777 1878.879 1393.942 2523.194 1188.359 2945.112
## 2018.781 1875.161 1389.946 2520.387 1184.383 2943.163
## 2018.785 1862.051 1378.914 2505.092 1174.379 2926.714
## 2018.789 1876.585 1388.616 2526.526 1182.155 2952.898
## 2018.793 1886.656 1394.962 2542.048 1187.049 2972.232
## 2018.797 1903.428 1406.314 2566.513 1196.227 3001.971
## 2018.801 1911.679 1411.278 2579.655 1199.930 3018.568
## 2018.805 1933.485 1426.363 2610.887 1212.291 3056.213
## 2018.809 1939.631 1429.734 2621.264 1214.623 3069.623
## 2018.813 1948.000 1434.759 2634.621 1218.368 3086.509
## 2018.817 1968.125 1448.541 2663.702 1229.594 3121.713
## 2018.821 1945.400 1430.385 2635.512 1213.527 3090.239
## 2018.825 1945.898 1429.543 2638.360 1212.260 3094.901
## 2018.829 1916.692 1406.617 2601.407 1192.146 3053.167
## 2018.833 1912.414 1402.249 2597.815 1187.882 3050.301
## 2018.837 1906.477 1396.659 2591.987 1182.581 3044.822
## 2018.841 1897.163 1388.574 2581.608 1175.159 3034.023
## 2018.845 1915.741 1401.171 2608.702 1185.362 3066.972
## 2018.849 1904.487 1391.660 2595.700 1176.732 3053.105
## 2018.853 1905.302 1391.095 2598.922 1175.724 3058.184
## 2018.857 1895.840 1382.934 2588.295 1168.256 3047.073
## 2018.861 1906.490 1389.642 2604.770 1173.439 3067.650
## 2018.865 1900.201 1383.839 2598.404 1167.983 3061.515
## 2018.869 1917.230 1395.242 2623.517 1177.152 3092.222
## 2018.873 1912.162 1390.345 2618.798 1172.470 3088.015
## 2018.876 1915.801 1391.868 2625.845 1173.243 3097.587
## 2018.880 1932.732 1403.169 2650.888 1182.313 3128.254
## 2018.884 1931.080 1400.791 2650.792 1179.773 3129.471
## 2018.888 1927.738 1397.176 2648.401 1176.187 3127.993
## 2018.892 1926.430 1395.060 2648.761 1173.875 3129.740
## 2018.896 1928.406 1395.357 2653.575 1173.610 3136.714
## 2018.900 1950.068 1410.083 2685.139 1185.565 3175.103
## 2018.904 1949.205 1408.291 2686.119 1183.527 3177.593
## 2018.908 1936.153 1397.581 2670.509 1173.946 3160.585
## 2018.912 1890.008 1362.698 2609.791 1143.930 3090.525
## 2018.916 1892.328 1363.274 2615.041 1143.916 3097.999
## 2018.920 1905.049 1371.441 2634.484 1150.317 3122.178
## 2018.924 1905.609 1370.727 2637.349 1149.212 3126.858
## 2018.928 1913.738 1375.530 2650.553 1152.766 3143.716
## 2018.932 1916.297 1376.272 2656.159 1152.889 3151.632
## 2018.936 1926.280 1382.415 2671.926 1157.570 3171.528
## 2018.940 1902.320 1363.869 2641.233 1141.430 3136.662
## 2018.944 1917.325 1373.660 2663.887 1149.187 3164.686
## 2018.948 1920.314 1374.715 2670.091 1149.578 3173.320
## 2018.952 1923.011 1375.557 2675.899 1149.790 3181.492
## 2018.956 1924.318 1375.391 2679.803 1149.153 3187.420
## 2018.960 1938.445 1384.511 2701.329 1156.333 3214.164
## 2018.964 1946.843 1389.472 2715.000 1160.008 3231.646
## 2018.968 1958.819 1397.015 2733.613 1165.851 3254.979
## 2018.972 1978.344 1410.003 2762.641 1176.268 3290.644
## 2018.976 1961.543 1396.735 2741.647 1164.615 3267.163
## 2018.980 2026.545 1442.537 2833.425 1202.587 3377.102
## 2018.984 2013.129 1431.702 2817.121 1192.976 3359.187
## 2018.988 2006.768 1425.971 2810.531 1187.657 3352.756
## 2018.992 1993.836 1415.517 2794.844 1178.380 3335.544
## 2018.996 1986.918 1409.408 2787.447 1172.755 3328.139
## 2019.000 1991.247 1411.396 2795.602 1173.922 3339.163
## 2019.004 1953.057 1382.834 2744.862 1149.494 3280.340
## 2019.008 1824.429 1289.446 2568.559 1070.824 3072.415
checkresiduals(fct.stlf.AMZN.train)
## Warning in checkresiduals(fct.stlf.AMZN.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,A,N)
## Q* = 483.57, df = 247.2, p-value < 0.00000000000000022
##
## Model df: 4. Total lags used: 251.2
#MSFT Data Analysis
#Subsetting the MSFT dataset
MSFT.df<- subset(raw.data,Name=="MSFT" ,stringsAsFactors =FALSE )
str(MSFT.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 27.4 27.6 27.9 27.9 27.9 ...
## $ high : num 27.7 27.9 28 28.1 28.1 ...
## $ low : num 27.3 27.5 27.8 27.9 27.9 ...
## $ close : num 27.6 27.9 27.9 28 28 ...
## $ volume: int 33318306 32247549 35990829 41715530 32663174 49650538 38804616 44109412 49078338 31425726 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 323 323 323 323 323 323 323 323 323 323 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(MSFT.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
MSFT.close<-MSFT.df[,5]
#Creating the time series
MSFT.close.full.ts <- ts(MSFT.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
MSFT.close.ts <- ts(MSFT.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
MSFT.test.close.ts <- ts(MSFT.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(MSFT.close.full.ts)+
ggtitle("MSFT stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(MSFT.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(MSFT.close.full.ts)

length(MSFT.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(MSFT.close.full.ts)

acf.MSFT.close.ts <- acf(MSFT.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.MSFT.close.ts, type="o",main="Correlogram for MSFT stock closing price")

#Decomposition of time series components
stl.MSFT.close.ts <- stl(MSFT.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.MSFT.close.ts) +
ggtitle("MSFT stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(MSFT.close.full.ts, series="Data") +
autolayer(trendcycle(stl.MSFT.close.ts), series="Trend") +
autolayer(seasadj(stl.MSFT.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of MSFT stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.MSFT.train <- stlf(MSFT.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.MSFT.train <- stlf(MSFT.close.full.ts, h = length(MSFT.close.full.ts) , lambda = BoxCox.lambda(MSFT.close.full.ts))
naive.MSFT.train <- rwf(MSFT.close.full.ts,h = length(MSFT.close.full.ts))
ets.stlf.MSFT.train <- stlf(MSFT.close.full.ts, t.window = 13, s.window = "periodic", h = length(MSFT.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(MSFT.close.full.ts))
fct.ets.MSFT.train <- forecast(ets.MSFT.train, h = 252)
fct.stlf.MSFT.train <- forecast(stlf.MSFT.train, h = 252)
fct.naive.MSFT.train <- forecast(naive.MSFT.train, h = 252)
fct.ets.stlf.MSFT.train <- forecast(ets.stlf.MSFT.train, h = 252)
accuracy(fct.ets.MSFT.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.04808428 0.6829617 0.4740037 0.0751454 0.9825343 0.0455147
## ACF1
## Training set -0.006535707
accuracy(fct.stlf.MSFT.train)
## ME RMSE MAE MPE MAPE
## Training set 0.003423836 0.6300816 0.4378964 -0.00658333 0.8773877
## MASE ACF1
## Training set 0.04204762 -0.0239638
accuracy(fct.naive.MSFT.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.05117928 0.6915943 0.464349 0.08587138 0.9467809 0.04458765
## ACF1
## Training set -0.01859929
accuracy(fct.ets.stlf.MSFT.train)
## ME RMSE MAE MPE MAPE
## Training set 0.05103304 0.7704712 0.4780085 0.08387454 0.9631248
## MASE ACF1
## Training set 0.04589925 -0.02210519
autoplot(MSFT.close.full.ts) +
autolayer(ets.MSFT.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.MSFT.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.MSFT.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.MSFT.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("MSFT Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.MSFT.train %>% forecast(h=252) %>%
autoplot() +
autolayer(MSFT.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.MSFT.train[["model"]]
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.993
## beta = 0.0001
##
## Initial states:
## l = 2.4542
## b = 0.0004
##
## sigma: 0.0059
##
## AIC AICc BIC
## -3921.656 -3921.608 -3895.977
summary(fct.stlf.MSFT.train)
##
## Forecast method: STL + ETS(A,A,N)
##
## Model Information:
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.993
## beta = 0.0001
##
## Initial states:
## l = 2.4542
## b = 0.0004
##
## sigma: 0.0059
##
## AIC AICc BIC
## -3921.656 -3921.608 -3895.977
##
## Error measures:
## ME RMSE MAE MPE MAPE
## Training set 0.003423836 0.6300816 0.4378964 -0.00658333 0.8773877
## MASE ACF1
## Training set 0.04204762 -0.0239638
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 88.12412 86.53137 89.75209 85.70216 90.62845
## 2018.012 88.34902 86.10743 90.66081 84.94837 91.91388
## 2018.016 88.66067 85.91621 91.51071 84.50456 93.06378
## 2018.020 89.35371 86.16601 92.68356 84.53368 94.50635
## 2018.024 90.09529 86.50625 93.86399 84.67565 95.93531
## 2018.028 90.37929 86.44269 94.53236 84.44193 96.82322
## 2018.032 90.84023 86.57189 95.36287 84.40963 97.86598
## 2018.036 90.62217 86.08142 95.45254 83.78804 98.13417
## 2018.040 90.94783 86.12016 96.10295 83.68884 98.97329
## 2018.044 91.10368 86.01351 96.55856 83.45688 99.60423
## 2018.048 90.32463 85.04910 95.99659 82.40586 99.17145
## 2018.052 90.55913 85.04073 96.51158 82.28260 99.85190
## 2018.056 91.22467 85.43944 97.48498 82.55492 101.00681
## 2018.060 91.11995 85.13318 97.61755 82.15482 101.28130
## 2018.064 90.66899 84.51708 97.36451 81.46299 101.14807
## 2018.068 91.49591 85.08190 98.49721 81.90471 102.46260
## 2018.072 91.55771 84.94954 98.79053 81.68283 102.89571
## 2018.076 91.08040 84.33118 98.48629 81.00106 102.69798
## 2018.080 90.42438 83.55781 97.97724 80.17592 102.28058
## 2018.084 90.14538 83.13448 97.87569 79.68775 102.28845
## 2018.088 90.17499 82.99635 98.10945 79.47357 102.64731
## 2018.092 91.01002 83.58988 99.23232 79.95553 103.94414
## 2018.096 90.01049 82.53049 98.31640 78.87253 103.08389
## 2018.100 90.55961 82.87154 99.11697 79.11853 104.03794
## 2018.104 90.87094 83.00047 99.65137 79.16501 104.70966
## 2018.108 91.88121 83.75717 100.96645 79.80528 106.21022
## 2018.112 92.71094 84.35173 102.08105 80.29254 107.49914
## 2018.116 93.13056 84.58061 102.73563 80.43563 108.29916
## 2018.120 93.05396 84.36947 102.83015 80.16570 108.50187
## 2018.124 93.35965 84.50063 103.35337 80.21911 109.16087
## 2018.127 93.15710 84.18307 103.30027 79.85227 109.20362
## 2018.131 92.47456 83.44423 102.69962 79.09206 108.65896
## 2018.135 92.31904 83.17510 102.69234 78.77439 108.74705
## 2018.139 92.44884 83.16006 103.00692 78.69609 109.17884
## 2018.143 93.47044 83.93079 104.33708 79.35363 110.70015
## 2018.147 93.59291 83.91115 104.64228 79.27234 111.12194
## 2018.151 93.77379 83.94425 105.01294 79.24121 111.61364
## 2018.155 93.65895 83.72009 105.04325 78.97103 111.73851
## 2018.159 93.73257 83.66260 105.28789 78.85734 112.09335
## 2018.163 93.85411 83.64838 105.58626 78.78483 112.50563
## 2018.167 94.51762 84.10684 106.50868 79.15271 113.59151
## 2018.171 93.76973 83.33948 105.80122 78.38160 112.91630
## 2018.175 93.29145 82.80947 105.40138 77.83275 112.57161
## 2018.179 93.12650 82.55353 105.36144 77.53968 112.61496
## 2018.183 93.33169 82.61941 105.74922 77.54597 113.12097
## 2018.187 94.18262 83.24318 106.88766 78.06950 114.44143
## 2018.191 94.38830 83.31015 107.27621 78.07743 114.94893
## 2018.195 94.51094 83.30648 107.56732 78.02056 115.35044
## 2018.199 96.38071 84.80321 109.90138 79.35016 117.97520
## 2018.203 96.07828 84.43487 109.69615 78.95683 117.83755
## 2018.207 96.33844 84.54982 110.14895 79.01024 118.41628
## 2018.211 97.00178 85.00957 111.07568 79.38170 119.51245
## 2018.215 97.87580 85.64826 112.25211 79.91771 120.88260
## 2018.219 99.54241 86.96000 114.36666 81.07218 123.28065
## 2018.223 100.02302 87.26085 115.08431 81.29631 124.15284
## 2018.227 99.44347 86.66246 114.54687 80.69494 123.65022
## 2018.231 98.91433 86.10921 114.06618 80.13624 123.20823
## 2018.235 98.99816 86.07676 114.31065 80.05627 123.56065
## 2018.239 99.50216 86.40001 115.05431 80.30269 124.46127
## 2018.243 98.28853 85.27425 113.75244 79.22247 123.11372
## 2018.247 97.62940 84.61923 113.10717 78.57477 122.48581
## 2018.251 97.74698 84.62024 113.38638 78.52823 122.87399
## 2018.255 98.55215 85.19961 114.48769 79.01058 124.16799
## 2018.259 98.62867 85.16660 114.71799 78.93342 124.50283
## 2018.263 99.67538 85.94697 116.11213 79.59876 126.12229
## 2018.267 100.01908 86.13767 116.66418 79.72588 126.81338
## 2018.271 100.29340 86.27049 117.13308 79.80039 127.41298
## 2018.275 100.41334 86.27475 117.41597 79.75808 127.80698
## 2018.279 100.74198 86.45336 117.95050 79.87473 128.47971
## 2018.283 100.06287 85.79389 117.26674 79.22963 127.80233
## 2018.287 99.80770 85.48877 117.09333 78.90758 127.68947
## 2018.291 99.19547 84.88862 116.48558 78.31832 127.09374
## 2018.295 99.16342 84.77136 116.57930 78.16829 127.27574
## 2018.299 99.42839 84.90076 117.03320 78.24242 127.85781
## 2018.303 100.67124 85.83850 118.67778 79.04922 129.76506
## 2018.307 101.17054 86.16043 119.41957 79.29748 130.66947
## 2018.311 101.33432 86.20547 119.75267 79.29512 131.11918
## 2018.315 102.16977 86.80356 120.90714 79.79306 132.48530
## 2018.319 101.90776 86.49863 120.71962 79.47463 132.35469
## 2018.323 101.52297 86.09408 120.38008 79.06686 132.05355
## 2018.327 101.79062 86.22588 120.83977 79.14391 132.64494
## 2018.331 102.45295 86.68092 121.78507 79.51260 133.78006
## 2018.335 102.36895 86.52493 121.81295 79.33030 133.88904
## 2018.339 101.98259 86.12273 121.46722 78.92667 133.57903
## 2018.343 102.40565 86.38225 122.11884 79.11945 134.38641
## 2018.347 101.66023 85.68934 121.32704 78.45527 133.57481
## 2018.351 100.99112 85.06041 120.62704 77.84954 132.86478
## 2018.355 100.34731 84.45376 119.95596 77.26470 132.18593
## 2018.359 100.78986 84.73156 120.62925 77.47535 133.01680
## 2018.363 100.45839 84.38088 120.34255 77.12163 132.76855
## 2018.367 100.43444 84.28065 120.43654 76.99325 132.94799
## 2018.371 99.99055 83.84088 120.00746 76.56065 132.53813
## 2018.375 100.76629 84.38901 121.09589 77.01431 133.83759
## 2018.378 100.69655 84.25311 121.13161 76.85481 133.95108
## 2018.382 101.12456 84.51947 121.78835 77.05581 134.76526
## 2018.386 101.59272 84.81785 122.49622 77.28537 135.63795
## 2018.390 100.92090 84.19822 121.77744 76.69394 134.89872
## 2018.394 99.09507 82.65158 119.61063 75.27447 132.52101
## 2018.398 98.93615 82.44814 119.52923 75.05684 132.49946
## 2018.402 99.94069 83.17966 120.90784 75.67463 134.13033
## 2018.406 99.84773 83.02961 120.90921 75.50501 134.20275
## 2018.410 100.17471 83.21654 121.43856 75.63632 134.87346
## 2018.414 99.78066 82.82642 121.05966 75.25316 134.51428
## 2018.418 100.31709 83.18111 121.85334 75.53425 135.48537
## 2018.422 100.84252 83.52644 122.63443 75.80680 136.44315
## 2018.426 101.89927 84.29468 124.08931 76.45547 138.16810
## 2018.430 103.06800 85.15028 125.68950 77.18110 140.06072
## 2018.434 103.66602 85.55040 126.56867 77.50123 141.13445
## 2018.438 104.93183 86.47971 128.29869 78.29094 143.17947
## 2018.442 105.87711 87.15286 129.62452 78.85249 144.76600
## 2018.446 103.90512 85.51530 127.23326 77.36442 142.10990
## 2018.450 104.86970 86.20415 128.58361 77.94021 143.72467
## 2018.454 104.51697 85.85081 128.25349 77.59215 143.42017
## 2018.458 105.22222 86.33353 129.27526 77.98489 144.66139
## 2018.462 105.03096 86.10862 129.15059 77.75111 144.59150
## 2018.466 105.36703 86.29972 129.70114 77.88566 145.29462
## 2018.470 104.71871 85.71615 128.98876 77.33533 144.55074
## 2018.474 105.09451 85.93898 129.59008 77.49826 145.31218
## 2018.478 105.17332 85.92836 129.81012 77.45496 145.63671
## 2018.482 104.89300 85.63627 129.56755 77.16336 145.43010
## 2018.486 104.96004 85.61719 129.77163 77.11304 145.73608
## 2018.490 105.03798 85.60689 129.98964 77.07065 146.05811
## 2018.494 105.18526 85.65106 130.29712 77.07641 146.48314
## 2018.498 105.40894 85.75502 130.70352 77.13496 147.02224
## 2018.502 105.82624 86.01004 131.36101 77.32656 147.85094
## 2018.506 106.23016 86.25427 132.00208 77.50856 148.66146
## 2018.510 106.63432 86.49836 132.64436 77.69034 149.47410
## 2018.514 106.11325 86.02254 132.08490 77.23924 148.90025
## 2018.518 106.50792 86.25941 132.71512 77.41486 149.69942
## 2018.522 106.02057 85.81129 132.19738 76.98887 149.17262
## 2018.526 106.70286 86.27134 133.20294 77.36055 150.40632
## 2018.530 107.28018 86.64924 134.07331 77.65985 151.48491
## 2018.534 107.08703 86.43040 133.93796 77.43575 151.39990
## 2018.538 106.72490 86.08150 133.58075 77.09798 151.05748
## 2018.542 106.40611 85.76688 133.27908 76.79064 150.77878
## 2018.546 106.26006 85.58634 133.20271 76.60109 150.76078
## 2018.550 104.96763 84.52197 131.62232 75.63807 148.99758
## 2018.554 104.04631 83.74539 130.52605 74.92770 147.79449
## 2018.558 105.17392 84.54879 132.11813 75.60030 149.71133
## 2018.562 106.34856 85.38656 133.77570 76.30220 151.70681
## 2018.566 106.57392 85.49339 134.18615 76.36486 152.25408
## 2018.570 105.26857 84.42512 132.57883 75.40129 150.45370
## 2018.574 103.71375 83.16680 130.64011 74.27245 148.26615
## 2018.578 105.01048 84.09763 132.46094 75.05553 150.45362
## 2018.582 105.72075 84.57732 133.51059 75.44426 151.74516
## 2018.586 105.54997 84.38223 133.39599 75.24441 151.68023
## 2018.590 106.84205 85.30542 135.21912 76.01921 153.87636
## 2018.594 106.56023 85.02564 134.95758 75.74574 153.64033
## 2018.598 106.99229 85.29085 135.64320 75.94696 154.51059
## 2018.602 106.48584 84.84076 135.08196 75.52576 153.92371
## 2018.606 106.52155 84.80429 135.24064 75.46471 154.17811
## 2018.610 107.20186 85.25817 136.25792 75.83003 155.43761
## 2018.614 107.58669 85.48683 136.88285 75.99939 156.23881
## 2018.618 108.14706 85.84833 137.74313 76.28399 157.31663
## 2018.622 107.80807 85.52763 137.40231 75.97637 156.98659
## 2018.625 107.75223 85.42206 137.43928 75.85570 157.09932
## 2018.629 107.24417 84.97457 136.87031 75.43872 156.50051
## 2018.633 107.82253 85.34947 137.75609 75.73502 157.60970
## 2018.637 107.26970 84.86928 137.12534 75.29028 156.93738
## 2018.641 107.69671 85.12965 137.80892 75.48735 157.80973
## 2018.645 106.67956 84.30046 136.55219 74.74106 156.39989
## 2018.649 107.42658 84.80238 137.66602 75.14742 157.77878
## 2018.653 108.16994 85.30059 138.77705 75.55020 159.15591
## 2018.657 108.00685 85.11636 138.66747 75.36275 159.09556
## 2018.661 109.11625 85.88842 140.27539 76.00175 161.06082
## 2018.665 109.37221 86.01871 140.73261 76.08600 161.66997
## 2018.669 108.77205 85.50712 140.03174 75.61624 160.91172
## 2018.673 109.87229 86.27005 141.63249 76.24652 162.87240
## 2018.677 110.71009 86.83511 142.88060 76.70558 164.41839
## 2018.681 109.78447 86.08155 141.73602 76.02794 163.13422
## 2018.685 109.93266 86.13118 142.04835 76.04284 163.57348
## 2018.689 109.54982 85.78459 141.63860 75.71658 163.15764
## 2018.693 109.25019 85.50071 141.34104 75.44462 162.87416
## 2018.697 109.49951 85.62643 141.79037 75.52544 163.47566
## 2018.701 110.72806 86.48071 143.57609 76.23281 165.66335
## 2018.705 111.04937 86.65900 144.12616 76.35848 166.38635
## 2018.709 111.56412 86.98067 144.94149 76.60727 167.42515
## 2018.713 110.40706 86.06150 143.46973 75.79034 165.74592
## 2018.717 111.21767 86.60282 144.69022 76.22788 167.26675
## 2018.721 117.39807 91.11328 153.29133 80.06771 177.58298
## 2018.725 118.62793 91.95674 155.10448 80.76105 179.82152
## 2018.729 118.66506 91.91996 155.27569 80.70052 180.10177
## 2018.733 118.67917 91.86641 155.41500 80.62574 180.34396
## 2018.737 117.73282 91.10655 154.22700 79.94710 178.99961
## 2018.741 119.62253 92.43223 156.95951 81.05165 182.34278
## 2018.745 120.59665 93.08309 158.42988 81.57862 184.17951
## 2018.749 121.34937 93.57043 159.59593 81.96553 185.65372
## 2018.753 122.44486 94.30768 161.24057 82.56526 187.70356
## 2018.757 122.72588 94.44818 161.75507 82.65572 188.39938
## 2018.761 122.98524 94.57271 162.23996 82.73255 189.06019
## 2018.765 123.61363 94.96633 163.24005 83.03854 190.34060
## 2018.769 123.07027 94.50528 162.60596 82.61674 189.65734
## 2018.773 123.56619 94.80203 163.42229 82.84022 190.71788
## 2018.777 122.84416 94.21202 162.53661 82.30924 189.73086
## 2018.781 122.55741 93.93955 162.25821 82.04874 189.47391
## 2018.785 122.19115 93.60979 161.86764 81.73979 189.08141
## 2018.789 121.51015 93.05194 161.03516 81.23724 188.15591
## 2018.793 121.98869 93.33684 161.82677 81.45117 189.18703
## 2018.797 123.13704 94.10691 163.56017 82.07691 191.35539
## 2018.801 122.55463 93.62197 162.86383 81.63698 190.59291
## 2018.805 122.70634 93.66927 163.19859 81.64902 191.07472
## 2018.809 123.07556 93.87390 163.83987 81.79452 191.92721
## 2018.813 122.51496 93.40634 163.17149 81.37011 191.19698
## 2018.817 123.16114 93.81103 164.20377 81.68527 192.52290
## 2018.821 124.36155 94.61467 166.02086 82.33801 194.80036
## 2018.825 125.32026 95.24259 167.49989 82.84139 196.67105
## 2018.829 124.51007 94.59661 166.47644 82.26669 195.50975
## 2018.833 123.56802 93.85664 165.26460 81.61288 194.11900
## 2018.837 124.59612 94.53408 166.84351 82.15809 196.11229
## 2018.841 123.70846 93.83459 165.70619 81.53917 194.81038
## 2018.845 123.34717 93.51396 165.31431 81.24081 194.41236
## 2018.849 123.37341 93.47190 165.47209 81.17805 194.68144
## 2018.853 123.19208 93.28120 165.33458 80.98986 194.59171
## 2018.857 123.15568 93.19469 165.40274 80.88982 194.75176
## 2018.861 124.22940 93.90280 167.05249 81.46032 196.83608
## 2018.865 123.63819 93.41947 166.33016 81.02563 196.03460
## 2018.869 124.35248 93.86959 167.46997 81.37822 197.50028
## 2018.873 124.73316 94.08089 168.13487 81.52931 198.38858
## 2018.876 124.91794 94.15224 168.52034 81.56245 198.93684
## 2018.880 125.92741 94.81087 170.08760 82.08995 200.92782
## 2018.884 126.59836 95.22745 171.17232 82.41335 202.33169
## 2018.888 126.82552 95.32800 171.62147 82.47077 202.96012
## 2018.892 126.50926 95.04258 171.28997 82.20378 202.63437
## 2018.896 126.27767 94.81772 171.07939 81.98792 202.45606
## 2018.900 126.43405 94.86843 171.42658 82.00373 202.96001
## 2018.904 125.77191 94.33905 170.59490 81.53247 202.02083
## 2018.908 125.32045 93.95966 170.06541 81.18746 201.45084
## 2018.912 123.73617 92.77846 167.90201 80.16960 198.87892
## 2018.916 124.03031 92.92852 168.44462 80.26969 199.62049
## 2018.920 123.41661 92.43619 167.67746 79.83077 198.75704
## 2018.924 123.26904 92.27417 167.58206 79.66925 198.71643
## 2018.928 124.12202 92.81929 168.93264 80.10077 200.44974
## 2018.932 122.99249 91.96417 167.41673 79.35844 198.66579
## 2018.936 123.65458 92.37430 168.49210 79.67679 200.06221
## 2018.940 123.53519 92.23297 168.43654 79.53307 200.07029
## 2018.944 124.01970 92.51726 169.25656 79.74581 201.15463
## 2018.948 123.46228 92.06790 168.56493 79.34446 200.38049
## 2018.952 122.67748 91.45916 167.54191 78.81002 199.19795
## 2018.956 122.96813 91.60747 168.08009 78.90924 199.93568
## 2018.960 123.50450 91.92818 168.97646 79.15257 201.11513
## 2018.964 125.34934 93.16610 171.78130 80.16203 204.64844
## 2018.968 125.09326 92.92970 171.52622 79.93942 204.41116
## 2018.972 123.07351 91.45802 168.69690 78.68547 200.99783
## 2018.976 121.81972 90.52399 166.98318 77.88090 198.95933
## 2018.980 123.48656 91.63622 169.53141 78.78515 202.17880
## 2018.984 126.04241 93.36678 173.38781 80.20394 207.02004
## 2018.988 125.25290 92.75917 172.34952 79.67251 205.81368
## 2018.992 123.81610 91.70045 170.36129 78.76537 203.43161
## 2018.996 123.34443 91.31618 169.78566 78.42078 202.79538
## 2019.000 123.49324 91.36515 170.11915 78.43740 203.28347
## 2019.004 120.34467 89.11467 165.61585 76.53820 197.78659
## 2019.008 115.29333 85.53316 158.33133 73.52837 188.85541
checkresiduals(fct.stlf.MSFT.train)
## Warning in checkresiduals(fct.stlf.MSFT.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,A,N)
## Q* = 443.84, df = 247.2, p-value = 0.0000000000002294
##
## Model df: 4. Total lags used: 251.2
#BAC Data Analysis
#Subsetting the BAC dataset
BAC.df<- subset(raw.data,Name=="BAC" ,stringsAsFactors =FALSE )
str(BAC.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 11.9 11.7 11.9 12.3 12.1 ...
## $ high : num 11.9 11.9 12.3 12.4 12.3 ...
## $ low : num 11.7 11.7 11.8 12.1 12.1 ...
## $ close : num 11.8 11.9 12.2 12.2 12.1 ...
## $ volume: int 145217221 103499848 231771561 192478919 143901737 158078545 170570245 192999906 235454104 178923836 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 61 61 61 61 61 61 61 61 61 61 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(BAC.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
BAC.close<-BAC.df[,5]
#Creating the time series
BAC.close.full.ts <- ts(BAC.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
BAC.close.ts <- ts(BAC.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
BAC.test.close.ts <- ts(BAC.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(BAC.close.full.ts)+
ggtitle("BAC stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(BAC.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(BAC.close.full.ts)

length(BAC.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(BAC.close.full.ts)

acf.BAC.close.ts <- acf(BAC.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.BAC.close.ts, type="o",main="Correlogram for BAC stock closing price")

#Decomposition of time series components
stl.BAC.close.ts <- stl(BAC.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.BAC.close.ts) +
ggtitle("BAC stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(BAC.close.full.ts, series="Data") +
autolayer(trendcycle(stl.BAC.close.ts), series="Trend") +
autolayer(seasadj(stl.BAC.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of BAC stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.BAC.train <- stlf(BAC.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.BAC.train <- stlf(BAC.close.full.ts, h = length(BAC.close.full.ts) , lambda = BoxCox.lambda(BAC.close.full.ts))
naive.BAC.train <- rwf(BAC.close.full.ts,h = length(BAC.close.full.ts))
ets.stlf.BAC.train <- stlf(BAC.close.full.ts, t.window = 13, s.window = "periodic", h = length(BAC.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(BAC.close.full.ts))
fct.ets.BAC.train <- forecast(ets.BAC.train, h = 252)
fct.stlf.BAC.train <- forecast(stlf.BAC.train, h = 252)
fct.naive.BAC.train <- forecast(naive.BAC.train, h = 252)
fct.ets.stlf.BAC.train <- forecast(ets.stlf.BAC.train, h = 252)
accuracy(fct.ets.BAC.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01398212 0.2916078 0.2062169 0.06101108 1.205143 0.05185413
## ACF1
## Training set -0.00255926
accuracy(fct.stlf.BAC.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01553614 0.2399161 0.1805356 0.06894188 1.046146 0.04539645
## ACF1
## Training set 0.04290586
accuracy(fct.naive.BAC.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01608765 0.2681374 0.1967649 0.06732246 1.147912 0.04947739
## ACF1
## Training set 0.05104166
accuracy(fct.ets.stlf.BAC.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01324364 0.2951216 0.2022643 0.05210772 1.166355 0.05086023
## ACF1
## Training set 0.006567539
autoplot(BAC.close.full.ts) +
autolayer(ets.BAC.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.BAC.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.BAC.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.BAC.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("BAC Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.BAC.train %>% forecast(h=252) %>%
autoplot() +
autolayer(BAC.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.BAC.train[["model"]]
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 5.2685
##
## sigma: 0.068
##
## AIC AICc BIC
## 2211.956 2211.975 2227.363
summary(fct.stlf.BAC.train)
##
## Forecast method: STL + ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 5.2685
##
## sigma: 0.068
##
## AIC AICc BIC
## 2211.956 2211.975 2227.363
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01553614 0.2399161 0.1805356 0.06894188 1.046146 0.04539645
## ACF1
## Training set 0.04290586
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 30.74741 30.35703 31.13998 30.15126 31.34868
## 2018.012 30.80090 30.24907 31.35711 29.95871 31.65332
## 2018.016 30.58894 29.91574 31.26869 29.56204 31.63118
## 2018.020 30.48789 29.71228 31.27225 29.30525 31.69100
## 2018.024 30.68187 29.81287 31.56181 29.35728 32.03204
## 2018.028 30.83399 29.88054 31.80056 29.38113 32.31753
## 2018.032 30.83968 29.81032 31.88434 29.27162 32.44352
## 2018.036 30.76153 29.66290 31.87765 29.08843 32.47554
## 2018.040 30.76143 29.59672 31.94581 28.98816 32.58072
## 2018.044 30.78312 29.55559 32.03251 28.91466 32.70270
## 2018.048 30.73430 29.44832 32.04432 28.77735 32.74750
## 2018.052 30.78138 29.43787 32.15112 28.73733 32.88678
## 2018.056 30.67634 29.28065 32.10045 28.55339 32.86578
## 2018.060 30.67174 29.22402 32.15007 28.47011 32.94498
## 2018.064 30.69970 29.20113 32.23108 28.42118 33.05495
## 2018.068 31.08188 29.52618 32.67252 28.71685 33.52862
## 2018.072 31.49984 29.88725 33.14948 29.04868 34.03767
## 2018.076 31.59819 29.93710 33.29850 29.07374 34.21438
## 2018.080 31.66499 29.95734 33.41404 29.07021 34.35660
## 2018.084 31.64068 29.88981 33.43511 28.98070 34.40257
## 2018.088 31.27493 29.49066 33.10502 28.56478 34.09225
## 2018.092 31.40356 29.57451 33.28059 28.62581 34.29354
## 2018.096 31.42843 29.55816 33.34885 28.58853 34.38563
## 2018.100 31.58490 29.67072 33.55138 28.67873 34.61341
## 2018.104 31.60544 29.65177 33.61358 28.63976 34.69853
## 2018.108 31.61429 29.62224 33.66299 28.59080 34.77029
## 2018.112 31.52592 29.49901 33.61167 28.45002 34.73947
## 2018.116 31.51317 29.45000 33.63738 28.38270 34.78641
## 2018.120 31.51306 29.41392 33.67541 28.32848 34.84550
## 2018.124 31.29440 29.16657 33.48768 28.06685 34.67504
## 2018.127 30.80070 28.65359 33.01558 27.54461 34.21530
## 2018.131 30.64716 28.47112 32.89319 27.34774 34.11030
## 2018.135 30.63651 28.42763 32.91757 27.28776 34.15409
## 2018.139 30.57168 28.33226 32.88549 27.17714 34.14023
## 2018.143 30.58725 28.31517 32.93590 27.14365 34.20996
## 2018.147 30.62730 28.32220 33.01116 27.13409 34.30472
## 2018.151 30.60318 28.26766 33.01964 27.06435 34.33135
## 2018.155 30.75857 28.38687 33.21335 27.16528 34.54619
## 2018.159 30.59927 28.20271 33.08115 26.96888 34.42923
## 2018.163 30.39443 27.97521 32.90124 26.73030 34.26343
## 2018.167 30.44357 27.99306 32.98382 26.73249 34.36458
## 2018.171 30.28997 27.81595 32.85600 26.54384 34.25130
## 2018.175 30.16586 27.66772 32.75823 26.38377 34.16837
## 2018.179 30.04942 27.52734 32.66796 26.23164 34.09285
## 2018.183 30.22849 27.67165 32.88393 26.35842 34.32919
## 2018.187 30.27125 27.68507 32.95820 26.35719 34.42102
## 2018.191 30.21790 27.60638 32.93239 26.26600 34.41067
## 2018.195 30.07279 27.43990 32.81091 26.08914 34.30260
## 2018.199 30.23399 27.56796 33.00736 26.20053 34.51856
## 2018.203 30.39182 27.69297 33.20015 26.30902 34.73070
## 2018.207 30.67733 27.94068 33.52552 26.53757 35.07800
## 2018.211 30.74734 27.98171 33.62667 26.56414 35.19650
## 2018.215 30.59055 27.80542 33.49163 26.37847 35.07387
## 2018.219 30.47706 27.67104 33.40128 26.23395 34.99666
## 2018.223 30.67739 27.83768 33.63738 26.38362 35.25253
## 2018.227 30.65179 27.78802 33.63804 26.32211 35.26798
## 2018.231 30.49374 27.61179 33.50044 26.13720 35.14210
## 2018.235 30.43832 27.53414 33.46947 26.04869 35.12495
## 2018.239 30.75083 27.80875 33.82191 26.30406 35.49934
## 2018.243 30.48152 27.52691 33.56745 26.01656 35.25367
## 2018.247 30.48712 27.50830 33.59945 25.98603 35.30052
## 2018.251 30.46731 27.46561 33.60472 25.93213 35.31994
## 2018.255 30.48133 27.45545 33.64511 25.91006 35.37516
## 2018.259 30.57650 27.52296 33.77008 25.96380 35.51676
## 2018.263 30.71429 27.63128 33.93945 26.05740 35.70368
## 2018.267 30.69366 27.58852 33.94314 26.00383 35.72113
## 2018.271 30.56065 27.43877 33.82915 25.84614 35.61810
## 2018.275 30.40385 27.26660 33.68997 25.66679 35.48917
## 2018.279 30.52345 27.35816 33.83974 25.74438 35.65574
## 2018.283 30.53673 27.34852 33.87813 25.72350 35.70830
## 2018.287 30.35940 27.15750 33.71679 25.52618 35.55633
## 2018.291 30.34112 27.11818 33.72175 25.47663 35.57447
## 2018.295 30.41691 27.16855 33.82509 25.51443 35.69326
## 2018.299 30.46864 27.19615 33.90311 25.53014 35.78606
## 2018.303 30.68158 27.37720 34.14999 25.69515 36.05172
## 2018.307 30.79119 27.46003 34.28849 25.76467 36.20635
## 2018.311 30.59522 27.25245 34.10645 25.55191 36.03261
## 2018.315 30.65493 27.28811 34.19236 25.57571 36.13324
## 2018.319 30.52618 27.14485 34.08039 25.42572 36.03106
## 2018.323 30.40251 27.00666 33.97352 25.28077 35.93399
## 2018.327 30.50765 27.08584 34.10673 25.34709 36.08290
## 2018.331 30.48079 27.03986 34.10121 25.29189 36.08956
## 2018.335 30.50319 27.04074 34.14730 25.28228 36.14905
## 2018.339 30.43460 26.95546 34.09763 25.18909 36.11029
## 2018.343 30.51921 27.01557 34.20887 25.23710 36.23647
## 2018.347 30.48636 26.96444 34.19651 25.17722 36.23584
## 2018.351 30.51024 26.96721 34.24369 25.16969 36.29621
## 2018.355 30.43445 26.87568 34.18587 25.07077 36.24880
## 2018.359 30.42338 26.84559 34.19601 25.03152 36.27105
## 2018.363 30.38105 26.78605 34.17312 24.96378 36.25933
## 2018.367 30.21434 26.60901 34.01908 24.78223 36.11291
## 2018.371 30.07474 26.45783 33.89336 24.62588 35.99546
## 2018.375 30.26822 26.62164 34.11853 24.77482 36.23822
## 2018.378 30.27313 26.60728 34.14490 24.75117 36.27681
## 2018.382 30.13206 26.45514 34.01722 24.59412 36.15713
## 2018.386 30.20942 26.50944 34.11976 24.63709 36.27385
## 2018.390 29.79775 26.10225 33.70616 24.23333 35.86024
## 2018.394 29.42052 25.72805 33.32843 23.86179 35.48324
## 2018.398 29.75827 26.02823 33.70565 24.14286 35.88210
## 2018.402 30.15647 26.38544 34.14667 24.47913 36.34653
## 2018.406 30.32159 26.52288 34.34152 24.60275 36.55793
## 2018.410 30.23983 26.42761 34.27554 24.50126 36.50121
## 2018.414 30.10756 26.28489 34.15603 24.35397 36.38937
## 2018.418 30.04090 26.20414 34.10570 24.26670 36.34857
## 2018.422 30.07885 26.22203 34.16588 24.27486 36.42137
## 2018.426 30.24998 26.36536 34.36683 24.40431 36.63892
## 2018.430 30.42298 26.51049 34.56974 24.53551 36.85848
## 2018.434 30.54035 26.60327 34.71378 24.61614 37.01746
## 2018.438 30.58591 26.62851 34.78180 24.63151 37.09823
## 2018.442 30.78965 26.80265 35.01714 24.79079 37.35109
## 2018.446 30.78773 26.78331 35.03483 24.76314 37.38002
## 2018.450 30.91391 26.88453 35.18801 24.85201 37.54833
## 2018.454 30.90732 26.86095 35.20062 24.82033 37.57197
## 2018.458 31.02614 26.95534 35.34594 24.90264 37.73213
## 2018.462 30.91714 26.83563 35.24993 24.77822 37.64391
## 2018.466 30.79587 26.70455 35.14078 24.64290 37.54209
## 2018.470 30.67476 26.57378 35.03164 24.50797 37.44020
## 2018.474 30.86555 26.73596 35.25303 24.65583 37.67858
## 2018.478 30.96727 26.81455 35.37997 24.72303 37.81970
## 2018.482 30.92058 26.75387 35.34951 24.65587 37.79870
## 2018.486 30.66514 26.49748 35.09747 24.40000 37.54944
## 2018.490 30.60178 26.42144 35.04904 24.31818 37.50981
## 2018.494 30.69240 26.48984 35.16397 24.37569 37.63844
## 2018.498 30.74197 26.51980 35.23528 24.39615 37.72210
## 2018.502 30.65085 26.41799 35.15713 24.28963 37.65173
## 2018.506 30.92866 26.66190 35.47073 24.51636 37.98502
## 2018.510 31.00972 26.72149 35.57537 24.56545 38.10297
## 2018.514 30.94725 26.64669 35.52747 24.48506 38.06369
## 2018.518 30.73095 26.42800 35.31599 24.26612 37.85571
## 2018.522 30.56958 26.26092 35.16269 24.09701 37.70762
## 2018.526 30.51442 26.19335 35.12220 24.02381 37.67578
## 2018.530 30.69226 26.34374 35.32948 24.16048 37.89943
## 2018.534 30.74145 26.37385 35.39989 24.18136 37.98192
## 2018.538 30.61532 26.24012 35.28368 24.04459 37.87189
## 2018.542 30.47135 26.08987 35.14834 23.89200 37.74205
## 2018.546 30.28711 25.90219 34.96996 23.70350 37.56771
## 2018.550 29.99245 25.61166 34.67372 23.41623 37.27164
## 2018.554 30.06184 25.66099 34.76528 23.45581 37.37577
## 2018.558 30.24085 25.81260 34.97365 23.59373 37.60047
## 2018.562 30.35307 25.90193 35.11082 23.67178 37.75166
## 2018.566 30.38431 25.91575 35.16163 23.67727 37.81369
## 2018.570 30.43749 25.95007 35.23579 23.70249 37.89980
## 2018.574 30.24657 25.75691 35.04955 23.50916 37.71699
## 2018.578 30.37881 25.86501 35.20795 23.60532 37.89004
## 2018.582 30.32231 25.79729 35.16494 23.53259 37.85506
## 2018.586 30.38784 25.84330 35.25209 23.56914 37.95450
## 2018.590 30.23204 25.68326 35.10293 23.40786 37.80979
## 2018.594 30.20811 25.64609 35.09445 23.36461 37.81037
## 2018.598 30.18625 25.61093 35.08812 23.32332 37.81314
## 2018.602 30.17178 25.58269 35.08962 23.28872 37.82397
## 2018.606 30.29396 25.68161 35.23710 23.37616 37.98564
## 2018.610 30.46650 25.82737 35.43837 23.50856 38.20290
## 2018.614 30.57168 25.91051 35.56765 23.58087 38.34576
## 2018.618 30.45645 25.78873 35.46132 23.45660 38.24505
## 2018.622 30.27764 25.60798 35.28686 23.27585 38.07386
## 2018.625 30.36624 25.67581 35.39831 23.33354 38.19823
## 2018.629 30.34880 25.64516 35.39630 23.29681 38.20525
## 2018.633 30.48135 25.75385 35.55471 23.39370 38.37815
## 2018.637 30.33224 25.60104 35.41171 23.23993 38.23933
## 2018.641 30.36115 25.61357 35.45915 23.24469 38.29742
## 2018.645 30.00711 25.27089 35.09644 22.90915 37.93119
## 2018.649 30.05951 25.30534 35.16890 22.93499 38.01511
## 2018.653 30.25875 25.47598 35.39866 23.09126 38.26177
## 2018.657 30.17963 25.38854 35.33016 23.00038 38.19980
## 2018.661 30.34535 25.52811 35.52398 23.12691 38.40928
## 2018.665 30.42890 25.59153 35.62974 23.18053 38.52761
## 2018.669 30.39492 25.54605 35.60950 23.12989 38.51553
## 2018.673 30.54201 25.66838 35.78331 23.23993 38.70428
## 2018.677 30.61040 25.71781 35.87275 23.28019 38.80568
## 2018.681 30.50225 25.60375 35.77286 23.16398 38.71109
## 2018.685 30.44572 25.53758 35.72824 23.09366 38.67367
## 2018.689 30.39976 25.48126 35.69489 23.03281 38.64788
## 2018.693 30.24619 25.32546 35.54597 22.87685 38.50238
## 2018.697 30.33659 25.39543 35.65886 22.93685 38.62799
## 2018.701 30.46898 25.50426 35.81682 23.03401 38.80026
## 2018.705 30.56126 25.57598 35.93168 23.09570 38.92791
## 2018.709 30.69922 25.68997 36.09559 23.19782 39.10633
## 2018.713 30.61163 25.59541 36.01729 23.10054 39.03386
## 2018.717 30.76081 25.71980 36.19322 23.21261 39.22474
## 2018.721 31.06694 25.98930 36.53769 23.46343 39.59018
## 2018.725 31.03507 25.94631 36.51918 23.41547 39.57962
## 2018.729 31.13091 26.02141 36.63779 23.48044 39.71110
## 2018.733 31.44521 26.29847 36.99101 23.73848 40.08561
## 2018.737 31.37906 26.22384 36.93563 23.66031 40.03682
## 2018.741 31.26509 26.10510 36.82880 23.54003 39.93470
## 2018.745 31.25762 26.08482 36.83633 23.51389 39.95103
## 2018.749 31.21847 26.03533 36.80975 23.45987 39.93200
## 2018.753 31.18775 25.99369 36.79220 23.41337 39.92230
## 2018.757 31.30511 26.08878 36.93382 23.49749 40.07755
## 2018.761 31.58418 26.33317 37.24930 23.72424 40.41300
## 2018.765 31.63109 26.36324 37.31517 23.74625 40.48974
## 2018.769 31.49303 26.22260 37.18208 23.60526 40.36023
## 2018.773 31.69504 26.39585 37.41471 23.76404 40.60980
## 2018.777 31.73917 26.42340 37.47751 23.78370 40.68331
## 2018.781 31.75869 26.42828 37.51382 23.78173 40.72936
## 2018.785 32.05925 26.69247 37.85244 24.02735 41.08880
## 2018.789 32.09338 26.71084 37.90445 24.03825 41.15112
## 2018.793 32.18208 26.77958 38.01515 24.09726 41.27427
## 2018.797 32.28527 26.86169 38.14143 24.16904 41.41356
## 2018.801 32.24173 26.80847 38.10980 24.11164 41.38913
## 2018.805 32.34450 26.89022 38.23560 24.18309 41.52791
## 2018.809 32.31159 26.84688 38.21534 24.13516 41.51523
## 2018.813 32.33264 26.85333 38.25314 24.13477 41.56274
## 2018.817 32.37173 26.87642 38.31033 24.15027 41.63034
## 2018.821 32.10793 26.62050 38.04127 23.89962 41.35952
## 2018.825 32.49996 26.96880 38.47854 24.22538 41.82135
## 2018.829 32.86326 27.29071 38.88479 24.52602 42.25097
## 2018.833 32.77057 27.19241 38.80004 24.42571 42.17133
## 2018.837 32.95029 27.34515 39.00861 24.56494 42.39592
## 2018.841 33.25272 27.61098 39.34928 24.81208 42.75751
## 2018.845 33.16179 27.51433 39.26639 24.71337 42.67979
## 2018.849 33.04843 27.39710 39.15927 24.59508 42.57688
## 2018.853 33.21597 27.53864 39.35470 24.72362 42.78783
## 2018.857 33.06456 27.38646 39.20648 24.57206 42.64224
## 2018.861 32.85789 27.18356 38.99858 24.37221 42.43468
## 2018.865 33.06209 27.35882 39.23352 24.53290 42.68662
## 2018.869 33.28565 27.55192 39.48933 24.71060 42.96021
## 2018.873 33.32508 27.57556 39.54664 24.72675 43.02783
## 2018.876 33.08851 27.34530 39.30633 24.50093 42.78653
## 2018.880 33.23054 27.46338 39.47423 24.60712 42.96890
## 2018.884 33.35652 27.56670 39.62482 24.69925 43.13328
## 2018.888 33.40250 27.59645 39.68912 24.72128 43.20810
## 2018.892 33.42663 27.60613 39.72982 24.72418 43.25842
## 2018.896 33.40526 27.57400 39.72142 24.68727 43.25774
## 2018.900 33.42197 27.57690 39.75407 24.68376 43.29967
## 2018.904 33.30423 27.45629 39.64157 24.56263 43.19089
## 2018.908 33.21944 27.36603 39.56456 24.47045 43.11891
## 2018.912 32.96877 27.12356 39.30833 24.23343 42.86074
## 2018.916 32.99061 27.13135 39.34634 24.23467 42.90816
## 2018.920 32.99456 27.12275 39.36501 24.22033 42.93547
## 2018.924 32.96580 27.08416 39.34829 24.17746 42.92600
## 2018.928 32.80088 26.92074 39.18434 24.01589 42.76354
## 2018.932 32.58869 26.71414 38.96915 23.81333 42.54776
## 2018.936 32.71748 26.82012 39.12267 23.90803 42.71514
## 2018.940 32.64575 26.74237 39.05929 23.82805 42.65707
## 2018.944 32.40752 26.51218 38.81563 23.60325 42.41157
## 2018.948 32.40884 26.50147 38.83116 23.58707 42.43547
## 2018.952 32.05484 26.16564 38.46185 23.26208 42.05917
## 2018.956 32.07376 26.17114 38.49634 23.26137 42.10274
## 2018.960 32.11533 26.19737 38.55534 23.28036 42.17179
## 2018.964 32.06858 26.14287 38.51862 23.22270 42.14127
## 2018.968 31.89495 25.97245 38.34430 23.05505 41.96757
## 2018.972 32.11201 26.15913 38.59348 23.22636 42.23444
## 2018.976 32.13424 26.16776 38.63143 23.22867 42.28156
## 2018.980 32.29932 26.30694 38.82425 23.35491 42.48980
## 2018.984 32.36595 26.35616 38.91033 23.39576 42.58698
## 2018.988 32.20776 26.20000 38.75260 23.24173 42.43047
## 2018.992 31.90648 25.91334 38.43951 22.96400 42.11220
## 2018.996 31.90245 25.89815 38.44883 22.94381 42.12945
## 2019.000 32.12764 26.09216 38.70690 23.12201 42.40562
## 2019.004 31.95004 25.91860 38.52780 22.95168 42.22672
## 2019.008 30.74741 24.81136 37.23456 21.89703 40.88729
checkresiduals(fct.stlf.BAC.train)
## Warning in checkresiduals(fct.stlf.BAC.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,N,N)
## Q* = 377.53, df = 249.2, p-value = 0.000000272
##
## Model df: 2. Total lags used: 251.2
#GOOGL Data Analysis
#Subsetting the GOOGL dataset
GOOGL.df<- subset(raw.data,Name=="GOOGL" ,stringsAsFactors =FALSE )
str(GOOGL.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 390 390 391 390 390 ...
## $ high : num 394 392 394 393 395 ...
## $ low : num 390 387 390 390 389 ...
## $ close : num 393 392 391 392 394 ...
## $ volume: int 6031199 4330781 3714176 2393946 3466971 5453980 5857528 5522500 7008464 4103315 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 208 208 208 208 208 208 208 208 208 208 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(GOOGL.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
GOOGL.close<-GOOGL.df[,5]
#Creating the time series
GOOGL.close.full.ts <- ts(GOOGL.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
GOOGL.close.ts <- ts(GOOGL.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
GOOGL.test.close.ts <- ts(GOOGL.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(GOOGL.close.full.ts)+
ggtitle("GOOGL stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(GOOGL.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(GOOGL.close.full.ts)

length(GOOGL.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(GOOGL.close.full.ts)

acf.GOOGL.close.ts <- acf(GOOGL.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.GOOGL.close.ts, type="o",main="Correlogram for GOOGL stock closing price")

#Decomposition of time series components
stl.GOOGL.close.ts <- stl(GOOGL.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.GOOGL.close.ts) +
ggtitle("GOOGL stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(GOOGL.close.full.ts, series="Data") +
autolayer(trendcycle(stl.GOOGL.close.ts), series="Trend") +
autolayer(seasadj(stl.GOOGL.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of GOOGL stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.GOOGL.train <- stlf(GOOGL.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.GOOGL.train <- stlf(GOOGL.close.full.ts, h = length(GOOGL.close.full.ts) , lambda = BoxCox.lambda(GOOGL.close.full.ts))
naive.GOOGL.train <- rwf(GOOGL.close.full.ts,h = length(GOOGL.close.full.ts))
ets.stlf.GOOGL.train <- stlf(GOOGL.close.full.ts, t.window = 13, s.window = "periodic", h = length(GOOGL.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(GOOGL.close.full.ts))
fct.ets.GOOGL.train <- forecast(ets.GOOGL.train, h = 252)
fct.stlf.GOOGL.train <- forecast(stlf.GOOGL.train, h = 252)
fct.naive.GOOGL.train <- forecast(naive.GOOGL.train, h = 252)
fct.ets.stlf.GOOGL.train <- forecast(ets.stlf.GOOGL.train, h = 252)
accuracy(fct.ets.GOOGL.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5733778 8.404768 6.011386 0.07504335 0.9150356 0.04479745
## ACF1
## Training set 0.01844196
accuracy(fct.stlf.GOOGL.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5762996 8.019304 5.725258 0.0758559 0.8623171 0.0426652
## ACF1
## Training set 0.03272594
accuracy(fct.naive.GOOGL.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5785835 9.149996 6.196542 0.07416261 0.9291594 0.04617726
## ACF1
## Training set 0.0454099
accuracy(fct.ets.stlf.GOOGL.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5747698 10.02627 6.326074 0.0737857 0.9539332 0.04714254
## ACF1
## Training set 0.0007302464
autoplot(GOOGL.close.full.ts) +
autolayer(ets.GOOGL.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.GOOGL.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.GOOGL.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.GOOGL.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("GOOGL Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.GOOGL.train %>% forecast(h=252) %>%
autoplot() +
autolayer(GOOGL.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.GOOGL.train[["model"]]
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 29.8402
##
## sigma: 0.2141
##
## AIC AICc BIC
## 5094.738 5094.757 5110.145
summary(fct.stlf.GOOGL.train)
##
## Forecast method: STL + ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 29.8402
##
## sigma: 0.2141
##
## AIC AICc BIC
## 5094.738 5094.757 5110.145
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5762996 8.019304 5.725258 0.0758559 0.8623171 0.0426652
## ACF1
## Training set 0.03272594
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 1100.457 1087.0998 1113.904 1080.0656 1121.060
## 2018.012 1106.443 1087.5236 1125.544 1077.5816 1135.728
## 2018.016 1106.729 1083.5800 1130.151 1071.4354 1142.660
## 2018.020 1110.932 1084.1692 1138.057 1070.1485 1152.564
## 2018.024 1114.349 1084.4005 1144.752 1068.7298 1161.030
## 2018.028 1118.796 1085.9397 1152.198 1068.7663 1170.100
## 2018.032 1118.638 1083.1756 1154.737 1064.6592 1174.104
## 2018.036 1115.042 1077.2222 1153.587 1057.4946 1174.287
## 2018.040 1116.002 1075.8920 1156.928 1054.9887 1178.925
## 2018.044 1116.259 1073.9978 1159.429 1051.9920 1182.650
## 2018.048 1115.073 1070.7978 1160.345 1047.7627 1184.717
## 2018.052 1120.067 1073.7309 1167.493 1049.6412 1193.041
## 2018.056 1125.496 1077.1599 1175.013 1052.0485 1201.705
## 2018.060 1124.037 1073.9357 1175.409 1047.9263 1203.121
## 2018.064 1125.761 1073.8799 1179.005 1046.9649 1207.744
## 2018.068 1135.922 1082.0913 1191.207 1054.1816 1221.065
## 2018.072 1136.899 1081.4082 1193.936 1052.6560 1224.758
## 2018.076 1133.427 1076.4484 1192.042 1046.9449 1223.736
## 2018.080 1128.671 1070.2922 1188.777 1040.0837 1221.297
## 2018.084 1122.877 1063.1772 1184.393 1032.3056 1217.696
## 2018.088 1116.441 1055.4875 1179.301 1023.9879 1213.352
## 2018.092 1119.166 1056.7152 1183.614 1024.4598 1218.544
## 2018.096 1120.264 1056.3975 1186.219 1023.4291 1221.984
## 2018.100 1118.347 1053.1926 1185.681 1019.5787 1222.212
## 2018.104 1124.472 1057.7916 1193.423 1023.4072 1230.847
## 2018.108 1126.014 1057.9838 1196.406 1022.9213 1234.631
## 2018.112 1129.385 1059.9648 1201.259 1024.2034 1240.305
## 2018.116 1127.916 1057.2962 1201.079 1020.9362 1240.845
## 2018.120 1125.370 1053.6149 1199.759 1016.6898 1240.212
## 2018.124 1122.033 1049.1958 1197.594 1011.7341 1238.703
## 2018.127 1120.428 1046.4697 1197.201 1008.4505 1238.989
## 2018.131 1110.758 1036.0054 1188.414 997.6009 1230.705
## 2018.135 1102.099 1026.5439 1180.645 987.7501 1223.443
## 2018.139 1099.684 1023.1107 1179.339 983.8136 1222.760
## 2018.143 1105.242 1027.3519 1186.305 987.3950 1230.510
## 2018.147 1105.723 1026.7309 1187.978 986.2272 1232.852
## 2018.151 1102.908 1022.9642 1186.205 981.9926 1231.666
## 2018.155 1100.745 1019.8412 1185.093 978.3970 1231.147
## 2018.159 1090.901 1009.3767 1175.956 967.6390 1222.421
## 2018.163 1090.130 1007.6224 1176.258 965.4005 1223.327
## 2018.167 1098.605 1014.7286 1186.195 971.8198 1234.077
## 2018.171 1097.241 1012.4302 1185.856 969.0627 1234.317
## 2018.175 1089.911 1004.4442 1179.271 960.7642 1228.162
## 2018.179 1084.415 998.2291 1174.581 954.2040 1223.936
## 2018.183 1086.304 999.0807 1177.598 954.5431 1227.587
## 2018.187 1087.169 998.9650 1179.535 953.9444 1230.129
## 2018.191 1090.614 1001.3194 1184.163 955.7583 1235.420
## 2018.195 1086.257 996.2440 1180.612 950.3381 1232.333
## 2018.199 1094.137 1002.8413 1189.870 956.2939 1242.358
## 2018.203 1092.353 1000.2379 1188.994 953.2928 1242.000
## 2018.207 1092.496 999.4799 1190.129 952.0941 1243.697
## 2018.211 1095.336 1001.2976 1194.084 953.4069 1248.280
## 2018.215 1083.729 989.3838 1182.868 941.3649 1237.306
## 2018.219 1089.381 993.8916 1189.758 945.3042 1244.889
## 2018.223 1090.584 994.1767 1191.969 945.1399 1247.672
## 2018.227 1087.122 990.0405 1189.272 940.6819 1245.415
## 2018.231 1080.806 983.2064 1183.560 933.6087 1240.059
## 2018.235 1090.611 991.6761 1194.795 941.4098 1252.091
## 2018.239 1096.775 996.6946 1202.200 945.8592 1260.190
## 2018.243 1088.234 987.7783 1194.121 936.7783 1252.390
## 2018.247 1089.393 988.0648 1196.243 936.6395 1255.060
## 2018.251 1093.750 991.3856 1201.729 939.4489 1261.182
## 2018.255 1100.081 996.5780 1209.292 944.0765 1269.435
## 2018.259 1104.599 1000.0578 1214.942 947.0439 1275.723
## 2018.263 1106.190 1000.7719 1217.501 947.3302 1278.833
## 2018.267 1104.412 998.3052 1216.501 944.5349 1278.281
## 2018.271 1103.425 996.5946 1216.328 942.4770 1278.576
## 2018.275 1101.268 993.7854 1214.913 939.3582 1277.590
## 2018.279 1106.135 997.6160 1220.910 942.6776 1284.224
## 2018.283 1105.036 995.8178 1220.600 940.5450 1284.369
## 2018.287 1100.873 991.1350 1217.044 935.6224 1281.170
## 2018.291 1102.559 991.9782 1219.666 936.0556 1284.325
## 2018.295 1105.150 993.6770 1223.240 937.3195 1288.457
## 2018.299 1107.267 994.9338 1226.309 938.1575 1292.069
## 2018.303 1112.016 998.6736 1232.162 941.4004 1298.544
## 2018.307 1114.812 1000.5761 1235.944 942.8670 1302.886
## 2018.311 1114.815 999.8520 1236.764 941.7944 1304.176
## 2018.315 1116.240 1000.4714 1239.086 942.0239 1307.011
## 2018.319 1114.303 997.9326 1237.841 939.2020 1306.169
## 2018.323 1111.671 994.7469 1235.853 935.7582 1304.557
## 2018.327 1112.759 995.0626 1237.803 935.7021 1307.002
## 2018.331 1113.163 994.7407 1239.024 935.0320 1308.693
## 2018.335 1113.429 994.2935 1240.095 934.2433 1310.227
## 2018.339 1108.975 989.4199 1236.149 929.1821 1306.585
## 2018.343 1114.906 994.2976 1243.227 933.5406 1314.310
## 2018.347 1112.389 991.2521 1241.328 930.2505 1312.774
## 2018.351 1100.177 979.1235 1229.113 918.1984 1300.591
## 2018.355 1094.925 973.5323 1224.288 912.4616 1296.027
## 2018.359 1098.643 976.3488 1229.000 914.8383 1301.305
## 2018.363 1100.429 977.3579 1231.654 915.4730 1304.457
## 2018.367 1097.919 974.3500 1229.732 912.2365 1302.881
## 2018.371 1091.621 967.8040 1223.767 905.5932 1297.128
## 2018.375 1096.893 972.0849 1230.124 909.3873 1304.100
## 2018.378 1095.811 970.4265 1229.708 907.4596 1304.072
## 2018.382 1101.040 974.6704 1236.017 911.2199 1310.993
## 2018.386 1101.143 974.1258 1236.859 910.3686 1312.262
## 2018.390 1093.467 966.3212 1229.396 902.5289 1304.947
## 2018.394 1085.341 958.1063 1221.441 894.3001 1297.117
## 2018.398 1082.663 954.9837 1219.297 890.9769 1295.291
## 2018.402 1087.643 959.0067 1225.329 894.5311 1301.920
## 2018.406 1086.542 957.3606 1224.861 892.6324 1301.824
## 2018.410 1086.098 956.3315 1225.093 891.3293 1302.450
## 2018.414 1079.549 949.6197 1218.790 884.5648 1296.313
## 2018.418 1082.022 951.3154 1222.134 885.8859 1300.155
## 2018.422 1081.563 950.2836 1222.337 884.5867 1300.747
## 2018.426 1092.773 960.1135 1235.029 893.7264 1314.264
## 2018.430 1104.346 970.2804 1248.110 903.1897 1328.185
## 2018.434 1108.668 973.6992 1253.430 906.1681 1334.073
## 2018.438 1109.737 974.0922 1255.266 906.2400 1336.353
## 2018.442 1112.909 976.4437 1259.353 908.1945 1340.962
## 2018.446 1147.418 1007.9447 1296.996 938.1531 1380.314
## 2018.450 1149.541 1009.3157 1299.964 939.1629 1383.769
## 2018.454 1152.864 1011.8035 1304.215 941.2466 1388.550
## 2018.458 1154.905 1013.1016 1307.093 942.1882 1391.909
## 2018.462 1145.035 1003.3301 1297.205 932.5010 1382.046
## 2018.466 1138.743 996.8933 1291.143 926.0211 1376.139
## 2018.470 1139.550 997.0553 1292.687 925.8780 1378.112
## 2018.474 1131.946 989.4131 1285.205 918.2483 1370.728
## 2018.478 1132.096 988.9715 1286.036 917.5300 1371.958
## 2018.482 1127.988 984.5844 1282.293 913.0294 1368.445
## 2018.486 1132.358 988.0620 1287.652 916.0726 1374.365
## 2018.490 1135.417 990.3250 1291.601 917.9515 1378.825
## 2018.494 1130.232 984.9504 1286.692 912.5101 1374.096
## 2018.498 1132.587 986.5642 1289.880 913.7690 1377.765
## 2018.502 1128.278 982.0099 1285.903 909.1187 1373.999
## 2018.506 1131.352 984.2939 1289.862 911.0220 1378.465
## 2018.510 1129.063 981.6160 1288.050 908.1732 1376.942
## 2018.514 1134.379 985.9766 1294.419 912.0666 1383.907
## 2018.518 1135.287 986.2597 1296.042 912.0559 1385.948
## 2018.522 1127.771 978.7579 1288.595 904.5938 1378.571
## 2018.526 1128.621 978.9941 1290.151 904.5414 1380.539
## 2018.530 1134.782 984.1380 1297.426 909.1863 1388.444
## 2018.534 1132.286 981.2860 1295.375 906.1804 1386.664
## 2018.538 1135.833 984.0175 1299.833 908.5179 1391.644
## 2018.542 1125.972 974.3728 1289.834 899.0188 1381.606
## 2018.546 1113.572 962.3976 1277.086 887.2981 1368.704
## 2018.550 1102.322 951.4957 1265.564 876.6107 1357.070
## 2018.554 1102.012 950.6827 1265.846 875.5674 1357.704
## 2018.558 1113.250 960.5102 1278.601 884.6899 1371.303
## 2018.562 1113.081 959.8282 1279.034 883.7723 1372.093
## 2018.566 1108.499 955.0861 1274.698 878.9788 1367.922
## 2018.570 1107.993 954.0996 1274.762 877.7738 1368.325
## 2018.574 1104.561 950.4238 1271.660 874.0029 1365.434
## 2018.578 1111.748 956.5189 1280.040 879.5597 1374.486
## 2018.582 1113.356 957.4821 1282.385 880.2184 1377.260
## 2018.586 1113.144 956.7728 1282.760 879.2819 1377.983
## 2018.590 1114.751 957.7380 1285.103 879.9440 1380.753
## 2018.594 1115.450 957.8694 1286.460 879.8114 1382.497
## 2018.598 1116.589 958.4068 1288.293 880.0669 1384.736
## 2018.602 1109.072 950.9968 1280.750 872.7451 1377.212
## 2018.606 1109.776 951.1388 1282.107 872.6263 1378.952
## 2018.610 1112.550 953.1823 1285.705 874.3207 1383.026
## 2018.614 1116.767 956.5510 1290.868 877.2785 1388.729
## 2018.618 1118.665 957.7919 1293.516 878.2087 1391.813
## 2018.622 1115.636 954.5154 1290.822 874.8351 1389.332
## 2018.625 1110.387 949.2072 1285.716 869.5285 1384.335
## 2018.629 1107.123 945.7233 1282.758 865.9619 1381.575
## 2018.633 1111.251 949.0132 1287.819 868.8470 1387.171
## 2018.637 1110.517 947.8516 1287.604 867.4940 1387.267
## 2018.641 1104.799 942.1287 1281.973 861.8010 1381.716
## 2018.645 1094.003 931.7659 1270.818 851.6968 1370.403
## 2018.649 1097.312 934.3117 1274.986 853.8764 1375.065
## 2018.653 1104.275 940.1990 1283.126 859.2345 1383.869
## 2018.657 1102.743 938.3180 1282.031 857.2037 1383.042
## 2018.661 1109.899 944.3810 1290.380 862.7287 1392.065
## 2018.665 1110.504 944.4555 1291.607 862.5587 1393.659
## 2018.669 1106.331 940.1659 1287.635 858.2405 1389.829
## 2018.673 1106.426 939.7789 1288.304 857.6340 1390.839
## 2018.677 1107.870 940.6241 1290.439 858.1993 1393.378
## 2018.681 1105.939 938.3900 1288.899 855.8392 1392.081
## 2018.685 1107.583 939.4203 1291.249 856.5818 1394.844
## 2018.689 1108.371 939.6706 1292.667 856.5839 1396.632
## 2018.693 1111.514 942.0712 1296.650 858.6289 1401.099
## 2018.697 1110.101 940.3159 1295.667 856.7275 1400.381
## 2018.701 1121.520 950.2635 1308.665 865.9400 1414.259
## 2018.705 1124.873 952.8550 1312.875 868.1665 1418.963
## 2018.709 1124.976 952.4835 1313.544 867.5798 1419.969
## 2018.713 1128.063 954.8332 1317.464 869.5772 1424.369
## 2018.717 1128.440 954.7133 1318.429 869.2305 1425.684
## 2018.721 1137.263 962.2919 1328.603 876.1918 1436.615
## 2018.725 1138.449 962.9093 1330.449 876.5452 1438.850
## 2018.729 1142.086 965.7613 1334.969 879.0199 1443.876
## 2018.733 1140.697 964.0344 1334.006 877.1494 1443.175
## 2018.737 1141.410 964.2243 1335.334 877.0988 1444.868
## 2018.741 1151.141 972.6259 1346.501 884.8394 1456.838
## 2018.745 1149.266 970.4594 1345.005 882.5535 1455.580
## 2018.749 1147.257 968.1743 1343.361 880.1563 1454.166
## 2018.753 1143.774 964.5496 1340.105 876.4903 1451.064
## 2018.757 1139.978 960.6436 1336.503 872.5595 1447.600
## 2018.761 1141.903 961.9429 1339.149 873.5646 1450.667
## 2018.765 1144.583 963.9286 1342.619 875.2205 1454.594
## 2018.769 1150.846 969.1706 1350.003 879.9628 1462.614
## 2018.773 1153.288 970.9403 1353.213 881.4142 1466.270
## 2018.777 1140.670 959.0291 1339.959 869.9038 1452.708
## 2018.781 1131.814 950.5439 1330.806 861.6447 1443.430
## 2018.785 1125.434 944.3143 1324.357 855.5256 1436.977
## 2018.789 1128.372 946.5401 1328.103 857.4124 1441.191
## 2018.793 1131.957 949.3527 1332.557 859.8547 1446.146
## 2018.797 1136.150 952.7164 1337.677 862.8186 1451.797
## 2018.801 1134.593 950.8672 1336.501 860.8494 1450.859
## 2018.805 1138.043 953.5578 1340.807 863.1766 1455.658
## 2018.809 1141.158 955.9449 1344.746 865.2167 1460.073
## 2018.813 1139.220 953.7538 1343.149 862.9259 1458.693
## 2018.817 1140.651 954.6160 1345.242 863.5242 1461.175
## 2018.821 1139.376 953.0287 1344.368 861.8063 1460.551
## 2018.825 1142.767 955.6675 1348.609 864.0855 1465.281
## 2018.829 1130.849 944.4497 1336.059 853.2652 1452.426
## 2018.833 1125.678 939.3456 1330.903 848.2280 1447.312
## 2018.837 1122.580 936.1199 1328.018 844.9680 1444.575
## 2018.841 1122.625 935.7369 1328.581 844.3946 1445.450
## 2018.845 1126.067 938.4258 1332.874 846.7232 1450.234
## 2018.849 1126.160 938.0877 1333.488 846.1930 1451.161
## 2018.853 1128.938 940.1768 1337.052 847.9554 1455.180
## 2018.857 1126.533 937.5847 1334.920 845.2981 1453.229
## 2018.861 1128.997 939.3907 1338.137 846.7938 1456.885
## 2018.865 1123.312 933.8416 1332.397 841.3476 1451.148
## 2018.869 1132.431 941.6557 1342.930 848.5142 1462.474
## 2018.873 1133.366 942.0822 1344.464 848.7085 1464.365
## 2018.876 1134.254 942.4677 1345.948 848.8645 1466.201
## 2018.880 1143.559 950.4480 1356.686 856.1870 1477.744
## 2018.884 1145.573 951.8490 1359.408 857.3013 1480.879
## 2018.888 1143.100 949.2038 1357.195 854.5983 1478.839
## 2018.892 1141.773 947.5933 1356.240 852.8726 1478.117
## 2018.896 1142.197 947.5630 1357.209 852.6381 1479.414
## 2018.900 1145.078 949.7480 1360.883 854.4931 1483.547
## 2018.904 1138.431 943.3484 1354.067 848.2543 1476.675
## 2018.908 1131.799 936.9673 1347.262 842.0361 1469.810
## 2018.912 1121.195 927.0170 1336.073 832.4588 1458.340
## 2018.916 1128.372 933.0715 1344.478 837.9610 1467.439
## 2018.920 1131.032 935.0610 1347.905 839.6338 1471.312
## 2018.924 1127.103 931.1237 1344.066 835.7246 1467.556
## 2018.928 1128.352 931.8454 1345.936 836.2041 1469.793
## 2018.932 1127.750 930.9038 1345.763 835.1178 1469.885
## 2018.936 1134.055 936.1721 1353.210 839.8785 1477.978
## 2018.940 1127.913 930.2522 1346.923 834.1067 1471.648
## 2018.944 1131.036 932.6606 1350.859 836.1752 1476.054
## 2018.948 1130.443 931.7301 1350.692 835.1016 1476.150
## 2018.952 1132.469 933.1529 1353.416 836.2428 1479.283
## 2018.956 1137.130 936.9432 1359.050 839.6118 1485.473
## 2018.960 1141.096 940.1085 1363.916 842.3926 1490.856
## 2018.964 1145.545 943.7069 1369.315 845.5809 1496.800
## 2018.968 1146.475 944.1463 1370.829 845.7971 1498.662
## 2018.972 1147.706 944.8557 1372.675 846.2675 1500.871
## 2018.976 1139.408 937.0156 1363.992 838.6981 1492.016
## 2018.980 1152.524 948.3911 1378.968 849.1999 1508.025
## 2018.984 1165.588 959.7221 1393.885 859.6612 1523.971
## 2018.988 1154.688 949.5457 1382.328 849.8939 1512.096
## 2018.992 1154.528 949.0101 1382.635 849.1951 1512.687
## 2018.996 1143.569 938.7940 1370.999 839.3982 1500.722
## 2019.000 1141.198 936.2814 1368.856 836.8441 1498.735
## 2019.004 1119.204 916.2038 1344.988 817.7957 1473.894
## 2019.008 1100.457 899.0578 1324.687 801.5148 1452.792
checkresiduals(fct.stlf.GOOGL.train)
## Warning in checkresiduals(fct.stlf.GOOGL.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,N,N)
## Q* = 443.5, df = 249.2, p-value = 0.000000000000449
##
## Model df: 2. Total lags used: 251.2
#NFLX Data Analysis
#Subsetting the NFLX dataset
NFLX.df<- subset(raw.data,Name=="NFLX" ,stringsAsFactors =FALSE )
str(NFLX.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 26 25.6 25.8 25.8 26.8 ...
## $ high : num 26.3 26 26.2 26.6 27.1 ...
## $ low : num 25.7 25 25.1 25.7 26.4 ...
## $ close : num 25.9 25.4 25.4 26.6 26.8 ...
## $ volume: int 25649820 29321782 34388802 40799094 31968685 26651786 34126330 34992125 36822583 38841173 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 335 335 335 335 335 335 335 335 335 335 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(NFLX.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
NFLX.close<-NFLX.df[,5]
#Creating the time series
NFLX.close.full.ts <- ts(NFLX.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
NFLX.close.ts <- ts(NFLX.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
NFLX.test.close.ts <- ts(NFLX.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(NFLX.close.full.ts)+
ggtitle("NFLX stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(NFLX.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(NFLX.close.full.ts)

length(NFLX.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(NFLX.close.full.ts)

acf.NFLX.close.ts <- acf(NFLX.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.NFLX.close.ts, type="o",main="Correlogram for NFLX stock closing price")

#Decomposition of time series components
stl.NFLX.close.ts <- stl(NFLX.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.NFLX.close.ts) +
ggtitle("NFLX stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(NFLX.close.full.ts, series="Data") +
autolayer(trendcycle(stl.NFLX.close.ts), series="Trend") +
autolayer(seasadj(stl.NFLX.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of NFLX stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.NFLX.train <- stlf(NFLX.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.NFLX.train <- stlf(NFLX.close.full.ts, h = length(NFLX.close.full.ts) , lambda = BoxCox.lambda(NFLX.close.full.ts))
naive.NFLX.train <- rwf(NFLX.close.full.ts,h = length(NFLX.close.full.ts))
ets.stlf.NFLX.train <- stlf(NFLX.close.full.ts, t.window = 13, s.window = "periodic", h = length(NFLX.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(NFLX.close.full.ts))
fct.ets.NFLX.train <- forecast(ets.NFLX.train, h = 252)
fct.stlf.NFLX.train <- forecast(stlf.NFLX.train, h = 252)
fct.naive.NFLX.train <- forecast(naive.NFLX.train, h = 252)
fct.ets.stlf.NFLX.train <- forecast(ets.stlf.NFLX.train, h = 252)
accuracy(fct.ets.NFLX.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1920541 2.596554 1.637497 0.1525287 1.98587 0.04526601
## ACF1
## Training set 0.1011783
accuracy(fct.stlf.NFLX.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01170198 2.35084 1.474051 -0.04412423 1.646918 0.0407478
## ACF1
## Training set 0.09369108
accuracy(fct.naive.NFLX.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1924918 2.592001 1.561829 0.1499934 1.745104 0.04317429
## ACF1
## Training set 0.08752539
accuracy(fct.ets.stlf.NFLX.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1579472 2.82128 1.670525 0.1042289 1.873435 0.046179
## ACF1
## Training set 0.07235613
autoplot(NFLX.close.full.ts) +
autolayer(ets.NFLX.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.NFLX.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.NFLX.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.NFLX.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("NFLX Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.NFLX.train %>% forecast(h=252) %>%
autoplot() +
autolayer(NFLX.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.NFLX.train[["model"]]
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9985
## beta = 0.0001
##
## Initial states:
## l = 5.0078
## b = 0.0061
##
## sigma: 0.0735
##
## AIC AICc BIC
## 2409.317 2409.365 2434.995
summary(fct.stlf.NFLX.train)
##
## Forecast method: STL + ETS(A,A,N)
##
## Model Information:
## ETS(A,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9985
## beta = 0.0001
##
## Initial states:
## l = 5.0078
## b = 0.0061
##
## sigma: 0.0735
##
## AIC AICc BIC
## 2409.317 2409.365 2434.995
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.01170198 2.35084 1.474051 -0.04412423 1.646918 0.0407478
## ACF1
## Training set 0.09369108
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 251.7742 245.9640 257.6864 242.9292 260.8577
## 2018.012 255.5221 247.2493 264.0000 242.9519 268.5721
## 2018.016 257.6722 247.5063 268.1469 242.2477 273.8190
## 2018.020 257.3812 245.6806 269.4933 239.6501 276.0748
## 2018.024 259.1735 246.0506 272.8125 239.3082 280.2460
## 2018.028 260.7327 246.3188 275.7677 238.9342 283.9841
## 2018.032 261.4024 245.8297 277.7006 237.8724 286.6297
## 2018.036 260.4532 243.8767 277.8575 235.4277 287.4151
## 2018.040 259.0547 241.5694 277.4690 232.6784 287.6039
## 2018.044 261.1126 242.5965 280.6650 233.2015 291.4476
## 2018.048 261.2583 241.8555 281.8014 232.0312 293.1526
## 2018.052 263.0131 242.6700 284.6044 232.3897 296.5562
## 2018.056 265.2542 243.9695 287.8969 233.2330 300.4520
## 2018.060 264.5973 242.5754 288.0800 231.4880 301.1236
## 2018.064 263.5412 240.8399 287.8046 229.4316 301.3049
## 2018.068 265.8254 242.2510 291.0734 230.4232 305.1425
## 2018.072 265.3815 241.1369 291.4030 228.9938 305.9259
## 2018.076 263.9149 239.0963 290.6099 226.6870 305.5322
## 2018.080 264.5834 239.0603 292.0898 226.3188 307.4876
## 2018.084 260.9294 235.0416 288.8908 222.1411 304.5685
## 2018.088 260.2505 233.7998 288.8759 220.6396 304.9488
## 2018.092 262.3474 235.1334 291.8490 221.6119 308.4343
## 2018.096 261.9306 234.1626 292.0886 220.3864 309.0657
## 2018.100 260.5378 232.3108 291.2523 218.3284 308.5664
## 2018.104 260.2260 231.4670 291.5749 217.2414 309.2694
## 2018.108 259.0461 229.8422 290.9377 215.4177 308.9621
## 2018.112 261.1296 231.2118 293.8498 216.4527 312.3626
## 2018.116 261.4782 231.0043 294.8605 215.9906 313.7699
## 2018.120 261.1527 230.1924 295.1237 214.9594 314.3895
## 2018.124 258.7943 227.5444 293.1452 212.1915 312.6517
## 2018.127 258.7834 227.0415 293.7299 211.4667 313.5971
## 2018.131 257.4567 225.3559 292.8574 209.6265 313.0070
## 2018.135 255.5676 223.1742 291.3519 207.3236 311.7449
## 2018.139 255.4153 222.5729 291.7508 206.5225 312.4803
## 2018.143 256.8984 223.4528 293.9505 207.1253 315.1091
## 2018.147 256.2829 222.4478 293.8234 205.9508 315.2843
## 2018.151 255.9686 221.7220 294.0218 205.0444 315.7986
## 2018.155 257.2069 222.3961 295.9369 205.4616 318.1215
## 2018.159 255.5562 220.4857 294.6367 203.4470 317.0473
## 2018.163 256.5726 220.9709 296.2956 203.6922 319.0954
## 2018.167 258.3263 222.1180 298.7736 204.5618 322.0084
## 2018.171 258.6991 222.0347 299.7095 204.2766 323.2898
## 2018.175 258.1651 221.1481 299.6274 203.2397 323.4912
## 2018.179 258.8638 221.3646 300.9182 203.2415 325.1440
## 2018.183 261.8350 223.6041 304.7516 205.1420 329.4911
## 2018.187 261.6489 223.0395 305.0468 204.4147 330.0870
## 2018.191 268.5365 228.7525 313.2770 209.5690 339.1009
## 2018.195 270.8361 230.3923 316.3637 210.9066 342.6605
## 2018.199 272.5147 231.4822 318.7533 211.7300 345.4805
## 2018.203 271.4583 230.1552 318.0642 210.2947 345.0293
## 2018.207 269.4036 227.9537 316.2426 208.0464 343.3701
## 2018.211 268.0639 226.3916 315.2180 206.4000 342.5542
## 2018.215 267.2093 225.2637 314.7339 205.1625 342.3101
## 2018.219 266.2607 224.0589 314.1373 203.8567 341.9431
## 2018.223 269.2035 226.2770 317.9421 205.7418 346.2647
## 2018.227 267.8163 224.6948 316.8410 204.0890 345.3565
## 2018.231 269.6992 225.9841 319.4444 205.1106 348.3977
## 2018.235 269.7223 225.6456 319.9359 204.6192 349.1851
## 2018.239 272.3578 227.5944 323.3946 206.2548 353.1402
## 2018.243 270.5730 225.6810 321.8246 204.3038 351.7234
## 2018.247 269.3374 224.2538 320.8727 202.8080 350.9636
## 2018.251 270.6211 225.0270 322.7889 203.3553 353.2691
## 2018.255 272.8101 226.5888 325.7383 204.6339 356.6805
## 2018.259 276.7842 229.7027 330.7287 207.3501 362.2778
## 2018.263 278.6249 230.9591 333.2845 208.3450 365.2706
## 2018.267 279.3841 231.2762 334.6037 208.4707 366.9393
## 2018.271 276.7972 228.6930 332.0886 205.9154 364.4974
## 2018.275 280.4451 231.5186 336.7142 208.3629 369.7093
## 2018.279 282.7450 233.1744 339.7971 209.7284 373.2688
## 2018.283 282.7012 232.8018 340.1907 209.2207 373.9432
## 2018.287 282.8405 232.5902 340.7921 208.8632 374.8396
## 2018.291 283.2860 232.6453 341.7433 208.7530 376.1108
## 2018.295 286.5381 235.1227 345.9244 210.8769 380.8522
## 2018.299 285.5501 233.9437 345.2237 209.6307 380.3478
## 2018.303 288.7472 236.3718 349.3448 211.7084 385.0271
## 2018.307 291.8369 238.7054 353.3450 213.6982 389.5782
## 2018.311 295.5444 241.5685 358.0612 216.1744 394.9013
## 2018.315 295.4914 241.1970 358.4375 215.6740 395.5556
## 2018.319 295.5578 240.9307 358.9496 215.2716 396.3551
## 2018.323 295.2169 240.3172 358.9881 214.5516 396.6434
## 2018.327 295.2512 240.0279 359.4583 214.1311 397.3956
## 2018.331 296.3096 240.6174 361.1136 214.5182 399.4249
## 2018.335 295.9622 240.0052 361.1377 213.8035 399.6946
## 2018.339 296.8638 240.4627 362.6094 214.0711 401.5254
## 2018.343 297.1623 240.4063 363.3800 213.8683 402.5992
## 2018.347 296.8260 239.8100 363.4105 213.1721 402.8732
## 2018.351 292.4224 235.7528 358.7015 209.3104 398.0239
## 2018.355 291.6552 234.7988 358.2200 208.2919 397.7395
## 2018.359 294.3958 236.8287 361.8281 210.0024 401.8774
## 2018.363 294.7116 236.7975 362.6081 209.8291 402.9567
## 2018.367 293.8876 235.8009 362.0547 208.7751 402.5922
## 2018.371 292.4167 234.2594 360.7411 207.2258 401.4027
## 2018.375 293.6058 234.9739 362.5370 207.7363 403.5799
## 2018.378 291.5973 232.9839 360.5864 205.7818 401.6967
## 2018.382 292.6608 233.5945 362.2332 206.1991 403.7117
## 2018.386 292.5301 233.1972 362.4785 205.6988 404.2067
## 2018.390 290.8935 231.5318 360.9527 204.0459 402.7786
## 2018.394 290.0573 230.5452 360.3630 203.0127 402.3645
## 2018.398 292.4864 232.3098 363.6129 204.4819 406.1194
## 2018.402 294.4456 233.6777 366.3118 205.5900 409.2770
## 2018.406 294.7136 233.6229 367.0197 205.4055 410.2720
## 2018.410 297.4879 235.6748 370.6812 207.1345 414.4774
## 2018.414 296.9982 234.9846 370.4955 206.3738 414.5010
## 2018.418 295.1159 233.1288 368.6630 204.5574 412.7317
## 2018.422 295.7508 233.3864 369.8000 204.6591 414.1920
## 2018.426 300.6107 237.1827 375.9315 207.9683 421.0893
## 2018.430 303.4825 239.3114 379.7162 209.7650 425.4341
## 2018.434 304.4879 239.8767 381.2957 210.1447 427.3790
## 2018.438 305.6961 240.6116 383.1155 210.6781 429.5858
## 2018.442 314.1927 247.4403 393.5645 216.7291 441.1935
## 2018.446 315.3376 248.1181 395.3153 217.2088 443.3289
## 2018.450 314.3467 247.0119 394.5360 216.0744 442.7073
## 2018.454 312.6775 245.3428 392.9488 214.4324 441.2030
## 2018.458 312.3160 244.7676 392.9094 213.7815 441.3849
## 2018.462 310.9375 243.3474 391.6595 212.3683 440.2450
## 2018.466 311.8749 243.8574 393.1596 212.6997 442.1053
## 2018.470 311.5290 243.3007 393.1330 212.0686 442.2987
## 2018.474 313.4983 244.6691 395.8611 213.1751 445.5004
## 2018.478 315.7381 246.2612 398.9126 214.4831 449.0564
## 2018.482 315.0361 245.4109 398.4604 213.5886 448.7845
## 2018.486 316.5593 246.4078 400.6596 214.3598 451.4101
## 2018.490 317.3733 246.8164 402.0135 214.6010 453.1121
## 2018.494 321.2745 249.7826 407.0527 217.1457 458.8450
## 2018.498 321.7646 249.9218 408.0221 217.1440 460.1279
## 2018.502 324.6436 252.0385 411.8454 218.9224 464.5334
## 2018.506 325.7393 252.6785 413.5396 219.3713 466.6103
## 2018.510 325.8732 252.5235 414.0840 219.1053 467.4289
## 2018.514 323.9977 250.7103 412.2221 217.3495 465.6118
## 2018.518 322.9178 249.5573 411.3088 216.1890 464.8316
## 2018.522 322.1819 248.6906 410.8048 215.2869 464.4986
## 2018.526 324.6720 250.4827 414.1689 216.7725 468.4056
## 2018.530 325.4974 250.9031 415.5371 217.0265 470.1252
## 2018.534 325.6381 250.7603 416.0832 216.7757 470.9431
## 2018.538 326.1445 250.9192 417.0680 216.7959 472.2421
## 2018.542 320.2723 245.8412 410.3789 212.1247 465.1164
## 2018.546 317.7911 243.5551 407.7598 209.9589 462.4540
## 2018.550 314.6411 240.7264 404.3279 207.3106 458.8951
## 2018.554 317.5666 242.8739 408.2210 209.1141 463.3867
## 2018.558 321.6692 245.9832 413.5367 211.7768 469.4435
## 2018.562 326.6015 249.7696 419.8560 215.0441 476.6053
## 2018.566 325.8219 248.8817 419.2842 214.1319 476.1916
## 2018.570 325.4071 248.2939 419.1510 213.4890 476.2591
## 2018.574 322.1883 245.4191 415.6249 210.8054 472.5917
## 2018.578 324.1071 246.7391 418.3101 211.8676 475.7596
## 2018.582 321.9223 244.7139 416.0278 209.9456 473.4578
## 2018.586 321.4726 244.1052 415.8436 209.2885 473.4652
## 2018.590 322.7547 244.9069 417.7581 209.8890 475.7849
## 2018.594 326.2848 247.5367 422.4001 212.1180 481.1116
## 2018.598 325.8476 246.9390 422.2310 211.4714 481.1360
## 2018.602 322.3030 243.8197 418.2855 208.5813 476.9942
## 2018.606 322.6843 243.8910 419.1056 208.5326 478.1073
## 2018.610 323.8234 244.5772 420.8472 209.0310 480.2375
## 2018.614 326.9167 246.8470 424.9671 210.9373 484.9934
## 2018.618 327.1835 246.8250 425.6492 210.8058 485.9553
## 2018.622 328.2142 247.4222 427.2612 211.2247 487.9441
## 2018.625 324.6584 244.3093 423.2837 208.3490 483.7581
## 2018.629 324.8067 244.1952 423.8177 208.1377 484.5548
## 2018.633 323.4633 242.8773 422.5298 206.8592 483.3369
## 2018.637 328.0785 246.3703 428.5170 209.8480 490.1629
## 2018.641 327.3708 245.5660 428.0054 209.0254 489.8038
## 2018.645 322.0386 241.0378 421.8358 204.9046 483.1825
## 2018.649 324.8211 243.0494 425.5885 206.5788 487.5400
## 2018.653 327.9924 245.3727 429.8190 208.5285 492.4276
## 2018.657 328.7796 245.7762 431.1328 208.7778 494.0872
## 2018.661 331.6090 247.8221 434.9482 210.4809 498.5174
## 2018.665 334.4324 249.8619 438.7583 212.1780 502.9428
## 2018.669 331.5416 247.3082 435.5665 209.8109 499.6132
## 2018.673 335.0490 249.8959 440.2179 211.9919 504.9724
## 2018.677 342.3912 255.5632 449.5731 216.8960 515.5441
## 2018.681 341.6106 254.7034 448.9713 216.0265 515.0857
## 2018.685 341.6005 254.4635 449.3131 215.7061 515.6724
## 2018.689 338.5288 251.7700 445.8936 213.2186 512.0879
## 2018.693 338.3000 251.3582 445.9628 212.7483 512.3703
## 2018.697 326.4431 241.6503 431.7145 204.0801 496.7585
## 2018.701 327.1180 241.9687 432.8868 204.2578 498.2608
## 2018.705 330.8925 244.7607 437.8817 206.6147 504.0100
## 2018.709 336.0770 248.6772 444.6168 209.9618 511.6933
## 2018.713 337.4610 249.5583 446.6685 210.6338 514.1755
## 2018.717 338.7755 250.3835 448.6353 211.2564 516.5640
## 2018.721 341.8452 252.6082 452.7687 213.1112 521.3607
## 2018.725 340.9014 251.6318 451.9506 212.1471 520.6553
## 2018.729 343.8356 253.7464 455.9198 213.9042 525.2714
## 2018.733 343.0259 252.8779 455.2664 213.0358 524.7489
## 2018.737 343.5284 253.0552 456.2333 213.0880 526.0278
## 2018.741 348.9324 257.1326 463.2599 216.5702 534.0471
## 2018.745 347.7474 255.9658 462.1429 215.4399 533.0095
## 2018.749 347.2832 255.3740 461.9154 214.8160 532.9605
## 2018.753 348.8200 256.3727 464.1640 215.5901 535.6671
## 2018.757 348.5096 255.9042 464.1257 215.0754 535.8285
## 2018.761 349.9543 256.8293 466.2615 215.7847 538.4104
## 2018.765 349.8784 256.5479 466.5131 215.4348 538.8943
## 2018.769 348.9590 255.5987 465.7174 214.4997 538.2112
## 2018.773 348.6025 255.0970 465.6186 213.9579 538.3038
## 2018.777 342.7179 250.2241 458.6486 209.5865 530.7342
## 2018.781 340.5234 248.2759 456.2565 207.7812 528.2651
## 2018.785 343.6218 250.5087 460.4491 209.6366 533.1422
## 2018.789 346.4250 252.5074 464.2763 211.2866 537.6124
## 2018.793 346.0105 251.9655 464.0989 210.7130 537.6145
## 2018.797 348.4064 253.6411 467.4217 212.0796 541.5235
## 2018.801 348.5509 253.5405 467.9405 211.8922 542.3030
## 2018.805 350.6991 255.0194 470.9571 213.0861 545.8716
## 2018.809 350.3777 254.5519 470.8954 212.5783 546.0032
## 2018.813 351.6497 255.3397 472.8210 213.1678 548.3545
## 2018.817 351.7756 255.2251 473.3168 212.9690 549.1087
## 2018.821 349.6928 253.3747 471.0532 211.2549 546.7785
## 2018.825 353.6149 256.2454 476.2905 213.6629 552.8326
## 2018.829 350.9582 253.9461 473.3073 211.5583 549.6968
## 2018.833 349.6544 252.7123 472.0118 210.3850 548.4463
## 2018.837 352.8563 255.0141 476.3539 212.2950 553.5026
## 2018.841 347.3952 250.5240 469.8494 208.2852 546.4214
## 2018.845 352.1322 254.0264 476.1180 211.2403 553.6359
## 2018.849 350.7005 252.6966 474.6574 209.9859 552.1986
## 2018.853 350.0001 251.9411 474.1116 209.2326 551.7844
## 2018.857 348.8417 250.8290 472.9891 208.1697 550.7235
## 2018.861 347.8028 249.8120 472.0145 207.1907 549.8272
## 2018.865 346.6620 248.7173 470.9097 206.1450 548.7838
## 2018.869 351.5119 252.2975 477.3358 209.1627 556.1837
## 2018.873 353.0657 253.3045 479.6200 209.9434 558.9410
## 2018.876 351.4538 251.8425 477.9233 208.5789 557.2345
## 2018.880 351.6089 251.7593 478.4479 208.4128 558.0186
## 2018.884 349.9464 250.2615 476.6828 207.0193 556.2332
## 2018.888 352.8474 252.3166 480.6659 208.7096 560.8983
## 2018.892 350.9514 250.6391 478.6043 207.1612 558.7793
## 2018.896 351.5880 250.9323 479.7345 207.3228 560.2427
## 2018.900 353.4496 252.1772 482.4105 208.3096 563.4425
## 2018.904 349.9909 249.2906 478.3709 205.7159 559.0990
## 2018.908 351.8560 250.5379 481.0523 206.7046 562.3054
## 2018.912 346.3221 246.0493 474.3803 202.7279 554.9983
## 2018.916 347.5991 246.8412 476.3179 203.3228 557.3688
## 2018.920 355.3183 252.6223 486.4068 208.2343 568.9058
## 2018.924 355.7384 252.7478 487.2644 208.2513 570.0644
## 2018.928 354.2699 251.4116 485.7316 207.0042 568.5344
## 2018.932 355.9512 252.5139 488.1855 207.8665 571.4884
## 2018.936 356.1892 252.4994 488.8122 207.7630 572.3872
## 2018.940 351.9079 248.9938 483.7088 204.6438 566.8359
## 2018.944 353.2595 249.8413 485.7454 205.2861 569.3210
## 2018.948 356.6654 252.2739 490.3894 207.2968 574.7425
## 2018.952 359.7752 254.4771 494.6594 209.1090 579.7437
## 2018.956 365.9722 259.0635 502.8461 212.9791 589.1551
## 2018.960 373.6568 264.8003 512.9175 217.8437 600.6875
## 2018.964 373.6756 264.6119 513.2742 217.5881 601.2872
## 2018.968 375.1343 265.5360 515.4564 218.2937 603.9418
## 2018.972 386.0343 273.7564 529.6058 225.3037 620.0653
## 2018.976 383.3577 271.4808 526.5524 223.2427 616.8308
## 2018.980 388.2236 275.0350 533.0583 226.2194 624.3544
## 2018.984 390.0325 276.2258 535.6908 227.1535 627.5196
## 2018.988 393.3235 278.5611 540.2034 229.0762 632.8017
## 2018.992 391.7051 277.1033 538.4921 227.7221 631.0784
## 2018.996 387.9160 273.9735 534.0219 224.9261 626.2463
## 2019.000 385.4111 271.8388 531.1763 222.9913 623.2409
## 2019.004 380.1468 267.5843 524.8153 219.2317 616.2699
## 2019.008 359.7582 251.7394 499.1484 205.5083 587.4987
checkresiduals(fct.stlf.NFLX.train)
## Warning in checkresiduals(fct.stlf.NFLX.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,A,N)
## Q* = 349.98, df = 247.2, p-value = 0.00001798
##
## Model df: 4. Total lags used: 251.2
#GOOG Data Analysis
#Subsetting the GOOG dataset
GOOG.df<- subset(raw.data,Name=="GOOG" ,stringsAsFactors =FALSE )
str(GOOG.df)
## 'data.frame': 975 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 285 286 287 288 289 290 291 292 293 294 ...
## $ open : num 568 561 567 559 565 ...
## $ high : num 568 566 567 568 605 ...
## $ low : num 553 559 557 559 562 ...
## $ close : num 558 560 557 567 567 ...
## $ volume: int 13052 41003 10772 7932 146697 5087530 6377658 4389569 3152406 3324742 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 207 207 207 207 207 207 207 207 207 207 ...
## $ year : num 2014 2014 2014 2014 2014 ...
library(forecast)
#sample <- msts(GOOG.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
GOOG.close<-GOOG.df[,5]
#Creating the time series
GOOG.close.full.ts <- ts(GOOG.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
GOOG.close.ts <- ts(GOOG.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
GOOG.test.close.ts <- ts(GOOG.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(GOOG.close.full.ts)+
ggtitle("GOOG stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(GOOG.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(GOOG.close.full.ts)

length(GOOG.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(GOOG.close.full.ts)

acf.GOOG.close.ts <- acf(GOOG.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.GOOG.close.ts, type="o",main="Correlogram for GOOG stock closing price")

#Decomposition of time series components
stl.GOOG.close.ts <- stl(GOOG.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.GOOG.close.ts) +
ggtitle("GOOG stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(GOOG.close.full.ts, series="Data") +
autolayer(trendcycle(stl.GOOG.close.ts), series="Trend") +
autolayer(seasadj(stl.GOOG.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of GOOG stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.GOOG.train <- stlf(GOOG.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.GOOG.train <- stlf(GOOG.close.full.ts, h = length(GOOG.close.full.ts) , lambda = BoxCox.lambda(GOOG.close.full.ts))
naive.GOOG.train <- rwf(GOOG.close.full.ts,h = length(GOOG.close.full.ts))
ets.stlf.GOOG.train <- stlf(GOOG.close.full.ts, t.window = 13, s.window = "periodic", h = length(GOOG.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(GOOG.close.full.ts))
fct.ets.GOOG.train <- forecast(ets.GOOG.train, h = 252)
fct.stlf.GOOG.train <- forecast(stlf.GOOG.train, h = 252)
fct.naive.GOOG.train <- forecast(naive.GOOG.train, h = 252)
fct.ets.stlf.GOOG.train <- forecast(ets.stlf.GOOG.train, h = 252)
accuracy(fct.ets.GOOG.train)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.02392601 16.96513 7.281503 -0.03213411 1.103146 0.03547849
## ACF1
## Training set 0.05639984
accuracy(fct.stlf.GOOG.train)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.04191424 13.3363 6.873737 -0.02393818 1.008508 0.03349169
## ACF1
## Training set 0.05770366
accuracy(fct.naive.GOOG.train)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.02211952 16.69131 6.837415 -0.03328996 1.035052 0.03331471
## ACF1
## Training set 0.05967275
accuracy(fct.ets.stlf.GOOG.train)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.04113292 16.83418 7.193387 -0.03446748 1.065072 0.03504915
## ACF1
## Training set -0.00502353
autoplot(GOOG.close.full.ts) +
autolayer(ets.GOOG.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.GOOG.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.GOOG.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.GOOG.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("GOOG Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.GOOG.train %>% forecast(h=252) %>%
autoplot() +
autolayer(GOOG.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.GOOG.train[["model"]]
## ETS(M,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 0.9983
##
## sigma: 0
##
## AIC AICc BIC
## -17313.31 -17313.29 -17297.90
summary(fct.stlf.GOOG.train)
##
## Forecast method: STL + ETS(M,N,N)
##
## Model Information:
## ETS(M,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 0.9983
##
## sigma: 0
##
## AIC AICc BIC
## -17313.31 -17313.29 -17297.90
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.04191424 13.3363 6.873737 -0.02393818 1.008508 0.03349169
## ACF1
## Training set 0.05770366
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 521.5223 511.7434 531.6822 506.7137 537.2225
## 2018.012 525.9752 512.0208 540.7115 504.9294 548.8517
## 2018.016 528.0999 510.9756 546.4117 502.3525 556.6291
## 2018.020 526.0908 506.5628 547.1846 496.8008 559.0506
## 2018.024 524.2458 502.6573 547.7719 491.9334 561.1013
## 2018.028 520.4923 497.2645 545.9962 485.7883 560.5359
## 2018.032 521.6965 496.5841 549.4840 484.2447 565.4267
## 2018.036 525.5261 498.3847 555.7937 485.1216 573.2721
## 2018.040 527.7453 498.8113 560.2426 484.7426 579.1202
## 2018.044 525.3105 495.1735 559.3535 480.5784 579.2242
## 2018.048 524.6242 493.1844 560.3453 478.0196 581.2976
## 2018.052 526.6796 493.6800 564.4067 477.8313 586.6523
## 2018.056 527.6163 493.2389 567.1445 476.7935 590.5659
## 2018.060 530.6160 494.6365 572.2402 477.4967 597.0326
## 2018.064 526.4240 489.8346 568.9208 472.4511 594.3186
## 2018.068 528.2937 490.3316 572.6270 472.3631 599.2475
## 2018.072 525.7932 487.1043 571.1579 468.8419 598.4928
## 2018.076 525.5850 485.8894 572.3432 467.2097 600.6296
## 2018.080 529.6017 488.3027 578.5317 468.9442 608.2817
## 2018.084 527.5664 485.5917 577.4841 465.9660 607.9342
## 2018.088 529.4417 486.2215 581.0948 466.0802 612.7401
## 2018.092 529.5450 485.3761 582.5570 464.8509 615.1566
## 2018.096 527.9680 483.1476 581.9540 462.3689 615.2572
## 2018.100 523.5236 478.5561 577.8180 457.7426 611.3830
## 2018.104 525.9489 479.7285 582.0248 458.4031 616.8393
## 2018.108 526.0838 479.0069 583.4222 457.3421 619.1444
## 2018.112 521.7069 474.5727 579.2357 452.9115 615.1436
## 2018.116 522.9860 474.8420 581.9937 452.7773 618.9627
## 2018.120 525.6945 476.2939 586.5279 453.7230 624.8020
## 2018.124 529.4322 478.5863 592.3656 455.4322 632.1435
## 2018.127 533.1464 480.8512 598.2038 457.1155 639.5138
## 2018.131 533.3461 480.2596 599.6265 456.2209 641.8511
## 2018.135 534.0432 480.0830 601.6688 455.7080 644.8983
## 2018.139 534.0648 479.3720 602.8442 454.7207 646.9494
## 2018.143 533.3708 478.0989 603.0924 453.2355 647.9276
## 2018.147 535.0096 478.7096 606.3167 453.4494 652.3424
## 2018.151 536.7205 479.3810 609.6397 453.7211 656.8825
## 2018.155 536.7290 478.7014 610.7646 452.7873 658.8755
## 2018.159 538.7109 479.5972 614.4448 453.2674 663.8483
## 2018.163 540.3512 480.2237 617.6897 453.5094 668.3260
## 2018.167 538.4108 478.0318 616.2467 451.2436 667.3149
## 2018.171 542.7184 480.7662 622.9979 453.3697 675.9256
## 2018.175 542.5645 479.9972 623.8870 452.3811 677.6547
## 2018.179 543.5468 480.1247 626.2736 452.1936 681.1528
## 2018.183 545.3334 480.8823 629.7337 452.5676 685.9311
## 2018.187 545.6755 480.5204 631.2703 451.9532 688.4353
## 2018.191 544.4802 478.9762 630.7381 450.2983 688.4758
## 2018.195 543.0752 477.2823 629.9063 448.5176 688.1504
## 2018.199 546.5526 479.3609 635.6504 450.0705 695.6849
## 2018.203 544.8489 477.4555 634.3932 448.1135 694.8442
## 2018.207 545.0949 477.0570 635.7670 447.4890 697.1552
## 2018.211 548.8080 479.3115 641.8737 449.1993 705.1762
## 2018.215 546.9714 477.3332 640.3981 447.1935 704.0583
## 2018.219 542.2504 473.1724 634.9442 443.2789 698.1175
## 2018.223 539.7804 470.7400 632.5516 440.8879 695.8616
## 2018.227 539.5619 470.0300 633.2360 440.0128 697.3223
## 2018.231 541.5007 470.9594 636.8951 440.5767 702.3980
## 2018.235 538.4262 468.1021 633.6146 437.8298 699.0344
## 2018.239 534.9842 464.9798 629.8019 434.8573 695.0087
## 2018.243 539.3508 467.7548 636.8239 437.0432 704.1926
## 2018.247 537.9074 466.1564 635.7631 435.4110 703.5122
## 2018.251 540.3404 467.4716 640.1204 436.3226 709.4734
## 2018.255 539.2471 466.1490 639.5329 434.9380 709.3685
## 2018.259 536.9136 463.9089 637.1854 432.7592 707.0893
## 2018.263 532.6781 460.2597 632.1391 429.3592 701.4741
## 2018.267 532.2321 459.4484 632.4150 428.4331 702.4046
## 2018.271 536.3811 462.0569 639.1980 430.4799 711.3832
## 2018.275 536.3783 461.5793 640.1064 429.8471 713.1081
## 2018.279 535.9883 460.8200 640.4577 428.9728 714.1412
## 2018.283 535.3175 459.8589 640.4000 427.9267 714.6630
## 2018.287 536.6896 460.4081 643.2660 428.1904 718.8305
## 2018.291 535.7008 459.2229 642.7398 426.9559 718.7654
## 2018.295 540.6696 462.4090 650.8158 429.4985 729.4854
## 2018.299 546.4303 466.1515 660.1105 432.5137 741.8050
## 2018.303 549.4695 467.8964 665.4895 433.8039 749.2347
## 2018.307 549.1707 467.2190 665.9850 433.0123 750.4908
## 2018.311 550.7959 467.9358 669.3136 433.4195 755.3523
## 2018.315 568.1007 479.8874 696.0469 443.4370 790.2631
## 2018.319 568.1321 479.4341 697.0972 442.8351 792.3037
## 2018.323 571.3935 481.2782 703.0277 444.1933 800.6702
## 2018.327 572.6600 481.7022 705.9619 444.3410 805.1783
## 2018.331 570.0633 479.3967 703.0213 442.1684 802.0457
## 2018.335 568.0601 477.5189 700.9667 440.3633 800.0555
## 2018.339 569.8346 478.3131 704.6646 440.8323 805.5643
## 2018.343 564.9947 474.4493 698.2486 437.3463 797.8613
## 2018.347 566.5022 475.0645 701.5261 437.6680 802.8189
## 2018.351 563.4058 472.4449 697.7416 435.2460 798.5307
## 2018.355 563.6290 472.1649 699.0396 434.8122 800.8956
## 2018.359 564.5775 472.3954 701.4559 434.8128 804.7360
## 2018.363 564.3934 471.8350 702.1250 434.1447 806.2825
## 2018.367 568.0195 473.9337 708.7113 435.7272 815.6575
## 2018.371 567.6152 473.2230 709.0436 434.9346 816.7734
## 2018.375 570.3205 474.6723 714.2402 435.9668 824.3612
## 2018.378 568.2213 472.7934 711.9098 434.1921 821.9353
## 2018.382 570.1757 473.7225 715.9448 434.7869 828.0020
## 2018.386 573.0265 475.2649 721.4195 435.8972 836.0262
## 2018.390 568.4523 471.6988 715.1370 432.7106 828.2774
## 2018.394 569.2728 471.8502 717.3895 432.6541 831.9797
## 2018.398 571.5504 473.0005 721.9709 433.4375 838.8348
## 2018.402 571.1332 472.3047 722.2620 432.6710 839.9130
## 2018.406 570.1753 471.2433 721.6812 431.5999 839.8094
## 2018.410 566.7596 468.5082 717.1520 429.1271 834.3519
## 2018.414 562.2568 465.0354 710.8708 426.0378 826.5160
## 2018.418 557.8799 461.6531 704.7821 423.0266 818.9355
## 2018.422 554.8349 459.1878 700.8084 420.7876 814.2036
## 2018.426 563.2358 464.5418 715.1755 425.1086 834.3172
## 2018.430 561.2623 462.8179 712.8977 423.4959 831.8686
## 2018.434 556.4553 459.1715 706.0401 420.2754 823.1795
## 2018.438 552.9728 456.4310 701.3070 417.8157 817.3743
## 2018.442 551.3329 454.9505 699.5271 416.4141 815.5734
## 2018.446 553.1290 455.8104 703.2818 416.9739 821.3034
## 2018.450 552.1061 454.7566 702.4841 415.9329 820.8341
## 2018.454 548.5676 452.0000 697.6051 413.4693 814.7870
## 2018.458 552.3877 454.2354 704.6472 415.1821 825.0290
## 2018.462 553.8581 454.8747 707.8985 415.5596 830.1134
## 2018.466 556.6490 456.4002 713.3302 416.6757 838.2259
## 2018.470 556.7972 456.1463 714.4387 416.3083 840.3910
## 2018.474 556.4211 455.5430 714.6819 415.6511 841.3603
## 2018.478 558.6615 456.6923 719.2515 416.4531 848.3411
## 2018.482 562.0336 458.5906 725.7320 417.8761 858.0236
## 2018.486 564.1175 459.6243 730.0988 418.5794 864.7943
## 2018.490 562.5933 458.2626 728.4284 417.2965 863.1066
## 2018.494 563.6472 458.6133 731.0797 417.4346 867.4901
## 2018.498 561.2700 456.6942 727.9579 415.6932 863.7488
## 2018.502 563.3464 457.7238 732.3340 416.3953 870.5747
## 2018.506 561.5209 456.1774 730.1228 414.9660 868.1036
## 2018.510 558.4735 453.8283 725.8361 412.8743 862.6915
## 2018.514 553.4723 450.1911 718.2471 409.7175 852.6159
## 2018.518 556.4862 451.8530 724.1772 410.9490 861.6197
## 2018.522 559.5244 453.5227 730.1879 412.1848 870.7876
## 2018.526 559.3035 453.0482 730.6668 411.6489 872.1139
## 2018.530 563.1173 455.2161 738.0583 413.2934 883.3240
## 2018.534 564.4680 455.7675 741.2536 413.6037 888.5693
## 2018.538 562.0112 453.8377 737.8849 411.8714 884.3890
## 2018.542 562.1039 453.5729 738.9061 411.5117 886.5130
## 2018.546 561.9242 453.1325 739.4551 411.0084 887.9596
## 2018.550 560.0679 451.6047 737.0950 409.6117 885.2085
## 2018.554 560.4857 451.5575 738.6702 409.4342 888.1331
## 2018.558 561.9551 452.1923 742.0805 409.8175 893.7253
## 2018.562 562.5703 452.2731 744.0113 409.7460 897.1876
## 2018.566 562.0534 451.6235 743.9619 409.0758 897.7747
## 2018.570 560.3869 450.2345 741.8916 407.8002 895.4147
## 2018.574 561.0961 450.3806 743.9833 407.7850 899.1196
## 2018.578 561.6334 450.4163 745.7779 407.6797 902.4007
## 2018.582 561.7629 450.1906 746.8553 407.3608 904.6382
## 2018.586 565.4251 452.2287 754.2048 408.8944 916.1177
## 2018.590 568.9986 454.1993 761.4528 410.3699 927.5223
## 2018.594 571.0093 455.1669 765.9417 411.0246 934.8886
## 2018.598 573.1611 456.2201 770.7102 411.7483 942.7090
## 2018.602 571.2439 454.6946 768.1307 410.3717 939.5522
## 2018.606 572.1674 454.9702 770.6873 410.4629 944.0839
## 2018.610 573.8205 455.7055 774.5812 410.9282 950.6451
## 2018.614 571.9052 454.1906 771.9785 409.5642 947.4322
## 2018.618 566.6188 450.5496 763.2379 406.4718 934.9846
## 2018.622 567.7953 450.9932 766.2384 406.7038 940.1805
## 2018.625 568.6416 451.2277 768.6473 406.7658 944.5029
## 2018.629 570.8104 452.2925 773.4903 407.5021 952.5286
## 2018.633 575.2520 454.7746 782.5613 409.3863 967.0442
## 2018.637 579.2402 456.9596 790.8693 411.0259 980.5026
## 2018.641 579.0948 456.5666 791.5060 410.5784 982.2215
## 2018.645 576.5097 454.6590 787.5805 408.9071 976.9136
## 2018.649 572.5495 451.8978 781.0868 406.5461 967.6564
## 2018.653 570.3972 450.2644 777.9554 405.0987 963.5608
## 2018.657 571.6151 450.7317 781.0956 405.3523 969.0944
## 2018.661 573.7451 451.7634 785.9595 406.0618 977.3141
## 2018.665 571.9585 450.3659 783.4839 404.8089 974.2041
## 2018.669 569.0135 448.2525 778.8286 402.9785 967.7203
## 2018.673 570.1092 448.6472 781.7468 403.1756 972.9384
## 2018.677 571.1631 449.0149 784.5974 403.3509 978.0718
## 2018.681 568.5076 447.0906 780.4514 401.6773 972.3411
## 2018.685 568.4387 446.7678 781.1767 401.2971 974.1715
## 2018.689 569.1256 446.9125 783.3319 401.2945 978.2334
## 2018.693 573.1546 449.1117 791.8583 402.9468 992.2928
## 2018.697 569.3728 446.5088 785.5151 400.7321 983.0633
## 2018.701 570.0105 446.6241 787.5886 400.7070 987.0275
## 2018.705 568.7975 445.6043 786.1283 399.7689 985.4455
## 2018.709 572.5896 447.6519 794.2590 401.2986 998.9831
## 2018.713 578.1980 450.7930 805.9834 403.7024 1018.3552
## 2018.717 579.7195 451.4378 809.8411 404.1008 1025.2838
## 2018.721 580.3336 451.5311 811.9404 404.0574 1029.4172
## 2018.725 574.9687 448.0028 802.3543 401.1135 1014.7997
## 2018.729 573.0981 446.5949 799.5847 399.8694 1011.1088
## 2018.733 570.1208 444.5167 794.6566 398.0887 1003.9643
## 2018.737 580.3915 450.4613 815.6511 402.7336 1038.4806
## 2018.741 579.8507 449.8624 815.4793 402.1393 1038.9721
## 2018.745 580.2530 449.8322 817.1724 402.0001 1042.4951
## 2018.749 582.4511 450.8793 822.4449 402.7209 1051.8763
## 2018.753 585.0758 452.1768 828.6051 403.6404 1062.7730
## 2018.757 585.2710 452.0206 829.9146 403.4009 1065.7298
## 2018.761 584.8212 451.4808 829.9261 402.8566 1066.5494
## 2018.765 587.9976 453.0990 837.2667 404.0297 1079.5210
## 2018.769 589.4395 453.6821 841.1287 404.3787 1086.7766
## 2018.773 588.7990 453.0314 840.7573 403.7477 1086.9818
## 2018.777 588.5416 452.6091 841.1634 403.2988 1088.4859
## 2018.781 581.6357 448.2495 828.0272 399.7226 1067.3819
## 2018.785 581.7088 448.0298 829.0748 399.4372 1069.9166
## 2018.789 583.8939 449.0612 834.4293 400.1461 1079.6562
## 2018.793 582.3901 447.9095 832.2635 399.1214 1076.8326
## 2018.797 580.2738 446.3974 828.8406 397.8113 1071.8997
## 2018.801 581.3509 446.7756 831.9366 398.0028 1077.8803
## 2018.805 585.3084 448.8485 840.9785 399.5377 1093.9261
## 2018.809 586.2487 449.1408 843.8390 399.6601 1099.5963
## 2018.813 589.2026 450.6110 850.9034 400.7144 1112.4648
## 2018.817 592.3439 452.1833 858.4153 401.8475 1126.2009
## 2018.821 593.4261 452.5513 861.6400 402.0284 1132.6269
## 2018.825 596.1305 453.8590 868.3153 402.9503 1145.0754
## 2018.829 600.4791 456.1100 878.5550 404.6131 1163.8630
## 2018.833 603.1401 457.3774 885.2582 405.4995 1176.5868
## 2018.837 603.7073 457.4379 887.4786 405.4366 1181.4489
## 2018.841 598.6515 454.2679 877.5694 402.8357 1164.8612
## 2018.845 595.2827 452.0673 871.3069 400.9967 1154.7436
## 2018.849 600.8167 454.9909 884.1974 403.1869 1178.4190
## 2018.853 604.4118 456.7873 893.0063 404.4880 1195.0667
## 2018.857 603.9899 456.2851 893.0846 403.9859 1196.1556
## 2018.861 603.4851 455.7370 892.9776 403.4484 1196.9113
## 2018.865 600.1873 453.5968 886.7561 401.6636 1186.6902
## 2018.869 598.5680 452.4164 884.1983 400.6319 1183.0357
## 2018.873 593.4923 449.2598 874.1155 398.0503 1165.9485
## 2018.876 588.7896 446.3128 864.8787 395.6324 1150.4402
## 2018.880 595.0876 449.6722 879.4912 398.1661 1177.3460
## 2018.884 591.0389 447.1098 871.6130 396.0533 1164.1554
## 2018.888 532.8068 412.7560 751.3266 368.7700 959.6768
## 2018.892 532.9818 412.6518 752.3690 368.5984 961.9793
## 2018.896 533.8842 412.9835 754.8661 368.7748 966.6710
## 2018.900 536.8029 414.5176 761.4222 369.9091 978.0671
## 2018.904 534.8340 413.1342 758.1675 368.7192 973.3149
## 2018.908 534.2441 412.5749 757.6808 368.1862 973.1226
## 2018.912 529.1433 409.3226 748.1414 365.5079 958.0331
## 2018.916 528.0403 408.4599 746.6133 364.7345 956.1148
## 2018.920 534.1428 411.8967 759.5687 367.3860 978.0764
## 2018.924 538.3722 414.2001 768.8624 369.1304 994.1714
## 2018.928 533.5663 411.1459 759.7925 366.6170 979.6707
## 2018.932 532.2143 410.1404 757.7431 365.7322 976.8726
## 2018.936 532.8453 410.3132 759.7141 365.7847 980.7610
## 2018.940 535.3632 411.6019 765.5432 366.7233 991.1188
## 2018.944 539.2649 413.6999 774.2610 368.3021 1006.4196
## 2018.948 531.4993 408.9149 759.0386 364.4210 981.4581
## 2018.952 530.8679 408.3427 758.4345 363.8832 981.0536
## 2018.956 530.4516 407.8989 758.2666 363.4478 981.3771
## 2018.960 531.0322 408.0450 760.1369 363.4809 985.1197
## 2018.964 534.1165 409.6653 767.1668 364.6829 997.5810
## 2018.968 536.6112 410.9321 773.0275 365.6031 1008.1472
## 2018.972 536.6015 410.7279 773.7109 365.3582 1009.9445
## 2018.976 538.1357 411.4274 777.6138 365.8284 1017.2473
## 2018.980 539.2123 411.8576 780.5768 366.0854 1022.9722
## 2018.984 537.9507 410.9236 778.6440 365.2647 1020.2991
## 2018.988 538.0294 410.7725 779.5171 365.0630 1022.4441
## 2018.992 538.7051 410.9696 781.6472 365.1364 1026.7610
## 2018.996 533.4737 407.7245 771.3725 362.4917 1009.7318
## 2019.000 529.0255 404.9308 762.7812 360.2020 995.6696
## 2019.004 530.6995 405.7202 766.9463 360.7468 1003.3946
## 2019.008 521.5223 400.1494 748.5735 356.2582 972.7562
checkresiduals(fct.stlf.GOOG.train)
## Warning in checkresiduals(fct.stlf.GOOG.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(M,N,N)
## Q* = 331.86, df = 249.2, p-value = 0.0003535
##
## Model df: 2. Total lags used: 251.2
#JPM Data Analysis
#Subsetting the JPM dataset
JPM.df<- subset(raw.data,Name=="JPM" ,stringsAsFactors =FALSE )
str(JPM.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 48.3 48.5 48.8 49.4 48.4 ...
## $ high : num 48.7 48.9 49.3 49.5 49.3 ...
## $ low : num 48.3 48.4 48.6 48.5 48.4 ...
## $ close : num 48.6 48.7 49.1 48.7 49.2 ...
## $ volume: int 15217458 13934328 16387566 21635732 18017634 20015681 20445200 24787660 24436578 23583917 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 264 264 264 264 264 264 264 264 264 264 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(JPM.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
JPM.close<-JPM.df[,5]
#Creating the time series
JPM.close.full.ts <- ts(JPM.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
JPM.close.ts <- ts(JPM.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
JPM.test.close.ts <- ts(JPM.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(JPM.close.full.ts)+
ggtitle("JPM stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(JPM.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(JPM.close.full.ts)

length(JPM.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(JPM.close.full.ts)

acf.JPM.close.ts <- acf(JPM.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.JPM.close.ts, type="o",main="Correlogram for JPM stock closing price")

#Decomposition of time series components
stl.JPM.close.ts <- stl(JPM.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.JPM.close.ts) +
ggtitle("JPM stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(JPM.close.full.ts, series="Data") +
autolayer(trendcycle(stl.JPM.close.ts), series="Trend") +
autolayer(seasadj(stl.JPM.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of JPM stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.JPM.train <- stlf(JPM.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.JPM.train <- stlf(JPM.close.full.ts, h = length(JPM.close.full.ts) , lambda = BoxCox.lambda(JPM.close.full.ts))
naive.JPM.train <- rwf(JPM.close.full.ts,h = length(JPM.close.full.ts))
ets.stlf.JPM.train <- stlf(JPM.close.full.ts, t.window = 13, s.window = "periodic", h = length(JPM.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(JPM.close.full.ts))
fct.ets.JPM.train <- forecast(ets.JPM.train, h = 252)
fct.stlf.JPM.train <- forecast(stlf.JPM.train, h = 252)
fct.naive.JPM.train <- forecast(naive.JPM.train, h = 252)
fct.ets.stlf.JPM.train <- forecast(ets.stlf.JPM.train, h = 252)
accuracy(fct.ets.JPM.train)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.05183864 1.130585 0.6734684 0.06007274 1.022109 0.05980557
## ACF1
## Training set 0.04608663
accuracy(fct.stlf.JPM.train)
## ME RMSE MAE MPE MAPE
## Training set 0.05336818 0.8090966 0.5920039 0.06204752 0.8726868
## MASE ACF1
## Training set 0.05257133 0.01267808
accuracy(fct.naive.JPM.train)
## ME RMSE MAE MPE MAPE
## Training set 0.05231076 0.8341204 0.6025578 0.05994199 0.9175906
## MASE ACF1
## Training set 0.05350854 0.01125168
accuracy(fct.ets.stlf.JPM.train)
## ME RMSE MAE MPE MAPE
## Training set 0.05949949 0.9200988 0.6368253 0.06620054 0.9423025
## MASE ACF1
## Training set 0.05655157 0.01302876
autoplot(JPM.close.full.ts) +
autolayer(ets.JPM.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.JPM.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.JPM.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.JPM.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("JPM Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.JPM.train %>% forecast(h=252) %>%
autoplot() +
autolayer(JPM.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.JPM.train[["model"]]
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9785
##
## Initial states:
## l = 0.9798
##
## sigma: 0.0002
##
## AIC AICc BIC
## -12621.52 -12621.50 -12606.11
summary(fct.stlf.JPM.train)
##
## Forecast method: STL + ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9785
##
## Initial states:
## l = 0.9798
##
## sigma: 0.0002
##
## AIC AICc BIC
## -12621.52 -12621.50 -12606.11
##
## Error measures:
## ME RMSE MAE MPE MAPE
## Training set 0.05336818 0.8090966 0.5920039 0.06204752 0.8726868
## MASE ACF1
## Training set 0.05257133 0.01267808
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2018.008 109.0690 106.31730 111.9668 104.91613 113.5641
## 2018.012 109.9990 106.12347 114.1682 104.18043 116.5058
## 2018.016 108.7007 104.11574 113.7082 101.84173 116.5503
## 2018.020 108.4715 103.24229 114.2587 100.67310 117.5795
## 2018.024 112.1204 105.92699 119.0831 102.91748 123.1308
## 2018.028 114.2023 107.21296 122.1663 103.84847 126.8491
## 2018.032 112.8274 105.49255 121.2585 101.98289 126.2526
## 2018.036 112.1254 104.41546 121.0646 100.74819 126.3992
## 2018.040 113.0002 104.73602 122.6802 100.83230 128.5077
## 2018.044 112.3923 103.80694 122.5258 99.77242 128.6668
## 2018.048 110.7772 102.05383 121.1312 97.96982 127.4366
## 2018.052 112.0692 102.78698 123.1942 98.46954 130.0270
## 2018.056 112.7438 103.00516 124.5161 98.50109 131.8013
## 2018.060 112.6966 102.63239 124.9492 97.99948 132.5795
## 2018.064 111.6057 101.41277 124.0765 96.73584 131.8772
## 2018.068 115.3200 104.14989 129.1739 99.06999 137.9465
## 2018.072 118.0337 106.03638 133.0920 100.62221 142.7313
## 2018.076 118.5439 106.13481 134.2387 100.56223 144.3561
## 2018.080 117.9068 105.32391 133.9040 99.69190 144.2655
## 2018.084 117.9508 105.06829 134.4337 99.32552 145.1729
## 2018.088 114.5585 102.10033 130.4794 96.54247 140.8409
## 2018.092 114.5835 101.85995 130.9392 96.20482 141.6419
## 2018.096 115.2983 102.16857 132.3001 96.35974 143.5017
## 2018.100 114.1845 101.04814 131.2465 95.24742 142.5199
## 2018.104 114.7362 101.23917 132.3853 95.30431 144.1209
## 2018.108 114.6732 100.95547 132.7048 94.94312 144.7539
## 2018.112 114.6168 100.68282 133.0268 94.59508 145.3889
## 2018.116 114.5718 100.42453 133.3585 94.26288 146.0345
## 2018.120 116.3943 101.59716 136.2361 95.19094 149.7497
## 2018.124 115.9788 101.06181 136.0615 94.61948 149.7920
## 2018.127 114.1945 99.49594 133.9885 93.14894 147.5249
## 2018.131 111.8703 97.52984 131.1545 91.33212 144.3244
## 2018.135 111.0771 96.73563 130.4109 90.54687 143.6463
## 2018.139 111.2753 96.69816 131.0274 90.42718 144.6163
## 2018.143 112.7150 97.59497 133.3785 91.12407 147.7135
## 2018.147 112.1601 96.99517 132.9456 90.51642 147.4063
## 2018.151 111.5172 96.33539 132.3789 89.85941 146.9291
## 2018.155 113.1094 97.34146 134.9729 90.65165 150.3579
## 2018.159 111.9892 96.33678 133.7143 89.69998 149.0172
## 2018.163 110.9201 95.37635 132.5164 88.78963 147.7440
## 2018.167 111.5956 95.70805 133.8073 89.00051 149.5660
## 2018.171 110.5039 94.74200 132.5566 88.09047 148.2142
## 2018.175 109.5276 93.86639 131.4612 87.26119 147.0496
## 2018.179 107.6399 92.32623 129.0433 85.85991 144.2244
## 2018.183 109.0596 93.21736 131.3887 86.56102 147.3599
## 2018.187 110.0165 93.76414 133.0841 86.96338 149.6997
## 2018.191 110.3355 93.84566 133.8553 86.96531 150.8811
## 2018.195 109.2053 92.88122 132.4903 86.07040 149.3475
## 2018.199 110.1486 93.41712 134.1807 86.46440 151.7016
## 2018.203 111.1556 93.99451 135.9824 86.89285 154.2159
## 2018.207 112.4733 94.78806 138.2711 87.50435 157.3799
## 2018.211 112.6027 94.73460 138.7774 87.39336 158.2503
## 2018.215 111.7598 93.99559 137.8029 86.70028 157.1935
## 2018.219 112.2382 94.19278 138.8360 86.80470 158.7507
## 2018.223 113.4960 94.93512 141.0777 87.37120 161.9062
## 2018.227 113.2570 94.62819 141.0178 87.04863 162.0435
## 2018.231 112.1388 93.71054 139.5887 86.21070 160.3692
## 2018.235 111.2647 92.96684 138.5299 85.52158 159.1783
## 2018.239 111.7547 93.17676 139.5852 85.64024 160.7806
## 2018.243 110.4555 92.14399 137.8497 84.70980 158.6826
## 2018.247 110.5913 92.11167 138.3461 84.62589 159.5416
## 2018.251 110.3814 91.84101 138.3002 84.34161 159.6801
## 2018.255 110.7984 92.00510 139.2395 84.42455 161.1350
## 2018.259 111.4955 92.36086 140.6296 84.66871 163.2047
## 2018.263 112.2125 92.72792 142.0632 84.92187 165.3475
## 2018.267 112.7194 92.94978 143.1700 85.05297 167.0603
## 2018.271 112.0272 92.35701 142.3429 84.50253 166.1429
## 2018.275 112.0810 92.27314 142.7169 84.37904 166.8606
## 2018.279 113.2432 92.93816 144.9005 84.88129 170.0675
## 2018.283 114.0210 93.33993 146.4743 85.16281 172.4586
## 2018.287 114.7746 93.72281 148.0226 85.42800 174.8322
## 2018.291 114.3540 93.32245 147.6222 85.04266 174.4949
## 2018.295 114.7589 93.47272 148.5980 85.11512 176.0834
## 2018.299 115.2542 93.68206 149.7323 85.23658 177.9049
## 2018.303 117.1780 94.82812 153.3110 86.13144 183.2182
## 2018.307 118.4630 95.54581 155.8417 86.66998 187.0914
## 2018.311 116.7329 94.29901 153.1720 85.59131 183.4931
## 2018.315 116.8620 94.26599 153.7053 85.51305 184.4962
## 2018.319 115.8843 93.51405 152.3216 84.84385 182.7375
## 2018.323 115.1128 92.89855 151.2889 84.28790 181.4798
## 2018.327 116.3514 93.59016 153.7408 84.80758 185.2540
## 2018.331 116.7469 93.73277 154.7391 84.87560 186.9431
## 2018.335 117.2460 93.94135 155.9273 84.99770 188.9210
## 2018.339 117.0067 93.67606 155.8120 84.73215 188.9917
## 2018.343 117.4252 93.83279 156.8650 84.81225 190.7860
## 2018.347 118.0975 94.15019 158.3812 85.02342 193.2815
## 2018.351 117.2324 93.49038 157.1369 84.43784 191.6739
## 2018.355 116.9186 93.18281 156.8783 84.14034 191.5300
## 2018.359 116.8656 93.04222 157.0867 83.97961 192.0814
## 2018.363 116.3431 92.60543 156.4439 83.57820 191.3587
## 2018.367 115.4778 91.95303 155.1764 83.00191 189.6979
## 2018.371 114.6539 91.32855 153.9795 82.44906 188.1394
## 2018.375 115.5873 91.81801 155.9608 82.80394 191.3392
## 2018.378 116.4760 92.27559 157.8817 83.13198 194.4785
## 2018.382 115.9901 91.86945 157.2850 82.75888 193.8111
## 2018.386 116.9912 92.39484 159.4327 83.14151 197.3269
## 2018.390 113.4160 90.05457 153.1426 81.20042 188.0019
## 2018.394 110.6902 88.23587 148.4731 79.67930 181.2174
## 2018.398 112.9405 89.56601 152.8226 80.72203 187.9574
## 2018.402 114.5308 90.46796 156.0317 81.41308 193.0644
## 2018.406 116.2355 91.43138 159.5066 82.15109 198.6543
## 2018.410 115.5939 90.93855 158.5902 81.71226 197.4723
## 2018.414 113.6712 89.65209 155.2694 80.63262 192.5748
## 2018.418 113.7022 89.57969 155.6028 80.53486 193.3134
## 2018.422 114.0877 89.72731 156.6037 80.61508 195.0891
## 2018.426 115.8136 90.69840 160.1634 81.35847 200.8853
## 2018.430 116.8373 91.23131 162.4239 81.74722 204.7033
## 2018.434 119.6131 92.81848 168.1543 82.97843 214.1610
## 2018.438 119.9696 92.93668 169.1781 83.03220 216.0995
## 2018.442 121.1504 93.54659 171.8627 83.47776 220.7849
## 2018.446 120.6817 93.17093 171.2442 83.13806 220.0478
## 2018.450 120.3670 92.88830 170.9318 82.87297 219.8131
## 2018.454 120.3571 92.78811 171.2322 82.75351 220.5915
## 2018.458 121.2063 93.19729 173.2826 83.03904 224.2958
## 2018.462 120.6566 92.77846 172.4833 82.66711 223.2443
## 2018.466 119.7869 92.17151 171.0269 82.14630 221.0897
## 2018.470 118.9942 91.61112 169.7248 81.66290 219.1918
## 2018.474 118.9952 91.52192 170.0358 81.55429 219.9847
## 2018.478 119.7702 91.88958 171.9372 81.80831 223.4593
## 2018.482 118.9535 91.31946 170.5676 81.31893 221.4266
## 2018.486 117.3132 90.26339 167.5113 80.44419 216.5656
## 2018.490 117.1466 90.07920 167.4666 80.26193 216.7525
## 2018.494 116.4334 89.57266 166.3024 79.82415 215.0627
## 2018.498 117.2731 89.98415 168.3161 80.11528 218.7063
## 2018.502 115.9940 89.14640 165.9798 79.41577 215.0325
## 2018.506 117.5379 89.97159 169.4563 80.03485 221.1716
## 2018.510 117.6179 89.93491 169.9200 79.97087 222.2317
## 2018.514 116.9746 89.47591 168.8733 79.57326 220.7094
## 2018.518 115.9715 88.80695 167.0759 79.00989 217.9064
## 2018.522 115.3208 88.34523 166.0094 78.61083 216.3483
## 2018.526 114.8722 88.00293 165.3587 78.30668 215.4939
## 2018.530 114.8432 87.90761 165.5756 78.19842 216.1124
## 2018.534 115.3586 88.13092 166.9297 78.34231 218.6798
## 2018.538 114.4750 87.53721 165.3601 77.84057 216.2424
## 2018.542 113.9183 87.13526 164.4713 77.49074 214.9696
## 2018.546 112.3287 86.12812 161.4377 76.66215 210.0492
## 2018.550 110.0593 84.71620 157.0360 75.51150 202.8745
## 2018.554 109.4279 84.27124 155.9942 75.12818 201.3513
## 2018.558 111.4303 85.38191 160.3485 75.97952 208.8927
## 2018.562 112.1788 85.74837 162.1610 76.23933 212.2133
## 2018.566 112.1343 85.65045 162.3256 76.13185 212.7296
## 2018.570 112.9615 86.05988 164.3278 76.42498 216.4230
## 2018.574 111.7596 85.28972 162.0516 75.78742 212.7249
## 2018.578 112.6855 85.75661 164.2666 76.12611 216.7989
## 2018.582 112.7815 85.74110 164.7321 76.08429 217.8527
## 2018.586 112.4910 85.50272 164.3728 75.86719 217.4654
## 2018.590 112.7330 85.57216 165.1511 75.89260 219.0730
## 2018.594 111.8336 84.98384 163.4830 75.40071 216.3843
## 2018.598 111.2403 84.57259 162.4693 75.04839 214.8444
## 2018.602 111.0782 84.41117 162.3737 74.89306 214.9091
## 2018.606 111.8929 84.81272 164.3757 75.18066 218.6693
## 2018.610 112.6482 85.17753 166.2713 75.43876 222.2831
## 2018.614 113.3525 85.51078 168.0752 75.67154 225.7722
## 2018.618 112.5424 84.98122 166.5598 75.22846 223.2932
## 2018.622 110.8444 83.94361 163.1156 74.38683 217.3800
## 2018.625 110.7168 83.80494 163.0865 74.25074 217.5612
## 2018.629 109.9396 83.29450 161.6481 73.82299 215.2362
## 2018.633 111.4882 84.11489 165.2703 74.43956 221.9470
## 2018.637 110.7449 83.62655 163.8894 74.03008 219.6992
## 2018.641 111.8952 84.21558 166.6761 74.46432 224.9819
## 2018.645 109.1029 82.56156 160.7921 73.14224 214.6154
## 2018.649 109.2549 82.58619 161.3598 73.13570 215.8530
## 2018.653 110.4011 83.17644 164.1174 73.57212 221.0515
## 2018.657 109.3140 82.49604 161.9644 73.01364 217.3901
## 2018.661 110.8440 83.30158 165.5935 73.61796 224.2191
## 2018.665 111.2885 83.48947 166.8384 73.73869 226.7528
## 2018.669 110.1482 82.78433 164.5319 73.16259 222.7494
## 2018.673 111.1212 83.27050 166.9619 73.51639 227.4720
## 2018.677 111.7069 83.53653 168.5413 73.69795 230.6652
## 2018.681 111.1712 83.17486 167.5748 73.39088 229.1062
## 2018.685 110.9714 83.00164 167.3698 73.23074 228.9696
## 2018.689 110.3890 82.61489 166.2935 72.90457 227.2020
## 2018.693 108.3620 81.41563 161.9675 71.94482 219.4281
## 2018.697 108.8884 81.65362 163.3812 72.10634 222.2610
## 2018.701 109.8603 82.13965 165.8204 72.46066 227.0389
## 2018.705 110.2793 82.31421 167.0207 72.57204 229.5392
## 2018.709 111.1496 82.73826 169.2750 72.87688 234.0716
## 2018.713 110.3269 82.22259 167.6188 72.45229 231.1628
## 2018.717 111.2109 82.65319 169.9182 72.76207 235.8143
## 2018.721 112.7658 83.44861 173.8362 73.35311 243.7005
## 2018.725 112.7227 83.36494 173.9951 73.26389 244.2854
## 2018.729 113.5707 83.76735 176.2911 73.54984 249.1181
## 2018.733 114.6035 84.26684 179.0672 73.90977 254.9932
## 2018.737 113.8665 83.80743 177.5441 73.53158 252.2039
## 2018.741 114.5049 84.09228 179.3755 73.72617 256.2120
## 2018.745 115.1746 84.39222 181.3043 73.93196 260.4709
## 2018.749 114.3151 83.86997 179.4567 73.50651 256.9715
## 2018.753 114.8797 84.11347 181.1297 73.66913 260.7204
## 2018.757 114.8764 84.05191 181.3992 73.59765 261.5849
## 2018.761 117.4269 85.34782 188.1396 74.56452 276.1751
## 2018.765 118.2327 85.71088 190.5214 74.81656 281.6907
## 2018.769 117.2841 85.15036 188.3674 74.36455 277.3484
## 2018.773 118.0771 85.50637 190.7251 74.61128 282.8438
## 2018.777 118.8848 85.86760 193.1522 74.86140 288.5818
## 2018.781 118.8150 85.76991 193.2785 74.76250 289.2319
## 2018.785 121.6679 87.18356 201.2784 75.80907 307.9381
## 2018.789 121.3974 86.98191 200.8729 75.63147 307.4037
## 2018.793 121.4982 86.97113 201.4838 75.59832 309.2542
## 2018.797 122.3642 87.35104 204.2193 75.86011 316.1811
## 2018.801 122.2959 87.25365 204.3720 75.76166 316.9837
## 2018.805 122.7201 87.40667 205.9062 75.85202 321.1365
## 2018.809 121.9247 86.94053 204.0166 75.47606 316.9981
## 2018.813 122.1821 87.00954 205.0808 75.50344 320.0164
## 2018.817 121.7147 86.71104 204.1060 75.25416 318.0843
## 2018.821 120.6890 86.12894 201.5674 74.79128 312.3803
## 2018.825 123.4528 87.46538 209.7522 75.77237 332.9605
## 2018.829 124.6830 88.01847 213.6963 76.16231 343.5136
## 2018.833 123.8957 87.56356 211.7548 75.79694 339.0141
## 2018.837 126.5265 88.80610 219.9451 76.70116 361.0594
## 2018.841 127.6179 89.27841 223.6645 77.02804 371.7777
## 2018.845 126.4776 88.65591 220.5741 76.53939 363.8768
## 2018.849 124.0428 87.39162 213.6373 75.57107 345.8819
## 2018.853 124.9851 87.79689 216.8214 75.84967 354.8356
## 2018.857 123.2587 86.88143 212.0348 75.14168 342.6869
## 2018.861 122.3169 86.35330 209.6108 74.72287 336.8754
## 2018.865 122.8561 86.56241 211.5525 74.85593 342.4088
## 2018.869 125.5943 87.85199 220.1859 75.79437 366.1697
## 2018.873 126.2629 88.11741 222.6383 75.96780 373.5826
## 2018.876 125.3055 87.58975 220.0584 75.55154 366.9344
## 2018.880 126.9857 88.34627 225.6918 76.08972 383.4778
## 2018.884 127.8030 88.67954 228.6942 76.31271 392.8644
## 2018.888 128.4644 88.93577 231.2370 76.47822 401.0913
## 2018.892 128.8586 89.06274 232.9387 76.54795 406.9197
## 2018.896 128.6964 88.92378 232.8293 76.42126 407.2666
## 2018.900 129.5589 89.27293 236.0986 76.65489 418.0911
## 2018.904 128.1502 88.54117 231.8770 76.09103 405.7059
## 2018.908 127.7097 88.27055 230.8494 75.86757 403.2332
## 2018.912 124.2559 86.54894 220.1784 74.56960 372.3265
## 2018.916 123.2152 85.98591 217.2938 74.12892 364.6919
## 2018.920 122.6741 85.66574 215.9733 73.86870 361.5170
## 2018.924 121.3172 84.94663 212.1465 73.31162 351.4206
## 2018.928 118.8654 83.68371 205.0814 72.34790 332.8964
## 2018.932 117.8571 83.13004 202.4098 71.91284 326.3426
## 2018.936 118.1333 83.21470 203.5399 71.95536 329.7267
## 2018.940 116.6414 82.42012 199.4524 71.34005 319.5416
## 2018.944 115.3013 81.69819 195.8555 70.77847 310.7951
## 2018.948 115.0807 81.53715 195.5079 70.63763 310.3051
## 2018.952 113.4520 80.66711 191.1283 69.96418 299.7737
## 2018.956 112.1889 79.97835 187.8356 69.42629 292.0914
## 2018.960 112.2762 79.97470 188.3461 69.40440 293.6697
## 2018.964 112.2140 79.89536 188.4367 69.32559 294.2327
## 2018.968 111.3942 79.43171 186.3955 68.95742 289.6175
## 2018.972 112.8350 80.11374 190.7356 69.45182 300.5882
## 2018.976 112.2548 79.77344 189.3500 69.17707 297.5094
## 2018.980 113.6536 80.42927 193.6420 69.65065 308.6176
## 2018.984 114.1019 80.60536 195.2289 69.76357 313.0518
## 2018.988 113.3326 80.17313 193.2633 69.42069 308.4004
## 2018.992 112.3425 79.62954 190.6697 68.99415 302.2049
## 2018.996 112.7049 79.76458 191.9871 69.07691 305.8917
## 2019.000 114.6155 80.66903 197.8852 69.73528 321.5438
## 2019.004 114.3288 80.47935 197.3172 69.57468 320.4449
## 2019.008 109.0690 77.79264 182.4001 67.53990 283.1864
checkresiduals(fct.stlf.JPM.train)
## Warning in checkresiduals(fct.stlf.JPM.train): The fitted degrees of
## freedom is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,N,N)
## Q* = 431.22, df = 249.2, p-value = 0.000000000006711
##
## Model df: 2. Total lags used: 251.2
#GE Data Analysis
#Subsetting the GE dataset
GE.df<- subset(raw.data,Name=="GE" ,stringsAsFactors =FALSE )
str(GE.df)
## 'data.frame': 1259 obs. of 8 variables:
## $ date : Factor w/ 1259 levels "2013-02-08","2013-02-11",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ open : num 22.5 22.5 22.5 23.1 23.2 ...
## $ high : num 22.6 22.5 22.6 23.5 23.5 ...
## $ low : num 22.4 22.4 22.5 23 23.1 ...
## $ close : num 22.5 22.4 22.6 23.4 23.4 ...
## $ volume: int 24424506 19738628 34139526 84933955 53990644 39288629 41218513 38092203 47809553 27830319 ...
## $ Name : Factor w/ 505 levels "A","AAL","AAP",..: 201 201 201 201 201 201 201 201 201 201 ...
## $ year : num 2013 2013 2013 2013 2013 ...
library(forecast)
#sample <- msts(GE.close, seasonal.periods=c(5,365.25))
#autoplot(sample)
GE.close<-GE.df[,5]
#Creating the time series
GE.close.full.ts <- ts(GE.close, start = c(2013,2,8), end=c(2018,2,7) , frequency = 251)
GE.close.ts <- ts(GE.close, start = c(2013,2,8), end=c(2017,2,7) , frequency = 251)
GE.test.close.ts <- ts(GE.close, start = c(2017,2,8), end=c(2018,2,7) , frequency = 251)
#Plotting the time series
autoplot(GE.close.full.ts)+
ggtitle("GE stock closing price")+
xlab("Time")+
ylab("Stock Price")

# Calculating critical value for autocorrelation considering 95% confidence
significance_level <- qnorm((1 + 0.95)/2)/sqrt(sum(!is.na(GE.close.full.ts)))
significance_level
## [1] 0.05530358
ggAcf(GE.close.full.ts)

length(GE.close.full.ts)
## [1] 1256
# Calculating autocorrelation for various lags in series
gglagplot(GE.close.full.ts)

acf.GE.close.ts <- acf(GE.close.full.ts,lag.max = 50, type = "correlation")

plot(acf.GE.close.ts, type="o",main="Correlogram for GE stock closing price")

#Decomposition of time series components
stl.GE.close.ts <- stl(GE.close.full.ts, s.window = "periodic", robust = TRUE)
autoplot(stl.GE.close.ts) +
ggtitle("GE stock closing price",
subtitle = "STL decomposition")

#Seasonality Adjusted Plot
autoplot(GE.close.full.ts, series="Data") +
autolayer(trendcycle(stl.GE.close.ts), series="Trend") +
autolayer(seasadj(stl.GE.close.ts), series="Seasonally Adjusted") +
xlab("Year") + ylab("Stock Price") +
ggtitle("STL Decomposition of GE stocks") +
scale_colour_manual(values=c("gray","blue","red"),
breaks=c("Data","Seasonally Adjusted","Trend"))

ets.GE.train <- stlf(GE.close.full.ts, s.window = "periodic", robust = TRUE, etsmodel="ZZN", damped=TRUE)
stlf.GE.train <- stlf(GE.close.full.ts, h = length(GE.close.full.ts) , lambda = BoxCox.lambda(GE.close.full.ts))
naive.GE.train <- rwf(GE.close.full.ts,h = length(GE.close.full.ts))
ets.stlf.GE.train <- stlf(GE.close.full.ts, t.window = 13, s.window = "periodic", h = length(GE.close.full.ts), robust = TRUE, method = "ets", lambda = BoxCox.lambda(GE.close.full.ts))
fct.ets.GE.train <- forecast(ets.GE.train, h = 252)
fct.stlf.GE.train <- forecast(stlf.GE.train, h = 252)
fct.naive.GE.train <- forecast(naive.GE.train, h = 252)
fct.ets.stlf.GE.train <- forecast(ets.stlf.GE.train, h = 252)
accuracy(fct.ets.GE.train)
## ME RMSE MAE MPE MAPE
## Training set -0.00579074 0.3618541 0.2420371 -0.03632035 0.9490124
## MASE ACF1
## Training set 0.07263464 -0.002120441
accuracy(fct.stlf.GE.train)
## ME RMSE MAE MPE MAPE
## Training set -0.004987172 0.2685805 0.1993221 -0.03050394 0.7741277
## MASE ACF1
## Training set 0.05981598 0.04274165
accuracy(fct.naive.GE.train)
## ME RMSE MAE MPE MAPE
## Training set -0.005466135 0.3054355 0.216988 -0.03614161 0.837588
## MASE ACF1
## Training set 0.06511749 0.0537607
accuracy(fct.ets.stlf.GE.train)
## ME RMSE MAE MPE MAPE
## Training set -0.005192369 0.2994199 0.2065807 -0.03231153 0.8021336
## MASE ACF1
## Training set 0.06199427 0.01187997
autoplot(GE.close.full.ts) +
autolayer(ets.GE.train,series="ETS method with damped", PI=FALSE) +
autolayer(stlf.GE.train,series="STLF method", PI=FALSE) +
autolayer(fct.naive.GE.train,series="naive method", PI=FALSE) +
autolayer(ets.stlf.GE.train,series="STLF with ETS method", PI=FALSE) +
ggtitle("GE Stock forecast")+
xlab("Time ")+
ylab("Stock Price")

fct.stlf.GE.train %>% forecast(h=252) %>%
autoplot() +
autolayer(GE.close.full.ts,series="ACTUAL", PI=FALSE) +
xlab("Time ")+
ylab("Stock Price")
## Warning: Ignoring unknown parameters: PI

fct.stlf.GE.train[["model"]]
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 273.0249
##
## sigma: 7.0685
##
## AIC AICc BIC
## 13879.01 13879.03 13894.42
fct.stlf.GE.train[]
## $model
## ETS(A,N,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 273.0249
##
## sigma: 7.0685
##
## AIC AICc BIC
## 13879.01 13879.03 13894.42
##
## $mean
## Time Series:
## Start = c(2018, 3)
## End = c(2019, 3)
## Frequency = 251
## [1] 15.89384 16.05915 16.18679 15.97917 16.48678 16.91610 17.07323
## [8] 16.81224 16.86647 16.94867 17.04574 17.10896 17.10529 17.25135
## [15] 17.00640 17.36740 17.65472 17.79801 17.72764 17.62474 17.24939
## [22] 17.20164 17.08956 17.25610 17.24036 17.14958 17.21694 17.38569
## [29] 17.49523 17.50928 17.36126 17.28257 17.35881 17.58017 17.60577
## [36] 17.64865 17.72908 17.91147 17.66089 17.48638 17.58303 17.73973
## [43] 18.54887 18.09220 18.30127 18.25664 18.18129 18.05300 17.95851
## [50] 17.96573 18.15840 18.18753 17.91104 17.97152 18.09654 18.04346
## [57] 17.96428 17.97130 17.96856 17.68373 17.68413 17.61062 17.82821
## [64] 17.64961 17.91866 17.84308 17.83913 17.46712 17.57706 17.37726
## [71] 17.31131 17.23777 17.48174 17.48428 17.69376 17.68052 17.37621
## [78] 17.48468 17.50889 17.40301 17.49015 17.73536 17.88586 17.86111
## [85] 17.84961 17.73738 17.74057 17.95116 18.13723 18.27884 18.24704
## [92] 18.24867 18.16286 18.02229 17.73065 17.72003 17.23101 16.89338
## [99] 16.91726 17.21095 17.73869 17.57641 17.71855 17.58942 17.35679
## [106] 17.60535 17.64619 17.79138 18.07638 18.24622 18.58374 18.48154
## [113] 18.40765 18.25345 18.00752 17.32746 16.97226 16.91832 16.98030
## [120] 16.91037 16.85077 16.75002 16.54842 16.80927 16.90565 16.91422
## [127] 17.05441 16.80872 16.93845 16.79107 16.75796 16.96526 16.79781
## [134] 16.78907 16.61861 16.20184 15.96411 15.62250 15.83083 16.07299
## [141] 16.19898 16.08509 15.83389 15.95369 16.05835 16.18660 16.31828
## [148] 16.31388 16.01684 15.58274 15.75834 15.90073 16.24164 16.01390
## [155] 15.61651 15.79728 15.81344 15.90023 15.94760 15.91803 15.56046
## [162] 15.86090 15.79785 15.52991 15.72764 16.26994 16.28797 16.46757
## [169] 16.51118 16.29762 15.80974 15.73638 15.63147 15.80931 16.56716
## [176] 16.87807 16.89849 16.79359 17.33832 17.40606 16.96593 16.84417
## [183] 16.77763 16.56447 16.62999 16.60690 16.53057 16.48243 16.51621
## [190] 16.86849 17.14684 17.33747 17.66803 17.68763 18.04129 17.68748
## [197] 17.58547 17.70600 17.60994 17.78748 17.72057 17.81470 17.86470
## [204] 17.77734 17.40972 17.47950 17.43186 17.54321 17.69761 17.55786
## [211] 17.44045 17.48953 17.58014 17.47346 17.45482 17.48444 17.74474
## [218] 17.58269 17.86960 18.01197 18.24239 18.37810 18.21629 18.27473
## [225] 18.41356 18.05192 18.03931 17.69218 17.73759 17.59586 17.23928
## [232] 16.95114 16.81626 16.90646 16.97563 17.18511 16.77255 16.61568
## [239] 16.20711 16.32473 15.64902 15.29121 15.72383 15.47279 15.60993
## [246] 15.68510 15.44162 15.24157 15.37114 15.75511 15.64003 15.89384
##
## $level
## [1] 80 95
##
## $x
## Time Series:
## Start = c(2013, 2)
## End = c(2018, 2)
## Frequency = 251
## [1] 22.500 22.450 22.580 23.390 23.410 23.290 23.750 23.410 23.260
## [10] 23.390 22.810 23.050 23.370 23.220 23.190 23.270 23.590 23.670
## [19] 23.680 23.770 23.620 23.410 23.490 23.690 23.440 23.250 23.320
## [28] 23.460 23.290 23.370 23.240 23.120 23.100 23.120 23.080 23.340
## [37] 23.000 23.080 22.930 23.120 23.060 23.580 23.590 23.460 22.810
## [46] 23.100 22.760 22.670 21.750 21.350 21.500 21.960 21.950 22.210
## [55] 22.270 22.290 22.150 22.320 22.570 22.580 22.680 23.010 22.780
## [64] 22.900 22.850 23.010 23.240 23.270 23.460 23.570 23.660 23.860
## [73] 23.660 23.530 23.600 23.640 23.600 23.320 23.640 23.660 23.320
## [82] 23.380 23.860 23.780 23.580 23.500 23.680 23.520 23.770 24.330
## [91] 23.980 23.250 23.360 22.930 23.110 23.250 23.320 23.190 23.340
## [100] 22.900 22.910 23.240 23.320 23.620 23.540 23.940 23.760 23.630
## [109] 23.430 23.540 23.630 24.720 24.860 24.710 24.620 24.690 24.650
## [118] 24.490 24.480 24.370 24.620 24.700 24.520 24.310 24.340 24.330
## [127] 24.250 24.270 24.200 24.070 24.000 23.950 23.850 23.720 23.610
## [136] 23.780 23.780 23.610 23.180 23.200 23.110 23.140 23.060 23.170
## [145] 23.160 23.160 23.390 23.870 24.090 23.850 23.780 24.140 24.450
## [154] 24.860 24.460 24.010 24.280 24.320 24.230 24.250 24.050 23.890
## [163] 24.170 24.330 24.100 24.050 23.940 23.670 23.570 24.250 24.400
## [172] 24.380 24.190 24.360 24.680 25.550 26.140 26.020 25.700 25.940
## [181] 25.880 26.090 26.210 26.370 26.140 26.540 26.430 26.420 26.900
## [190] 26.600 27.050 27.010 27.050 27.150 26.990 27.200 27.220 27.030
## [199] 26.960 26.910 27.080 26.730 26.780 26.830 26.660 26.660 26.560
## [208] 26.640 26.450 26.940 27.190 27.140 26.580 26.540 26.840 26.980
## [217] 27.030 27.410 27.320 27.360 27.400 27.610 27.830 27.830 27.890
## [226] 28.030 27.500 27.480 27.260 27.290 27.210 27.220 26.960 26.730
## [235] 26.970 27.340 27.200 26.580 26.290 25.990 25.820 24.950 25.070
## [244] 25.460 25.290 25.500 25.130 24.350 24.570 24.520 24.950 25.190
## [253] 25.050 25.430 25.390 25.440 25.740 25.650 25.400 25.120 24.940
## [262] 25.290 25.270 25.300 25.500 25.470 25.120 25.650 25.930 26.220
## [271] 26.130 26.040 25.900 25.760 25.340 25.110 25.430 25.650 25.280
## [280] 25.270 25.400 25.410 25.700 25.620 25.810 25.880 25.890 25.870
## [289] 26.040 26.230 26.020 25.850 25.750 25.950 25.580 25.430 25.710
## [298] 25.820 26.120 26.560 26.590 26.580 26.420 26.460 26.600 26.780
## [307] 26.760 26.890 26.770 26.680 26.580 26.190 26.530 26.440 26.420
## [316] 26.850 26.920 26.760 26.600 26.670 26.610 26.300 26.490 26.510
## [325] 26.510 26.570 26.660 26.740 26.790 26.830 26.790 26.550 26.770
## [334] 27.180 27.440 27.410 27.150 26.960 27.040 26.820 26.870 26.890
## [343] 26.930 26.970 26.680 26.580 26.420 26.290 26.430 26.280 26.400
## [352] 26.610 26.860 26.750 26.370 26.320 26.200 26.550 26.660 26.610
## [361] 27.020 26.610 26.460 25.980 26.020 25.910 25.940 25.790 25.590
## [370] 25.450 25.640 25.150 25.350 25.270 25.020 25.440 25.500 25.660
## [379] 25.790 25.610 25.830 25.880 25.640 26.070 26.050 26.360 26.430
## [388] 26.150 26.200 26.010 26.130 26.010 25.980 25.850 25.950 25.960
## [397] 26.100 26.080 25.900 25.950 26.020 25.870 25.920 26.210 26.270
## [406] 26.210 26.290 26.080 26.020 25.930 25.550 25.630 25.420 25.620
## [415] 25.160 25.120 25.400 25.220 24.810 25.250 24.780 24.270 23.950
## [424] 24.100 24.280 24.250 24.820 25.030 25.450 25.190 25.440 25.640
## [433] 25.520 25.880 25.660 25.670 25.810 25.700 25.700 25.820 26.360
## [442] 26.410 26.470 26.380 26.520 26.420 26.460 26.610 27.010 26.920
## [451] 26.850 26.990 27.000 26.860 26.870 26.490 26.020 26.050 26.380
## [460] 26.090 26.010 25.690 25.580 25.270 25.410 24.890 24.590 24.490
## [469] 24.660 25.140 25.620 25.710 25.880 25.830 25.780 25.700 25.570
## [478] 25.270 25.060 24.600 24.070 24.080 24.370 24.030 23.980 23.860
## [487] 23.780 23.580 23.590 23.850 24.040 24.280 24.480 24.590 24.380
## [496] 23.840 24.080 23.890 24.210 24.470 24.160 24.500 24.520 24.640
## [505] 24.720 24.770 24.890 25.150 25.170 25.250 25.010 25.210 25.170
## [514] 25.390 25.910 25.890 25.990 26.110 25.860 25.660 25.820 25.420
## [523] 25.640 25.170 25.190 25.400 25.040 25.450 25.310 25.640 25.330
## [532] 25.400 25.470 25.270 24.910 24.800 24.860 25.120 24.810 24.840
## [541] 24.940 25.180 25.020 25.010 25.730 28.510 27.630 27.730 27.460
## [550] 27.280 27.250 27.020 26.620 26.910 26.850 26.800 26.880 27.120
## [559] 27.090 27.080 27.310 27.270 26.920 26.810 27.040 27.360 26.920
## [568] 27.030 27.210 27.410 27.270 27.310 27.350 27.640 27.720 27.680
## [577] 27.520 27.520 27.630 27.270 27.280 27.330 27.530 27.260 27.290
## [586] 27.240 27.330 27.630 27.510 27.390 27.210 27.220 27.270 27.370
## [595] 27.240 27.420 27.550 27.260 27.040 27.090 26.640 26.570 26.660
## [604] 26.780 26.310 26.470 25.890 26.020 26.270 26.470 26.660 26.770
## [613] 27.040 27.240 27.140 26.850 26.630 26.260 25.750 25.950 26.100
## [622] 26.260 26.120 26.100 25.870 25.900 26.100 26.030 25.790 26.240
## [631] 25.710 25.860 25.790 26.080 26.210 26.070 25.730 25.190 24.590
## [640] 23.870 23.270 24.010 25.010 25.160 24.820 23.880 24.570 24.510
## [649] 24.000 24.960 24.550 24.680 24.950 24.770 25.300 25.930 25.350
## [658] 24.800 25.090 25.110 25.140 24.910 24.920 24.310 24.570 25.220
## [667] 25.190 25.470 26.820 27.290 27.770 28.030 28.070 28.090 27.870
## [676] 27.600 28.030 28.980 28.990 28.780 28.850 29.580 29.510 29.550
## [685] 29.460 29.390 29.340 28.920 29.400 29.590 29.540 29.640 29.920
## [694] 29.750 30.120 30.670 30.160 30.280 30.360 30.320 30.520 30.270
## [703] 30.660 30.590 30.660 30.360 30.360 29.940 30.170 29.970 30.030
## [712] 30.490 30.370 30.190 30.470 30.650 30.260 30.260 30.320 30.980
## [721] 30.550 30.280 30.400 30.490 30.950 30.830 30.900 31.280 31.050
## [730] 31.150 30.710 30.740 30.250 28.970 28.450 28.580 28.640 28.240
## [739] 29.060 28.490 28.490 28.000 28.590 28.240 28.040 28.310 28.000
## [748] 28.210 29.100 28.640 28.240 28.670 29.180 28.540 28.170 28.280
## [757] 28.300 27.450 28.260 28.860 29.340 29.080 29.020 29.410 29.220
## [766] 28.960 29.230 29.400 29.140 29.880 30.180 30.220 30.460 30.290
## [775] 30.060 30.050 29.940 30.340 30.270 30.280 30.170 30.960 30.920
## [784] 31.090 31.060 31.070 31.110 31.490 31.480 31.830 31.790 31.930
## [793] 31.230 30.980 30.900 30.630 30.790 30.710 30.810 30.980 31.020
## [802] 31.030 31.060 31.150 31.150 30.980 30.760 30.680 30.900 30.930
## [811] 30.900 30.750 30.890 30.630 30.070 29.890 30.120 29.870 30.480
## [820] 30.340 30.090 29.640 29.960 29.710 29.610 29.360 29.560 29.490
## [829] 29.850 30.090 30.020 30.120 30.230 30.110 30.050 29.940 30.120
## [838] 30.140 30.310 30.240 30.040 29.830 30.440 30.710 30.640 30.600
## [847] 30.830 30.940 30.780 31.190 29.820 29.320 29.940 30.550 31.480
## [856] 31.490 31.450 31.740 31.820 32.200 32.210 32.260 32.360 32.630
## [865] 32.880 32.910 32.930 32.780 32.590 32.060 31.640 31.470 31.280
## [874] 31.250 31.140 31.150 31.050 31.130 31.170 31.280 31.270 31.300
## [883] 31.270 31.290 31.240 31.240 31.190 31.290 31.430 31.250 31.320
## [892] 31.230 31.220 31.210 31.230 31.360 31.370 31.240 31.200 31.290
## [901] 31.050 31.060 31.040 30.110 30.490 29.850 29.700 29.750 29.680
## [910] 29.430 29.670 29.850 30.040 29.890 29.540 29.880 29.900 29.530
## [919] 29.620 29.640 29.500 29.500 29.270 29.080 28.860 28.920 28.900
## [928] 28.770 28.890 28.850 28.980 29.060 29.070 28.980 28.920 28.650
## [937] 28.870 28.630 29.220 29.100 28.880 28.490 28.280 28.440 29.310
## [946] 29.420 29.630 30.410 30.710 30.510 30.750 30.740 30.790 30.670
## [955] 30.870 31.180 31.340 31.440 31.250 31.050 30.760 31.390 31.340
## [964] 31.110 31.170 31.600 31.530 31.780 31.860 31.740 31.500 31.260
## [973] 31.750 31.920 32.250 32.130 31.820 31.880 31.900 31.700 31.710
## [982] 31.600 31.690 31.700 31.520 31.610 31.460 31.370 31.470 31.390
## [991] 31.360 31.270 31.230 31.210 30.530 29.750 30.000 30.370 30.320
## [1000] 30.010 29.960 29.700 29.690 29.680 29.700 29.660 29.560 29.430
## [1009] 29.590 29.720 30.040 30.280 30.350 30.450 30.370 30.520 30.330
## [1018] 30.020 30.190 29.940 29.810 30.190 30.190 30.120 30.000 29.860
## [1027] 29.800 29.660 30.280 29.860 29.540 29.760 29.750 29.880 29.740
## [1036] 29.390 29.530 29.620 29.720 29.440 29.620 29.680 29.870 29.800
## [1045] 29.880 30.020 29.970 29.930 29.990 30.010 30.040 29.770 29.560
## [1054] 29.640 29.840 30.000 30.270 29.550 29.550 29.450 29.260 29.080
## [1063] 28.990 28.940 28.990 29.230 29.200 29.220 29.070 28.930 28.700
## [1072] 28.870 28.270 28.180 28.040 27.410 27.480 28.050 28.180 28.280
## [1081] 27.830 27.490 27.450 27.360 27.380 27.720 27.880 27.980 27.930
## [1090] 27.680 27.590 27.940 28.940 28.450 28.690 28.940 29.000 28.800
## [1099] 28.130 27.780 27.550 27.570 27.610 27.210 27.080 27.020 27.010
## [1108] 27.450 27.350 26.310 26.150 26.040 26.380 26.580 26.790 26.780
## [1117] 26.820 26.890 26.940 26.690 25.910 25.430 25.440 25.590 25.790
## [1126] 25.530 25.610 25.440 25.520 25.760 25.780 25.630 25.560 25.710
## [1135] 25.300 25.200 25.360 25.140 25.100 24.750 24.550 24.490 24.600
## [1144] 24.390 24.300 24.490 24.470 24.440 24.280 24.550 25.140 24.760
## [1153] 24.920 24.020 23.820 23.720 23.910 24.110 24.260 23.930 24.460
## [1162] 24.200 24.320 24.750 24.870 25.110 24.930 24.370 24.240 24.180
## [1171] 24.570 24.800 24.480 24.540 24.390 23.430 23.360 23.070 23.050
## [1180] 22.980 23.360 23.190 23.120 23.580 23.830 22.320 21.890 21.525
## [1189] 21.320 20.790 20.410 20.160 20.020 19.940 20.140 20.130 20.210
## [1198] 20.120 19.990 20.490 19.020 17.900 18.260 18.250 18.210 17.980
## [1207] 17.830 18.150 18.190 18.120 18.410 18.480 18.290 17.880 17.950
## [1216] 17.760 17.660 17.710 17.710 17.650 17.910 17.760 17.640 17.820
## [1225] 17.760 17.590 17.450 17.470 17.500 17.430 17.380 17.360 17.450
## [1234] 17.980 18.150 18.530 18.540 18.280 18.560 18.929 19.020 18.760
## [1243] 18.210 17.350 16.770 16.260 16.170 16.890 16.440 16.180 16.130
## [1252] 16.280 15.950 16.170 16.020 15.640
##
## $upper
## Time Series:
## Start = c(2018, 3)
## End = c(2019, 3)
## Frequency = 251
## 80% 95%
## 2018.008 16.45404 16.74300
## 2018.012 16.83812 17.23623
## 2018.016 17.12883 17.60713
## 2018.020 17.07552 17.62832
## 2018.024 17.67288 18.26963
## 2018.028 18.18072 18.81579
## 2018.032 18.42377 19.10009
## 2018.036 18.27297 19.00084
## 2018.040 18.40751 19.17322
## 2018.044 18.56224 19.36205
## 2018.048 18.72574 19.55674
## 2018.052 18.85430 19.71579
## 2018.056 18.91883 19.81177
## 2018.060 19.11561 20.03238
## 2018.064 18.95770 19.91341
## 2018.068 19.34179 20.30943
## 2018.072 19.65701 20.63848
## 2018.076 19.84047 20.84081
## 2018.080 19.83054 20.85812
## 2018.084 19.79052 20.84614
## 2018.088 19.50834 20.60416
## 2018.092 19.51626 20.63674
## 2018.096 19.46667 20.61438
## 2018.100 19.66063 20.82141
## 2018.104 19.69334 20.87552
## 2018.108 19.65960 20.86647
## 2018.112 19.76297 20.98610
## 2018.116 19.95349 21.18721
## 2018.120 20.09129 21.33810
## 2018.124 20.14497 21.40928
## 2018.127 20.05738 21.34724
## 2018.131 20.02965 21.34121
## 2018.135 20.13497 21.45970
## 2018.139 20.36459 21.69440
## 2018.143 20.42449 21.76940
## 2018.147 20.49859 21.85736
## 2018.151 20.60431 21.97460
## 2018.155 20.79705 22.17310
## 2018.159 20.61707 22.02194
## 2018.163 20.50297 21.93255
## 2018.167 20.62001 22.05909
## 2018.171 20.78765 22.23262
## 2018.175 21.51462 22.92985
## 2018.179 21.15466 22.60853
## 2018.183 21.36554 22.82174
## 2018.187 21.35880 22.83100
## 2018.191 21.32560 22.81536
## 2018.195 21.24729 22.75747
## 2018.199 21.19776 22.72640
## 2018.203 21.23422 22.77538
## 2018.207 21.42725 22.97015
## 2018.211 21.48135 23.03514
## 2018.215 21.27717 22.85933
## 2018.219 21.35712 22.94806
## 2018.223 21.49101 23.08679
## 2018.227 21.47466 23.08552
## 2018.231 21.43631 23.06368
## 2018.235 21.47003 23.10872
## 2018.239 21.49531 23.14576
## 2018.243 21.28539 22.96448
## 2018.247 21.31307 23.00354
## 2018.251 21.27928 22.98555
## 2018.255 21.48639 23.19050
## 2018.259 21.36505 23.09115
## 2018.263 21.61396 23.33445
## 2018.267 21.57730 23.31321
## 2018.271 21.59976 23.34660
## 2018.275 21.31943 23.10013
## 2018.279 21.43515 23.21945
## 2018.283 21.29714 23.10456
## 2018.287 21.26874 23.09076
## 2018.291 21.23418 23.07122
## 2018.295 21.45752 23.28904
## 2018.299 21.48419 23.32561
## 2018.303 21.67924 23.51720
## 2018.307 21.69248 23.54114
## 2018.311 21.46931 23.34739
## 2018.315 21.58105 23.46180
## 2018.319 21.62433 23.51313
## 2018.323 21.56226 23.46752
## 2018.327 21.65598 23.56501
## 2018.331 21.87745 23.77987
## 2018.335 22.02230 23.92424
## 2018.339 22.02472 23.93743
## 2018.343 22.03776 23.96032
## 2018.347 21.96927 23.90819
## 2018.351 21.99401 23.94170
## 2018.355 22.18606 24.12887
## 2018.359 22.35843 24.29795
## 2018.363 22.49475 24.43383
## 2018.367 22.49010 24.43987
## 2018.371 22.51247 24.47070
## 2018.375 22.46395 24.43627
## 2018.378 22.37139 24.36139
## 2018.382 22.15816 24.17593
## 2018.386 22.17058 24.19746
## 2018.390 21.80286 23.87122
## 2018.394 21.55831 23.65834
## 2018.398 21.59817 23.70486
## 2018.402 21.84977 23.94437
## 2018.406 22.28813 24.35487
## 2018.410 22.17947 24.26528
## 2018.414 22.31235 24.39651
## 2018.418 22.22998 24.33089
## 2018.422 22.06646 24.19128
## 2018.426 22.28230 24.39789
## 2018.430 22.33425 24.45485
## 2018.434 22.46859 24.58701
## 2018.438 22.71409 24.82084
## 2018.442 22.86843 24.97133
## 2018.446 23.15724 25.24513
## 2018.450 23.09389 25.19604
## 2018.454 23.05333 25.16786
## 2018.458 22.94892 25.08123
## 2018.462 22.77240 24.92881
## 2018.466 22.25747 24.46844
## 2018.470 22.00115 24.24468
## 2018.474 21.97859 24.23333
## 2018.478 22.04522 24.30285
## 2018.482 22.01023 24.28015
## 2018.486 21.98325 24.26470
## 2018.490 21.92487 24.22081
## 2018.494 21.79004 24.10781
## 2018.498 22.00732 24.31326
## 2018.502 22.09941 24.40545
## 2018.506 22.12425 24.43671
## 2018.510 22.24972 24.55905
## 2018.514 22.08014 24.41422
## 2018.518 22.19707 24.52865
## 2018.522 22.10282 24.45201
## 2018.526 22.09564 24.45410
## 2018.530 22.27101 24.62117
## 2018.534 22.16149 24.53064
## 2018.538 22.17255 24.54909
## 2018.542 22.06147 24.45727
## 2018.546 21.76713 24.20061
## 2018.550 21.60871 24.06674
## 2018.554 21.37565 23.86627
## 2018.558 21.54625 24.02768
## 2018.562 21.74244 24.21215
## 2018.566 21.85325 24.32002
## 2018.570 21.78645 24.26832
## 2018.574 21.61920 24.12662
## 2018.578 21.72451 24.22929
## 2018.582 21.81876 24.32205
## 2018.586 21.93046 24.43044
## 2018.590 22.04482 24.54122
## 2018.594 22.05847 24.56153
## 2018.598 21.85672 24.38856
## 2018.602 21.55782 24.12918
## 2018.606 21.70211 24.26624
## 2018.610 21.82259 24.38205
## 2018.614 22.08885 24.62852
## 2018.618 21.93860 24.50176
## 2018.622 21.66706 24.26688
## 2018.625 21.81437 24.40638
## 2018.629 21.84266 24.43951
## 2018.633 21.92204 24.51828
## 2018.637 21.97281 24.57144
## 2018.641 21.96769 24.57459
## 2018.645 21.72645 24.36694
## 2018.649 21.95887 24.58208
## 2018.653 21.92958 24.56358
## 2018.657 21.75364 24.41432
## 2018.661 21.91137 24.56257
## 2018.665 22.31961 24.93491
## 2018.669 22.34847 24.96819
## 2018.673 22.49527 25.10706
## 2018.677 22.54270 25.15691
## 2018.681 22.40228 25.03852
## 2018.685 22.06561 24.74517
## 2018.689 22.02882 24.71978
## 2018.693 21.96970 24.67451
## 2018.697 22.11215 24.80877
## 2018.701 22.67532 25.31919
## 2018.705 22.91839 25.54419
## 2018.709 22.94830 25.57809
## 2018.713 22.88602 25.52928
## 2018.717 23.30324 25.91089
## 2018.721 23.36816 25.97619
## 2018.725 23.05682 25.70341
## 2018.729 22.98201 25.64326
## 2018.733 22.94790 25.61963
## 2018.737 22.80718 25.50060
## 2018.741 22.86940 25.56317
## 2018.745 22.86716 25.56806
## 2018.749 22.82633 25.53842
## 2018.753 22.80600 25.52711
## 2018.757 22.84487 25.56868
## 2018.761 23.11509 25.81715
## 2018.765 23.33307 26.01918
## 2018.769 23.48746 26.16434
## 2018.773 23.74627 26.40347
## 2018.777 23.77456 26.43544
## 2018.781 24.05235 26.69198
## 2018.785 23.80172 26.47284
## 2018.789 23.73963 26.42351
## 2018.793 23.84257 26.52246
## 2018.797 23.78484 26.47701
## 2018.801 23.93000 26.61386
## 2018.805 23.89370 26.58760
## 2018.809 23.97691 26.66874
## 2018.813 24.02733 26.72039
## 2018.817 23.97570 26.68027
## 2018.821 23.71776 26.45506
## 2018.825 23.78232 26.51926
## 2018.829 23.76059 26.50607
## 2018.833 23.85560 26.59753
## 2018.837 23.98245 26.71759
## 2018.841 23.89262 26.64319
## 2018.845 23.81957 26.58393
## 2018.849 23.86859 26.63405
## 2018.853 23.94804 26.71144
## 2018.857 23.88283 26.65914
## 2018.861 23.88215 26.66467
## 2018.865 23.91671 26.70175
## 2018.869 24.12043 26.89044
## 2018.873 24.01425 26.80131
## 2018.876 24.23776 27.00776
## 2018.880 24.35548 27.11943
## 2018.884 24.53881 27.29011
## 2018.888 24.65222 27.39802
## 2018.892 24.54420 27.30675
## 2018.896 24.59993 27.36271
## 2018.900 24.71548 27.47247
## 2018.904 24.45957 27.24833
## 2018.908 24.46257 27.25687
## 2018.912 24.22012 27.04537
## 2018.916 24.26566 27.09202
## 2018.920 24.17462 27.01636
## 2018.924 23.92879 26.80251
## 2018.928 23.73459 26.63519
## 2018.932 23.65101 26.56666
## 2018.936 23.72773 26.64087
## 2018.940 23.78950 26.70177
## 2018.944 23.95177 26.85226
## 2018.948 23.66994 26.60704
## 2018.952 23.57152 26.52539
## 2018.956 23.29790 26.28845
## 2018.960 23.39240 26.37810
## 2018.964 22.93868 25.98253
## 2018.968 22.70892 25.78590
## 2018.972 23.01510 26.06186
## 2018.976 22.85702 25.92830
## 2018.980 22.96270 26.02740
## 2018.984 23.02643 26.08950
## 2018.988 22.87388 25.96085
## 2018.992 22.75196 25.85939
## 2018.996 22.85155 25.95292
## 2019.000 23.12399 26.19891
## 2019.004 23.05815 26.14661
## 2019.008 23.24335 26.31583
##
## $lower
## Time Series:
## Start = c(2018, 3)
## End = c(2019, 3)
## Frequency = 251
## 80% 95%
## 2018.008 15.313172 14.996684
## 2018.012 15.240425 14.788682
## 2018.016 15.186431 14.629210
## 2018.020 14.801841 14.138976
## 2018.024 15.208455 14.486165
## 2018.028 15.548979 14.774151
## 2018.032 15.606261 14.770839
## 2018.036 15.211898 14.292377
## 2018.040 15.169684 14.189570
## 2018.044 15.164387 14.128932
## 2018.048 15.180973 14.094310
## 2018.052 15.164071 14.025768
## 2018.056 15.075159 13.880808
## 2018.060 15.159569 13.925639
## 2018.064 14.800058 13.486774
## 2018.068 15.137667 13.812384
## 2018.072 15.394180 14.051084
## 2018.076 15.488541 14.113841
## 2018.080 15.339112 13.909669
## 2018.084 15.152531 13.663954
## 2018.088 14.646091 13.059604
## 2018.092 14.522708 12.880994
## 2018.096 14.323262 12.615695
## 2018.100 14.457063 12.728598
## 2018.104 14.374742 12.596619
## 2018.108 14.202724 12.361605
## 2018.112 14.222249 12.346360
## 2018.116 14.366061 12.475150
## 2018.120 14.439792 12.524171
## 2018.124 14.398999 12.441682
## 2018.127 14.160830 12.129512
## 2018.131 14.006749 11.913459
## 2018.135 14.044242 11.922287
## 2018.139 14.262168 12.144174
## 2018.143 14.239652 12.083986
## 2018.147 14.239342 12.050268
## 2018.151 14.286524 12.073154
## 2018.155 14.461175 12.247392
## 2018.159 14.097945 11.783560
## 2018.163 13.826680 11.424288
## 2018.167 13.897580 11.477212
## 2018.171 14.045336 11.623709
## 2018.175 15.008125 12.741544
## 2018.179 14.392278 11.979728
## 2018.183 14.607807 12.208408
## 2018.187 14.505642 12.056530
## 2018.191 14.364522 11.856750
## 2018.195 14.155443 11.572546
## 2018.199 13.988312 11.337176
## 2018.203 13.951505 11.261508
## 2018.207 14.153782 11.481796
## 2018.211 14.146584 11.443762
## 2018.215 13.743903 10.911783
## 2018.219 13.777745 10.924409
## 2018.223 13.896344 11.044236
## 2018.227 13.783109 10.871853
## 2018.231 13.635162 10.653769
## 2018.235 13.600555 10.579594
## 2018.239 13.553308 10.488941
## 2018.243 13.128709 9.902889
## 2018.247 13.084821 9.813267
## 2018.251 12.940751 9.588497
## 2018.255 13.191963 9.894309
## 2018.259 12.905606 9.477473
## 2018.263 13.228610 9.882642
## 2018.267 13.083345 9.656704
## 2018.271 13.035413 9.560959
## 2018.275 12.477394 8.751683
## 2018.279 12.587439 8.875287
## 2018.283 12.262672 8.374078
## 2018.287 12.124616 8.135559
## 2018.291 11.974738 7.874536
## 2018.295 12.280095 8.297666
## 2018.299 12.240624 8.205124
## 2018.303 12.496081 8.549118
## 2018.307 12.435477 8.427609
## 2018.311 11.955642 7.666352
## 2018.315 12.070193 7.808988
## 2018.319 12.062930 7.762974
## 2018.323 11.865993 7.417114
## 2018.327 11.951267 7.517313
## 2018.331 12.266477 7.975725
## 2018.335 12.443074 8.212656
## 2018.339 12.367454 8.065159
## 2018.343 12.310867 7.945354
## 2018.347 12.107182 7.591878
## 2018.351 12.071588 7.500693
## 2018.355 12.339804 7.892718
## 2018.359 12.570703 8.218081
## 2018.363 12.736627 8.439722
## 2018.367 12.653377 8.283184
## 2018.371 12.618250 8.198909
## 2018.375 12.456082 7.915641
## 2018.378 12.211901 7.492542
## 2018.382 11.737636 6.654839
## 2018.386 11.681969 6.518629
## 2018.390 10.883697 4.898135
## 2018.394 10.296434 3.326959
## 2018.398 10.291316 3.237303
## 2018.402 10.724996 4.371847
## 2018.406 11.513718 6.014469
## 2018.410 11.222101 5.391479
## 2018.414 11.404278 5.719804
## 2018.418 11.162792 5.176433
## 2018.422 10.751397 4.160716
## 2018.426 11.108561 4.965052
## 2018.430 11.133830 4.974845
## 2018.434 11.324004 5.343894
## 2018.438 11.729677 6.119524
## 2018.442 11.953607 6.503341
## 2018.446 12.428082 7.307889
## 2018.450 12.239739 6.950199
## 2018.454 12.092620 6.653837
## 2018.458 11.820660 6.109032
## 2018.462 11.400188 5.206622
## 2018.466 10.251453 1.338979
## 2018.470 9.595318 -3.416415
## 2018.474 9.455490 -3.844205
## 2018.478 9.522341 -3.734947
## 2018.482 9.352880 -4.193676
## 2018.486 9.199945 -4.567381
## 2018.490 8.968396 -5.050019
## 2018.494 8.538214 -5.785043
## 2018.498 8.988138 -5.100293
## 2018.502 9.122724 -4.899532
## 2018.506 9.094238 -4.995237
## 2018.510 9.309231 -4.628426
## 2018.514 8.805678 -5.564930
## 2018.518 9.006591 -5.273794
## 2018.522 8.680530 -5.831054
## 2018.526 8.570179 -6.026986
## 2018.530 8.924590 -5.526536
## 2018.534 8.556175 -6.115487
## 2018.538 8.492967 -6.236332
## 2018.542 8.102773 -6.766150
## 2018.546 7.155349 -7.787723
## 2018.550 6.540421 -8.335533
## 2018.554 5.587043 -9.025101
## 2018.558 6.082556 -8.722232
## 2018.562 6.629906 -8.338168
## 2018.566 6.874392 -8.162596
## 2018.570 6.543633 -8.453953
## 2018.574 5.834616 -8.980405
## 2018.578 6.090506 -8.831557
## 2018.582 6.300066 -8.706245
## 2018.586 6.563159 -8.532994
## 2018.590 6.826888 -8.347262
## 2018.594 6.761431 -8.423843
## 2018.598 5.947326 -9.038870
## 2018.602 4.573159 -9.826034
## 2018.606 5.067381 -9.600887
## 2018.610 5.426772 -9.423109
## 2018.614 6.298653 -8.885933
## 2018.618 5.621070 -9.350066
## 2018.622 4.277782 -10.055210
## 2018.625 4.821938 -9.825471
## 2018.629 4.799749 -9.855797
## 2018.633 5.006779 -9.771822
## 2018.637 5.084979 -9.750908
## 2018.641 4.919088 -9.854928
## 2018.645 3.496836 -10.462720
## 2018.649 4.577571 -10.055793
## 2018.653 4.271747 -10.207923
## 2018.657 3.024251 -10.662044
## 2018.661 3.823585 -10.420122
## 2018.665 5.591625 -9.607513
## 2018.669 5.581324 -9.632812
## 2018.673 6.027732 -9.379714
## 2018.677 6.088841 -9.359916
## 2018.681 5.419581 -9.781554
## 2018.685 3.607657 -10.602064
## 2018.689 3.163788 -10.759919
## 2018.693 2.455510 -10.959992
## 2018.697 3.306411 -10.750916
## 2018.701 5.897539 -9.596625
## 2018.705 6.670436 -9.096328
## 2018.709 6.671025 -9.115717
## 2018.713 6.347332 -9.363243
## 2018.717 7.629009 -8.373517
## 2018.721 7.738156 -8.294362
## 2018.725 6.639118 -9.217093
## 2018.729 6.268086 -9.492096
## 2018.733 6.031697 -9.662428
## 2018.737 5.348448 -10.074340
## 2018.741 5.487599 -10.016860
## 2018.745 5.355474 -10.105558
## 2018.749 5.048649 -10.279391
## 2018.753 4.820587 -10.405144
## 2018.757 4.867536 -10.400070
## 2018.761 5.898697 -9.869528
## 2018.765 6.603467 -9.430991
## 2018.769 7.037351 -9.130799
## 2018.773 7.774450 -8.532246
## 2018.777 7.777138 -8.549980
## 2018.781 8.512892 -7.839680
## 2018.785 7.692914 -8.665563
## 2018.789 7.411940 -8.926265
## 2018.793 7.651493 -8.741334
## 2018.797 7.383097 -8.988136
## 2018.801 7.755831 -8.688110
## 2018.805 7.558940 -8.879037
## 2018.809 7.735888 -8.744639
## 2018.813 7.809686 -8.698189
## 2018.817 7.565902 -8.929895
## 2018.821 6.608686 -9.677128
## 2018.825 6.743673 -9.600984
## 2018.829 6.571419 -9.736851
## 2018.833 6.815359 -9.585068
## 2018.837 7.159763 -9.348393
## 2018.841 6.760913 -9.657959
## 2018.845 6.401295 -9.916664
## 2018.849 6.485984 -9.878185
## 2018.853 6.680110 -9.764813
## 2018.857 6.345464 -10.001943
## 2018.861 6.244626 -10.081464
## 2018.865 6.277979 -10.076950
## 2018.869 6.925811 -9.660059
## 2018.873 6.451978 -9.999047
## 2018.876 7.154436 -9.526132
## 2018.880 7.462095 -9.304509
## 2018.884 7.964029 -8.896845
## 2018.888 8.233266 -8.666899
## 2018.892 7.826779 -9.053447
## 2018.896 7.923684 -8.986621
## 2018.900 8.202037 -8.751614
## 2018.904 7.313241 -9.523665
## 2018.908 7.240608 -9.595622
## 2018.912 6.278803 -10.266320
## 2018.916 6.358678 -10.232553
## 2018.920 5.901463 -10.517958
## 2018.924 4.670129 -11.133786
## 2018.928 3.371110 -11.607020
## 2018.932 2.493230 -11.840024
## 2018.936 2.943637 -11.749508
## 2018.940 3.227466 -11.688131
## 2018.944 4.120871 -11.417500
## 2018.948 1.544235 -12.052784
## 2018.952 -1.854538 -12.304708
## 2018.956 -4.175484 -12.872965
## 2018.960 -3.767504 -12.758615
## 2018.964 -6.031685 -13.611770
## 2018.968 -6.930666 -14.044304
## 2018.972 -5.932884 -13.590978
## 2018.976 -6.603838 -13.908058
## 2018.980 -6.318833 -13.786136
## 2018.984 -6.176862 -13.732789
## 2018.988 -6.805053 -14.037469
## 2018.992 -7.281660 -14.285292
## 2018.996 -7.044910 -14.176805
## 2019.000 -6.184949 -13.780697
## 2019.004 -6.514504 -13.942598
## 2019.008 -5.916648 -13.684516
##
## $fitted
## Time Series:
## Start = c(2013, 2)
## End = c(2018, 2)
## Frequency = 251
## [1] 22.49785 22.50582 22.59304 22.73895 23.26511 23.71573 23.57054
## [8] 23.78461 23.20062 23.29279 23.40861 22.88982 23.14799 23.37941
## [15] 23.29887 23.03410 23.55677 23.76784 23.78391 23.62474 23.69481
## [22] 23.34088 23.37911 23.42309 23.70736 23.46558 23.22288 23.34814
## [29] 23.53646 23.36783 23.37322 23.16045 23.03893 23.15112 23.25633
## [36] 23.14204 23.31056 23.06593 23.18808 22.77528 22.97548 23.15452
## [43] 23.71686 24.17557 23.04086 22.99738 23.02938 22.72448 22.53275
## [50] 21.62975 21.33767 21.66862 21.96126 21.82552 22.26975 22.36774
## [57] 22.25487 22.10841 22.35208 22.55939 22.34943 22.71509 22.93979
## [64] 22.94129 22.79467 23.05604 22.98550 23.22414 23.07266 23.53880
## [71] 23.43547 23.68792 23.79244 23.76749 23.52635 23.73426 23.65543
## [78] 23.38229 23.42115 23.65682 23.54691 23.36623 23.60095 23.95565
## [85] 23.74484 23.56616 23.42765 23.64721 23.60515 23.96865 24.37509
## [92] 23.88050 23.25288 23.25492 22.88106 22.92201 23.24067 22.99872
## [99] 22.95887 23.33455 23.10765 23.30350 23.11440 23.39536 23.50741
## [106] 23.47264 24.11250 23.78909 23.68789 23.64496 23.62852 23.95310
## [113] 24.62845 24.78479 24.58319 24.46866 24.27132 24.43360 24.44925
## [120] 24.51324 24.30479 24.61194 24.60466 24.37188 24.49081 24.38342
## [127] 24.32510 24.36175 24.08652 24.27352 23.99018 23.97043 24.08640
## [134] 23.73595 23.71130 23.52131 23.49937 23.60500 23.33257 23.33897
## [141] 23.35790 23.17882 23.04112 22.89470 23.26516 23.21356 23.21040
## [148] 23.54613 23.86794 23.93900 23.59959 23.91103 24.27353 24.69237
## [155] 24.66295 24.19371 24.10664 24.29666 24.34627 24.20521 24.21082
## [162] 23.78645 24.10984 24.16172 24.15818 24.22990 24.35990 23.90198
## [169] 23.82132 23.63520 24.11348 24.13922 24.32129 24.15702 24.49889
## [176] 25.24990 25.77474 26.15959 25.91760 26.04948 25.96924 25.69602
## [183] 26.06351 26.18234 26.23466 26.22180 26.53568 26.39903 26.44665
## [190] 26.92280 26.83426 27.18992 27.11909 27.26816 27.12260 27.19696
## [197] 27.05508 27.19552 27.07865 26.88517 27.04543 27.01008 26.78283
## [204] 26.79076 26.73667 26.40731 26.68737 26.54772 26.67116 26.60433
## [211] 26.85758 27.10965 27.10543 26.63665 26.46151 26.82449 26.98749
## [218] 27.24408 27.32316 27.49182 27.45113 27.56405 27.72142 27.72825
## [225] 27.86249 27.98594 27.75121 27.48034 27.21906 27.24331 27.17939
## [232] 26.97327 27.00106 26.87143 26.78595 27.01156 27.44872 26.90574
## [239] 26.49452 26.05722 26.08222 25.38638 24.76961 25.30918 25.27915
## [246] 25.40624 25.52241 24.92127 24.26980 24.62166 24.80747 25.00157
## [253] 25.21613 25.17261 25.55625 25.27033 25.73178 26.00035 25.70006
## [260] 25.21181 25.15152 24.96721 25.35991 25.34679 25.30598 25.57838
## [267] 25.32172 25.38200 25.82239 26.03234 26.17136 26.06072 25.78763
## [274] 25.87102 25.69503 25.38133 25.12438 25.39622 25.67984 25.36297
## [281] 25.34270 25.40452 25.33026 25.63263 25.66780 25.93916 25.92542
## [288] 25.87808 25.92777 26.14306 26.08520 25.89433 25.92984 25.86967
## [295] 26.48514 25.21120 25.59354 25.65502 25.78352 26.00828 26.47042
## [302] 26.58463 26.71478 26.42601 26.33514 26.64756 26.86169 26.72911
## [309] 26.85097 26.79084 26.67294 26.38577 26.21321 26.47152 26.58031
## [316] 26.32230 27.02620 26.89132 26.74862 26.40857 26.74014 26.48749
## [323] 26.30738 26.43211 26.62219 26.50837 26.69438 26.66787 26.54637
## [330] 26.87384 26.84504 26.69729 26.59549 26.95543 27.26794 27.41289
## [337] 27.39857 27.08480 26.93922 27.13086 26.98377 26.92469 26.81777
## [344] 26.93240 26.88678 26.62420 26.40863 26.41258 25.99409 26.22389
## [351] 26.28043 26.58273 26.95124 26.75263 26.82259 26.27388 26.23568
## [358] 26.35951 26.57594 26.72236 26.80016 27.10600 26.88386 26.37813
## [365] 25.91351 25.90275 25.75953 25.52475 25.57475 25.55146 25.48408
## [372] 25.58216 25.13418 25.26398 25.12861 25.19510 25.48738 25.49847
## [379] 25.76166 25.62092 25.68335 25.75010 25.85343 25.76965 25.96468
## [386] 26.04339 26.27430 26.17653 25.99523 25.96171 26.14664 26.27045
## [393] 26.07528 25.89684 25.70221 26.03092 26.01224 26.15449 26.20398
## [400] 25.89880 25.79794 25.78070 25.98756 26.03422 26.43094 26.09610
## [407] 25.96415 26.38278 26.09416 26.05170 25.92043 25.51751 25.39029
## [414] 25.62124 25.60306 24.99338 25.24387 25.70283 25.19482 24.94710
## [421] 25.30225 24.64412 23.99158 23.89359 24.05865 24.41250 24.80894
## [428] 25.04612 25.04942 25.35373 25.54798 25.47421 25.42599 25.47967
## [435] 25.84828 25.52086 25.74422 25.80184 25.66330 25.71298 25.84309
## [442] 26.59260 26.56296 26.58386 26.60155 26.50350 26.63829 26.28774
## [449] 26.57432 27.06582 26.84853 26.98037 26.92647 27.05467 26.87717
## [456] 26.78550 26.23849 26.05232 26.03310 26.42202 26.23257 25.92244
## [463] 25.60655 25.56022 25.33009 25.33094 24.87427 24.60138 24.71247
## [470] 24.55947 25.33142 25.71776 25.88173 25.99221 25.71917 25.81658
## [477] 25.80209 25.27584 25.25143 24.78367 24.59431 23.95100 23.81714
## [484] 24.13651 23.93122 24.04261 23.90867 23.90948 23.25110 23.48968
## [491] 23.58733 24.13334 23.82142 24.28529 24.84062 24.19852 23.95455
## [498] 24.10787 23.68630 24.11845 24.52825 24.43967 24.53553 24.56837
## [505] 24.75885 24.83449 24.64245 25.19854 25.42282 25.23929 25.06535
## [512] 25.04280 25.24650 25.23826 25.45381 25.91311 25.97369 25.83840
## [519] 26.35834 26.03976 25.76178 25.77193 25.34787 25.38417 25.13913
## [526] 25.11945 25.46611 25.04491 25.40731 25.34461 25.73351 25.40352
## [533] 25.40609 25.38346 25.20721 24.96093 24.94169 24.89696 25.12271
## [540] 24.86938 24.95559 24.77755 25.05278 25.09780 25.12724 26.27130
## [547] 28.19270 27.77640 27.68688 27.42090 27.18012 27.17144 27.01924
## [554] 26.75280 26.92067 26.70558 26.84489 26.96176 27.08788 27.04655
## [561] 27.09471 27.30491 27.08202 26.93554 26.75454 27.17838 27.25939
## [568] 27.09652 26.99370 27.20109 27.20580 27.33938 27.18728 27.33995
## [575] 27.58733 27.84283 27.67999 27.64500 27.52199 27.44103 27.34826
## [582] 27.29498 27.24608 27.57853 27.43456 27.38155 27.21612 27.31900
## [589] 27.56331 27.49745 27.49629 27.35911 27.28761 27.21503 27.37234
## [596] 27.16527 27.35229 27.37685 27.25355 26.74135 26.88552 26.64562
## [603] 26.75402 27.00233 26.67355 26.39079 26.37878 25.77981 26.18234
## [610] 26.29617 26.54392 26.85047 26.86578 27.29616 27.16387 27.08149
## [617] 26.73949 26.47710 25.83305 25.52593 25.91239 26.13523 26.20759
## [624] 26.09702 26.02316 25.73418 26.06855 26.15192 26.03160 25.88724
## [631] 26.07726 25.78693 25.77471 25.76421 26.20955 26.10431 26.06472
## [638] 25.63585 24.92266 24.42988 23.62088 23.41696 24.16287 25.08204
## [645] 25.07912 24.66559 23.96357 24.62982 24.57843 24.11715 24.95930
## [652] 24.37660 24.41708 25.06878 24.87883 25.52329 25.76635 25.09838
## [659] 24.90321 25.10320 25.15023 25.14412 24.88142 24.68106 24.51464
## [666] 24.54280 25.05310 25.31275 25.78122 26.80642 27.40795 27.80972
## [673] 27.90774 27.81551 28.04471 27.82719 27.71064 28.49673 29.16939
## [680] 29.00584 28.70246 29.16439 29.61316 29.29973 29.50369 29.42895
## [687] 29.26851 29.39704 28.90943 29.36362 29.58873 29.55958 29.84380
## [694] 30.06359 29.85365 30.31231 30.66568 30.35750 30.10926 30.31943
## [701] 30.37618 30.46000 30.38096 30.60988 30.64038 30.68065 30.29294
## [708] 30.14319 29.97177 30.15162 30.01635 30.14183 30.41338 30.30073
## [715] 30.18756 30.52024 30.58692 30.24781 30.27176 30.48892 30.89681
## [722] 30.71181 30.36326 30.54281 30.57967 30.85651 30.86186 30.98328
## [729] 31.04949 31.03721 30.93616 30.71568 30.65189 30.04516 28.78352
## [736] 28.36716 28.63276 28.68193 28.35296 28.80265 28.40383 28.26567
## [743] 28.07484 28.20417 28.06216 28.26605 28.16015 28.09011 28.23733
## [750] 28.94597 28.55363 28.29608 28.89580 29.17128 28.62263 28.26886
## [757] 28.36641 28.18510 27.73941 28.50779 28.93638 29.18503 29.10981
## [764] 29.05981 29.46721 29.26623 28.96036 29.30991 29.26149 29.35746
## [771] 30.04174 30.26529 30.17878 30.39999 30.07347 30.03338 29.98843
## [778] 30.01577 30.33750 30.22628 30.31356 30.25809 31.02083 30.92649
## [785] 31.01299 31.01250 31.11164 31.22856 31.51171 31.49310 31.87544
## [792] 31.88625 31.79669 31.12965 31.03877 30.99222 31.09593 30.50688
## [799] 30.83766 30.77736 30.94047 30.93857 30.96807 31.06174 31.26252
## [806] 31.16312 30.83672 30.79720 30.75254 30.87037 30.88791 30.90849
## [813] 30.74696 30.72466 30.63695 30.02375 30.01700 30.02163 30.02947
## [820] 30.44167 30.33486 29.88756 29.70441 29.84567 29.68613 29.56397
## [827] 29.48998 29.56073 29.61068 29.84697 29.91437 30.08699 30.13381
## [834] 30.16146 30.15743 30.20091 30.02645 30.10184 30.13160 30.24662
## [841] 30.23523 30.15091 29.95423 30.51248 30.67612 30.64154 30.54120
## [848] 30.75857 30.77846 30.77408 30.92306 29.63040 29.32946 30.10511
## [855] 30.84975 31.38909 31.56352 31.37536 31.63087 31.95456 32.22183
## [862] 32.28028 32.41783 32.44724 32.83125 32.81964 32.86515 32.84198
## [869] 32.64980 32.23308 31.87487 31.61017 31.50132 31.23908 31.22429
## [876] 31.08062 31.03966 31.19027 31.17785 31.17298 31.35811 31.13514
## [883] 31.36651 31.19497 31.27049 31.34998 31.15039 31.18543 31.20572
## [890] 31.21384 31.12576 31.13886 31.33717 31.34064 31.27146 31.16798
## [897] 31.23488 31.43210 31.29036 31.26000 31.36911 31.04863 30.91405
## [904] 30.82480 30.20497 30.57112 30.03633 29.56670 29.53689 29.77088
## [911] 29.44000 29.71017 29.86435 30.02028 29.69611 29.70400 29.85209
## [918] 29.75934 29.63465 29.89977 29.63888 29.60438 29.53091 29.15153
## [925] 28.82193 28.81791 28.87087 29.00111 29.20916 29.07475 28.86395
## [932] 28.91095 29.37515 29.10715 28.74184 28.86070 28.61451 28.74645
## [939] 28.67822 29.20812 29.05991 28.86561 28.50996 28.49038 28.59851
## [946] 29.41847 29.61645 29.63362 30.61137 30.52256 30.46032 30.81221
## [953] 30.68261 30.89547 30.62560 30.92200 31.20442 31.28263 31.23212
## [960] 31.28467 31.02770 30.81422 31.48672 31.26341 31.04314 31.18255
## [967] 31.64931 31.46968 31.76902 31.87369 31.89278 31.41365 31.42021
## [974] 31.82983 32.05330 32.33085 32.03887 31.85220 31.96025 31.68333
## [981] 31.69014 31.50689 31.61546 31.60770 31.50399 31.35595 31.53662
## [988] 31.50814 31.40782 31.57742 31.15902 31.27902 31.06029 31.29413
## [995] 30.85946 30.35689 29.96897 29.86390 30.44654 30.35212 29.87214
## [1002] 29.86739 29.76002 29.89937 29.63161 29.81870 29.74893 29.62956
## [1009] 29.31633 29.86716 29.96032 30.12876 30.13359 30.38005 30.49560
## [1016] 30.42430 30.55535 30.32795 30.10350 30.05069 30.14654 29.97834
## [1023] 30.27400 30.14857 30.05956 29.78103 29.83243 29.73545 29.75628
## [1030] 30.27098 29.80772 29.57919 29.85793 29.81416 29.88822 29.65310
## [1037] 29.34361 29.57467 29.75027 29.73515 29.46569 29.66798 29.78931
## [1044] 29.72041 29.69690 29.93665 30.11205 30.45596 29.64919 30.11656
## [1051] 29.98282 29.99426 29.69184 29.50240 29.64436 29.95638 30.01764
## [1058] 30.10465 29.58675 29.62621 29.41743 29.21125 29.08435 28.98831
## [1065] 28.76402 28.99022 29.18556 29.33174 29.11138 29.23414 28.88328
## [1072] 28.69756 28.64160 28.33810 28.05582 27.99917 27.36367 27.63369
## [1079] 28.05154 28.31044 28.27172 27.63771 27.55871 27.46544 27.29237
## [1086] 27.43547 27.87534 27.97599 27.96418 27.92265 27.60778 27.59206
## [1093] 28.07415 29.05570 28.54055 28.66974 28.94100 28.94607 28.71157
## [1100] 27.94411 27.77324 27.23805 27.36022 27.62459 27.39361 27.41848
## [1107] 26.91377 27.10271 27.36679 27.20097 26.47472 26.17755 26.13862
## [1114] 26.57303 26.69580 27.02100 26.70920 26.76912 26.78466 26.77396
## [1121] 26.23597 25.67384 25.39405 25.48126 25.54364 25.75093 25.46364
## [1128] 25.47858 25.61045 25.58360 25.76561 25.87220 25.46719 25.64549
## [1135] 25.61313 25.27807 25.33834 25.24828 25.13417 24.98630 24.47212
## [1142] 24.39375 24.26868 24.73280 24.54791 24.38355 24.41480 24.30560
## [1149] 24.51777 24.34892 24.63407 25.22493 24.75715 24.72654 23.73281
## [1156] 23.93524 23.81486 24.13805 23.95717 23.99951 24.04837 24.47040
## [1163] 24.25683 24.35100 24.73091 24.64265 25.29724 24.88997 24.19721
## [1170] 24.36716 24.53622 24.58194 24.91830 24.50941 24.39681 24.06672
## [1177] 23.38063 23.28946 23.19089 23.57627 23.20521 23.37474 23.11369
## [1184] 23.51866 23.62985 23.51042 22.22771 21.83887 21.35930 21.37095
## [1191] 20.77159 20.34798 20.12056 20.04783 20.23277 20.37372 20.29265
## [1198] 20.49429 20.13725 20.30361 20.17915 18.92530 18.01852 18.16685
## [1205] 18.42137 18.14467 18.07279 17.87998 18.06400 17.83087 18.18703
## [1212] 18.36475 18.58507 18.43817 17.74175 17.83515 17.80821 17.74975
## [1219] 17.60412 17.69160 17.67930 18.16418 17.59813 17.92599 17.96278
## [1226] 17.99366 17.73075 17.27953 17.53091 17.64493 17.04753 17.36687
## [1233] 16.99901 17.49599 17.84014 17.80449 18.26217 18.41673 18.36303
## [1240] 18.62300 19.11706 18.64808 18.61988 17.83802 17.45997 16.11305
## [1247] 15.91592 16.57968 16.65651 16.56916 16.25257 15.89335 16.09033
## [1254] 16.07388 16.53542 15.90689
##
## $method
## [1] "STL + ETS(A,N,N)"
##
## $residuals
## Time Series:
## Start = c(2013, 2)
## End = c(2018, 2)
## Frequency = 251
## [1] 0.048264845 -1.254389333 -0.294527977 15.012527824
## [5] 3.380650695 -10.003477559 4.245161080 -8.837555809
## [9] 1.379051850 2.268435963 -13.830225833 3.678408268
## [13] 5.162462765 -3.713298990 -2.530073552 5.460241236
## [17] 0.783127949 -2.320060652 -2.465410361 3.441566210
## [21] -1.769424833 1.615281641 2.598062809 6.285981988
## [25] -6.301142572 -5.034270987 2.259599426 2.617240349
## [29] -5.769064954 0.050701947 -3.104187064 -0.935766850
## [33] 1.408625368 -0.719828777 -4.084231276 4.599704875
## [37] -7.189499147 0.324643215 -5.949768334 7.908647093
## [41] 1.945048172 9.940018822 -2.999908088 -17.039270835
## [45] -5.291386180 2.364709751 -6.165872903 -1.236225508
## [49] -17.327115632 -6.010350219 3.476014087 6.354817267
## [53] -0.247233010 8.463512131 0.005552153 -1.735514112
## [57] -2.327883753 4.699289753 4.893526628 0.465055095
## [61] 7.440838912 6.740719805 -3.651815791 -0.946244695
## [65] 1.262464839 -1.060134159 5.880809454 1.065908994
## [69] 9.009901908 0.734791988 5.285884317 4.090015791
## [73] -3.141615706 -5.615022866 1.735030750 -2.232148700
## [77] -1.309446191 -1.454085811 5.148460096 0.075210908
## [81] -5.316014214 0.321797067 6.145874235 -4.191403430
## [85] -3.899665006 -1.556693565 5.942479279 -2.999264710
## [89] 3.903952725 8.724276818 -9.549908943 -14.854369904
## [93] 2.495995757 -7.501418378 5.263248386 7.570138474
## [97] 1.846317982 4.416480699 8.820856819 -10.043196440
## [101] -4.546620679 -1.477475773 4.772253993 5.279427960
## [105] 0.766488536 11.076803475 -8.435391035 -3.771019163
## [109] -6.074153074 -2.475748425 0.034900770 18.659142466
## [113] 5.728184271 -1.850358685 0.905270067 5.439065500
## [117] 9.260430229 1.379410972 0.752152597 -3.500191853
## [121] 7.708837810 2.170749263 -2.078820938 -1.505917353
## [125] -3.681317786 -1.300866993 -1.823500512 -2.230491343
## [129] 2.739108657 -4.918316874 0.235667537 -0.489397933
## [133] -5.664650220 -0.378424839 -2.396241187 6.116651552
## [137] 6.632527154 0.117942931 -3.547312154 -3.233019682
## [141] -5.758410367 -0.898760265 0.435081196 6.339346602
## [145] -2.440512851 -1.241579285 4.183814183 7.676577259
## [149] 5.323433803 -2.126059424 4.272852973 5.499883000
## [153] 4.298083837 4.152195751 -4.983648175 -4.426798933
## [157] 4.193171360 0.567168558 -2.823201019 1.084831889
## [161] -3.879781854 2.467898965 1.451822372 4.079093933
## [165] -1.403446854 -4.341733344 -10.138150157 -5.516655956
## [169] -5.953686866 14.716470861 6.948398583 5.839790175
## [173] -3.183844579 4.922785303 4.452394189 7.620535693
## [177] 9.478938555 -3.641020991 -5.614577750 -2.845180384
## [181] -2.312871595 10.198693040 3.827942275 4.929794403
## [185] -2.478333528 8.392385144 -2.797926145 0.553695393
## [189] 12.089353895 -8.636490298 5.811152501 -4.874650615
## [193] -1.870783023 -3.214343588 -3.586743435 0.082636129
## [197] 4.474484529 -4.486482048 -3.205033199 0.667573252
## [201] 0.935277247 -7.523994036 -0.075886296 1.051817671
## [205] -2.046425544 6.703047400 -3.390241631 2.453442812
## [209] -5.872774700 8.984477770 8.981094335 0.822912503
## [213] -14.100340282 -2.569161283 10.084469159 4.182608062
## [217] 1.147844149 4.532941055 -0.086314205 -3.614355946
## [221] -1.401862590 1.267195182 3.015130080 2.825795339
## [225] 0.766687325 1.233768926 -6.938046556 -0.009324209
## [229] 1.114822419 1.272715206 0.832245842 6.683970847
## [233] -1.107513369 -3.789584823 4.945561455 8.923284832
## [237] -6.794303261 -8.709156837 -5.396414295 -1.748884762
## [241] -6.803301939 -10.980209350 7.483877446 3.827516963
## [245] 0.274235533 2.385870757 -9.935813644 -14.070142097
## [249] 7.329099602 -2.497359354 3.545056029 4.727762311
## [253] -4.174349059 6.510702505 -4.233914788 4.301012733
## [257] 0.211396029 -9.045516824 -7.664576479 -2.310038323
## [261] -5.296359225 8.109169442 -2.275616959 -1.184629444
## [265] 4.927589614 -2.765525671 -5.086306235 6.836612608
## [269] 2.783878968 4.901589865 -1.081356654 -0.539622836
## [273] 2.903454908 -2.865405958 -9.057186728 -6.848106103
## [277] 7.723282963 6.475554550 -10.185520756 -2.353068718
## [281] 1.453358711 0.139181755 9.431767353 -0.323697848
## [285] 3.659138287 -1.532534433 -0.917420758 -0.208989212
## [289] 2.915563263 2.276128312 -1.698275038 -1.146677345
## [293] -4.645860509 2.080809250 -23.557406697 5.538743412
## [297] 2.986739322 4.245099239 8.730175451 14.498010973
## [301] 3.171660244 -0.123175998 -7.829557188 0.898514283
## [305] 7.008560736 3.536973774 -2.725714815 4.312200835
## [309] -2.170262858 -2.962539513 -2.474062089 -5.145031069
## [313] 8.352157879 -0.833620098 -4.247186269 14.025922981
## [317] -2.863935422 -3.521759945 -3.963401092 6.936450053
## [321] -3.470518274 -4.947311026 4.819662779 2.061355221
## [325] -2.979832749 1.635272425 -0.916834878 1.925752990
## [329] 6.495530353 -1.176976207 -1.475653076 -3.920375318
## [333] 4.655323283 6.077047291 4.705214817 -0.079136382
## [337] -6.777736523 -3.371567937 2.719312010 -8.383592456
## [341] -3.062696897 -0.933146632 3.015255878 1.013050524
## [345] -5.536783526 -1.175643743 0.300303526 -3.229323855
## [349] 11.423234877 1.472698707 3.148742626 0.725188692
## [353] -2.454135584 -0.070351465 -12.034145186 1.212559597
## [357] -0.935130252 5.038120281 2.236981091 -2.995420567
## [361] 5.914531468 -13.318242229 -11.302295154 -10.420199280
## [365] 2.764511842 0.187676666 4.664013040 6.803988227
## [369] 0.389987401 -2.586601593 3.984703093 -10.959571827
## [373] 5.446428927 0.152093709 -2.722698218 6.198872367
## [377] 0.321651294 4.130830650 0.730391726 -0.279620697
## [381] 3.776357441 3.352430297 -5.493841439 7.783186727
## [385] 2.218282321 8.293754467 4.101956546 -0.694045169
## [389] 5.342735937 1.254444275 -0.434961045 -6.806425365
## [393] -2.479326928 -1.211579852 6.397925734 -1.843067603
## [397] 2.286079225 -1.944972143 -7.917298660 1.326875124
## [401] 5.751905198 2.305514252 -1.753017775 4.590571940
## [405] -4.239726093 2.978209384 8.511361711 -7.940488213
## [409] -1.931791319 -3.162283124 -9.530775877 2.876126082
## [413] 0.754722083 -0.031643578 -11.242819400 3.171892139
## [417] 3.952610517 -12.290581091 -9.619152603 7.600430428
## [421] -13.074617805 -9.147569325 -0.996526255 4.951998942
## [425] 5.348510675 -3.952786546 0.274393097 -0.403533726
## [429] 10.112170630 -4.136876194 -2.752070911 4.236011132
## [433] 2.394035787 10.277870022 -4.847877993 3.816374960
## [437] 1.695253708 -2.621841529 0.942372801 2.756826565
## [441] 13.488903508 -4.837969422 -2.464433609 -5.397139279
## [445] -2.165360790 -2.209008780 -4.732209700 8.521177006
## [449] 11.669771746 -3.935060505 0.039542395 0.259699159
## [453] 1.982079047 -5.246356947 -0.192686252 -7.869383247
## [457] -5.707480591 -0.060432604 9.088793638 -8.715455392
## [461] -5.812307033 -5.996898912 -0.679412960 -7.374177315
## [465] 2.026948976 -11.069501184 -7.028863768 -2.733267671
## [469] -1.294955951 14.422464948 7.350048500 -0.199507362
## [473] -0.044877234 -4.201998183 1.565981717 -3.002209825
## [477] -5.959992718 -0.147533119 -4.814401840 -4.534130847
## [481] -12.754480318 3.097140354 13.317243069 -2.564558893
## [485] 1.168223439 -4.372649553 -3.067408567 -7.821476132
## [489] 7.935310603 8.526690069 10.777246572 3.549322781
## [493] 15.901333368 7.444492343 -11.333153550 -8.609241436
## [497] 3.012187705 -5.227468863 12.538651284 8.538472571
## [501] -8.962594360 1.475950752 -0.380744556 1.761911587
## [505] -0.960790263 -1.599188412 6.129371634 -1.221667917
## [509] -6.393790819 0.270313134 -1.385534326 4.200129362
## [513] -1.928062690 3.840279264 11.712950329 -0.598355198
## [517] 0.423742609 7.052880559 -13.007938384 -9.814367168
## [521] 1.501170736 -9.005739815 7.445830405 -5.412254148
## [525] 1.279838662 7.084887849 -10.758044848 10.225111473
## [529] -2.467099989 7.528423406 -10.299815265 -0.089502762
## [533] 1.625403667 -2.872793639 -7.445949271 -4.002988347
## [537] -2.033757726 5.576591670 -7.805404836 -0.730054607
## [541] -0.388866562 10.050258258 -0.820513182 -2.199134461
## [545] 15.323614673 61.304030956 -15.701767755 -1.287355155
## [549] -6.254352890 -3.852806586 1.901374398 -4.102268880
## [553] -10.704670694 4.216749900 -1.899583269 2.525304555
## [557] 0.942940927 4.277989122 0.057415037 0.905075674
## [561] 5.855013654 -0.952355578 -4.373563347 -3.372666546
## [565] 7.676097686 4.951490022 -9.191728194 -1.799726715
## [569] 5.860619235 5.702899644 1.748283975 -0.802640310
## [573] 4.436117117 8.246183026 3.667955899 -4.519226585
## [577] -4.414535081 -3.446939511 2.977657186 -4.677543498
## [581] -1.863995196 0.956227161 7.774131156 -8.731612505
## [585] -3.954485958 -3.864739684 3.105018963 8.542504981
## [589] -1.467491934 -2.948059539 -7.828845042 -3.795253031
## [593] -0.480386393 4.228419132 -3.612723355 6.950470257
## [597] 5.426087441 -3.191235356 -5.795805972 9.381849063
## [601] -6.569046460 -2.011591628 -2.510329623 -5.977181724
## [605] -9.628579355 2.093162754 -12.770868649 6.219488413
## [609] 2.298411548 4.584911261 3.087123248 -2.156940799
## [613] 4.694586578 -1.530914022 -0.648075830 -6.240831388
## [617] -2.920918662 -5.723068776 -2.141547396 10.911985348
## [621] 4.877758193 3.267745602 -2.291108595 0.077685684
## [625] -3.972930963 4.279858772 0.820253890 -3.180304219
## [629] -6.258443307 9.191821925 -9.507372256 1.886493616
## [633] 0.394015906 8.183852003 0.011811673 -0.894842479
## [637] -8.666104052 -11.327582644 -8.233416471 -13.517762958
## [641] -8.224671806 14.059665206 20.822747645 1.957865622
## [645] -6.463333705 -19.063844720 14.712623472 -2.943152785
## [649] -14.046227451 20.677263833 -10.129715620 7.440016725
## [653] 13.151045281 -7.443544089 10.564332645 10.460621212
## [657] -10.638611302 -7.442462257 4.667942089 0.170729788
## [661] -0.257082298 -5.858002945 0.960456810 -9.087106408
## [665] 1.358353946 16.845637291 3.438349605 3.991718122
## [669] 27.313875661 13.076833426 9.985986640 6.148737361
## [673] 4.540329223 7.670732116 -4.883316170 -6.294540486
## [677] 8.898442513 13.884977979 -5.215161939 -6.523552251
## [681] 4.244458414 12.204225624 -3.048821518 7.362210794
## [685] -1.287792812 -1.145120998 2.094319209 -13.906104976
## [689] 14.298742873 6.671245327 -1.440208904 2.379899762
## [693] 2.276321107 -9.375936986 7.985017887 10.903501047
## [697] -15.375041010 -2.349097578 7.579202690 0.017218906
## [701] 4.377961547 -5.767721536 8.514260368 -0.608217525
## [705] 0.601188256 -9.783869572 2.033158274 -6.102477789
## [709] 5.959492481 -5.458086880 0.409612520 10.552421341
## [713] -1.317899037 -3.348314763 8.563902177 3.967800829
## [717] -9.943452328 0.368792080 1.461180981 15.089292238
## [721] -10.652400281 -13.164885004 1.115973498 -1.611078970
## [725] 11.390170081 -0.817459895 1.177394018 9.235100521
## [729] 0.015716518 3.506170716 -6.969212221 0.747133608
## [733] -12.234659811 -31.717279197 -9.541727692 6.058666646
## [737] 0.207178146 -12.574699219 20.291518657 -8.954105940
## [741] 2.450748295 -7.472142584 14.591924355 1.011039128
## [745] -0.621574641 1.242850696 -4.495931143 3.373998325
## [749] 24.725189572 -8.807624250 -8.903894215 10.647575384
## [753] 8.250535730 -18.211407176 -12.849868713 0.314953031
## [757] -1.881140067 -20.443455267 14.572690729 10.100275597
## [761] 11.757824128 -3.058997986 -2.609628619 10.235294170
## [765] -7.252129019 -8.913018831 7.843298317 2.643946463
## [769] -3.546827403 15.472872238 4.161944621 -1.369287170
## [773] 8.524228201 -3.336675353 -0.404752588 0.499065668
## [777] -1.450937041 9.782165749 -2.044981268 1.624803922
## [781] -4.340392473 21.479093583 -3.121989269 5.068951876
## [785] 1.458512812 1.784283744 -0.051089944 8.196357180
## [789] -0.998612812 10.664020287 -2.719162704 1.395622050
## [793] -17.853501160 -4.646216288 -4.296657759 -11.157370883
## [797] -9.463954130 6.215684965 -0.852451800 6.255706934
## [801] 2.463151551 2.832037450 2.850433488 2.744722095
## [805] -3.510403226 -5.688466878 -2.362341087 -3.601580926
## [809] 4.544338358 1.842081559 0.373552551 -4.884727704
## [813] 4.406990135 -2.903205473 -17.204375241 -4.005677653
## [817] 3.096113591 -4.539525131 13.626996257 -3.089135187
## [821] -7.396014839 -7.366488348 7.622723610 -4.038797484
## [825] -2.256669885 -6.007890763 2.066790578 -2.087793243
## [829] 7.113189993 7.281504139 3.164766173 0.993327809
## [833] 2.902505751 -1.550504242 -3.233293840 -7.843611026
## [837] 2.812524750 1.149085631 5.389917115 -0.200259509
## [841] -5.882164020 -9.621826335 14.665028125 6.044742008
## [845] -1.107166210 -1.271582504 8.859792649 5.595414126
## [849] 0.047266588 12.882751786 -33.492872548 -9.146683995
## [853] 18.088682193 13.488924090 19.636475607 3.171798558
## [857] -3.575682047 11.504216292 5.998594168 7.870843864
## [861] -0.381104386 -0.654296628 -1.872460354 5.945342576
## [865] 1.601234294 2.968843916 2.132774533 -2.033143549
## [869] -1.950058198 -5.562534536 -7.457059182 -4.419738907
## [873] -6.945451526 0.341176607 -2.627516981 2.158357325
## [877] 0.320914068 -1.877597905 -0.244778347 3.340866791
## [881] -2.758276814 5.145178376 -3.021670829 2.968331228
## [885] -0.952593303 -3.440817395 1.234381510 3.265684936
## [889] 7.022202920 1.128991384 6.063156448 2.841333162
## [893] -3.664086818 -4.084732290 -1.295433619 6.001753885
## [897] 4.228488310 -6.018227892 -2.822713644 0.938018707
## [901] -9.956686108 0.353086665 3.900600362 -21.772389941
## [905] 8.647777925 -21.779706496 -10.042973250 5.435006779
## [909] 4.236036037 -10.087502557 6.795812706 4.162930569
## [913] 5.259644815 -3.901450184 -4.622398870 5.242107467
## [917] 1.430980699 -6.797058587 -0.434018669 -7.731423627
## [921] -4.105427158 -3.083908158 -7.668781521 -2.082163803
## [925] 1.097799764 2.946569281 0.841109228 -6.674121038
## [929] -9.269124999 -6.507530650 3.355665244 4.319101951
## [933] -8.914857272 -3.691862483 5.135136194 -6.057246520
## [937] 7.341360133 -3.339807317 15.680121364 -3.151325576
## [941] -5.210641610 -10.768972381 -6.528045745 -1.433762877
## [945] 20.595499822 0.044864164 0.401416720 23.302219386
## [949] 3.023296679 -0.383159218 8.863545437 -2.221729016
## [953] 3.299968580 -6.938732829 7.512667390 8.009111380
## [957] 4.238658128 4.933972869 0.558309333 -7.312100498
## [961] -8.268135011 17.903260866 -4.607675720 -4.782974878
## [965] 3.945034127 13.101016257 -3.767994350 9.811273180
## [969] 2.893641146 -4.251161687 -12.446500494 -4.813641373
## [973] 10.413759240 2.873490119 6.322468046 -6.471860876
## [977] -6.986594440 0.885655809 -1.923365410 0.528159239
## [981] 0.629373974 2.937225218 2.358730478 2.920883226
## [985] 0.504314859 7.996003376 -2.412877306 -4.341900399
## [989] 1.954315510 -5.899247277 6.280891428 -0.282028338
## [993] 5.284372680 -2.628582628 -10.110077846 -18.234516797
## [997] 0.930161461 15.238123198 -3.843750146 -10.322816430
## [1001] 2.627805793 -4.984136912 -2.080808048 -6.533402377
## [1005] 2.028452258 -4.718330351 -5.601168656 -5.891438271
## [1009] 8.058270082 -4.383282856 2.389884166 4.566987313
## [1013] 6.542864684 2.126946392 -3.821486885 2.915575340
## [1017] -6.858370509 -9.289691734 2.607010834 -3.319256670
## [1021] -10.086151770 6.365898623 -2.538832222 -0.860785865
## [1025] -1.788024824 2.354427996 -0.966778980 -2.240039602
## [1029] 15.717077902 -12.353087512 -7.942256475 5.363291598
## [1033] -3.215859575 1.964545462 -4.417904280 -7.765260772
## [1037] 5.485221923 1.341438146 -0.899850472 -8.730623377
## [1041] 4.557454642 0.356533902 2.406368060 2.368141487
## [1045] 5.452940289 2.498179815 -4.266093144 -15.876165815
## [1049] 10.160105686 -3.202597416 1.715663131 -6.699584457
## [1053] -3.904978549 4.068060928 5.817248130 1.307295144
## [1057] 7.605216409 -16.539571108 -1.086443250 -5.203549661
## [1061] -4.617641936 -3.824419156 -2.738935528 -1.398939727
## [1065] 6.524083873 6.978129427 0.421354984 -3.270556081
## [1069] -1.203420816 -8.842903533 -5.275507252 4.962148803
## [1073] -10.571449609 -4.466733413 -0.443619232 -16.318702454
## [1077] 3.189078857 11.588002689 3.610759219 -0.861031303
## [1081] -12.387534304 -4.070325809 -2.989211512 -2.889670948
## [1085] 2.394843317 7.844815405 0.129887766 0.112290189
## [1089] -0.955098727 -6.744160792 -0.490675390 9.658535261
## [1093] 24.676465358 -17.411280902 4.275456721 7.782939639
## [1097] 1.708848446 -4.216511932 -16.524350646 -4.571164385
## [1101] -6.173522379 9.094537367 6.863617254 -11.364212260
## [1105] -8.539494132 -10.843685628 2.593764278 9.470506604
## [1109] -0.459212359 -23.832451343 -8.542153987 -3.590424317
## [1113] 6.336975855 0.185277536 2.518474138 -6.481521618
## [1117] 2.964752361 3.242228620 4.171752210 -2.243947399
## [1121] -8.496795839 -6.229062570 1.167546904 2.776156332
## [1125] 6.321763919 -5.663453087 3.736747739 -0.982104556
## [1129] -2.311843761 4.527439998 0.370885569 -6.235411010
## [1133] 2.367231773 1.655960324 -7.969228256 -1.969966402
## [1137] 0.549015150 -2.727471327 -0.858063627 -5.874954497
## [1141] 1.908385913 2.352054862 8.093545167 -8.417550829
## [1145] -6.053406875 2.600681093 1.348800038 3.274863104
## [1149] -5.799943722 4.915015046 12.588145041 -11.617019637
## [1153] 4.044033319 -17.216497830 2.072566739 -5.127389114
## [1157] 2.269788952 -0.676570135 7.299024126 -1.665361450
## [1161] 9.981358843 -6.578556828 1.533969606 9.793376215
## [1165] 3.448546823 11.623133056 -9.220395832 -12.803832000
## [1169] 1.036064428 -4.541851937 0.829201766 5.382814943
## [1173] -10.823122405 0.750100722 -0.166093202 -15.117536957
## [1177] -0.481920409 -5.085762023 -3.256641790 -13.876749217
## [1181] 3.603053900 -4.300267257 0.145849075 1.444221563
## [1185] 4.748429966 -27.272179450 -7.447666261 -6.803810195
## [1189] -0.838377617 -12.243907477 -7.443723707 -3.806542426
## [1193] -2.017823259 -2.155496620 -1.872269388 -4.934586185
## [1197] -1.673363137 -7.599074386 -2.953797887 3.800894323
## [1201] -22.713667785 -18.874276310 4.379255705 1.513785365
## [1205] -3.870490409 -2.973730175 -4.357494583 4.863321908
## [1209] 2.283523867 5.196027688 4.079210614 2.122744135
## [1213] -5.439121164 -10.133601856 3.715594508 -1.337143404
## [1217] -2.627789822 -0.704639016 1.869148941 -0.734915987
## [1221] 4.104405491 -7.258361341 0.737612971 -1.893873614
## [1225] -3.621155118 -7.180299478 -4.937400154 3.308603177
## [1229] -0.541201673 -3.768566746 5.721861887 -0.119209331
## [1233] 7.766414942 8.583438865 5.574662111 13.177683741
## [1237] 5.111280034 -2.508161646 3.635522514 5.744108600
## [1241] -1.850442302 2.092879144 -7.546189215 -8.584396474
## [1245] -11.806297294 2.378150311 4.075393054 5.192048172
## [1249] -3.582159306 -6.370952589 -1.984152242 6.218566821
## [1253] -2.247663264 1.549278583 -8.388068394 -4.208834191
##
## $lambda
## [1] 1.999924
## attr(,"biasadj")
## [1] FALSE
##
## $series
## [1] "GE.close.full.ts"
checkresiduals(fct.stlf.GE.train)
## Warning in checkresiduals(fct.stlf.GE.train): The fitted degrees of freedom
## is based on the model used for the seasonally adjusted data.

##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,N,N)
## Q* = 461.96, df = 249.2, p-value = 0.00000000000000655
##
## Model df: 2. Total lags used: 251.2