---
title: "Google Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
source_code: embed
---
```{r setup, include=FALSE, message=FALSE}
library(lubridate)
library(quantmod)
library(flexdashboard)
library(dygraphs)
```
Column
-----------------------------------------------------------------------
### Google Price
```{r}
invisible(getSymbols("GOOG", src = "yahoo", from='2016-01-01'))
GOOG_x <- GOOG
dygraph(GOOG_x[, -5], main = "Google") %>%
dyCandlestick() %>%
dyAxis("y", label="Closing Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesOpts = list(strokeWidth = 3),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 130)
daily_stock_returns <- function(ticker, start_year){
symbol <- getSymbols(ticker, src = 'yahoo', auto.assign = FALSE, warnings = FALSE)
data <- periodReturn(symbol, period='monthly', subset=paste(start_year, "::", sep = ""), type ='log')
colnames(data) <- as.character(ticker)
assign(ticker, data, .GlobalEnv)
}
```
Column
-----------------------------------------------------------------------
### Monthly Return
```{r message = FALSE}
year <- ymd("2014-08-02")
duration <- ymd("2017-01-02")
daily_stock_returns('GOOG', year)
merged_returns <- merge.xts(GOOG)
merged_returns_percent <- merged_returns * 100
dygraph(merged_returns_percent, main = "Monthly Return") %>%
dyAxis("y", label = "Return(%)") %>%
dyOptions(colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 0.2,
highlightSeriesOpts = list(strokeWidth = 2)) %>%
dyRangeSelector(height = 65)
```
-----------------------------------------------------------------------
### Metrics Table
```{r}
what_metrics <- yahooQF(c("Price/Sales",
"P/E Ratio"
,"Previous Close","52-week Low", "52-week High",
"Market Capitalization"))
tickers <- c("GOOG")
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","Previous Close","52-week Low", "52-week High","Market Cap")
DT::datatable(metrics)
```