Column

Closing Price Comparison

Column

Twitter

Microsoft

Apple

---
title: "ANLY 512: Data Visualization - Dashboard Laboratory"
author: "Swetha Prasad"
date: "December 18, 2017"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    source_code: embed
---

```{r setup, message=FALSE, warning=FALSE}
library(quantmod)
library(plyr)
library(flexdashboard)
library(dygraphs)
library(lubridate)
library(RColorBrewer)
library(DT)
```

Column {data-width=500}
-------------------------------------------------------------------
```{r message=FALSE, warning=FALSE}

what_metrics <- yahooQF(c("Price/Sales", 
                          "P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "Dividend Yield", 
                          "Market Capitalization"))

tickers <- c("TWTR", "MSFT", "AAPL")

# 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)]) 

#Change colnames
colnames(metrics) <- c("Symbol", "Revenue Multiple", "Earnings Multiple", "Div Yield", "Market Cap")

#Persist this to the csv file
DT::datatable(metrics) %>%
  formatRound(columns=c('Revenue Multiple', 'Earnings Multiple', 'Div Yield'), digits=2)
```


### Closing Price Comparison
```{r, echo=FALSE, message = FALSE}
ticker <- c("TWTR", "MSFT", "AAPL")
invisible(getSymbols(ticker, from="2016-01-01", to="2017-12-18"))
closing_price <- do.call(merge, lapply(ticker, function(x) Cl(get(x))))

dateperiod<-c("2016-01-01", "2017-12-18")
dygraph(closing_price, main="CLOSING PRICE (USD)", group="Stock") %>%
    dyAxis("y", label="Closing Price (USD)") %>%
    dyOptions(axisLineWidth = 2.0,  colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
    dyHighlight(highlightSeriesBackgroundAlpha = 1.0,
              highlightSeriesOpts = list(strokeWidth = 3)) %>%
    dyRangeSelector(height = 45)
```


Column {data-width=500}
-----------------------------------------------------------------
### Twitter 
```{r message=FALSE, warning=FALSE} 
startdate <- ymd("2016-01-01")
invisible(getSymbols("TWTR", src = "yahoo", from=startdate))
Twitter <- TWTR[,-5]
colnames(Twitter) <- c("Open","High","Low","Close","Adjusted")
```

```{r message=FALSE, warning=FALSE}
dygraph(Twitter, main = "TWITTER") %>%
  dyAxis("y", label="Price (USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyCandlestick()
```


### Microsoft

```{r message=FALSE, warning=FALSE}
startdate <- ymd("2016-01-01")
invisible(getSymbols("MSFT", src = "yahoo", from=startdate))
Microsoft <- MSFT[,-5]
colnames(Microsoft) <-c ("Open","High","Low","Close","Adjusted")
```

```{r message=FALSE, warning=FALSE}
dygraph(Microsoft, main = "MICROSOFT") %>%
  dyAxis("y", label="Price (USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyCandlestick()
```


### Apple

```{r message=FALSE, warning=FALSE}
startdate <- ymd("2016-01-01")
invisible(getSymbols("AAPL", src = "yahoo", from=startdate))
Apple <- AAPL[,-5]
colnames(Apple) <- c("Open","High","Low","Close","Adjusted")
```

```{r message=FALSE, warning=FALSE}
dygraph(Apple, main = "APPLE") %>%
  dyAxis("y", label="Price (USD)") %>%
  dyOptions(axisLineWidth = 1.5,  colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyCandlestick()
```