Witht the given stock, conduct the Bollinger Bands analysis by answering the questions below.
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().
Hint: Take stock, pipe it to mutate(sd2up = SMA + 2 * SD, sd2down = SMA - 2 * SD), and assign the result to stock.
Hint: Take stock, pipe it to dplyr::select to keep date, close, SMA, sd2up, and sd2down, and assign the result to stock_selected.
Hint: Take stock_selected, pipe it to gather(key = type, value = price, close:sd2down), and assign the result to stock_long.
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.
Hint: A correct answer must show the per-share profit each scenario, the difference between the buying price and the selling price.
upper 171.1634, 240.4095 = $404,561.37 shares 5842.37 I would have 5842.37 shares of the upper 2 sd with a million dollars at the price of $171.16. I would have made $404,561.37 by selling all the shares at a price of 240.41.
lower 156.2116, 226.3835 = $449,210.56 shares 6401.57 I would have 6401.57 shares of the lower 2 sd with a million dollars at the price of $156.21. I would have made $449,210.56 by selling all the shares at a price of 226.38.
This means that the lower 2 sd would have made more of a profit by $44,649.19.
upper 173.0323,242.1628 = $399,523.67 shares 5779.27
I would have 5779.27 shares of the upper 2 sd with a million dollars at the price of $173.03. I would have made $399,523.67 by selling all the shares at a price of 242.16.
lower 156.2116, 226.3835 = $449,210.56 shares 6401.57 I would have 6401.57 shares of the lower 2 sd with a million dollars at the price of $156.21. I would have made $404,561.37 by selling all the shares at a price of 226.38.
This means that the lower 2 sd would have made more of a profit by $49,686.89.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.