---
title: "ANLY 512 - Dashboard Laboratory"
author: "Shirong Liu"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
orientation: rows
horizontal_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(xts)
library(quantmod)
library(ggplot2)
library(plotly)
library(reshape)
library(reshape2)
library(data.table)
library(kableExtra)
```
```{r loading data, include=FALSE}
# 5 years of security data
getSymbols(c('VTV', 'QQQ', 'TLT', 'BNO'), src = 'yahoo', from = '2017-10-01', auto.assign = TRUE)
```
## Intro text {.sidebar data-width=550}
Investment Summary:
When making financial investment decisions, it is important to consider both intraday/short-term trading data and longer-term pricing ranges. The reason for the former is intraday/short-term trading and volume data provide insights into momentum around specific securities or assets, while the reason for the latter is that longer-term trading ranges shed light on the stage in the economic cycle we are currently in and how rich/cheap specific assets are considering that stage.
So in my dashboard, I included a 30-day (business days) candlestick plot for each of the 4 ETFs (VTV, QQQ, TLT, BNO) on the top; this shares some information on how well each ETF is trading in the near-term, and it looks like VTV, QQQ and TLT are all in a short-term down-trend (related to the Fed hiking interest rates) while BNO has been trading more rangebound recently. I then put a set of longer-term price charts on the bottom (1-month, Year-to-Date and 5-year); these charts put the current prices into context with historical levels. We see that VTV and QQQ are getting close to pre-pandemic levels, while TLT (Treasury bond ETF) has cheapened significantly to pre-pandemic era due to the higher interest rate now. BNO, on the other hand, has been increasing since summer of 2020. In concurrence with "buying low and selling high", I would tactically start to allocate more into the two stock ETF (VTV and QQQ) since they have sold off decently from the highs. I would hold off investing in TLT since there is no clear end yet to the current hiking cycle the Fed has initiated so TLT will continue selling off as long as interest rate keeps getting higher. I would shun away from the oil ETF (BNO) since it is at the historical high right now.
Financial Metrics:
```{r}
what_metrics <- yahooQF(c("Percent Change From 52-week Low",
"Percent Change From 52-week High",
"50-day Moving Average",
"Percent Change From 50-day Moving Average",
"P/E Ratio",
"Earnings/Share",
"Dividend/Share"))
tickers <- c("VTV", "QQQ", "TLT", "BNO")
# Not all the metrics are returned by Yahoo.
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)
#Add tickers as the first column and remove the first column which had date stamps
metrics <- data.frame(Symbol=tickers, metrics[,2:length(metrics)])
metrics_t <- transpose(metrics)
metrics_t <- metrics_t[-1, ]
colnames(metrics_t) <- tickers
rownames(metrics_t) <- c("Pct.Chg.from.52w.Low", "Pct.Chg.from.52w.High", "50d.MA", "Pct.Chg.from.50d.MA", "P/E.Ratio", "Earnings/Share", "Dividend/Share")
tab1 <- metrics_t %>%
kable() %>%
kable_styling()
tab1
```
## Row {data-width=350 .tabset .tabset-fade}
### VTV: Vanguard Value Stock ETF
```{r}
vtv.df = as.data.frame(VTV)
colnames(vtv.df) <- c("Open","High","Low","Close")
vtv.df = vtv.df[c("Open","High","Low","Close")]
vtv_last_month <- tail(vtv.df, n = 31)
vtv_candle <- vtv_last_month %>% plot_ly(x = ~index(vtv_last_month), type="candlestick",
open = ~vtv_last_month$Open, close = ~vtv_last_month$Close,
high = ~vtv_last_month$High, low = ~vtv_last_month$Low)
vtv_candle
```
### QQQ: Invesco Growth Stock ETF
```{r}
qqq.df = as.data.frame(QQQ)
colnames(qqq.df) <- c("Open","High","Low","Close")
qqq.df = qqq.df[c("Open","High","Low","Close")]
qqq_last_month <- tail(qqq.df, n = 31)
qqq_candle <- qqq_last_month %>% plot_ly(x = ~index(qqq_last_month), type="candlestick",
open = ~qqq_last_month$Open, close = ~qqq_last_month$Close,
high = ~qqq_last_month$High, low = ~qqq_last_month$Low)
qqq_candle
```
### TLT: iShares Long-Term Treasury Bond ETF
```{r}
tlt.df = as.data.frame(TLT)
colnames(tlt.df) <- c("Open","High","Low","Close")
tlt.df = tlt.df[c("Open","High","Low","Close")]
tlt_last_month <- tail(tlt.df, n = 31)
tlt_candle <- tlt_last_month %>% plot_ly(x = ~index(tlt_last_month), type="candlestick",
open = ~tlt_last_month$Open, close = ~tlt_last_month$Close,
high = ~tlt_last_month$High, low = ~tlt_last_month$Low)
tlt_candle
```
### BNO: United States Brent Oil ETF
```{r}
bno.df = as.data.frame(BNO)
colnames(bno.df) <- c("Open","High","Low","Close")
bno.df = bno.df[c("Open","High","Low","Close")]
bno_last_month <- tail(bno.df, n = 31)
bno_candle <- bno_last_month %>% plot_ly(x = ~index(bno_last_month), type="candlestick",
open = ~bno_last_month$Open, close = ~bno_last_month$Close,
high = ~bno_last_month$High, low = ~bno_last_month$Low)
bno_candle
```
## Row {data-height=350 .tabset .tabset-fade}
### 1M
```{r, fig.width=20}
data_1m <- cbind(tail(VTV, 31)$VTV.Close, tail(QQQ, 31)$QQQ.Close, tail(TLT, 31)$TLT.Close, tail(BNO, 31)$BNO.Close)
colnames(data_1m) <- c("VTV","QQQ","TLT","BNO")
data_1m <- as.data.frame(data_1m)
data_1m$date <- as.Date(row.names(data_1m))
data_1m_molten <- melt(data_1m, id = c("date"), variable.name = "Security", value.name = "Price")
ggplot(data_1m_molten, aes(x = date, y = Price, group = Security, color = Security)) +
geom_line() +
labs(x = "Date") +
theme_bw()
```
### YTD
```{r, fig.width=20}
data_ytd <- cbind(VTV["2022"]$VTV.Close, QQQ["2022"]$QQQ.Close, TLT["2022"]$TLT.Close, BNO["2022"]$BNO.Close)
colnames(data_ytd) <- c("VTV","QQQ","TLT","BNO")
data_ytd <- as.data.frame(data_ytd)
data_ytd$date <- as.Date(row.names(data_ytd))
data_ytd_molten <- melt(data_ytd, id = c("date"), variable.name = "Security", value.name = "Price")
ggplot(data_ytd_molten, aes(x = date, y = Price, group = Security, color = Security)) +
geom_line() +
labs(x = "Date", y = "Price in USD") +
theme_bw()
```
### 5Y
```{r, fig.width=20}
data_5y <- cbind(VTV$VTV.Close, QQQ$QQQ.Close, TLT$TLT.Close, BNO$BNO.Close)
colnames(data_5y) <- c("VTV","QQQ","TLT","BNO")
data_5y <- as.data.frame(data_5y)
data_5y$date <- as.Date(row.names(data_5y))
data_5y_molten <- melt(data_5y, id = c("date"), variable.name = "Security", value.name = "Price")
ggplot(data_5y_molten, aes(x = date, y = Price, group = Security, color = Security)) +
geom_line() +
labs(x = "Date", y = "Price in USD") +
theme_bw()
```