Row

Stock Price - BAC

Stock Price - Citi

Stock Price - JPM

Stock Price - WFC

[1] "BAC" "JPM" "C"   "WFC"
[1] "USD1MTD156N"

Row

Rolling Shape-Ratio for Three Stocks

Row

Current Basic Metrics

Basic metrics for Four stocks, in order to frame a general picture and details of the four stocks. Apple is having the biggest market cap, which Microsoft second, while Twitter is the smallest according to this.

Row

Monthly Return

Monthly return analysis, to see if it’s possible to get the highest monthly return for short term investment.

Row

Daily Returns

---
title: "ANLY 512: Dashboard Laboratory"
author: "Yang Lu & Jiayi Zhang"
Date: "October 31 2019"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
    vertical_layout: scroll
---

```{r message=FALSE, include=FALSE, warning=FALSE}


library(flexdashboard)
library(dygraphs)
library(quantmod)
library(dplyr)
library(DT)
library(xts)
library(tidyquant)  
library(knitr)
library(dygraphs)
library(lubridate)
library(ggplot2)
library(tidyr)
library(tidyverse)


```


Sidebar {.sidebar}
-----------------------------------------------------------------------

### Financial Data Lab

1. From Stock Price charts, we could see that:
  + Three of the stock price decreased in the past one year (from Oct 1st,2018 to Oct 1st, 2019), except the JPMorgan Chase. However, all the four stock price hit the bottom on December 26,2018.
  + Bank of America Corporation has been more stable price flow compared to the other three. 
  + Citigroup has experienced the most extreme dropped on Dec26th,2018. It took about one year for this stock to come back to the earliest price (the price of Oct1st,2018) 
  + In general, JPMorgan stock price gradually increase in the past one year
  + Compared with other three stocks, Wells Fargo has a more changeable daily price
  
2. Based on 30-day rolling Sharpe Ratio, we could see that:
  + All Sharpe Ratios are below zero. They are within a similar range from -2 to 0.
  + Both Sharpe Ratio of Chase and WellsFargo are always lower than -1. Looking back the whole year, BOA and Citi's range is basiclly between -1 to -2

3. The Basic Metrics show that:
  + Citi has the lowest Price-to-Earning-Growth and Earnings Multiple.JPM is the highest, and BAC is second highest.
  + JPM has the highest Market cap which is almost 2 times than other three 
  
4. The Monthly Return chart shows that. 
  + All four stocks fluctuate within a similar range.
  + For the most recent month, WallsFargo has has a more stable/ Lower Monthly Return.
  
5. The Daily Return charts show that:
  + BOA has the highest daily earning. Citi has more low price in daily return among all four stocks.

In conclusion, considering the negative sharpe ratio, we do not recommend to buy in new stock from these four stocks. When we look at the Price-to-Earning-Growth (PEG), we could also get the same conclusion that the higher PEG means higher risk of investment. Still, this is not a good time to invest on these four stock as a long term investment. But short term hedge strategy may still work based on high volatility. 
  

Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Stock Price - BAC

```{r}
tickers <- c("BAC", "JPM", "C", "WFC")
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2018-10-01')
AAPL  <- BAC[,1:4]
MSFT  <- C[,1:4]
GOOGL <- JPM[,1:4]
FB    <- WFC[,1:4]

dygraph(AAPL, main = "Bank of America Corporation (BAC)") %>% 
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 55)%>% 
  dyLegend(show = "onmouseover")


```


###  Stock Price -  Citi

```{r}

dygraph(MSFT, main = "Citigroup Inc. (C)") %>% 
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 55)%>% 
  dyLegend(show = "onmouseover")


```

###  Stock Price -  JPM

```{r}

dygraph(GOOGL, main = "JPMorgan Chase & Co. (JPM)") %>% 
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 55)%>% 
  dyLegend(show = "onmouseover")


```

###  Stock Price -  WFC

```{r}

dygraph(FB, main = "Wells Fargo & Company (WFC)") %>% 
  dyCandlestick() %>% 
  dyAxis("y", label="Price") %>%
  dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightCircleSize = 4,
              highlightSeriesBackgroundAlpha = 1) %>%
  dyRangeSelector(height = 55)%>% 
  dyLegend(show = "onmouseover")


```



```{r, message = FALSE, warning= FALSE, ecol = FALSE}

getSymbols(c("BAC", "JPM", "C", "WFC"), from = '2018-10-01', to = '2019-10-29')
getSymbols('USD1MTD156N', src = 'FRED')

AAPL.ret <- periodReturn(BAC, period = 'daily')
GOOGL.ret <- periodReturn(JPM, period = 'daily')
MSFT.ret <- periodReturn(C, period = 'daily')
FB.ret <- periodReturn(WFC, period = 'daily')
ret <- merge(AAPL.ret, GOOGL.ret, MSFT.ret, FB.ret)
colnames(ret) <- c('AAPL_ret', 'GOOGLE_ret', 'MSFT_ret', 'FB_ret')

rf <- mean(USD1MTD156N['2018/10 to 2019/10'], na.rm = T) / 100
# Average 1-M LIBOR as Risk-Free Rate for simplification

```


