Skip to content
Open

111 #21

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b609f8e
Merge pull request #14 from ytyky/main
ytyky May 4, 2022
1f83db3
Merge pull request #17 from ytyky/tt1
ytyky May 5, 2022
071cbdb
Merge pull request #18 from ytyky/tt1
Juntiantian May 5, 2022
9686870
Merge pull request #19 from ytyky/main
ytyky May 5, 2022
044a636
rephase questions
ytyky May 5, 2022
f5d00e0
add library zoo for time conversion in 05
ytyky May 5, 2022
db43088
correct typo in time, add month and year to df.crypto
ytyky May 5, 2022
f2c6b6d
update result, include 9 graphs with description
ytyky May 5, 2022
eb3036e
write summary
ytyky May 5, 2022
82ee955
Merge pull request #20 from ytyky/yty
ytyky May 5, 2022
2c48237
build up pages
ytyky May 5, 2022
a8e201b
update short title
ytyky May 5, 2022
65cf1df
render update short title
ytyky May 5, 2022
cd853a0
Merge pull request #22 from ytyky/main
ytyky May 5, 2022
5df9f09
Merge pull request #23 from ytyky/tt1
Juntiantian May 5, 2022
b6cfae8
Merge pull request #24 from ytyky/main
ytyky May 5, 2022
837c8cb
add library scales
ytyky May 5, 2022
c57b8e1
add marketcap vc date graph, adjust theme and label
ytyky May 6, 2022
0731585
Merge pull request #25 from ytyky/tt1
Juntiantian May 6, 2022
690c899
rename columns in missing value part
ytyky May 6, 2022
f1163be
Update 06-interactive.Rmd
Juntiantian May 6, 2022
6518455
Merge pull request #26 from ytyky/yty
ytyky May 6, 2022
fb41b86
rewrite data transformation
ytyky May 6, 2022
7bced1c
add missing "+" sign
ytyky May 6, 2022
accd185
Merge pull request #27 from ytyky/datatransformation
ytyky May 6, 2022
9e7a130
update pages, rewrite data transformation
ytyky May 6, 2022
146198b
rotate x label of some graphs to make them clear
ytyky May 6, 2022
a201529
Merge pull request #28 from ytyky/datatransformation
ytyky May 6, 2022
a2b52a8
rotate x label of some graphs and render
ytyky May 6, 2022
0e8bc77
spacing readme
ytyky May 6, 2022
28ca799
fix typo and catch error in writing
ytyky May 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 02-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ We use [coinmarketcap](https://coinmarketcap.com) api to verified top 5 cryptocu
library(tidyverse)
library(ggplot2)
library(coinmarketcapr)
library(zoo)
library(scales)
```

```{r}
Expand Down
48 changes: 37 additions & 11 deletions 03-cleaning.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Select Data

The original data includes the records which is more than one year, so we firstly choose the data between 2021-04-29 to 2022-04-30.
The original data includes the records which is more than one year, so we firstly choose the data between the end of April last year to the beginning of May 2022.

```{r}
BTC<-BTC[(nrow(BTC)-370):(nrow(BTC)-4),]
Expand All @@ -14,26 +14,51 @@ USDT<-USDT[(nrow(USDT)-370):(nrow(USDT)-4),]

## Combine the Data

we will combine the price of each cryptocurrency into one table df.close
we combine the price of each cryptocurrency into one table, df.close:

```{r}
df.close<-data.frame(cbind(BTC[,1],BTC[,2],BNB[,2],ETH[,2],USDC[,2],USDT[,2]))
colnames(df.close)<-c("Date","BTC","BNB","ETH","USDC","USDT")
head(df.close)
```

Here, we transform the table df.close into the new table df.close1 which will be helpful for plotting.

| Date | BTC | BNB | ETH | USDC | USDT | Price |
| :----: | :----: | :----: | :----: | :----: | :----: | :----: |
| record |


* Date: date of the crypto record
* BTC: price of Bitcoin
* BNB: price of Binance Coin
* ETH: price of Ethereum
* USDC: price of USD Coin
* USDT: price of USD Tether

(all price are in USD)

This table can help us quickly find price of all 5 cryptos we selected given date information.

Then we create a comprehensive tidy data table include all financial information, df.crypto:

| date | cryptocurrency | price | volume | market_cap |
| :----: | :----: | :----: | :----: | :----: |
| record |


```{r}
df.close1<- gather(df.close[,2:6], cryptocurrency, price)
df.close1$price<-as.numeric(df.close1$price)
head(df.close1)
```

## Calculate the Return and Volatility

Firstly, we calculate the return of each date by the formula: (final price/ initial price)-1.
Then we calculate the 15 days volatility of each cryto by calculating the stand deviation of 15 days return, and multiply square root of 356. (For stocks, the volatility is stand deviation multiply square root of 250, but the cryptocurrency can be traded every day, so we choose square root of 356 )
Firstly, we calculate the return of each date by the formula:
$$\frac{final\: pric e - initial\: price}{initial\: price}$$
Then we calculate the 15 days volatility of each crypto by calculating the stand deviation of 15 days return, and multiply square root of 365.

$$sd(15 \: days \: return) \cdot \sqrt{365}$$

(For stocks, the volatility is stand deviation multiply square root of 250, but the cryptocurrency can be traded every day, so we choose square root of 365)

```{r}
# volatility
Expand Down Expand Up @@ -113,9 +138,9 @@ for (i in 16:nrow(USDT)){
}
```

## Combine All the Value into One table
## Combine All the Value into One Table

Finally, we combine the volatility, return, and market capitalization and volume with the df.close1, creating the final table df.crpyto
Finally, we add the volatility, return, into df.crpyto, plus month and year column seperated from date in case we want to group data. The fianl format of our table df.crypto:

```{r}
df.close1$Date<-rep(df.close$Date,5)
Expand All @@ -128,6 +153,7 @@ df.crypto<-
volume=c(BTC$total_volume,BNB$total_volume,ETH$total_volume,
USDC$total_volume,USDT$total_volume))
df.crypto$Date<-as.Date(df.crypto$Date)
df.crypto$year <- strftime(df.crypto$Date, "%Y") # Create year column
df.crypto$month <- strftime(df.crypto$Date, "%m")
head(df.crypto)
```


10 changes: 8 additions & 2 deletions 04-missing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ library(redav)
```

