Hint: Use library().
Hint: Use tq_get() from the tidyquant package.
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: There are many resources on the Web. For example, Google something like “ggplot2 adding subtitle”.
Hint: Take stock, pipe it to dplyr::select to keep only three variables (date, close, and sd2down), and pipe it to dplyr::filter to select the rows where closing prices are smaller than the lower band.
If the stock price falls below the lower band, the stock may be considered oversold.
When the bands narrow, it may be used as an indication that volatility is about to rise.
The first buying oppurtunity is May 7 2018 and the closing price is $69.3
Hint: Take stock, pipe it to dplyr::select to keep only three variables (date, close, and sd2up), and pipe it to dplyr::filter to select the rows where closing prices are greater than the upper band.
The first selling date is May 16, 2018 at $75.23.
1000000/69.33=14423.77* 75.23 =1085100.25-1000000 = 85,100.25 you would have made $85,100.25
Hint: Change echo and results in the chunk options. The published webpage should display charts.