ETFs being compared: VT - Vanguard Total World Stock Market, VYM - Vanguard Hig Dividend Yield, VOO - Vanguard S&P 500, QQQ - NASDAQ 100.
Based on historical data, QQQ clearly has the highest total returns (507.5%). VOO has significantly higher price growth than VYM, but VYM makes up the lost price growth on a much higher dividend payout. VOO and VYM, therefore, have comparable total returns over the past 10 years. VT had sginificanly lower total return (160.9%) than the other three ETFs. Looking at the volatility box plot, we can say VT and QQQ are slightly more volatile but volatility looks more or less the same.
---
title: "ETF comparision dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(quantmod)
library(ggplot2)
library(ggrepel)
library(dplyr)
library(FRAPO)
getSymbols("VT",src="yahoo") # Total World Stock ETF
getSymbols("VYM",src="yahoo") # Total US Stock Market ETF
getSymbols("VOO",src="yahoo") # S&P 500 ETF
getSymbols("QQQ",src="yahoo") # NASDAQ ETF
str(VT)
str(VYM)
str(VOO)
str(QQQ)
VT <- VT[index(VT) > '2011-01-01']
VYM <- VYM[index(VYM) > '2011-01-01']
VOO <- VOO[index(VOO) > '2011-01-01']
QQQ <- QQQ[index(QQQ) > '2011-01-01']
```
Column {data-width=575}
-----------------------------------------------------------------------
### Growth of $1,000 over 10 years {data-height=700}
```{r fig.width=8}
numberOfVT <- 1000/as.numeric(VT$VT.Close[1])
ReturnVT <- numberOfVT * VT$VT.Close
numberOfVYM <- 1000/as.numeric(VYM$VYM.Close[1])
ReturnVYM <- numberOfVYM * VYM$VYM.Close
numberOfVOO <- 1000/as.numeric(VOO$VOO.Close[1])
ReturnVOO <- numberOfVOO * VOO$VOO.Close
numberOfQQQ <- 1000/as.numeric(QQQ$QQQ.Close[1])
ReturnQQQ <- numberOfQQQ * QQQ$QQQ.Close
returns <- cbind(ReturnVT, ReturnVYM, ReturnVOO, ReturnQQQ)
colnames(returns) <- c("VT", "VYM", "VOO", "QQQ")
totalGrowth <- returns[index(returns) == '2020-09-11']
library(reshape2)
dates <- index(returns)
returns_m <- as.data.frame(returns)
returns_m$dates <- dates
returns_m <- melt(returns_m, id = "dates")
colnames(returns_m) <- c("Date", "ETF", "Value")
totalGrowth_m <- as.data.frame(totalGrowth)
totalGrowth_m$date <- index(totalGrowth)
totalGrowth_m <- melt(totalGrowth_m, id = "date")
colnames(totalGrowth_m) <- c("Date", "ETF", "Value")
p <- ggplot(returns_m, aes(Date, Value, color = ETF)) +
geom_line() + geom_label(aes(label=sprintf("%0.f", round(Value, digits = 0))),
data = totalGrowth_m, size = 3.2, hjust = 0.25) +
labs(x = "Years", y = "Growth ($)", title = "Growth of $1000 invested on 2011-01-03") +
scale_color_manual(values = c("#548C2F", "#29335C", "#C57B57", "#8963BA")) +
theme_minimal() + theme(text=element_text(size=14))
p
```
### Write-up {data-height=300}
ETFs being compared: **VT** - Vanguard Total World Stock Market, **VYM** - Vanguard Hig Dividend Yield, **VOO** - Vanguard S&P 500, **QQQ** - NASDAQ 100.
Based on historical data, QQQ clearly has the highest total returns (507.5%). VOO has significantly higher price growth than VYM, but VYM makes up the lost price growth on a much higher dividend payout. VOO and VYM, therefore, have comparable total returns over the past 10 years. VT had sginificanly lower total return (160.9%) than the other three ETFs. Looking at the volatility box plot, we can say VT and QQQ are slightly more volatile but volatility looks more or less the same.
```{r}
```
Column {data-width=325}
-----------------------------------------------------------------------
### Total Dividends Paid
```{r fig.width=6}
VT.div <- getDividends("VT", from = "2011-01-03", to = Sys.Date(), src = "yahoo")
VYM.div <- getDividends("VYM", from = "2011-01-03", to = Sys.Date(), src = "yahoo")
VOO.div <- getDividends("VOO", from = "2011-01-03", to = Sys.Date(), src = "yahoo")
QQQ.div <- getDividends("QQQ", from = "2011-01-03", to = Sys.Date(), src = "yahoo")
VT.dates <- as.Date(index(VT.div))
VT.price <- subset(returns_m, returns_m$ETF == "VT")
VT.price <- subset(VT.price, VT.price$Date %in% VT.dates)
VT.totalDiv <- VT.price$Value * VT.div$VT.div * numberOfVT/4/100
VYM.dates <- as.Date(index(VYM.div))
VYM.price <- subset(returns_m, returns_m$ETF == "VYM")
VYM.price <- subset(VYM.price, VYM.price$Date %in% VYM.dates)
VYM.totalDiv <- VYM.price$Value * VYM.div$VYM.div * numberOfVYM/4/100
VOO.dates <- as.Date(index(VOO.div))
VOO.price <- subset(returns_m, returns_m$ETF == "VOO")
VOO.price <- subset(VOO.price, VOO.price$Date %in% VOO.dates)
VOO.totalDiv <- VOO.price$Value * VOO.div$VOO.div * numberOfVOO/4/100
QQQ.dates <- as.Date(index(QQQ.div))
QQQ.price <- subset(returns_m, returns_m$ETF == "QQQ")
QQQ.price <- subset(QQQ.price, QQQ.price$Date %in% QQQ.dates)
QQQ.totalDiv <- QQQ.price$Value * QQQ.div$QQQ.div * numberOfQQQ/4/100
#ggplot(VYM.totalDiv, aes(index(VYM.totalDiv))) +
# geom_area(data=VYM.totalDiv, aes(y=VYM.totalDiv), alpha = 0.5) +
# geom_area(data=VOO.totalDiv, aes(y=VOO.totalDiv), alpha = 0.5)
total.div <- c(sum(VT.totalDiv), sum(VYM.totalDiv), sum(VOO.totalDiv), sum(QQQ.totalDiv))
total.div <- as.data.frame(total.div)
total.div$ETF <- c("VT","VYM","VOO","QQQ")
rownames(total.div) <- c("VT","VYM","VOO","QQQ")
total.div %>%
dplyr::mutate(ETF = factor(ETF, levels = c("VT", "VYM", "VOO", "QQQ"))) %>%
ggplot(aes(y=total.div)) +
geom_col(aes(x=ETF, fill = ETF), width = 0.5) +
geom_text(aes(data=total.div, x=ETF, label = sprintf("%0.f", round(total.div, digits = 0))),
size = 5, vjust=-0.25) +
theme_classic() +
labs(x = "ETF", y = "Total Dividend ($)", title = "Total Dividend Payout since 2011") +
scale_fill_manual(values = c("#548C2F", "#29335C", "#C57B57", "#8963BA")) +
theme(text=element_text(size=18))
```
### Volatility through the years
```{r fig.width=6}
prices <- cbind(VT$VT.Close, VYM$VYM.Close, VOO$VOO.Close, QQQ$QQQ.Close)
prices <- as.data.frame(prices)
VT.returns <- returnseries(prices$VT.Close)
VYM.returns <- returnseries(prices$VYM.Close)
VOO.returns <- returnseries(prices$VOO.Close)
QQQ.returns <- returnseries(prices$QQQ.Close)
percentReturns <- as.data.frame(cbind(VT.returns, VYM.returns, VOO.returns, QQQ.returns))
colnames(percentReturns) <- c("VT", "VYM", "VOO", "QQQ")
percentReturns$dates <- as.Date(dates)
percentReturns <- percentReturns[-1,]
percentReturns_m <- melt(percentReturns, id = "dates")
colnames(percentReturns_m) <- c("Date", "ETF", "Returns")
ggplot(data = percentReturns_m, aes(x=ETF, y=Returns, color = ETF)) +
geom_jitter(alpha = 0.2) + geom_boxplot(alpha = 0.8) + theme_classic() +
labs(x = "ETF", y = "% Return", title = "Distribution of % return") +
# scale_fill_manual(values = c("#548C2F", "#29335C", "#C57B57", "#8963BA")) +
scale_color_manual(values = c("#548C2F", "#29335C", "#C57B57", "#8963BA")) +
theme(text=element_text(size=18))
```
Column {data-width=100}
-----------------------------------------------------------------------
### Value of $1000 in 2020
```{r fig.height=40}
#
value20 <- totalGrowth_m$Value+total.div$total.div
value2020 <- as.data.frame(value20)
value2020$ETF <- c("VT", "VYM", "VOO", "QQQ")
value2020$type <- c("ETF", "ETF", "ETF", "ETF")
x1 <- (value20[1]-1000)/1000
x1 <- round(x1, digits = 2)
x2 <- (value20[2]-1000)/1000
x2 <- round(x2, digits = 2)
x3 <- (value20[3]-1000)/1000
x3 <- round(x3, digits = 2)
x4 <- (value20[4]-1000)/1000
x4 <- round(x4, digits = 2)
value2020$times <- c(x1,x2,x3,x4)
value2020 %>%
dplyr::mutate(ETF = factor(ETF, levels = c("QQQ", "VOO", "VYM", "VT"))) %>%
ggplot(aes(x = type, y=value20, fill = ETF)) +
geom_col(position = "stack", color = "white", size = 30) +
geom_text(aes(label = paste(times, "X\nto\n", "$", sprintf("%0.f", round(value20, digits = 0)) )),
position = position_stack(vjust = .5), size = 20, color = "white") +
scale_fill_manual(values = c("#8963BA", "#C57B57", "#29335C", "#548C2F")) +
theme_classic() +
theme(legend.position = "none", axis.line = element_blank(), axis.ticks = element_blank(),
axis.title = element_blank(), axis.text = element_blank(), text=element_text(size=40))
```