---
title: "Lab 1 Dashboard"
author: "Chandi Prasanna Malepu"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE, message=FALSE}
# list of libraries we are using in this dashboard
library(flexdashboard)
library(lubridate)
library(dygraphs)
library(DT)
library(tidyverse)
library(tidyquant)
library(dplyr)
```
# Intro text {.sidebar}
## -**Stock Analysis**
The dashboard provides historical stocks of -**Twitter(TWTR), Google(GOOGL), Microsoft(MSFT) and Netflix(NFLX) for the past 3 years**.The aim is to identify which one of the four will produce the most short term gains.From the Stock Price change comparison chart all of them performed a similar movement trend,while -**Google seems to be slightly more fluctuated than Netflix**.
Google has the highest stock price, TWTR has the lowest stock price, while Netflix is in the middle.If we are considering for a long term investment, I would definitely recommend Twitter, because of its lowest stock price.
From the 4 stocks -**Microsoft and NetFLix are more stable **it is showing the increase in growth,these -**two stocks can produce short term gains easily**.
# Stock Dashboard
Column {data-width=550}
-----------------------------------------------------------------------
### overall 3-Year Trends
```{r,echo=FALSE, message = FALSE}
ticker <- c("TWTR", "GOOGL", "MSFT","NFLX")
invisible(getSymbols(ticker, from="2016-01-01", to="2019-01-01"))
ClosingPricesOfStocks <- do.call(merge, lapply(ticker, function(x) Cl(get(x))))
DatePeriod<-c("2016-01-01", "2019-01-01")
dygraph(ClosingPricesOfStocks, main="Stock Price Change of Companies over 3 years", group="Stock") %>%
dyAxis("y", label="Closing Price Of Stocks") %>%
dyOptions(colors = RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 2.5,
highlightSeriesBackgroundAlpha = 1,
highlightSeriesOpts = list(strokeWidth = 2))%>%
dyRangeSelector(height = 70)
```
Column {.tabset data-width=550}
-----------------------------------------------------------------------
### Table View
```{r}
library(plyr)
library(quantmod)
what_metrics <- yahooQF(c("Price/Sales",
"P/E Ratio",
"Price/EPS Estimate Next Year",
"PEG Ratio",
"Dividend Yield",
"Market Capitalization"))
tickers <- c("TWTR", "GOOGL", "MSFT", "NFLX")
# 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", "Earnings Multiple",
"Earnings Multiple (Forward)", "Div Yield", "Market Cap")
#Persist this to the csv file
#write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
datatable(head(metrics, 20), options = list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#FFFF66', 'color': '#330033'});",
"}")
))
```
# Stocks of TWTR,GOOGL,MSFT,NFLX
Row {data-height=400}
-----------------------------------------------------------------------
### Twitter
```{r}
invisible(getSymbols("TWTR", src = "yahoo", from='2016-01-01'))
TWTR_Stocks <- TWTR
dygraph(TWTR_Stocks[, -5], main = "Twitter") %>%
dyCandlestick() %>%
dyAxis("y", label="Closing Price Of Stocks") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 2.5,
highlightSeriesOpts = list(strokeWidth = 2),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 50)
```
### Google
```{r}
invisible(getSymbols("GOOGL", src = "yahoo", from='2016-01-01'))
GOOGL_Stocks <- GOOGL
dygraph(GOOGL_Stocks[, -5], main = "Google") %>%
dyCandlestick() %>%
dyAxis("y", label="Closing Price Of Stocks") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 2.5,
highlightSeriesOpts = list(strokeWidth = 2),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 50)
```
Row {data-height=400}
-----------------------------------------------------------------------
### Netflix
```{r}
invisible(getSymbols("NFLX", src = "yahoo", from='2016-01-01'))
NFLX_Stocks <- NFLX
dygraph(NFLX_Stocks[, -5], main = "Netflix") %>%
dyCandlestick() %>%
dyAxis("y", label="Closing Price Of Stocks") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 2.5,
highlightSeriesOpts = list(strokeWidth = 2),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 50)
```
### Microsoft
```{r}
invisible(getSymbols("MSFT", src = "yahoo", from='2016-01-01'))
MSFT_Stocks <- MSFT
dygraph(MSFT_Stocks[, -5], main = "Microsoft") %>%
dyCandlestick() %>%
dyAxis("y", label="Closing Price Of Stocks") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 2.5,
highlightSeriesOpts = list(strokeWidth = 2),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 50)
```