```{r}
plot_missing(df.crpyto)
missing_crypto_show_case <- df.crypto %>%
rename(
date = Date,
crypto = cryptocurrency,
capital = market_cap
)
plot_missing(missing_crypto_show_case)
```

Observed that volatility and return contains missing values. Take a look into number of missing value in columns we found:

```{r}
colSums(is.na(df.crypto)) %>%
colSums(is.na(missing_crypto_show_case)) %>%
sort(decreasing = TRUE)
```

Expand Down
130 changes: 126 additions & 4 deletions 05-results.Rmd
Original file line number Diff line number Diff line change
@@ -1,38 +1,160 @@
# Results

## Overview

The price trend of top 5 cryptos are drawed below. As addressed before, the price of different cryptocurriencies vary a lot and hence we plot them separately by facet

```{r}
ggplot(data = df.close1, aes(x = as.Date(Date), y = price)) +
geom_line() +
facet_wrap(~cryptocurrency,scales = "free") +
xlab("date") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

We can obtain a general idea of the trend over a year. the price of BTC, ETH and BNB are high at end of April last year, then it bounce up and down, and for the last 5 months (start from the end of 2021) they have a decreasing trend. USDC and USDT have price around 1 dollar since they are stable coin. By nature stable coin are expected to have same value as fiat currency it targets to. From the line plot above we saw that the price range of USDC and USDT is centered around 1 (USD), but still have volatility.

We then examine the data range by boxplot, by facet

```{r}
ggplot(df.close1, aes(price)) +
geom_boxplot() + coord_flip() +
facet_wrap(~cryptocurrency,scales = "free")+
theme_grey(16)
```

Observed that the Bitcoin is undoubtly a giant in the current market. ETH and BNB are also expensive. The median price per ETH past year is around 3000. The median price per BNB past year is around 400. The rest two kinds of coin, USDC and USDT are waving around 1 dollar, and this is due to the fact that they are "stable coin" that linked to US dollar. The range of USDC and USDT are related small compared to other top cryptos, but they have do a lot of outliers in themselves.

## Correlation

We are also interested in the correlation between each cryptocurrency, hence we draw a correlation map to visulize the relationship

```{r}
## plot matrix for price
plot(df.close[,2:6],pch=20, cex=0.1)
```

Observed that the top cryptos in the market can divided into 2 groups. BTC, BNB and ETH have strong positive correlation, their price in general go up and down together. USDC and USDT have weak positive correlation, since they have target price at 1 USD.

## How hot is the market?

The crypto market move fast with uncertainty, and we tried to compare the trading volatility over all cryptos past year

```{r}
## plot volatility by crypto
ggplot(df.crypto, aes(x=Date,y=volatility))+
geom_line()+
facet_wrap(~cryptocurrency,scales = "free")
facet_wrap(~cryptocurrency,scales = "free") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

