---
title: "Stock Analysis"
author: "Qiong Duan"
date: "November 7, 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)
library(pdfetch)
library(lubridate)
tickers <- c("BTC-USD", "ETH-USD", "XRP-USD", "BCH-USD")
invisible(getSymbols(tickers,src="yahoo",from="2019-01-01"))
```
Cryptocurrencies Stock Prices
=====================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
### Cryptocurrencies
Bitcoin [BTC]
Bitcoin celebrated its 10th birthday on 3rd Jan 2019. It has the biggest trade volume and the highest price among all of the cryptocurrencies. The price has more than doubled (almost triped) in 2019 with a relatively low volatility rate, far outpacing other cryptocurrencies.
Ethereum [ETH]
After Bitcoin, Ethereum is the second-largest cryptocurrency and one of the best long-term altcoins that are potent and promising. Many big blockchain companies are investing in ethereum. So far in 2019, the price has increased 30%.
Ripple [XRP]
Ripple is on the third place based on the market cap. It is becoming the hot choice for the go-to blockchain for banking and financial institutions. However, it is the only one that has an decreased price among all four cyptocurrencies - almost 20% down in 2019. Even though the price is low for each Ripple coin, it shows a high signs of volatility (highest % of change during a day).
Bitcoin Cash [BCH]
Bitcoin Cash was created to overcome one of the major challenges being faced by Bitcoin - Scalability - by increasing the “block size”, BCH can process a higher number of transactions per second when compared to Bitcoin. Just like its parent coin, BCH experienced a boost in growth in 2019 - almost 90% increase on price. Based on the daily % change - it is more volatile than Bitcoin and Ethereum.
Conclusion
Based on the analysis above, Bitcoin has the most growing opportunies and the lowest volatility recently. However, it is around a highest point now (9000+), I will still hold and try to buy it on a lower price later.
Row {data-height=100}
-----------------------------------------------------------------------
### BTC
```{r}
price_BTC <- getQuote("BTC-USD",what = yahooQF(c("Last Trade (Price Only)")))
change_BTC <- getQuote("BTC-USD",what = yahooQF(c("Change")))
change_BTC_pct <- getQuote("BTC-USD",what = yahooQF(c("Change in Percent")))
#valueBox(
# value = paste('$',round(price_BTC[2],digits=2)),
# caption = "BTC Current Price", color = ifelse(change_BTC[2] > 0, "success", "warning"))
valueBox(
value = paste('$',round(change_BTC[2],digits=2)," (",round(change_BTC_pct[2],digits=2),'%',")", sep = ''),
caption = "BTC Daily Change", color = ifelse(change_BTC[2] > 0, "success", "warning"))
```
### ETH
```{r}
price_ETH <- getQuote("ETH-USD",what = yahooQF(c("Last Trade (Price Only)")))
change_ETH <- getQuote("ETH-USD",what = yahooQF(c("Change")))
change_ETH_pct <- getQuote("ETH-USD",what = yahooQF(c("Change in Percent")))
#valueBox(
# value = paste('$',round(price_ETH[2],digits=2)),
# caption = "ETH Current Price", color = ifelse(change_BTC[2] > 0, "success", "warning"))
valueBox(
value = paste('$',round(change_ETH[2],digits=2)," (",round(change_ETH_pct[2],digits=2),'%',")", sep = ''),
caption = "ETH Daily Change", color = ifelse(change_ETH[2] > 0, "success", "warning"))
```
### XRP
```{r}
price_XRP <- getQuote("XRP-USD",what = yahooQF(c("Last Trade (Price Only)")))
change_XRP <- getQuote("XRP-USD",what = yahooQF(c("Change")))
change_XRP_pct <- getQuote("XRP-USD",what = yahooQF(c("Change in Percent")))
#valueBox(
# value = paste('$',round(price_XRP[2],digits=2)),
# caption = "XRP Current Price", color = ifelse(change_XRP[2] > 0, "success", "warning"))
valueBox(
value = paste('$',round(change_XRP[2],digits=2)," (",round(change_XRP_pct[2],digits=2),'%',")", sep = ''),
caption = "XRP Daily Change", color = ifelse(change_XRP[2] > 0, "success", "warning"))
```
### BCH
```{r}
price_BCH <- getQuote("BCH-USD",what = yahooQF(c("Last Trade (Price Only)")))
change_BCH <- getQuote("BCH-USD",what = yahooQF(c("Change")))
change_BCH_pct <- getQuote("BCH-USD",what = yahooQF(c("Change in Percent")))
#valueBox(
# value = paste('$',round(price_BCH[2],digits=2)),
# caption = "BCH Current Price", color = ifelse(change_BCH[2] > 0, "success", "warning"))
valueBox(
value = paste('$',round(change_BCH[2],digits=2)," (",round(change_BCH_pct[2],digits=2),'%',")", sep = ''),
caption = "BCH Daily Change", color = ifelse(change_BCH[2] > 0, "success", "warning"))
```
Row {data-height=200}
-----------------------------------------------------------------------
### YTD Overview - Adj.Closing Price
```{r}
#a 'xts' object of each stock's adjusted price as a column
prices <- do.call(merge,lapply(tickers, function(x) Ad(get(x))))
dygraph(prices,group="stock") %>%
dyAxis("y",label="Adjusted Closing Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height=40) %>%
dyLegend(show = "onmouseover")
```
### YTD Overview - Volume
```{r}
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2019-01-01')
volume <- data.frame(`BTC-USD`$'BTC-USD.Volume',`ETH-USD`$'ETH-USD.Volume',`XRP-USD`$'XRP-USD.Volume',`BCH-USD`$'BCH-USD.Volume')
dygraph(volume,group="stock") %>%
dyAxis("y",label="Volume") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height=40) %>%
dyLegend(show = "onmouseover")
```
Row {.tabset .tabset-fade data-height=300}
-----------------------------------------------------------------------
### BTC
```{r}
symbol <- getSymbols(tickers, src = 'yahoo', auto.assign = TRUE, warnings = FALSE, from = '2019-01-01')
`BTC-USD` <- `BTC-USD` [,1:4]
`ETH-USD` <- `ETH-USD`[,1:4]
`XRP-USD` <- `XRP-USD`[,1:4]
`BCH-USD` <- `BCH-USD`[,1:4]
dygraph(`BTC-USD`, main = "BTC") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 55)%>%
dyLegend(show = "onmouseover")
```
### ETH
```{r}
dygraph(`ETH-USD`, main = "ETH") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 55)%>%
dyLegend(show = "onmouseover")
```
### XRP
```{r}
dygraph(`XRP-USD`, main = "XRP") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 55)%>%
dyLegend(show = "onmouseover")
```
### BCH
```{r}
dygraph(`BCH-USD`, main = "BCH") %>%
dyCandlestick() %>%
dyAxis("y", label="Price") %>%
dyOptions(colors= RColorBrewer::brewer.pal(5, "Set2")) %>%
dyHighlight(highlightCircleSize = 4,
highlightSeriesBackgroundAlpha = 1) %>%
dyRangeSelector(height = 55)%>%
dyLegend(show = "onmouseover")
```
Row {data-height=250}
-----------------------------------------------------------------------
### Current Basic Metrics
```{r}
what_m <- yahooQF(c("Last Trade (Price Only)", "Open",
"Change","Change in Percent",
"Days High", "Days Low", "Volume", "Market Capitalization"))
ms <- getQuote(paste(tickers, sep="", collapse=";"), what=what_m)
ms <- data.frame( ms[,2:length(ms)])
colnames(ms) <- c("Price", "Open", "Change", "% Change", "High", "Low", "Volume", "Market Cap")
DT::datatable(ms)
```