Row

Stock Price - BAC

See stock price trend to get a genral sense of the performance of the four stocks. Apple is steadily increasing in recent month, Microsoft is also steady in a long run, while Twitter see downward trend in recent.

Stock Price - Citi

Stock Price - JPM

Stock Price - WFC

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

Row

Rolling Sharpe-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:
  + All four stocks have upward trends during past 1 year.
  + Microsoft has been more stable compared to the other three. 
  + Google has been more volatile in contrast. 
  + Apple shows two big drops in recent months, and Facebook shows big drops in earlier months during past 1 year.
  
2. Based on 30-day rolling Sharpe Ratio, we could see that:
  + All Sharpe Ratios are below zero. They are within a similar range.
  + However, Apple shows a decreasing trend recently, and all the other three show upward trend. Google, especially, shows a steady increasing trend.

3. The Basic Metrics show that:
  + Apple has the lowest Revenue Multiple and Earnings Multiple.Facebook is the highest, and Google is second highest.
  + Apple and Microsoft pay dividends while the other two do not.
  
4. The Monthly Return chart shows that. 
  + All four stocks fluctuate within a similar range.
  + For the most recent month, Facebook has second lowest Monthly Return.
  
5. The Daily Return charts show that:
  + Apple has the highest daily loss and lowest daily return in all four stocks.

In conclusion, we recommend selling Apple stocks. If capital is not of a concern, Google is recommended. Or else, Microsoft is an alternative.
  

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

### Stock Price - BAC
See stock price trend to get a genral sense of the performance of the four stocks.
Apple is steadily increasing in recent month, Microsoft is also steady in a long run, while Twitter see downward trend in recent.

```{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 Sharpe-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', 'Chase_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 Sharp Ratio for BOA, Chase, Citi & S&P500 \n (2018.10-2019.10)') + 
  xlab('Time') + 
  ylab('Shart 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','Chase','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 in October 2018")

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

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

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

```