Witht the given stock, conduct the Bollinger Bands analysis by answering the questions below.

Q1 Calculate 20-day moving averages and 20-day running standard deviation. Save the result under stock and print it.

Hint: Take stock, pipe it to tidyquant::tq_mutate to calculate 20-day moving averages, pipe it to tidyquant::tq_mutate to calculate 20-day running standard deviation, pipe it to rename() to rename value to SD, and assign the result to stock. To calculate the running standard deviation, use runSD in place of SMA. You can see all the available functions in tidyquant::tq_mutate using tq_mutate_fun_options().

Q2 Calculate the Bollinger Bands. Save the result under stock and print it.

Hint: Take stock, pipe it to mutate(sd2up = SMA + 2 * SD, sd2down = SMA - 2 * SD), and assign the result to stock.

Q3 Select variables to build the Bollinger Bands. Save the result under stock_selected and print it.

Hint: Take stock, pipe it to dplyr::select to keep date, close, SMA, sd2up, and sd2down, and assign the result to stock_selected.

Q4 Transform data to long form from wide form for graphing.Save the result under stock_long and print it.

Hint: Take stock_selected, pipe it to gather(key = type, value = price, close:sd2down), and assign the result to stock_long.

Q5 Visualize data.

Hint: Take stock_selected and pipe it to ggplot(). Map date to the x-axis, price to the y-axis, and type to color in the line chart.

Q6 If you had invested $1 million on the day of the first buying point and sold all the shares on the following selling point, how much would you have won or lost?

2020-02-27 buying point: close at 158.18, sd2down at 162.5136

2020-06-08 selling point: close at 188.36, sd2up at 188.1478

I would have bought 6,321.912 shares with $1 million at the price of $158.18 on 2/27/2020. I would have sold these shares at $188.36 on 6/8/2020 resulting in $190,795.30 in profit.

Q7 An analyst may tinker with the width of the Bollinger Bands depending the volatility of the stock. Which of the following scenarios would have yield the largest profit? Elaborate your answer.

Hint: A correct answer must show the per-share profit each scenario, the difference between the buying price and the selling price.

  1. the upper band being 2 sd up from the average and the lower band 2 sd below (standard)
  2. the upper band being 2.5 sd up from the average and the lower band 2 sd below

Using 2.5 sd, the new buying point would be on 2019-06-03 at closing price: $119.84. With this buying point, the per share profit would be $68.52 as opposed to $30.18 per share profit for scenario 1 with 2 sd. Therefore, scenario 2 yields a higher profit and would have been the better decision in this case.

Q8 Hide the messages, the code, and its results on 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.