Q1 Get stock prices from the past 10 years

## # A tibble: 5,032 x 8
## # Groups:   symbol [2]
##    symbol date        open  high   low close   volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 DIS    2009-05-04  22.0  22.9  21.8  22.9 17603700     19.9
##  2 DIS    2009-05-05  22.7  23.3  22.7  23.2 16806900     20.2
##  3 DIS    2009-05-06  25.0  26.3  24.7  25.9 49777100     22.5
##  4 DIS    2009-05-07  25.8  26.2  25.0  25.3 23981600     22.1
##  5 DIS    2009-05-08  25.7  26    25    25.5 18172900     22.2
##  6 DIS    2009-05-11  25.1  25.2  24.7  24.7 14656600     21.5
##  7 DIS    2009-05-12  24.9  24.9  23.9  24.3 15536900     21.2
##  8 DIS    2009-05-13  23.9  24.0  23.4  23.6 14055900     20.6
##  9 DIS    2009-05-14  23.6  24.0  23.3  23.5 11893400     20.5
## 10 DIS    2009-05-15  23.5  24.2  23.3  23.4 20991800     20.4
## # ... with 5,022 more rows

Q2 Create a line chart:

Q3 Calculate the yearly returns:

## # A tibble: 22 x 3
## # Groups:   symbol [2]
##    symbol date       yearly.returns
##    <chr>  <date>              <dbl>
##  1 DIS    2009-12-31        0.427  
##  2 DIS    2010-12-31        0.176  
##  3 DIS    2011-12-30        0.0165 
##  4 DIS    2012-12-31        0.348  
##  5 DIS    2013-12-31        0.553  
##  6 DIS    2014-12-31        0.249  
##  7 DIS    2015-12-31        0.129  
##  8 DIS    2016-12-30        0.00672
##  9 DIS    2017-12-29        0.0476 
## 10 DIS    2018-12-31        0.0361 
## # ... with 12 more rows

Q4 Create a boxplot

Q5 Which of the two stocks is the typical yearly return expected to be higher?

-Apple’s yearly return is expected to be higher than Disney because Apple’s median yearly return is higher than Disney.

Q6 Create a density plot:

Q7 Create a kurtosis and skewness

## # A tibble: 2 x 2
## # Groups:   symbol [2]
##   symbol skewness.1
##   <chr>       <dbl>
## 1 DIS         0.608
## 2 AAPL       -0.442
## # A tibble: 2 x 2
## # Groups:   symbol [2]
##   symbol kurtosis.1
##   <chr>       <dbl>
## 1 DIS        -0.755
## 2 AAPL       -1.05

Q8 Would you consider the standard deviation as an appropriate measure of risk for the stocks listed?

-Apple has a negative skewness which means large negative returns will occur more often. Disney has a positive skewness which means large positive returns are likely to occur more often. Apple and Disney both have kurtosis that is below zero so larger returns of both positive and negative are less likely to occur more often (they will have skinnier tails). Because of this information, I have determined that standard deviation is not an appropriate measure of risk for these stocks because they are not normally distributed so there is a greater chance of variation.

Q9 Import Disney’s Stock

## # A tibble: 251 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2018-05-02 100.  101.   99.2  99.6  9286400     98.1
##  2 2018-05-03  99.1  99.2  97.7  98.8 10450800     97.2
##  3 2018-05-04  98.7 101.   98.6 101.   9980100     99.6
##  4 2018-05-07 102.  103.  102.  102.  10181100    101. 
##  5 2018-05-08 101.  103.  101.  102.  14229500    100. 
##  6 2018-05-09 102.  102.   99.3 100.0 18345700     98.4
##  7 2018-05-10 100.  102.  100.  102.   8927300    100. 
##  8 2018-05-11 102.  102.  101.  102.   7036000    100. 
##  9 2018-05-14 102.  103.  102.  102.   9891900    101. 
## 10 2018-05-15 102.  103.  102.  103.   5762400    101. 
## # ... with 241 more rows

Q 10a Calculate 20 day moving averages and 20-day running standard deviation:

