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

## # A tibble: 189 x 8
##    symbol date        open  high   low close  volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>
##  1 AMZN   2020-01-02 1875  1898. 1864. 1898. 4029000    1898.
##  2 AMZN   2020-01-03 1864. 1886. 1864. 1875. 3764400    1875.
##  3 AMZN   2020-01-06 1860  1904. 1860  1903. 4061800    1903.
##  4 AMZN   2020-01-07 1904. 1914. 1892. 1907. 4044900    1907.
##  5 AMZN   2020-01-08 1898. 1911  1886. 1892. 3508000    1892.
##  6 AMZN   2020-01-09 1910. 1918. 1896. 1901. 3167300    1901.
##  7 AMZN   2020-01-10 1905. 1907. 1880  1883. 2853700    1883.
##  8 AMZN   2020-01-13 1891. 1898  1881. 1891. 2780800    1891.
##  9 AMZN   2020-01-14 1886. 1887. 1859. 1869. 3440900    1869.
## 10 AMZN   2020-01-15 1872. 1879. 1855. 1862. 2896600    1862.
## # ... with 179 more rows

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

## # A tibble: 189 x 10
##    symbol date        open  high   low close  volume adjusted   SMA    SD
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl> <dbl> <dbl>
##  1 AMZN   2020-01-02 1875  1898. 1864. 1898. 4029000    1898.    NA    NA
##  2 AMZN   2020-01-03 1864. 1886. 1864. 1875. 3764400    1875.    NA    NA
##  3 AMZN   2020-01-06 1860  1904. 1860  1903. 4061800    1903.    NA    NA
##  4 AMZN   2020-01-07 1904. 1914. 1892. 1907. 4044900    1907.    NA    NA
##  5 AMZN   2020-01-08 1898. 1911  1886. 1892. 3508000    1892.    NA    NA
##  6 AMZN   2020-01-09 1910. 1918. 1896. 1901. 3167300    1901.    NA    NA
##  7 AMZN   2020-01-10 1905. 1907. 1880  1883. 2853700    1883.    NA    NA
##  8 AMZN   2020-01-13 1891. 1898  1881. 1891. 2780800    1891.    NA    NA
##  9 AMZN   2020-01-14 1886. 1887. 1859. 1869. 3440900    1869.    NA    NA
## 10 AMZN   2020-01-15 1872. 1879. 1855. 1862. 2896600    1862.    NA    NA
## # ... with 179 more rows

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

## # A tibble: 189 x 12
##    symbol date        open  high   low close volume adjusted   SMA    SD sd2up
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl> <dbl> <dbl> <dbl>
##  1 AMZN   2020-01-02 1875  1898. 1864. 1898. 4.03e6    1898.    NA    NA    NA
##  2 AMZN   2020-01-03 1864. 1886. 1864. 1875. 3.76e6    1875.    NA    NA    NA
##  3 AMZN   2020-01-06 1860  1904. 1860  1903. 4.06e6    1903.    NA    NA    NA
##  4 AMZN   2020-01-07 1904. 1914. 1892. 1907. 4.04e6    1907.    NA    NA    NA
##  5 AMZN   2020-01-08 1898. 1911  1886. 1892. 3.51e6    1892.    NA    NA    NA
##  6 AMZN   2020-01-09 1910. 1918. 1896. 1901. 3.17e6    1901.    NA    NA    NA
##  7 AMZN   2020-01-10 1905. 1907. 1880  1883. 2.85e6    1883.    NA    NA    NA
##  8 AMZN   2020-01-13 1891. 1898  1881. 1891. 2.78e6    1891.    NA    NA    NA
##  9 AMZN   2020-01-14 1886. 1887. 1859. 1869. 3.44e6    1869.    NA    NA    NA
## 10 AMZN   2020-01-15 1872. 1879. 1855. 1862. 2.90e6    1862.    NA    NA    NA
## # ... with 179 more rows, and 1 more variable: sd2down <dbl>

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

## # A tibble: 189 x 5
##    date       close   SMA sd2up sd2down
##    <date>     <dbl> <dbl> <dbl>   <dbl>
##  1 2020-01-02 1898.    NA    NA      NA
##  2 2020-01-03 1875.    NA    NA      NA
##  3 2020-01-06 1903.    NA    NA      NA
##  4 2020-01-07 1907.    NA    NA      NA
##  5 2020-01-08 1892.    NA    NA      NA
##  6 2020-01-09 1901.    NA    NA      NA
##  7 2020-01-10 1883.    NA    NA      NA
##  8 2020-01-13 1891.    NA    NA      NA
##  9 2020-01-14 1869.    NA    NA      NA
## 10 2020-01-15 1862.    NA    NA      NA
## # ... with 179 more rows

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

## # A tibble: 756 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2020-01-02 close 1898.
##  2 2020-01-03 close 1875.
##  3 2020-01-06 close 1903.
##  4 2020-01-07 close 1907.
##  5 2020-01-08 close 1892.
##  6 2020-01-09 close 1901.
##  7 2020-01-10 close 1883.
##  8 2020-01-13 close 1891.
##  9 2020-01-14 close 1869.
## 10 2020-01-15 close 1862.
## # ... with 746 more rows

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.

## Warning: Removed 57 row(s) containing missing values (geom_path).

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?

Today, you would have more than $1 million.In that time, you would have obtained an additional $595,478.18. Totaling to $1,595,478.18

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.

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

Scenario 2. the upper band being 2.5 sd up from the average and the lower band 2 sd below

Scenario 2 would result in a larger profit. Considering 2.5 sd up would create a higher average than 2 sd up, with a constant 2 sd below. *Buy/Sell at sd up

Scenario 1 Buy:$1917.55 Sell:$3424.40

Scenario 2 Buy:$1927.43 Sell:$3494.55

## # A tibble: 189 x 12
##    symbol date        open  high   low close volume adjusted   SMA    SD sd2up
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl> <dbl> <dbl> <dbl>
##  1 AMZN   2020-01-02 1875  1898. 1864. 1898. 4.03e6    1898.    NA    NA    NA
##  2 AMZN   2020-01-03 1864. 1886. 1864. 1875. 3.76e6    1875.    NA    NA    NA
##  3 AMZN   2020-01-06 1860  1904. 1860  1903. 4.06e6    1903.    NA    NA    NA
##  4 AMZN   2020-01-07 1904. 1914. 1892. 1907. 4.04e6    1907.    NA    NA    NA
##  5 AMZN   2020-01-08 1898. 1911  1886. 1892. 3.51e6    1892.    NA    NA    NA
##  6 AMZN   2020-01-09 1910. 1918. 1896. 1901. 3.17e6    1901.    NA    NA    NA
##  7 AMZN   2020-01-10 1905. 1907. 1880  1883. 2.85e6    1883.    NA    NA    NA
##  8 AMZN   2020-01-13 1891. 1898  1881. 1891. 2.78e6    1891.    NA    NA    NA
##  9 AMZN   2020-01-14 1886. 1887. 1859. 1869. 3.44e6    1869.    NA    NA    NA
## 10 AMZN   2020-01-15 1872. 1879. 1855. 1862. 2.90e6    1862.    NA    NA    NA
## # ... with 179 more rows, and 1 more variable: sd2down <dbl>

Q8 Hide the messages, the code, and its results on the webpage.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.