Page 1: Graphic View

Data source: Yahoo Finance

Column

Overview

Column

NYSE: CHL

NYSE: BABA

NYSE: TSM

NASDAQ: SINA

Page 2: Tabular View

Data source: Yahoo Finance

Row

Key Metrics

Row

NYSE: CHL

NYSE: BABA

NYSE: TSM

NASDAQ: SINA

---
title: "ANLY-512: Dashboard Laboratory"
author: "Zhengxiao Wei"
date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
    navbar:
      - { title: "About", href: "https://moodle.harrisburgu.edu/pluginfile.php/524006/mod_assign/introattachment/0/Lab1%20Dashboarding.html?forcedownload=1", align: right }
---

```{r setup, include=F}
if(!require(DT)) {install.packages("DT")}
if(!require(dygraphs)) {install.packages("dygraphs")}
if(!require(flexdashboard)) {install.packages("flexdashboard")}
if(!require(quantmod)) {install.packages("quantmod")}
if(!require(RColorBrewer)) {install.packages("RColorBrewer")}

library(dygraphs)
library(flexdashboard)
library(quantmod) #for web scraping only
```

```{r setup-data, cache=F, include=F}
#choose four public companies
tickers <- c("CHL","BABA","TSM","SINA")
invisible(getSymbols(tickers,src="yahoo",from="2015-01-01"))
```

Page 1: Graphic View
=======================================================================
Data source: Yahoo Finance

Column
-----------------------------------------------------------------------

### Overview

```{r}
#a 'xts' object of each stock's adjusted price as a column
prices <- do.call(merge,lapply(tickers, function(x) Ad(get(x))))

dygraph(prices,main="Stocks Performance: 2015-2019",group="stock") %>%
  dyAxis("y",label="Adjusted Closing Price (USD)") %>%
  dyOptions(colors=RColorBrewer::brewer.pal(4,"Set1")) %>%
  dyHighlight(highlightSeriesOpts=list(strokeWidth=2)) %>%
  dyRangeSelector(height=50)
```

Column {.tabset}
-----------------------------------------------------------------------

### NYSE: CHL

```{r}
colnames(CHL) <- c("Open","High","Low","Close","Volume","Adjusted")

dygraph(CHL[,-5],main="China Mobile Limited") %>%
  dyCandlestick() %>%
  dyAxis("y",label="Price (USD)") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize=3,
              highlightSeriesOpts=list(strokeWidth=2)) %>%
  dyRangeSelector(height=50)
```

### NYSE: BABA

```{r}
colnames(BABA) <- c("Open","High","Low","Close","Volume","Adjusted")

dygraph(BABA[,-5],main="Alibaba Group Holding Limited") %>%
  dyCandlestick() %>%
  dyAxis("y",label="Price (USD)") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize=3,
              highlightSeriesOpts=list(strokeWidth=2)) %>%
  dyRangeSelector(height=50)
```

### NYSE: TSM

```{r}
colnames(TSM) <- c("Open","High","Low","Close","Volume","Adjusted")

dygraph(TSM[,-5],main="Taiwan Semiconductor Manufacturing Company Limited") %>%
  dyCandlestick() %>%
  dyAxis("y",label="Price (USD)") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize=3,
              highlightSeriesOpts=list(strokeWidth=2)) %>%
  dyRangeSelector(height=50)
```

### NASDAQ: SINA

```{r}
colnames(SINA) <- c("Open","High","Low","Close","Volume","Adjusted")

dygraph(SINA[,-5],main="SINA Corporation") %>%
  dyCandlestick() %>%
  dyAxis("y",label="Price (USD)") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize=3,
              highlightSeriesOpts=list(strokeWidth=2)) %>%
  dyRangeSelector(height=50)
```

Page 2: Tabular View {data-orientation=rows}
=======================================================================
Data source: Yahoo Finance

Row
-----------------------------------------------------------------------

### Key Metrics

```{r}
metrics <- getQuote(paste(tickers,sep="",collapse=";"),
                    what=yahooQF(c("P/E Ratio",
                                   "Price/EPS Estimate Next Year",
                                   "52-week Low",
                                   "52-week High",
                                   "50-day Moving Average",
                                   "200-day Moving Average",
                                   "Average Daily Volume",
                                   "Dividend Yield",
                                   "Market Capitalization")))
DT::datatable(metrics[-1])
```

Row {.tabset}
-----------------------------------------------------------------------

### NYSE: CHL

```{r}
CHL <- as.data.frame(CHL)
CHL <- cbind("Date"=rownames(CHL),CHL)
rownames(CHL) <- NULL
DT::datatable(CHL)
```

### NYSE: BABA

```{r}
BABA <- as.data.frame(BABA)
BABA <- cbind("Date"=rownames(BABA),BABA)
rownames(BABA) <- NULL
DT::datatable(BABA)
```

### NYSE: TSM

```{r}
TSM <- as.data.frame(TSM)
TSM <- cbind("Date"=rownames(TSM),TSM)
rownames(TSM) <- NULL
DT::datatable(TSM)
```

### NASDAQ: SINA

```{r}
SINA <- as.data.frame(SINA)
SINA <- cbind("Date"=rownames(SINA),SINA)
rownames(SINA) <- NULL
DT::datatable(SINA)
```