Q1 Import Tesla for the last one year.

Hint: Copy and revise the importing part of the code from above.

## # A tibble: 251 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2018-10-24  301.  304.  286.  288. 20058300     288.
##  2 2018-10-25  317.  321   301.  315. 20840700     315.
##  3 2018-10-26  308.  340.  307.  331. 27425500     331.
##  4 2018-10-29  337.  347.  326.  335. 14486000     335.
##  5 2018-10-30  328.  338.  322.  330.  9126700     330.
##  6 2018-10-31  333.  342   329.  337.  7624300     337.
##  7 2018-11-01  338.  348.  335.  344.  8000100     344.
##  8 2018-11-02  344.  349.  341.  346.  7808000     346.
##  9 2018-11-05  340.  344.  330.  341.  7831000     341.
## 10 2018-11-06  339.  349.  336.  341.  6762900     341.
## # … with 241 more rows

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

Hint: Copy and revise the moving average part of the code from above.

## # A tibble: 251 x 9
##    date        open  high   low close   volume adjusted SMA.short SMA.long
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>     <dbl>    <dbl>
##  1 2018-10-24  301.  304.  286.  288. 20058300     288.        NA       NA
##  2 2018-10-25  317.  321   301.  315. 20840700     315.        NA       NA
##  3 2018-10-26  308.  340.  307.  331. 27425500     331.        NA       NA
##  4 2018-10-29  337.  347.  326.  335. 14486000     335.        NA       NA
##  5 2018-10-30  328.  338.  322.  330.  9126700     330.        NA       NA
##  6 2018-10-31  333.  342   329.  337.  7624300     337.        NA       NA
##  7 2018-11-01  338.  348.  335.  344.  8000100     344.        NA       NA
##  8 2018-11-02  344.  349.  341.  346.  7808000     346.        NA       NA
##  9 2018-11-05  340.  344.  330.  341.  7831000     341.        NA       NA
## 10 2018-11-06  339.  349.  336.  341.  6762900     341.        NA       NA
## # … with 241 more rows

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

Hint: Copy and revise the transformation part of the code from above.

## # A tibble: 753 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2018-10-24 close  288.
##  2 2018-10-25 close  315.
##  3 2018-10-26 close  331.
##  4 2018-10-29 close  335.
##  5 2018-10-30 close  330.
##  6 2018-10-31 close  337.
##  7 2018-11-01 close  344.
##  8 2018-11-02 close  346.
##  9 2018-11-05 close  341.
## 10 2018-11-06 close  341.
## # … with 743 more rows

Q4 Visualize data.

Hint: Copy and revise the visualization part of the code from above.

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?

The first bullish crossover being on July 2nd where the SMA short rises above the SMA long at a closing price of $224.55. That would give you 4,453 shares. The first bearish crossover on August 16th where the SMA short falls below the SMA long at a closing price of $219.94. That would result in $979,392.82, making a loss of $20,607.18.

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

The time lag was 21 business days from June 3rd to July 2nd.

Q7 What would you change in the moving average model to reduce the time lag? Create another chart below with the change, and count the reduced time lag (in days).

## # A tibble: 251 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2018-10-24  301.  304.  286.  288. 20058300     288.
##  2 2018-10-25  317.  321   301.  315. 20840700     315.
##  3 2018-10-26  308.  340.  307.  331. 27425500     331.
##  4 2018-10-29  337.  347.  326.  335. 14486000     335.
##  5 2018-10-30  328.  338.  322.  330.  9126700     330.
##  6 2018-10-31  333.  342   329.  337.  7624300     337.
##  7 2018-11-01  338.  348.  335.  344.  8000100     344.
##  8 2018-11-02  344.  349.  341.  346.  7808000     346.
##  9 2018-11-05  340.  344.  330.  341.  7831000     341.
## 10 2018-11-06  339.  349.  336.  341.  6762900     341.
## # … with 241 more rows
## # A tibble: 251 x 9
##    date        open  high   low close   volume adjusted SMA.short SMA.long
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>     <dbl>    <dbl>
##  1 2018-10-24  301.  304.  286.  288. 20058300     288.        NA       NA
##  2 2018-10-25  317.  321   301.  315. 20840700     315.        NA       NA
##  3 2018-10-26  308.  340.  307.  331. 27425500     331.        NA       NA
##  4 2018-10-29  337.  347.  326.  335. 14486000     335.        NA       NA
##  5 2018-10-30  328.  338.  322.  330.  9126700     330.        NA       NA
##  6 2018-10-31  333.  342   329.  337.  7624300     337.        NA       NA
##  7 2018-11-01  338.  348.  335.  344.  8000100     344.        NA       NA
##  8 2018-11-02  344.  349.  341.  346.  7808000     346.        NA       NA
##  9 2018-11-05  340.  344.  330.  341.  7831000     341.        NA       NA
## 10 2018-11-06  339.  349.  336.  341.  6762900     341.        NA       NA
## # … with 241 more rows
## # A tibble: 753 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2018-10-24 close  288.
##  2 2018-10-25 close  315.
##  3 2018-10-26 close  331.
##  4 2018-10-29 close  335.
##  5 2018-10-30 close  330.
##  6 2018-10-31 close  337.
##  7 2018-11-01 close  344.
##  8 2018-11-02 close  346.
##  9 2018-11-05 close  341.
## 10 2018-11-06 close  341.
## # … with 743 more rows

I changed SMA long to a smaller number to reduce the time lag, resulting in a time lag of 12 business days.

Q8 Hide the messages and the code, but display results of the code from the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.