Load packages and data

library(fpp3)
library(readxl)
# install and load any package necessary

Questions

Exercise 1

tsla <- read_excel("//Users//mattmullis//Downloads//tlsa.xlsx")


tslats <- tsla %>% 
  mutate(row=row_number()) %>% 
  as_tsibble(index='row') %>% 
  slice(210:253)
#i sliced the data because nathan (who has more finance experience) says that the past year's values dont matter at all.
autoplot(tslats)
## Plot variable not specified, automatically selected `.vars = Close`

tslatsdiff <- tslats %>% 
  mutate(Close=difference(Close)) 
  
check <- tslatsdiff %>% features(Close,ljung_box, lag=10)
check
## # A tibble: 1 × 2
##   lb_stat lb_pvalue
##     <dbl>     <dbl>
## 1    15.6     0.112
autoplot(tslatsdiff)
## Plot variable not specified, automatically selected `.vars = Close`
## Warning: Removed 1 row(s) containing missing values (geom_path).

tslatsdiff
## # A tsibble: 44 x 3 [1]
##    Date                  Close   row
##    <dttm>                <dbl> <int>
##  1 2022-09-16 00:00:00  NA       210
##  2 2022-09-19 00:00:00   5.72    211
##  3 2022-09-20 00:00:00  -0.340   212
##  4 2022-09-21 00:00:00  -7.93    213
##  5 2022-09-22 00:00:00 -12.2     214
##  6 2022-09-23 00:00:00 -13.3     215
##  7 2022-09-26 00:00:00   0.680   216
##  8 2022-09-27 00:00:00   6.93    217
##  9 2022-09-28 00:00:00   4.87    218
## 10 2022-09-29 00:00:00 -19.6     219
## # … with 34 more rows
#this is white noise. 
#this looks much more stable, so I should use a difference of the first order. 
tslats %>% ACF(difference(Close)) %>% autoplot()

tslats %>% PACF(difference(Close)) %>% autoplot()

#it doesnt look like values for q or p are appropriate. 
tslatsfit <- tslats %>% 
  model(ARIMA(Close~pdq(0,1,0)),
        ARIMA(Close~pdq(0,2,0)))
glance(tslatsfit)
## # A tibble: 2 × 8
##   .model                      sigma2 log_lik   AIC  AICc   BIC ar_roots ma_roots
##   <chr>                        <dbl>   <dbl> <dbl> <dbl> <dbl> <list>   <list>  
## 1 ARIMA(Close ~ pdq(0, 1, 0))   78.0   -154.  312.  313.  316. <cpl>    <cpl>   
## 2 ARIMA(Close ~ pdq(0, 2, 0))  182.    -169.  340.  340.  342. <cpl>    <cpl>
#looks like the first difference is the better model. 
tslatsfc <- tslatsfit %>% 
  forecast(h=1)
tslatsfc
## # A fable: 2 x 4 [1]
## # Key:     .model [2]
##   .model                        row       Close .mean
##   <chr>                       <dbl>      <dist> <dbl>
## 1 ARIMA(Close ~ pdq(0, 1, 0))   254  N(184, 78)  184.
## 2 ARIMA(Close ~ pdq(0, 2, 0))   254 N(179, 182)  179.
hilo(tslatsfc)
## # A tsibble: 2 x 6 [1]
## # Key:       .model [2]
##   .model     row       Close .mean                  `80%`                  `95%`
##   <chr>    <dbl>      <dist> <dbl>                 <hilo>                 <hilo>
## 1 ARIMA(C…   254  N(184, 78)  184. [172.8965, 195.5282]80 [166.9062, 201.5184]95
## 2 ARIMA(C…   254 N(179, 182)  179. [162.1280, 196.7120]80 [152.9742, 205.8658]95

#i feel like this is a pretty good forecast, however I subscribe to the efficient market hypothesis and we know that stocks are a random walk. Because of this, im not going to do any other model. I do think that a negative trend will continue, so my prediction will be a little less than my model’s. My prediction is 178.69. I guess my prediction interval will be 170-190.