# Load packages
library(tidyverse)
library(tidyquant)
symbols <- c("AAPL", "BBWI", "CCEP", "DKS", "DLTR")
prices <- tq_get(x = symbols,
get = "stock.prices",
from = "2012-01-01",
to = "2017-01-01")
asset_returns_tbl <- prices %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "quarterly",
type = "log") %>%
ungroup() %>%
set_names(c("asset", "date", "returns"))
asset_returns_tbl
## # A tibble: 100 × 3
## asset date returns
## <chr> <date> <dbl>
## 1 AAPL 2012-03-30 0.377
## 2 AAPL 2012-06-29 -0.0263
## 3 AAPL 2012-09-28 0.137
## 4 AAPL 2012-12-31 -0.221
## 5 AAPL 2013-03-28 -0.178
## 6 AAPL 2013-06-28 -0.103
## 7 AAPL 2013-09-30 0.191
## 8 AAPL 2013-12-31 0.169
## 9 AAPL 2014-03-31 -0.0383
## 10 AAPL 2014-06-30 0.198
## # ℹ 90 more rows
asset_returns_tbl %>%
ggplot(aes(x = returns)) +
geom_density(aes(color = asset), show.legend = FALSE, alpha = 1) +
geom_histogram(aes(fill = asset), show.legend = FALSE, alpha = 0.3, binwidth = 0.01) +
facet_wrap(~asset, ncol = 1)
what does the plot tell you? which stock do you expect higher monthly returns? which stock has highest typical monthly return?
The wider the data is spread on individual stocks in the histogram/density graph. The riskier the stock is on a quarterly basis. The closer the data is to the center of the graph the less volatile the stock is but less rewarding as well. Based on the information I believe that CCEP will outperform the other 4 stocks I chose. closely followed by BBWI. Typically CCEP has the highest return.
Hide the code, messages, and warnings