-From stock price, we find that: + FaceBook’s and Apple’s stock price steadily rised in the past 4 years. + The most volatile stock is AliNVDA. + SBAC has the lowest price, but it has a steady growing trend.
Column {.tabset data-width=600}
Column {.tabset data-width=600}
Column {.tabset data-width=600}
###NTES
Column {.tabset data-width=300}
###NVDA
To sum up, our decision is to choose FaceBook. + It has the second highest stock return. + It has a very high trading volume, which indicate the high liquidity of the stock. + Its PE ratio is not too high as AliNVDA, which mean investors paying less to get the earnings from FaceBook comparing with AliNVDA.
---
title: "Stock Selection"
output:
flexdashboard::flex_dashboard:
theme: united
storyboard: true
orientation: rows
vertical_layout: fill
source_code: embed
social: menu
---
```{r setup, include=FALSE}
library(flexdashboard)
library(quantmod)
library(ggplot2)
library(tidyr)
library(plyr)
library(dygraphs)
library(DT)
library(tidyquant)
library(lubridate)
tickers <- c("NVDA","NTES","EQIX","SBAC")
```
```{r,message=FALSE, include=FALSE}
#choose three companies: AliNVDA, FaceBook, Apple, and SBAC
getSymbols(tickers, src='yahoo', from='2004-12-31', to= '2021-03-2021')
```
-----------------------------------------------------------------------
Stock Price {data-orientation=rows}
=====================================
----------------------------------------
```{r}
StockPrices <- do.call(merge, lapply(tickers, function(x) Cl(get(x))))
dateperiod<-c("2004-12-31", "2021-03-2021")
dygraph(StockPrices, main="Stock Price", group="Stock") %>%
dyAxis("y", label="Stock Price(USD)") %>%
dyAxis("x", label="Time") %>%
dyOptions(axisLineWidth = 1.0, colors = RColorBrewer::brewer.pal(6, "Set1")) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 2.0,
highlightSeriesOpts = list(strokeWidth = 3)) %>%
dyRangeSelector(height = 60)
```
***
-From stock price, we find that:
+ FaceBook's and Apple's stock price steadily rised in the past 4 years.
+ The most volatile stock is AliNVDA.
+ SBAC has the lowest price, but it has a steady growing trend.
Column {.tabset data-width=600}
Stock Return {data-orientation=rows}
=====================================
```{r}
stocks <- cbind(NVDA$BA.Adjusted,NTES$NTES.Adjusted, EQIX$EQIX.Adjusted, SBAC$SBAC.Adjusted)
stock_return <- apply(stocks, 1, function(x) {x / stocks[1,]}) %>%
t %>% as.xts
plot(as.zoo(stock_return), screens = 4, col=10:12, lty = 18:20, xlab = "Time", ylab = "Return",main='Return for Selected Stocks')
legend("topleft", c("NVDA", "NTES", "EQIX","SBAC"), lty = 18:20, col=10:12, cex = 0.8)
```
Column {.tabset data-width=600}
Key Factors {data-orientation=rows}
=====================================
----------------------------------------
```{r}
what_metrics <- yahooQF(c("Price/Sales",
"P/E Ratio",
"Price/EPS Estimate Next Year",
"PEG Ratio",
"Dividend Yield",
"Market Capitalization"))
metrics <- getQuote(paste(tickers, sep = "",collapse = ";"),what = what_metrics)
metrics <- data.frame(Symbol=tickers, metrics[,2:length(metrics)])
colnames(metrics) <- c("Symbol", "P-E Ratio", "Price EPS Estimate Next Year", "Div Yield", "Market Cap")
DT::datatable(metrics)
```
Column {.tabset data-width=600}
Stock Volume {data-orientation=rows}
=====================================
Row
-------------------------------------
### NVDA
```{r}
invisible(getSymbols("NVDA", src = "yahoo", from='2004-12-31', to= '2021-03-2021'))
candleChart(NVDA, up.col = "blue", dn.col = "blue", theme = "white")
```
### NTES
```{r}
invisible(getSymbols("NTES", src = "yahoo", from='2004-12-31', to= '2021-03-2021'))
candleChart(NTES, up.col = "yellow", dn.col = "red", theme = "white")
```
Row
-------------------------------------
### EQIX
```{r}
invisible(getSymbols("AAP", src = "yahoo", from='2004-12-31', to= '2021-03-2021'))
candleChart(EQIX, up.col = "red", dn.col = "red", theme = "white")
```
### SBAC
```{r}
invisible(getSymbols("SBAC", src = "yahoo", from='2004-12-31', to= '2021-03-2021'))
candleChart(SBAC, up.col = "green", dn.col = "red", theme = "white")
```
```{r}
invisible(getSymbols("NTES", from = "2017-01-01", auto.assign=TRUE))
NTES <- as.data.frame(NTES)
# Simple Moving Averages (SMA)
# 20-day SMA
sma20 <- SMA(NTES$NTES.Close, n=20)
# 50-day SMA
sma50 <- SMA(NTES$NTES.Close, n=50)
# 200-day SMA
sma200 <- SMA(NTES$NTES.Close, n=200)
# Exponential Moving Average (EMA)
# 14-day EMA
ema14 <- EMA(NTES$NTES.Close, n=14)
# Bollinger Bands
bb20 <- BBands(NTES$NTES.Close, sd=2.0, n=14, maType=EMA)
# Overall data frame
NTESplusBB <- data.frame(NTES,bb20)
# Relative Strength Indicator
rsi14 <- RSI(NTESplusBB$NTES.Close, n=14)
#MACD
macd <- MACD(NTESplusBB$NTES.Close, nFast = 12, nSlow = 26,
nSig = 9, maType = SMA)
# allData
allData <- data.frame(NTES,sma20,sma50,sma200,ema14,bb20,rsi14,macd)
```
Technical Analysis:Candlestick Chart with Bollinger Bands {data-orientation=rows}
=====================================
----------------------------------------
###NTES
```{r}
m <- cbind(allData[,1:4], allData[,11], allData[,12], allData[,13])
colnames(m)[5] <- "dn"
colnames(m)[6] <- "mavg"
colnames(m)[7] <- "up"
dygraph(m, main = "Bollinger Bands" ) %>%
dyCandlestick() %>%
dyRangeSelector(height = 60)
```
Column {.tabset data-width=300}
```{r}
invisible(getSymbols("NVDA", from = "2017-01-01", auto.assign=TRUE))
NVDA <- as.data.frame(NVDA)
# Simple Moving Averages (SMA)
# 20-day SMA
sma20 <- SMA(NVDA$NVDA.Close, n=20)
# 50-day SMA
sma50 <- SMA(NVDA$NVDA.Close, n=50)
# 200-day SMA
sma200 <- SMA(NVDA$NVDA.Close, n=200)
# Exponential Moving Average (EMA)
# 14-day EMA
ema14 <- EMA(NVDA$NVDA.Close, n=14)
# Bollinger Bands
bb20 <- BBands(NVDA$NVDA.Close, sd=2.0, n=14, maType=EMA)
# Overall data frame
NVDAplusBB <- data.frame(NVDA,bb20)
# Relative Strength Indicator
rsi14 <- RSI(NVDAplusBB$NVDA.Close, n=14)
#MACD
macd <- MACD(NVDAplusBB$NVDA.Close, nFast = 12, nSlow = 26,
nSig = 9, maType = SMA)
# allData
allData2 <- data.frame(NVDA,sma20,sma50,sma200,ema14,bb20,rsi14,macd)
```
###NVDA
```{r}
m <- cbind(allData2[,1:4], allData2[,11], allData2[,12], allData2[,13])
colnames(m)[5] <- "dn"
colnames(m)[6] <- "mavg"
colnames(m)[7] <- "up"
dygraph(m, main = "Bollinger Bands" ) %>%
dyCandlestick() %>%
dyRangeSelector(height = 50)
```
Summary {data-orientation=rows}
=====================================
----------------------------------------
***
1. From stock price, we find that :
-FaceBook's and Apple's stock price steadily rised in the past 4 years.
+ The most volatile stock is AliNVDA.
+ SBAC has the lowest price, but it has a steady growing trend.
2. From stock return, we find that :
+ The return of Apple is lower than the return of FackBook.
+ As a relative new company, AliNVDA's returns are more fluctuate, and getting higher in recent period
3. From key factors:
+ Apple has the largest market cap while SBAC has the smaller market cap
+ Apple has the lowest EPS estimated next year
+ AliNVDA has the highest PE ratio while Apple has the lowest PE ratio.
4. From stock volume:
+ SBAC has the lowest trading volume among four stocks.
5. From bollinger bands:
+ FaceBook has a big drop in April while AliNVDA is relative stable recently.
To sum up, our decision is to choose FaceBook.
+ It has the second highest stock return.
+ It has a very high trading volume, which indicate the high liquidity of the stock.
+ Its PE ratio is not too high as AliNVDA, which mean investors paying less to get the earnings from FaceBook comparing with AliNVDA.