## # A tibble: 1,006 x 7
##    date        open  high   low close  volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>
##  1 2015-03-09  194.  194.  188.  191. 6736700     191.
##  2 2015-03-10  188.  194.  188.  190. 5530900     190.
##  3 2015-03-11  191.  196.  191.  194. 4974900     194.
##  4 2015-03-12  194.  194.  190.  191. 4149300     191.
##  5 2015-03-13  189.  192.  187.  189. 5434300     189.
##  6 2015-03-16  192   196.  190.  196. 5628800     196.
##  7 2015-03-17  195.  199.  194.  195. 4883200     195.
##  8 2015-03-18  195.  201.  193.  201. 4756300     201.
##  9 2015-03-19  202   205.  195.  196. 8475200     196.
## 10 2015-03-20  197.  199.  196.  198. 4269500     198.
## # ... with 996 more rows
## # A tibble: 1,006 x 8
##    date        open  high   low close  volume adjusted daily.returns
##    <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>         <dbl>
##  1 2015-03-09  194.  194.  188.  191. 6736700     191.       0      
##  2 2015-03-10  188.  194.  188.  190. 5530900     190.      -0.00293
##  3 2015-03-11  191.  196.  191.  194. 4974900     194.       0.0180 
##  4 2015-03-12  194.  194.  190.  191. 4149300     191.      -0.0138 
##  5 2015-03-13  189.  192.  187.  189. 5434300     189.      -0.0125 
##  6 2015-03-16  192   196.  190.  196. 5628800     196.       0.0372 
##  7 2015-03-17  195.  199.  194.  195. 4883200     195.      -0.00496
##  8 2015-03-18  195.  201.  193.  201. 4756300     201.       0.0307 
##  9 2015-03-19  202   205.  195.  196. 8475200     196.      -0.0252 
## 10 2015-03-20  197.  199.  196.  198. 4269500     198.       0.0124 
## # ... with 996 more rows

You are evaluating the performance of two stocks, Microsoft and Apple, for future investment.

Q1 Import stock prices of Microsoft and Apple for the last 20 years.

Hint: Add group_by(symbol) at the end of the code so that calculations below will be done per stock.

## # A tibble: 10,064 x 8
## # Groups:   symbol [2]
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 AAPL   1999-03-08  1.19  1.24  1.19  1.23 137667600    0.819
##  2 AAPL   1999-03-09  1.23  1.23  1.20  1.22  79923200    0.813
##  3 AAPL   1999-03-10  1.22  1.22  1.16  1.16 136570000    0.775
##  4 AAPL   1999-03-11  1.15  1.21  1.14  1.15 118414800    0.767
##  5 AAPL   1999-03-12  1.15  1.20  1.15  1.19  67849600    0.790
##  6 AAPL   1999-03-15  1.19  1.25  1.19  1.22  88040400    0.811
##  7 AAPL   1999-03-16  1.25  1.27  1.25  1.27  99957200    0.845
##  8 AAPL   1999-03-17  1.28  1.29  1.21  1.22  91579600    0.811
##  9 AAPL   1999-03-18  1.23  1.27  1.22  1.27  56770000    0.845
## 10 AAPL   1999-03-19  1.28  1.29  1.17  1.20 134125600    0.798
## # ... with 10,054 more rows

Q2 Describe the first observation (first row) using all variables.

The symbol shows what stock you are looking at, The date shows the date of that stock, open shows the opening price of the stock, high shows the highest that stock was that day, low shows the lowest that stock was that day, volume shows how many trades of that stock were made that day, and adjusted stands for the closing proce adjusted to dividens for the stock that day.

Q3 Create a line chart for adjusted closing prices of both stocks.

Hint: Use ggplot2::facet_wrap. Refer to the ggplot2 cheatsheet. See the section for Faceting.

Q4 Calculate yearly returns, and save the result under returns_yearly.

Hint: Take the adjusted variable from Stocks, and calculate yearly returns using tq_transmute(), instead of tq_mutate(), which is used when periodicity changes. Another difference between the two is that tq_transmute() returns only newly-created columns while tq_mutate() adds new columns to existing variables.

## # A tibble: 42 x 3
## # Groups:   symbol [2]
##    symbol date       yearly.returns
##    <chr>  <date>              <dbl>
##  1 AAPL   1999-12-31          1.99 
##  2 AAPL   2000-12-29         -0.711
##  3 AAPL   2001-12-31          0.472
##  4 AAPL   2002-12-31         -0.346
##  5 AAPL   2003-12-31          0.491
##  6 AAPL   2004-12-31          2.01 
##  7 AAPL   2005-12-30          1.23 
##  8 AAPL   2006-12-29          0.180
##  9 AAPL   2007-12-31          1.33 
## 10 AAPL   2008-12-31         -0.569
## # ... with 32 more rows

Q5 Create a boxplot for returns of both stocks.

Hint: Refer to the ggplot2 cheatsheet. Look for geom_boxplot under Two Variables. Note that the discrete variable should be mapped to the x-axis and the continuous variable to the y-axis.

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

Hint: Discuss your answer in terms of the median in the boxplot you created in Q5. Google “Interpreting boxplots in R” to find the information you need.

Apple is expected to have the higher yearly return due to the median being higher than microsofts.

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

Hint: Discuss your answer in terms of the interquartile range (the middle 50%) of the boxplot you created in Q5.

Apple will most likely be riskier due to the middle quartile not being in the middle in the interquartile.The box plot is uneven and taller.

Q8. Hide both the code and the results of the code on the webpage.

Hint: Change echo and results in the chunk options. The published webpage should display charts.

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

Q10. Use the correct slug.