Observed that all top cryptos are decresing volatility through time. This means that the market is becoming stable and rational. Noticed that BNB has the highest volatility at the begining of our records. This is a relatively new cryptocurrency compared with BTC and ETH. We sepeculate that people are passion about new crypto when it first published. The stable coin USDC, USDT are more stable than last year and thus they probably become mature financial product (since they are suppose to fix their price to 1 usd).

```{r}
monthly_volatility <- aggregate(cbind(volatility, market_cap) ~ month + year + cryptocurrency,
df.crypto,
FUN = mean)
monthly_volatility <- monthly_volatility %>% filter((month != "04") | (year != "2021"))
monthly_volatility$Date <- as.yearmon(paste(monthly_volatility$year, monthly_volatility$month), "%Y %m")
```

```{r}
## plot volatility vs market capitalization
ggplot(df.crypto, aes(x=market_cap,y=volatility))+
ggplot(monthly_volatility, aes(x=market_cap,y=volatility))+
geom_point(pch=5, cex=0.2)+
facet_wrap(~cryptocurrency, scales = "free")
facet_wrap(~cryptocurrency, scales = "free") +
scale_x_continuous(labels = unit_format(unit = "B", scale = 1e-9)) +
xlab("marketcap in billions") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

Then we plot a scatter plot between volatility and market_cap, facet by different cryptocurrenies (we calculate a monthly average on volatility and marketcap over 1 year window, so there are 12 data points in each facet graph). The volatility is high when marketcap is high for all cryptos. This means price is extremely unstable when marketcap is high.

```{r}
ggplot(df.crypto, aes(x=Date,y=volume))+
geom_line(pch=5, cex=0.2)+
facet_wrap(~cryptocurrency, scales = "free_y") +
scale_y_continuous(labels = unit_format(unit = "B", scale = 1e-9)) +
ylab("volume in billions") +
xlab("date") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

Another indicator of the crypto market is cooling down is that the dot plot between date and volume. We see a decreasing trend in trading volume of BTC, ETH and BNB over a year. This implies that less amount of coins are trading in the market.

The other group of our interests, USDC and USDT, have continuous trading volumes, indicate that people treat these two type of coins as a tool to exchange their fiat currency in and out of the blockchian industry for varied purposes. The trading market is cooling down but people joined in the crypto industry did not simply leave.

## Dive into Stable Coin

