Q1 Import Tesla for the last ten months.

## # A tibble: 209 x 8
##    symbol date        open  high   low close   volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 TSLA   2019-06-14  211.  217.  210.  215.  7433400     215.
##  2 TSLA   2019-06-17  215.  227   214.  225. 12316800     225.
##  3 TSLA   2019-06-18  229.  235.  223.  225. 12715800     225.
##  4 TSLA   2019-06-19  225.  228.  221.  226.  6575100     226.
##  5 TSLA   2019-06-20  223   227.  216.  220. 11863500     220.
##  6 TSLA   2019-06-21  216.  222.  216.  222.  8202100     222.
##  7 TSLA   2019-06-24  223.  226.  221.  224.  5750800     224.
##  8 TSLA   2019-06-25  224.  225.  219.  220.  6182100     220.
##  9 TSLA   2019-06-26  220.  227.  218.  219.  8507200     219.
## 10 TSLA   2019-06-27  219.  223.  217.  223.  6339700     223.
## # … with 199 more rows

Q2 Calculate 15-day and 50-day simple moving averages.

## # A tibble: 209 x 10
##    symbol date        open  high   low close  volume adjusted SMA.short SMA.long
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>     <dbl>    <dbl>
##  1 TSLA   2019-06-14  211.  217.  210.  215.  7.43e6     215.        NA       NA
##  2 TSLA   2019-06-17  215.  227   214.  225.  1.23e7     225.        NA       NA
##  3 TSLA   2019-06-18  229.  235.  223.  225.  1.27e7     225.        NA       NA
##  4 TSLA   2019-06-19  225.  228.  221.  226.  6.58e6     226.        NA       NA
##  5 TSLA   2019-06-20  223   227.  216.  220.  1.19e7     220.        NA       NA
##  6 TSLA   2019-06-21  216.  222.  216.  222.  8.20e6     222.        NA       NA
##  7 TSLA   2019-06-24  223.  226.  221.  224.  5.75e6     224.        NA       NA
##  8 TSLA   2019-06-25  224.  225.  219.  220.  6.18e6     220.        NA       NA
##  9 TSLA   2019-06-26  220.  227.  218.  219.  8.51e6     219.        NA       NA
## 10 TSLA   2019-06-27  219.  223.  217.  223.  6.34e6     223.        NA       NA
## # … with 199 more rows

Q3 Transform data to long form from wide form for graphing.

## # A tibble: 627 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2019-06-14 close  215.
##  2 2019-06-17 close  225.
##  3 2019-06-18 close  225.
##  4 2019-06-19 close  226.
##  5 2019-06-20 close  220.
##  6 2019-06-21 close  222.
##  7 2019-06-24 close  224.
##  8 2019-06-25 close  220.
##  9 2019-06-26 close  219.
## 10 2019-06-27 close  223.
## # … with 617 more rows

Q4 Visualize data.

Q5 If you had invested $1 million on the day of the first bullish crossover and sold your shares on the following bearish crosover, how much would you have won or lost?

SMA bullish crossover 9/19/19 close 246.60 SMA bearish crossover 3/17/20 close 430.20 1000000 (investment) / 246.60 (share price) = 4055 (shares) 4055 (shares) * 430.20 (share price) = 1744461 (total sale) 1744461 (total sale) - 1000000 (investment) = 744461 (total gain) Not counting potential dividends, a 1,000,000 dollar investment into Tesla on the day of the first bullish crossover of September 19th, 2019 would have yielded a 744,461 dollar profit if sold on the day of the first bearish crossover of March 17th, 2020.

Q6 The bearish crossover missed the actual high. How long (in days) was the time lag?

The high occurred on February 19th. Nineteen business days later (or 27 calendar days) on March 17th, the bearish crossover registered, resulting in a 487.22 loss of stock price.

Q7 What would you change in the moving average model to reduce the time lag?

To reduce the time lag, I would lower the SMA.long day length to 30 and the SMA.short day length to 10. Since Tesla is a volatile stock, using a smaller time window to reduce the time lag would result in catching losses much quicker.

Q7.a Create another chart below with the change, and count the reduced time lag (in days).

## # A tibble: 209 x 12
##    symbol date        open  high   low close volume adjusted SMA.short SMA.long
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl>     <dbl>    <dbl>
##  1 TSLA   2019-06-14  211.  217.  210.  215. 7.43e6     215.        NA       NA
##  2 TSLA   2019-06-17  215.  227   214.  225. 1.23e7     225.        NA       NA
##  3 TSLA   2019-06-18  229.  235.  223.  225. 1.27e7     225.        NA       NA
##  4 TSLA   2019-06-19  225.  228.  221.  226. 6.58e6     226.        NA       NA
##  5 TSLA   2019-06-20  223   227.  216.  220. 1.19e7     220.        NA       NA
##  6 TSLA   2019-06-21  216.  222.  216.  222. 8.20e6     222.        NA       NA
##  7 TSLA   2019-06-24  223.  226.  221.  224. 5.75e6     224.        NA       NA
##  8 TSLA   2019-06-25  224.  225.  219.  220. 6.18e6     220.        NA       NA
##  9 TSLA   2019-06-26  220.  227.  218.  219. 8.51e6     219.        NA       NA
## 10 TSLA   2019-06-27  219.  223.  217.  223. 6.34e6     223.        NA       NA
## # … with 199 more rows, and 2 more variables: SMA.shortnew <dbl>,
## #   SMA.longnew <dbl>

New Bearish cross occurs on March 6th, seven business days (or 13 calendar days) sooner. This is a total time lag of twelve business days (or 14 calendar days). Closing price that day was 703.48, saving the investor 273.28 per share, and resulting in a profit of 1,852,611.40 dollars instead.