DC 5

# ---------------------------------------------------------
# SERIES 2: Amazon Stock Price (2018)
# -------------------------------------------------------   
amzn_data <- gafa_stock |> 
  filter(Symbol == "AMZN", year(Date) == 2018) |> 
  mutate(trading_day = row_number()) |> 
  update_tsibble(index = trading_day, regular = TRUE)

# 1. Visualize
amzn_data |> autoplot(Close) + 
  labs(title = "Amazon Stock Price (2018)", y = "Closing Price")

# 2. Fit the ETS Model
amzn_fit <- amzn_data |> model(ETS(Close))

# 3. View the Parameters 
report(amzn_fit)
Series: Close 
Model: ETS(A,N,N) 
  Smoothing parameters:
    alpha = 0.9513253 

  Initial states:
     l[0]
 1189.606

  sigma^2:  1349.224

     AIC     AICc      BIC 
3199.909 3200.006 3210.486 
# Amazon Stock Price (2018) first 30 days to compare with Excel
amzn_data_30 <- gafa_stock |> 
  filter(Symbol == "AMZN", year(Date) == 2018) |> 
  head(30) |>  
  mutate(trading_day = row_number()) |> 
  update_tsibble(index = trading_day, regular = TRUE)

# Fit the ETS Model
amzn_fit_30 <- amzn_data_30 |> model(ETS(Close))
# Visualize
amzn_data_30 |> autoplot(Close) + 
  labs(title = "Amazon Stock Price (2018)", y = "Closing Price")

# View the Parameters 
report(amzn_fit_30)
Series: Close 
Model: ETS(M,N,N) 
  Smoothing parameters:
    alpha = 0.96103 

  Initial states:
     l[0]
 1189.064

  sigma^2:  5e-04

     AIC     AICc      BIC 
306.7269 307.6500 310.9305 

View(amzn_data)```