You are evaluating the performance of two stocks, Microsoft and Apple, for future investment.
Hint: Add group_by(symbol) at the end of the code so that calculations below will be done per stock.
The symbol determines whether the row listed is Microsoft or Apple stock. The date determines what date the stock prices were recorded. The open column determines what the opening price of the stock was. The high column determines what the highest stock price of the day was. The low column determies what the lowest recorded stock price of the day was. The close column determines what the price of the stock was at the close of the business day. The volume column determines how many stocks were traded that particular day. The adjusted column determines the closing price adjusted to dividends and stock prices. On March 8, 1999, Microsoft had an opening price of $38.87500. The high of that day was $39.80857 and the low was $38.75000. The closing price was $39.75000 with a volume of 46726000 and adjusted price of $28.72423.
Hint: Use ggplot2::facet_wrap. Refer to the ggplot2 cheatsheet. See the section for Faceting.
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.
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.
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.
The median yearly return for Apple is higher than Microsoft so the typical yearly return for Apple is expected to be higher.
Hint: Discuss your answer in terms of the interquartile range (the middle 50%) of the boxplot you created in Q5.
Apple has a larger interquartile range than Microsoft. This means Apple has more variation so that means it is riskier than Microsoft.
Hint: Change echo and results in the chunk options. The published webpage should display charts.