## # A tibble: 251 x 9
##    date        open  high   low close   volume adjusted   SMA    SD
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl> <dbl> <dbl>
##  1 2018-05-02 100.  101.   99.2  99.6  9286400     98.1    NA    NA
##  2 2018-05-03  99.1  99.2  97.7  98.8 10450800     97.2    NA    NA
##  3 2018-05-04  98.7 101.   98.6 101.   9980100     99.6    NA    NA
##  4 2018-05-07 102.  103.  102.  102.  10181100    101.     NA    NA
##  5 2018-05-08 101.  103.  101.  102.  14229500    100.     NA    NA
##  6 2018-05-09 102.  102.   99.3 100.0 18345700     98.4    NA    NA
##  7 2018-05-10 100.  102.  100.  102.   8927300    100.     NA    NA
##  8 2018-05-11 102.  102.  101.  102.   7036000    100.     NA    NA
##  9 2018-05-14 102.  103.  102.  102.   9891900    101.     NA    NA
## 10 2018-05-15 102.  103.  102.  103.   5762400    101.     NA    NA
## # ... with 241 more rows

Q10b Calculate the Bollinger Bands:

## # A tibble: 251 x 11
##    date        open  high   low close volume adjusted   SMA    SD sd2up
##    <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl> <dbl> <dbl> <dbl>
##  1 2018-05-02 100.  101.   99.2  99.6 9.29e6     98.1    NA    NA    NA
##  2 2018-05-03  99.1  99.2  97.7  98.8 1.05e7     97.2    NA    NA    NA
##  3 2018-05-04  98.7 101.   98.6 101.  9.98e6     99.6    NA    NA    NA
##  4 2018-05-07 102.  103.  102.  102.  1.02e7    101.     NA    NA    NA
##  5 2018-05-08 101.  103.  101.  102.  1.42e7    100.     NA    NA    NA
##  6 2018-05-09 102.  102.   99.3 100.0 1.83e7     98.4    NA    NA    NA
##  7 2018-05-10 100.  102.  100.  102.  8.93e6    100.     NA    NA    NA
##  8 2018-05-11 102.  102.  101.  102.  7.04e6    100.     NA    NA    NA
##  9 2018-05-14 102.  103.  102.  102.  9.89e6    101.     NA    NA    NA
## 10 2018-05-15 102.  103.  102.  103.  5.76e6    101.     NA    NA    NA
## # ... with 241 more rows, and 1 more variable: sd2down <dbl>

Q10c Keep variables to build the Bollinger Bands:

## # A tibble: 251 x 5
##    date       close   SMA sd2up sd2down
##    <date>     <dbl> <dbl> <dbl>   <dbl>
##  1 2018-05-02  99.6    NA    NA      NA
##  2 2018-05-03  98.8    NA    NA      NA
##  3 2018-05-04 101.     NA    NA      NA
##  4 2018-05-07 102.     NA    NA      NA
##  5 2018-05-08 102.     NA    NA      NA
##  6 2018-05-09 100.0    NA    NA      NA
##  7 2018-05-10 102.     NA    NA      NA
##  8 2018-05-11 102.     NA    NA      NA
##  9 2018-05-14 102.     NA    NA      NA
## 10 2018-05-15 103.     NA    NA      NA
## # ... with 241 more rows

Q10d Transform data to long form from wide form for graphing

## # A tibble: 1,004 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2018-05-02 close  99.6
##  2 2018-05-03 close  98.8
##  3 2018-05-04 close 101. 
##  4 2018-05-07 close 102. 
##  5 2018-05-08 close 102. 
##  6 2018-05-09 close 100.0
##  7 2018-05-10 close 102. 
##  8 2018-05-11 close 102. 
##  9 2018-05-14 close 102. 
## 10 2018-05-15 close 103. 
## # ... with 994 more rows

Q10e Visualize data

Q11 Import Apple’s Stock

## # A tibble: 251 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2018-05-02  175.  178.  174.  177. 66539400     174.
##  2 2018-05-03  176.  178.  174.  177. 34068200     174.
##  3 2018-05-04  178.  184.  178.  184. 56201300     181.
##  4 2018-05-07  185.  188.  185.  185. 42451400     182.
##  5 2018-05-08  185.  186.  184.  186. 28402800     183.
##  6 2018-05-09  187.  187.  185.  187. 23211200     185.
##  7 2018-05-10  188.  190.  188.  190. 27989300     187.
##  8 2018-05-11  189.  190.  187.  189. 26212200     186.
##  9 2018-05-14  189.  190.  188.  188. 20778800     186.
## 10 2018-05-15  187.  187.  185.  186. 23695200     184.
## # ... with 241 more rows

