---
title: "Financial Analyze"
author: "Yiran Huang"
date: "3/15/2020"
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(dygraphs)
library(tidyverse)
library(pdfetch)
```
# Intro text {.sidebar}
##Stock Analysis
This dashboard provides historical stocks data of JP Morgan Chase, The Goldman Sachs Group Inc., Morgan Stanley and Black Rock, for the past 1 year, as well as their comparison chart.
Based on the Stock Close Price comparison chart, all of them performed a similar movement trend, while BLK seems to be slightly more fluctuated than JPM, MS and GS. BLK has the highest stock price, MS has the lowest stock price, while JPM and GS is in the middle. However, JPM and MS seem to be more capable to maintain the stability on their trends.
If considering of a long term investment, I would definitely recommend MS, because of its lowest stock price, which potentially possess more room for the price moving up as time goes by,and it maintain a really stable trend which has the lowest risk.
JP Morgan Chase stock prices, adjusted closing prices and trading volumes are more stable, consistent and growing as compare to other companies, JPM is another good choice.
According to the recent stock price and trend of each stock, the entire stock market is affected by the Corona Virus, the stock price is a bluff down, can be regarded as a good opportunity to buy bottom.
# Stock Dashboard
Column {data-width=550}
--------------------------------------------------------------------------
### Compare Closing Price
```{r message = FALSE}
tickers <- c("JPM", "GS", "MS","BLK")
invisible(getSymbols(tickers, from="2017-12-31", to="2019-12-31"))
ClosePrices <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dygraph(ClosePrices, main="Stock Close Prices ($)", group="Stock") %>%
dyAxis("y", label="Closing Price($)") %>%
dyOptions(axisLineWidth = 2.0, colors = RColorBrewer::brewer.pal(8, "Set1")) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 1.0,
highlightSeriesOpts = list(strokeWidth = 3)) %>%
dyRangeSelector(height = 70)
```
Stock Price
=====================================
Column {.tabset data-height=550}
-----------------------------------------------------------------------
### JP Morgan Chase
```{r}
invisible(getSymbols("JPM", src = "yahoo", from='2018-12-31'))
JPM_x <- JPM
dygraph(JPM_x[, -5], main = "JPM") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesOpts = list(strokeWidth = 3),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 70)
```
### The Goldman Sachs Group Inc.
```{r}
invisible(getSymbols("GS", src = "yahoo", from='2018-12-31'))
GS_x <- GS
dygraph(GS_x[, -5], main = "GS") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesOpts = list(strokeWidth = 3),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 70)
```
### Morgan Stanley
```{r}
invisible(getSymbols("MS", src = "yahoo", from='2018-12-31'))
MS_x <- MS
dygraph(JPM_x[, -5], main = "MS") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesOpts = list(strokeWidth = 3),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 70)
```
### Black Rock
```{r}
invisible(getSymbols("BLK", src = "yahoo", from='2018-12-31'))
BLK_x <- BLK
dygraph(BLK_x[, -5], main = "BLK") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set1")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesOpts = list(strokeWidth = 3),
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 70)
```
Trading Volume Comparison
=====================================
Column { data-height=600}
-----------------------------------------------------------------------
### Trading Volume
```{r}
tickers <- c("JPM", "GS", "MS","BLK")
invisible(getSymbols(tickers, from="2017-12-31", to="2019-12-31"))
trdVol <- cbind(JPM[,5],GS[,5],MS[,5],BLK[,5])
colnames(trdVol) <-c("JPM","GS","MS","BLK")
#plot
dygraph(trdVol, main = "Trading Volume for Last 2 Year") %>%
dyOptions(strokeWidth = 2,colors = RColorBrewer::brewer.pal(5, "Set1"))%>%
dyHighlight(highlightCircleSize = 3,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = TRUE)%>%
dyLegend(width = 400) %>% dyAxis("y", label="Trading Volume") %>%
dyRangeSelector(dateWindow = c("2018-12-31", "2019-12-31"))
```