GE <- read.csv("https://raw.githubusercontent.com/JohnKHancock/raw.github/master/CUNY_DATA_624/stock_data_GE.csv", header = TRUE, stringsAsFactors = FALSE) 

GE$date <- as.Date(GE$date, "%m/%d/%Y")
GE$month = lubridate::month(GE$date)
GE$year = lubridate::year(GE$date)
GE.monthly <- GE %>% 
              group_by(year, month)  %>% 
              summarise(priceMean = mean(close, na.rm = TRUE)) %>% 
              as.data.frame()
## `summarise()` has grouped output by 'year'. You can override using the `.groups` argument.
GE_avg_prices <- GE.monthly$priceMean
GE.ts = ts(data=GE_avg_prices, frequency = 12, start=c(1969,12), end=c(2019,12)) 
autoplot(GE.ts)

GE_Stationary <- diff(GE.ts)
autoplot(GE_Stationary)

ggseasonplot(GE_Stationary)

ggsubseriesplot(GE.ts)

ggseasonplot(GE.ts, year.labels=FALSE, continuous=TRUE, polar = TRUE)

Naive Method

Using the naïve method, all forecasts for the future are equal to the last observed value of the series. The naïve method assumes that the most recent observation is the only important one, and all previous observations provide no information for the future. This can be thought of as a weighted average where all of the weight is given to the last observation.

The Average Method

Using the average method, all future forecasts are equal to a simple average of the observed data. This method assumes that all observations are of equal importance, and gives them equal weights when generating forecasts.

Exponential Approach

For example, it may be sensible to attach larger weights to more recent observations than to observations from the distant past. This is exactly the concept behind simple exponential smoothing. Forecasts are calculated using weighted averages, where the weights decrease exponentially as observations come from further in the past — the smallest weights are associated with the oldest observations:

\[\hat{y}_{T+1|T} = \alpha y_T + \alpha(1- \alpha)y_{T-1} + \alpha(1- \alpha)^2y_{T-2}... \]

Simple Exponential Smoothin

GE_20 <- window(GE.ts, start=1999, end=2009)

fit_GE <- ses(GE_20, 5)
summary(fit_GE)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = GE_20, h = 5) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
## 
##   Initial states:
##     l = 32.341 
## 
##   sigma:  2.1102
## 
##      AIC     AICc      BIC 
## 764.9995 765.2046 773.3869 
## 
## Error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -0.153372 2.092723 1.616038 -0.9123344 4.857943 0.2375752
##                   ACF1
## Training set 0.2109708
## 
## Forecasts:
##          Point Forecast     Lo 80    Hi 80    Lo 95    Hi 95
## Feb 2009       13.78486 11.080489 16.48924 9.648878 17.92085
## Mar 2009       13.78486  9.960491 17.60924 7.935989 19.63374
## Apr 2009       13.78486  9.101060 18.46867 6.621604 20.94813
## May 2009       13.78486  8.376518 19.19321 5.513513 22.05622
## Jun 2009       13.78486  7.738180 19.83155 4.537258 23.03247
GE_Stock <- window(GE.ts, start=1999)
# Estimate parameters
GE_Simple_EXpo <- ses(GE_Stock, h=5)
# Accuracy of one-step-ahead training errors
round(accuracy(GE_Simple_EXpo),2)
##                 ME RMSE  MAE  MPE MAPE MASE ACF1
## Training set -0.08 1.68 1.24 -0.7 5.16 0.22 0.23