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 chart of stock prices in question 1 shows the stock prices of Microsoft and Apple for each day over the last 20 years. The chart shows several prices over the course of the day. It shows the opening price, the highest price, the lowest price, and then the closing price for each day. The volume shows how many shares were traded during the day. the adjusted is the price after dividends are taken from the stock price.
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.
Apple has the higher expected yearly returns. The median yearly return for Apple over the past 20 years is higher than Microsoft’s. the median yearly return for Apple is at about .5, while Microsoft is at about .25.
Hint: Discuss your answer in terms of the interquartile range (the middle 50%) of the boxplot you created in Q5.
Apple looks to be the riskier stock. Apple has a larger interquartile range, creating a higher range of possible expected returns. Apple also has more outliers, which shows that the stock can go both higher and lower than expected. Microsoft’s interquartile range is smaller, creating a more dense area for expected returns.
Hint: Change echo and results in the chunk options. The published webpage should display charts.