```{r}
ggplot(rbind(df.crypto[df.crypto$cryptocurrency=="USDC",],
df.crypto[df.crypto$cryptocurrency=="USDT",]),
aes(Date, volume)) + geom_col()+
facet_wrap(~cryptocurrency,scales="free")
facet_wrap(~cryptocurrency,scales="free") +
scale_y_continuous(labels = unit_format(unit = "B", scale = 1e-9)) +
xlab("date") +
ylab("volume in billions") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

The volume of USDC are smaller than USDT during the one year window we observed. They are similar tools that link to US dollar but it seems like USDT is popular than USDC. This might due to the fact that USDT launched eariler than USDC. USDT has a suspicious volume spike in November 2021, after browsing news and external information (other market data source) we suspect this is an error record.

```{r}
# check 11.3.2021 USDT volume data, and it seems wrong, confirmed with coinmarketcap data 65.772B
#ggplot(data = df.crypto %>% filter(cryptocurrency == "USDT"), aes(x=Date, y=volume)) + geom_line()
```

```{r}
ggplot(rbind(df.crypto[df.crypto$cryptocurrency=="USDC",],
df.crypto[df.crypto$cryptocurrency=="USDT",]),
aes(fill=cryptocurrency, y=market_cap, x=Date)) +
geom_bar(position="stack", stat="identity") +
scale_y_continuous(labels = unit_format(unit = "B", scale = 1e-9)) +
ylab("marketcap in billions") +
xlab("date") +
theme_grey(16)
```

We can stack two stable coins' market cap together to get a general sense of how many US dollar go virtual -- around 150 billion USD are now converted to stable coins. A 100% increase in amount of dollors are now tokens on the blockchain.

## Crypto as an Investment

The top 3 cryptocurrencies (in market cap), BTC, BNB and ETH are mostly trading as a financial products instead of currencies. People invest in cryptos and expect returns in it. We can visualize the monthly returns of these cryptos to have a sense about what it looks like

```{r}
monthly_returns <- aggregate(return ~ month + year + cryptocurrency,
df.crypto,
FUN = sum)
monthly_returns <- monthly_returns %>% filter((month != "04") | (year != "2021")) %>% filter(cryptocurrency != "USDC" & cryptocurrency != "USDT")
monthly_returns$Date <- as.yearmon(paste(monthly_returns$year, monthly_returns$month), "%Y %m")
```

```{r}
ggplot(monthly_returns, aes(x=Date,y=return, colour=cryptocurrency,group=cryptocurrency))+
geom_line() +
xlab("date") +
theme_grey(16) +
theme(axis.text.x = element_text(size=10, angle = 90))
```

The monthly return are similar. From the graph we observed that the return rate vary a lot, so investing in crypto might be risky

```{r}
ggplot(rbind(df.crypto[df.crypto$cryptocurrency=="BTC",],
df.crypto[df.crypto$cryptocurrency=="ETH",],
df.crypto[df.crypto$cryptocurrency=="BNB",]),
aes(fill=cryptocurrency, y=market_cap, x=Date)) +
geom_bar(position="stack", stat="identity") +
scale_y_continuous(labels = unit_format(unit = "B", scale = 1e-9)) +
ylab("marketcap in billions") +
xlab("date") +
theme_grey(16)
```

Unlike stable coin, the market cap of top 3 cryptos goes up and down just like their price. The mining process is slow since with the increase of time, more and more computational power requires to mine a coin. Thus the total market capital is mainly decided by price in the trading market.

4 changes: 2 additions & 2 deletions 06-interactive.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ library(plotly)

## Add Buttons and Range Slider

We put the volatility of USDC and USDT into one plot because the volatility of the two cryptos have similar trends. In this interactive plot, we create three buttons that includes three options: showing the volatility of USDC, showing the volatility of USDT, and showing both cryptos.
In this interactive plot, we also add the range slider, so if people want to observe the plot of volatility in a specific range, the can move the buttons which are in the two side of the range slider.
We put the volatility of USDC and USDT into one plot because the volatility of the two cryptos have similar trends. In this interactive plot, we create three buttons that include three options: showing the volatility of USDC, showing the volatility of USDT, and showing both cryptos.
In this interactive plot, we also add the range slider, so if people want to observe the plot of volatility in a specific range, they can move the buttons which are in the two sides of the range slider. With the two design, people can easily compare the two cryptos in detail.


```{r}
Expand Down
1 change: 1 addition & 0 deletions 07-conclusion.Rmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Conclusion

After series of analysis on top cryptocurrencies, we know that the trading market of cryptos are cooling down compare with last year. We identified there are mainly 2 groups of cryptos, one group is stable coins linked to fiat currencies and they have less volatility and price per coin is close to 1 unit of the currency they linked to. Another group is those famous cryptos that does not rely on real money, and they have high volatility. Although we observed a decreasing trend in price and returns from top 3 cryptos, we find volume of 2 stable coins increase drastically, indicating the crypto world is still expanding.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@

*This repo was initially generated from a bookdown template available here: https://github.com/jtr13/EDAVtemplate.*

Project Proposal

Cryptocurrency market is trending and we are interested in comparing and contrasting different types of cryptocurrencies, providing insights in the field. After exploring multiple websites that provide crypto market data, we developed a few questions that are hard to answer directly through any single sources:

1.The correlation between major cryptocurrencies, are they moved upward or downward together?

2.how “hot” is a cryptocurrency, by trading frequency, volume, etc

3.how big the crypto market is, i.e, market cap of major cryptocurrencies, compare with each other and figure out the relationships between volatility and the market cap.
Data Sources:

Yahoo Finance https://finance.yahoo.com/cryptocurrencies/

Coinbase https://developers.coinbase.com/api/v2

CoinmarketCap https://coinmarketcap.com

To answer the question we made, we plan to collect and integrate the closing price, volume and market cap of different cryptocurrencies in the past one years, then calculate the related value and make several graphs based on these data.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion _output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ bookdown::gitbook:
config:
toc:
before: |
<li><a href="./">SHORT TITLE HERE</a></li>
<li><a href="./">Crypto</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
Binary file added data/.DS_Store
Binary file not shown.
Loading