With the given stock, conduct the Bollinger Bands analysis by answering the questions below.
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.
## Warning: Removed 57 row(s) containing missing values (geom_path).
Hint: A correct answer must show the per-share profit each scenario, the difference between the buying price and the selling price.
Buying price: 2020-02-27 at 158.18; Selling price: 2020-06-08 at 188.36; –Per share profit: 30.18
Buying price: 2020-02-27 at 158.18; Selling price: 2020-06-10 at 196.84; –Per share profit: 38.66
The second scenario will yield more profit, where the Bollinger Band is wider. If the upper Bollinger Band is 2.5 instead of 2, R is finding a higher buying price when filtering for a day when the closing goes higher than the high band, at 2.5 standard deviations. The closing price will be lower at 2 standard deviations because the range is lower.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.