library(fpp2)
## Loading required package: ggplot2
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
library(ggplot2)
library(tseries)
library(fGarch)
## Loading required package: timeDate
## Loading required package: timeSeries
## Loading required package: fBasics
library(psych)
##
## Attaching package: 'psych'
## The following object is masked from 'package:fBasics':
##
## tr
## The following object is masked from 'package:timeSeries':
##
## outlier
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
# Read in Data
AMZN<-read.csv("AMZN.csv")
describe(AMZN)
## vars n mean sd median trimmed mad
## Date* 1 1258 629.50 363.30 629.50 629.50 466.28
## Open 2 1258 1077.14 536.02 948.42 1062.72 656.75
## High 3 1258 1086.94 540.72 954.85 1072.67 665.59
## Low 4 1258 1065.42 529.70 941.27 1050.76 651.78
## Close 5 1258 1076.69 535.43 948.59 1062.27 659.24
## Adj.Close 6 1258 1076.69 535.43 948.59 1062.27 659.24
## Volume 7 1258 4211749.36 2255753.79 3595750.00 3842917.66 1417736.25
## min max range skew kurtosis se
## Date* 1.00 1258.00 1257.00 0.00 -1.20 10.24
## Open 286.28 2038.11 1751.83 0.29 -1.38 15.11
## High 290.79 2050.50 1759.71 0.29 -1.39 15.25
## Low 285.25 2013.00 1727.75 0.29 -1.37 14.93
## Close 286.95 2039.51 1752.56 0.29 -1.38 15.10
## Adj.Close 286.95 2039.51 1752.56 0.29 -1.38 15.10
## Volume 1091200.00 23856100.00 22764900.00 2.58 11.40 63599.16
# Set up a Time Series
AMZNdaily<-ts(AMZN$Adj.Close, frequency = 365, start = c(2014,11))
# Plot Of Time series Data
plot(AMZNdaily,xlab = "Days", ylab = "Adjusted Close Price", main = "Amazon Daily Adjusted Close Price")
# Simple STL Forcast of Timeseries
AMZNfc<-forecast(AMZNdaily, h = 30, level = 95)
AMZNfc
## Point Forecast Lo 95 Hi 95
## 2017.4740 1813.261 1746.084 1880.438
## 2017.4767 1829.298 1734.705 1923.890
## 2017.4795 1831.859 1716.140 1947.577
## 2017.4822 1826.600 1693.027 1960.173
## 2017.4849 1827.177 1677.843 1976.511
## 2017.4877 1834.787 1671.179 1998.396
## 2017.4904 1839.741 1662.986 2016.497
## 2017.4932 1839.221 1650.210 2028.233
## 2017.4959 1840.415 1639.875 2040.955
## 2017.4986 1836.852 1625.392 2048.312
## 2017.5014 1855.564 1633.704 2077.425
## 2017.5041 1867.639 1635.827 2099.452
## 2017.5068 1876.218 1634.847 2117.589
## 2017.5096 1870.475 1619.893 2121.056
## 2017.5123 1867.413 1607.933 2126.894
## 2017.5151 1850.098 1581.998 2118.197
## 2017.5178 1864.047 1587.583 2140.511
## 2017.5205 1853.563 1568.966 2138.160
## 2017.5233 1866.471 1573.953 2158.989
## 2017.5260 1862.529 1562.286 2162.773
## 2017.5288 1865.450 1557.662 2173.239
## 2017.5315 1858.657 1543.492 2173.823
## 2017.5342 1864.762 1542.376 2187.149
## 2017.5370 1869.333 1539.871 2198.794
## 2017.5397 1884.805 1548.405 2221.205
## 2017.5425 1887.464 1544.254 2230.674
## 2017.5452 1891.368 1541.469 2241.266
## 2017.5479 1903.504 1547.030 2259.978
## 2017.5507 1905.898 1542.957 2268.839
## 2017.5534 1906.468 1537.162 2275.774
# Plot of Forecast
autoplot(AMZNfc, ylab = "Forcasted Adj. Close", xlab = "Days", main = "Forecasted Adjusted Close Price for AMZN")
# Creating Classical Multiplicative Decomposition
AMZNdecomp<-decompose(AMZNdaily, type = "multiplicative")
autoplot(AMZNdecomp)
# Constructing ETS Model
AMZNets<- ets(AMZNdaily, model = "ZZZ")
## Warning in ets(AMZNdaily, model = "ZZZ"): I can't handle data with
## frequency greater than 24. Seasonality will be ignored. Try stlf() if you
## need seasonal forecasts.
AMZNets
## ETS(M,A,N)
##
## Call:
## ets(y = AMZNdaily, model = "ZZZ")
##
## Smoothing parameters:
## alpha = 0.9999
## beta = 1e-04
##
## Initial states:
## l = 328.8244
## b = 1.1665
##
## sigma: 0.0185
##
## AIC AICc BIC
## 16164.63 16164.67 16190.31
autoplot(AMZNets)
AMZNetsfc<-forecast(AMZNets, h= 30)
AMZNetsfc
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2017.4740 1779.164 1736.909 1821.419 1714.540 1843.788
## 2017.4767 1780.328 1720.546 1840.110 1688.900 1871.757
## 2017.4795 1781.493 1708.243 1854.743 1669.467 1893.519
## 2017.4822 1782.657 1698.037 1867.277 1653.242 1912.072
## 2017.4849 1783.822 1689.171 1878.473 1639.065 1928.578
## 2017.4877 1784.986 1681.253 1888.719 1626.341 1943.632
## 2017.4904 1786.151 1674.055 1898.246 1614.715 1957.586
## 2017.4932 1787.315 1667.425 1907.206 1603.959 1970.672
## 2017.4959 1788.480 1661.258 1915.701 1593.911 1983.048
## 2017.4986 1789.644 1655.479 1923.809 1584.456 1994.832
## 2017.5014 1790.809 1650.030 1931.587 1575.507 2006.111
## 2017.5041 1791.973 1644.867 1939.079 1566.994 2016.953
## 2017.5068 1793.138 1639.954 1946.321 1558.864 2027.412
## 2017.5096 1794.302 1635.263 1953.341 1551.072 2037.532
## 2017.5123 1795.467 1630.769 1960.164 1543.584 2047.349
## 2017.5151 1796.631 1626.454 1966.808 1536.368 2056.894
## 2017.5178 1797.796 1622.300 1973.291 1529.399 2066.192
## 2017.5205 1798.960 1618.294 1979.626 1522.655 2075.265
## 2017.5233 1800.125 1614.422 1985.827 1516.117 2084.132
## 2017.5260 1801.289 1610.674 1991.904 1509.769 2092.809
## 2017.5288 1802.454 1607.042 1997.865 1503.597 2101.310
## 2017.5315 1803.618 1603.516 2003.720 1497.588 2109.648
## 2017.5342 1804.783 1600.089 2009.476 1491.730 2117.835
## 2017.5370 1805.947 1596.754 2015.140 1486.014 2125.880
## 2017.5397 1807.111 1593.507 2020.716 1480.431 2133.791
## 2017.5425 1808.276 1590.341 2026.211 1474.973 2141.579
## 2017.5452 1809.440 1587.252 2031.629 1469.632 2149.249
## 2017.5479 1810.605 1584.235 2036.975 1464.402 2156.808
## 2017.5507 1811.769 1581.287 2042.252 1459.277 2164.262
## 2017.5534 1812.934 1578.403 2047.464 1454.250 2171.617
autoplot(AMZNetsfc, ylab = "Forecasted Adjusted Close", main= "ETS Forecast of AMZN Adjusted Close Price")
# Creating a GARCH forecast
AMZNgarch<-garch(AMZNdaily)
##
## ***** ESTIMATION WITH ANALYTICAL GRADIENT *****
##
##
## I INITIAL X(I) D(I)
##
## 1 2.580169e+05 1.000e+00
## 2 5.000000e-02 1.000e+00
## 3 5.000000e-02 1.000e+00
##
## IT NF F RELDF PRELDF RELDX STPPAR D*STEP NPRELDF
## 0 1 1.031e+04
## 1 2 9.346e+03 9.36e-02 1.09e+00 1.9e-06 1.1e+04 1.0e+00 6.11e+03
## 2 4 9.327e+03 1.94e-03 1.51e-03 8.6e-08 2.8e+00 5.0e-02 5.10e+00
## 3 6 9.299e+03 3.09e-03 3.06e-03 1.7e-07 2.0e+00 1.0e-01 5.86e-02
## 4 8 9.294e+03 4.99e-04 4.98e-04 3.4e-08 1.4e+01 2.0e-02 1.40e-02
## 5 10 9.286e+03 8.80e-04 8.79e-04 6.7e-08 2.5e+00 4.0e-02 3.51e-03
## 6 12 9.284e+03 1.57e-04 1.57e-04 1.3e-08 2.7e+01 8.0e-03 2.23e-03
## 7 14 9.282e+03 2.96e-04 2.96e-04 2.7e-08 4.1e+00 1.6e-02 3.45e-03
## 8 17 9.282e+03 5.67e-06 5.67e-06 5.4e-10 5.8e+02 3.2e-04 4.31e-03
## 9 19 9.281e+03 1.13e-05 1.13e-05 1.1e-09 7.3e+01 6.4e-04 5.17e-03
## 10 21 9.281e+03 2.26e-06 2.26e-06 2.2e-10 1.4e+03 1.3e-04 5.22e-03
## 11 23 9.281e+03 4.52e-07 4.52e-07 4.3e-11 7.2e+03 2.6e-05 5.26e-03
## 12 25 9.281e+03 9.03e-07 9.03e-07 8.7e-11 9.0e+02 5.1e-05 5.27e-03
## 13 27 9.281e+03 1.81e-07 1.81e-07 1.7e-11 1.8e+04 1.0e-05 5.27e-03
## 14 29 9.281e+03 3.61e-07 3.61e-07 3.5e-11 2.2e+03 2.0e-05 5.27e-03
## 15 31 9.281e+03 7.22e-07 7.22e-07 6.9e-11 1.1e+03 4.1e-05 5.28e-03
## 16 34 9.281e+03 1.44e-08 1.44e-08 1.4e-12 2.2e+05 8.2e-07 5.28e-03
## 17 36 9.281e+03 2.89e-09 2.89e-09 2.8e-13 1.1e+06 1.6e-07 5.28e-03
## 18 38 9.281e+03 5.78e-09 5.78e-09 5.5e-13 1.4e+05 3.3e-07 5.28e-03
## 19 40 9.281e+03 1.16e-08 1.16e-08 1.1e-12 7.0e+04 6.6e-07 5.28e-03
## 20 42 9.281e+03 2.31e-09 2.31e-09 2.2e-13 1.4e+06 1.3e-07 5.28e-03
## 21 44 9.281e+03 4.62e-10 4.62e-10 4.4e-14 7.0e+06 2.6e-08 5.28e-03
## 22 46 9.281e+03 9.24e-11 9.24e-11 8.9e-15 1.6e+00 5.2e-09 -2.81e-03
## 23 48 9.281e+03 1.85e-10 1.85e-10 1.8e-14 4.4e+06 1.0e-08 5.28e-03
## 24 50 9.281e+03 -1.08e+06 3.70e-11 3.5e-15 1.6e+00 2.1e-09 -2.81e-03
##
## ***** FALSE CONVERGENCE *****
##
## FUNCTION 9.281359e+03 RELDX 3.546e-15
## FUNC. EVALS 50 GRAD. EVALS 24
## PRELDF 3.697e-11 NPRELDF -2.809e-03
##
## I FINAL X(I) D(I) G(I)
##
## 1 2.580169e+05 1.000e+00 2.632e-04
## 2 9.254468e-01 1.000e+00 7.992e+01
## 3 2.431892e-10 1.000e+00 1.428e+02
summary(AMZNgarch)
##
## Call:
## garch(x = AMZNdaily)
##
## Model:
## GARCH(1,1)
##
## Residuals:
## Min 1Q Median 3Q Max
## 0.4939 0.7962 0.9037 0.9881 1.0611
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## a0 2.580e+05 2.856e+05 0.904 0.366
## a1 9.254e-01 1.018e+00 0.909 0.363
## b1 2.432e-10 9.235e-01 0.000 1.000
##
## Diagnostic Tests:
## Jarque Bera Test
##
## data: Residuals
## X-squared = 194.73, df = 2, p-value < 2.2e-16
##
##
## Box-Ljung test
##
## data: Squared.Residuals
## X-squared = 1217.2, df = 1, p-value < 2.2e-16
AMZNgarch
##
## Call:
## garch(x = AMZNdaily)
##
## Coefficient(s):
## a0 a1 b1
## 2.580e+05 9.254e-01 2.432e-10
plot(AMZNgarch)
# Analysis of Amazon Adjusted Close Price Time Series Models
When looking at the Amazon stock prices I looked to take a multiplicative approch due to the increain trend seen with the increase in the Amazon stock prices. Additionally the multiplicative nature of a retail based product will typically have a seasonality affect.
The simple timeseries forecast with stl and the ETS model produced very simliar results on their forecast results. When looking at the decomposition plots the seasonality of the stock price appears to be represented once again along with the overall increasng trend of the stock price.
The garch model seems to have some similarities in the resuiduals but appears to devaite from the other models. In regards to the ETS model one factor that also needs to be taken into account for is the seasonality factor will not be accounted for sure to the daily frequency of the data which could cause the forecast to deviate from other models.