Q12a Calculate 20 day moving averages and 20-day running standard deviation:

## # A tibble: 251 x 9
##    date        open  high   low close   volume adjusted   SMA    SD
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl> <dbl> <dbl>
##  1 2018-05-02  175.  178.  174.  177. 66539400     174.    NA    NA
##  2 2018-05-03  176.  178.  174.  177. 34068200     174.    NA    NA
##  3 2018-05-04  178.  184.  178.  184. 56201300     181.    NA    NA
##  4 2018-05-07  185.  188.  185.  185. 42451400     182.    NA    NA
##  5 2018-05-08  185.  186.  184.  186. 28402800     183.    NA    NA
##  6 2018-05-09  187.  187.  185.  187. 23211200     185.    NA    NA
##  7 2018-05-10  188.  190.  188.  190. 27989300     187.    NA    NA
##  8 2018-05-11  189.  190.  187.  189. 26212200     186.    NA    NA
##  9 2018-05-14  189.  190.  188.  188. 20778800     186.    NA    NA
## 10 2018-05-15  187.  187.  185.  186. 23695200     184.    NA    NA
## # ... with 241 more rows

Q12b Calculate the Bollinger Bands:

## # A tibble: 251 x 11
##    date        open  high   low close volume adjusted   SMA    SD sd2up
##    <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl> <dbl> <dbl> <dbl>
##  1 2018-05-02  175.  178.  174.  177. 6.65e7     174.    NA    NA    NA
##  2 2018-05-03  176.  178.  174.  177. 3.41e7     174.    NA    NA    NA
##  3 2018-05-04  178.  184.  178.  184. 5.62e7     181.    NA    NA    NA
##  4 2018-05-07  185.  188.  185.  185. 4.25e7     182.    NA    NA    NA
##  5 2018-05-08  185.  186.  184.  186. 2.84e7     183.    NA    NA    NA
##  6 2018-05-09  187.  187.  185.  187. 2.32e7     185.    NA    NA    NA
##  7 2018-05-10  188.  190.  188.  190. 2.80e7     187.    NA    NA    NA
##  8 2018-05-11  189.  190.  187.  189. 2.62e7     186.    NA    NA    NA
##  9 2018-05-14  189.  190.  188.  188. 2.08e7     186.    NA    NA    NA
## 10 2018-05-15  187.  187.  185.  186. 2.37e7     184.    NA    NA    NA
## # ... with 241 more rows, and 1 more variable: sd2down <dbl>

Q12c Keep variables to build the Bollinger Bands:

## # A tibble: 251 x 5
##    date       close   SMA sd2up sd2down
##    <date>     <dbl> <dbl> <dbl>   <dbl>
##  1 2018-05-02  177.    NA    NA      NA
##  2 2018-05-03  177.    NA    NA      NA
##  3 2018-05-04  184.    NA    NA      NA
##  4 2018-05-07  185.    NA    NA      NA
##  5 2018-05-08  186.    NA    NA      NA
##  6 2018-05-09  187.    NA    NA      NA
##  7 2018-05-10  190.    NA    NA      NA
##  8 2018-05-11  189.    NA    NA      NA
##  9 2018-05-14  188.    NA    NA      NA
## 10 2018-05-15  186.    NA    NA      NA
## # ... with 241 more rows

Q12d Transform data to long form from wide form for graphing

## # A tibble: 1,004 x 3
##    date       type  price
##    <date>     <chr> <dbl>
##  1 2018-05-02 close  177.
##  2 2018-05-03 close  177.
##  3 2018-05-04 close  184.
##  4 2018-05-07 close  185.
##  5 2018-05-08 close  186.
##  6 2018-05-09 close  187.
##  7 2018-05-10 close  190.
##  8 2018-05-11 close  189.
##  9 2018-05-14 close  188.
## 10 2018-05-15 close  186.
## # ... with 994 more rows

Q12e Visualize data

Q13 Which of the two stocks is expected to be riskier?

Q14 Which stock would we buy?