Row {}
-----------------------------------------------------------------------

### Rolling Shape-Ratio for Three Stocks

```{r, message=FALSE, warning=FALSE}
mean_roll_30 <- rollapply(ret, 30, FUN = mean)
mean_roll_30 <- mean_roll_30[complete.cases(mean_roll_30), ]

sd_roll_30 <- rollapply(ret, 30, FUN = sd)
sd_roll_30 <- sd_roll_30[complete.cases(sd_roll_30), ]

sharp.ratio <- (mean_roll_30 - rf) / sd_roll_30
colnames(sharp.ratio) <- c('BOA_SR', 'JPM_SR', 'Citi_SR', 'WFC_SR')
sharp.ratio.df <- data.frame(date=index(sharp.ratio), coredata(sharp.ratio))
sharp.ratio.melt <- gather(sharp.ratio.df, key = 'company', value = 'Sharp_Ratio', -date)

ggplot(data = sharp.ratio.melt, aes(x = date, y = Sharp_Ratio)) + 
  geom_line(alpha = 0.3) + 
  geom_hline(yintercept = 0) +
  facet_grid(company ~.) + 
  ggtitle('30-Day Rolling Sharpe Ratio for BOA, JPM, Citi & WellsFargo \n (2018.10-2019.10)') + 
  xlab('Time') + 
  ylab('Sharpe Ratio')

count.sharp <- apply(sharp.ratio > 0, 2, sum)
# From the result we found that TWTR has the most days with positive sharpe ratio
```


Row {}
-----------------------------------------------------------------------

### Current Basic Metrics

Basic metrics for Four stocks, in order to frame a general picture and details of the four stocks.
Apple is having the biggest market cap, which Microsoft second, while Twitter is the smallest according to this.

```{r}
what_m <- yahooQF(c("Price/Sales", 
                          "P/E Ratio",
                          "Price/EPS Estimate Next Year",
                          "PEG Ratio",
                          "Dividend Yield", 
                          "Market Capitalization"))

ms <- getQuote(paste(tickers, sep="", collapse=";"), what=what_m)
ms <- data.frame(Symbol=tickers, ms[,2:length(ms)]) 
# colnames(ms) <- c("Symbol", "Revenue Multiple", "Earnings Multiple", 
# "Earnings Multiple (Forward)", "Price-to-Earnings-Growth", "Div Yield", "Market Cap")
 colnames(ms) <- c("Symbol", "Price-to-Earnings-Growth","Earnings Multiple (Forward)", "Div Yield", "Market Cap")

DT::datatable(ms)

```

Row {}
-----------------------------------------------------------------------

### Monthly Return

Monthly return analysis, to see if it's possible to get the highest monthly return for short term investment.

```{r}

m.rt.APPL <- monthlyReturn(AAPL)
m.rt.GOOGL <- monthlyReturn(GOOGL)
m.rt.MSFT <- monthlyReturn(MSFT)
m.rt.FB <- monthlyReturn(FB)

mg.return <- merge.xts(m.rt.APPL,m.rt.GOOGL, m.rt.MSFT, m.rt.FB)
colnames(mg.return) <- c('BOA','JPM','Citi','WFC')


dygraph(mg.return, main = "Monthly Return") %>%
  dyAxis("y", label = "Return") %>%
  dyOptions(colors = RColorBrewer::brewer.pal(5, "Set2")) %>%
  dyHighlight(highlightSeriesBackgroundAlpha = 0.5,
               highlightSeriesOpts = list(strokeWidth = 4)) %>%
  dyRangeSelector(height = 55)
  
```


Row {}
-----------------------------------------------------------------------



### Daily Returns



```{r, message=FALSE, warning=FALSE}
tickers <- c("BAC", "JPM", "C", "WFC")
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2018-10-01')


AAPL_return<-dailyReturn(BAC$BAC.Adjusted)
plot(AAPL_return, xlab="Time",ylab = "Return",main = "BOA Daily Return")

GOOGL_return<-dailyReturn(JPM$JPM.Adjusted)
plot(GOOGL_return, xlab="Time",ylab = "Return",main = "JPM Daily Return")

MSFT_return<-dailyReturn(C$C.Adjusted)
plot(MSFT_return, xlab="Time",ylab = "Return",main = "Citi Daily Return")

FB_return<-dailyReturn(WFC$WFC.Adjusted)
plot(FB_return, xlab="Time",ylab = "Return",main = "WFC Daily Return")

```