Column

Closing Prices

[1] "AAPL" "MSFT" "TWTR" "GOOG" "FB"  

Financial metrics

Column

Apple

Microsoft

Twitter

Google

Facebook

---
title: "ANLY 512 Dashboard Laboratory"
author: "Sowmya Puranam"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social : menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(lubridate)
library(quantmod)
library(flexdashboard)
library(dygraphs)
```


Column {.tabset data-width=700}
-----------------------------------------------------------------------

###  Closing Prices

```{r message=FALSE, echo=FALSE}
ticker<-c("AAPL","MSFT","TWTR" , "GOOG", "FB")
getSymbols(ticker)

closeprices<-do.call(merge, lapply(ticker, function(x) Cl(get(x))))


#graph

timeperiod<-c("2016-07-01","2018-07-01")
dygraph(closeprices, main = "Closing Prices") %>%
  dyRebase(value = 100) %>%
  dyOptions(axisLineWidth = 4.0,colors=RColorBrewer::brewer.pal(8,"Dark2"))%>%
  dyRangeSelector(dateWindow=timeperiod)%>%
  dyAxis("y",label="Price (USD)") %>%
  dyHighlight(highlightCircleSize = 5,highlightSeriesBackgroundAlpha = 1.0,
              highlightSeriesOpts = list(strokeWidth = 3)) %>%
  dyRangeSelector(height = 70)




```


### Financial metrics
```{r}


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

tickers <- c("AAPL","MSFT","TWTR" , "GOOG", "FB")
# 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", "P-E Ratio", "Price EPS Estimate Next Year", "Div Yield", "Market Cap")

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

Column {.tabset data-width=550}
-----------------------------------------------------------------------

### Apple

```{r}

invisible(getSymbols("AAPL", src = "yahoo", from='2016-07-01'))
APPLE_x <- AAPL
dygraph(APPLE_x[, -5], main = "Apple") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Closing Price") %>%
  dyOptions(colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightSeriesOpts = list(strokeWidth = 3)) %>%
  dyRangeSelector(height = 70)


```

### Microsoft

```{r}
invisible(getSymbols("MSFT", src = "yahoo", from='2016-07-01'))
MICROSOFT_x <- MSFT
dygraph(MICROSOFT_x[, -5], main = "Microsoft") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Closing Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 70)

```


### Twitter

```{r}
invisible(getSymbols("TWTR", src = "yahoo", from='2016-07-01'))
TWITTER_x <- TWTR
dygraph(TWITTER_x[, -5], main = "Twitter") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Closing Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 70)
```


### Google

```{r}
invisible(getSymbols("GOOG", src = "yahoo", from='2016-07-01'))
GOOGLE_x<- GOOG
dygraph(GOOGLE_x[,-5], main = "Google") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Closing Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 70)

```


### Facebook

```{r}
invisible(getSymbols("FB", src = "yahoo", from='2016-07-01'))
FACEBOOK_x <- FB
dygraph(FACEBOOK_x[, -5], main = "Facebook") %>%
  dyCandlestick() %>%
  dyAxis("y", label="Closing Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesOpts = list(strokeWidth = 3),
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 70)

```