# Get historical stock price
symbols <- c("VGS.AX", "VAS.AX", "MPL.AX")
prices <- tq_get(symbols,
get = "stock.prices",
from = "2014-11-27") # VGS.AX listed on 2014-11-27
# Calculate returns
returns <- prices %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily",
col_rename = "Ra")
returns
# ASX200 Index
ASX200 <- "^AXJO" %>%
tq_get(get = "stock.prices",
from = "2014-11-27") %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily",
col_rename = "Rb")
# Calculate portfolio returns
wts <- c(0.2955, 0.3029, 0.4016)# weights
portfolio_returns <- returns %>%
tq_portfolio(assets_col = symbol,
returns_col = Ra,
weights = wts,
col_rename = "Ra")
portfolio_returns
# Cummulative return on $10,000
portfolio_growth <- returns %>%
tq_portfolio(assets_col = symbol,
returns_col = Ra,
weights = wts,
col_rename = "investment.growth",
wealth.index = TRUE) %>%
mutate(investment.growth = investment.growth * 10000)
portfolio_returns <- portfolio_returns %>% mutate(growth_Ra = cumsum(Ra))
portfolio_returns
ASX200 <- ASX200 %>% mutate(growth_Rb = cumsum(Rb))
ASX200
Plots
# Plots -----------------------------------------------------------------------
portfolio_returns %>%
ggplot(aes(x = date, y = Ra)) +
geom_bar(stat = "identity", fill = palette_light()[[1]]) +
labs(title = "Portfolio Returns",
subtitle = "30% VGS, 30% VAS, and 40% MPL",
caption = "Cormac Gallagher 2018",
x = "", y = "Daily Returns") +
geom_smooth(method = "lm") +
theme_tq() +
scale_color_tq() +
scale_y_continuous(labels = scales::percent)

portfolio_growth %>%
ggplot(aes(x = date, y = investment.growth)) +
geom_line(size = 1, color = palette_light()[[1]]) +
labs(title = "Portfolio Growth",
subtitle = "30% VGS, 30% VAS, and 40% MPL",
caption = "Cormac Gallaghe 2018",
x = "", y = "Portfolio Value") +
geom_smooth(method = "loess") +
#theme_tq() +
#scale_color_tq() +
theme_bw() +
scale_y_continuous(labels = scales::dollar)
