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 would occur on July 2nd and the closing price of Tesla is 224.55. 1 million dollarts invested in Tesla would get you 4,453 shares.

The first bearish crossover is on August 16th where the closing price was 219.94. Which would mean you would lose 20,607.178 dollars on a 1 million dollar investment.

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

The time lag between the bullish crossover and the bottom of the graph was 21 business days, or 29 days total.

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.      331.       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

You can change the number in the code from question 2 and make them more similar in value to get the moving averages more similar. The reduced time lag is 6 Business days or 8 days total.

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.