See stock price trend to get a genral sense of the performance of the three stocks. Apple is steadily increasing in recent month, Microsoft is also steady in a long run, while Twitter see downward trend in recent.
[1] "AAPL" "GOOGL" "MSFT" "FB"
[1] "USD1MTD156N"
Basic metrics for three stocks, in order to frame a general picture and details of the three stocks. Apple is having the biggest market cap, which Microsoft second, while Twitter is the smallest according to this.
Monthly return analysis, to see if it’s possible to get the highest monthly return for short term investment.
---
title: "ANLY 512: Dashboard Laboratory"
author: "Ting Tu & Jianan Guo"
Date: "October 29 2017"
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 - AAPL
See stock price trend to get a genral sense of the performance of the three 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("AAPL", "GOOGL", "MSFT", "FB")
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2016-10-01')
AAPL <- AAPL[,1:4]
GOOGL <- GOOGL[,1:4]
MSFT <- MSFT[,1:4]
FB <- FB[,1:4]
dygraph(AAPL, main = "Apple") %>%
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 - MSFT
```{r}
dygraph(MSFT, main = "Microsoft") %>%
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 - GOOGL
```{r}
dygraph(GOOGL, main = "Google") %>%
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 - Facebook
```{r}
dygraph(FB, main = "Facebook") %>%
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('AAPL', 'GOOGL','MSFT', 'FB'), from = '2016-10-01', to = '2017-10-29')
getSymbols('USD1MTD156N', src = 'FRED')
AAPL.ret <- periodReturn(AAPL, period = 'daily')
GOOGL.ret <- periodReturn(GOOGL, period = 'daily')
MSFT.ret <- periodReturn(MSFT, period = 'daily')
FB.ret <- periodReturn(FB, 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['2016/10 to 2017/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('AAPL_SR', 'GOOGL_SR', 'MSFT_SR', 'FB_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 Apple, Google, Microsoft & Facebook \n (2016.10-2017.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 three stocks, in order to frame a general picture and details of the three 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")
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('Apple','Google','Microsoft','Facebook')
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("AAPL", "GOOGL", "MSFT", "FB")
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2017-09-27')
AAPL_return<-dailyReturn(AAPL$AAPL.Adjusted)
plot(AAPL_return, xlab="Time",ylab = "Return",main = "Apple Daily Return in October 2017")
GOOGL_return<-dailyReturn(GOOGL$GOOGL.Adjusted)
plot(GOOGL_return, xlab="Time",ylab = "Return",main = "Google Daily Return in June 2017")
MSFT_return<-dailyReturn(MSFT$MSFT.Adjusted)
plot(MSFT_return, xlab="Time",ylab = "Return",main = "Microsoft Daily Return in June 2017")
FB_return<-dailyReturn(FB$FB.Adjusted)
plot(FB_return, xlab="Time",ylab = "Return",main = "Facebook Daily Return in June 2017")
```