Here is the link to the published document: https://shiny.byui.edu/connect/#/apps/86/access
For this case study we are going to be looking at 11 different stocks (“CXW”, “F”, “GM”, “JCP”, “KR”, “WDC”, “NKE”,“T”, “WDAY”, “WFC”, “WMT”), and see how their performance has been over the past 5 years and what may have contributed to their performance
First, here is a dygraph showing the performance of the adjusted stocks from the past 5 years
tickers <- c("CXW", "F", "GM", "JCP", "KR", "WDC", "NKE","T", "WDAY", "WFC", "WMT")
stocks <- tickers %>%
tq_get(get = "stock.prices", from = "2012-11-04")
stock <- stocks %>%
select("symbol", "adjusted", "date") %>%
group_by(symbol) %>%
tq_transmute(select = adjusted, mutate_fun = periodReturn, period = "daily",
col_rename = "Ra")
tick_xts5 <- stocks %>%
select("symbol", "adjusted", "date") %>%
spread(key = symbol, value = adjusted) %>%
tk_xts()
tick_xts5 %>%
dygraph(main = "Kroger Stock Price Since 1990/Oct", xlab = "Year", ylab = "Adjusted") %>%
dyRangeSelector(height = 20)
This next plot shows how much money we are making if we invested $25,000 with an equal weight on the stocks.
wts <- vector()
for (i in tickers) {
wts[i] <- 1/length(tickers)
}
#wts <- c(1/11, 1/11, 1/11, 1/11, 1/11, 1/11, 1/11, 1/11, 1/11, 1/11, 1/11)
port <- stock %>%
tq_portfolio(assets_col = symbol, returns_col = Ra, weights = wts,
col_rename = "investment.growth", wealth.index = TRUE) %>%
mutate(investment.growth = investment.growth * 25000)
port %>%
ggplot(aes(y = investment.growth, x = date)) +
geom_point(size = .5, alpha = .5) +
geom_smooth() +
theme_bw()
These next 2 plots show the individual adjusted returns on each stock, and how the volume takes effects the adjusted returns. It seems that the higher the trade volume, the lower the return.
stocks %>%
ggplot(aes(x = date, y = adjusted, col = symbol)) +
geom_line() +
facet_wrap( ~ fct_reorder(symbol, adjusted)) +
theme_bw()
labs(title = "Adjusted Stock Price Per Tick")
## $title
## [1] "Adjusted Stock Price Per Tick"
##
## attr(,"class")
## [1] "labels"
stocks %>%
ggplot(aes(volume, adjusted, color = symbol)) +
geom_point(size = 0.03) +
scale_x_sqrt() +
labs(title = "Stock Returns vs Volume", x = "Trade Volume", y = "Adjusted Returns",
color = "Ticker Symbol") +
theme(plot.title = element_text(size=12))