Overview

Column

ETF List

Column

Daily Price each ETF

Overall Daily Price

---
title: "ANLY 512 Lab 1"
author: "Janvich Vanichpipat"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE, source_code = TRUE}
library(flexdashboard)
library(quantmod)
library(dplyr)
library(plyr)
library(DT)
library(formattable)
library(highcharter)
library(viridisLite)
library(ggplot2)
library(broom)
library(lubridate)
library(tidyquant)
library(tidyr)
```

# Intro text {.sidebar}

<b>Introduction:</b>

This dashboard objectives is to purchase ETF for key objective of maximizing profits. ETF (exchange-traded fund) is a type of pooled investment security that operates much like a mutual fund. The factors that will be used to analyze are P-E Ration, Dividend Yield, and Market Cap.

<b>P-E Ratio:</b>

The price-to-earnings ratio is the ratio for valuing a company that measures its current share price relative to its earnings per share (EPS).

<b>Dividend Yield:</b>

The dividend yield, expressed as a percentage, is a financial ratio (dividend/price) that shows how much a company pays out in dividends each year relative to its stock price.

<b>Market Cap:</b>

Market capitalization, or "market cap", is the aggregate market value of a company represented in a dollar amount. Since it represents the “market” value of a company, it is computed based on the current market price (CMP) of its shares and the total number of outstanding shares.

Source: Investopedia

# Overview {data-icon="fa-list"}

Column {data-height=500}
-----------------------------------------------------------------------

### ETF List

```{r}
what_metrics <- yahooQF(c("Price/Sales", 
                          "P/E Ratio",
                          "PEG Ratio",
                          "Dividend Yield", 
                          "Market Capitalization"))

tickers <- c("XLE", "QQQ", "VUG", "VWO")
# 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$P.E.Ratio<- round(metrics$P.E.Ratio, digits = 2)
metrics$Dividend.Yield <- paste(format(round(metrics$Dividend.Yield * 100, 2), trim = TRUE))
metrics$Market.Capitalization <- paste(format(round(metrics$Market.Capitalization / 1e9, 2), trim = TRUE))

#Change colnames
colnames(metrics) <- c("Symbol", "P-E Ratio", "Div Yield (%)", "Market Cap (Billion)")

#write this to the csv file
write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
DT::datatable(metrics)
```

Column {data-height=600}
-----------------------------------------------------------------------

### Daily Price each ETF {data-width=600}

```{r}
start = as.Date("2020-09-30")
end = as.Date("2022-09-30")
ds = getSymbols(tickers, src = "yahoo", from = start, to = end)
etf = as.xts(data.frame(
  A = XLE[, "XLE.Adjusted"],
  B = QQQ[, "QQQ.Adjusted"],
  C = VUG[, "VUG.Adjusted"],
  D = VWO[, "VWO.Adjusted"]))
names(etf) = c("XLE", "QQQ", "VUG", "VWO")
index(etf) = as.Date(index(etf))

etf_series1 = tidy(etf) %>% 
  ggplot(aes(x=index,y=value, color=series)) + 
  geom_line() +
  facet_grid(series~.,scales = "free") + 
  labs(title = "Daily ETF Prices September 2020 - September 2022",
       subtitle = "End of Day Adjusted Prices",
       caption = " Source: Yahoo Finance") +
  xlab("Date") + ylab("Price") +
  scale_color_manual(values = c("Red", "Orange", "Green","Blue"))
etf_series1
```

### Overall Daily Price {data-width=600}

```{r}
etf_series2 = tidy(etf) %>% 
  ggplot(aes(x=index,y=value, color=series)) +
  labs(title = "Daily ETF Prices September 2020 - September 2022",
       subtitle = "End of Day Adjusted Prices",
       caption = " Source: Yahoo Finance") +
  xlab("Date") + ylab("Price") +
  scale_color_manual(values = c("Red", "Orange", "Green","Blue"))+
  geom_line()
etf_series2
```