diff --git a/02-data.Rmd b/02-data.Rmd index c7aa6eb..b890911 100644 --- a/02-data.Rmd +++ b/02-data.Rmd @@ -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} diff --git a/03-cleaning.Rmd b/03-cleaning.Rmd index 9c19b24..8bb63fa 100644 --- a/03-cleaning.Rmd +++ b/03-cleaning.Rmd @@ -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),] @@ -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 @@ -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) @@ -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) ``` - - diff --git a/04-missing.Rmd b/04-missing.Rmd index 81b1892..7235b29 100644 --- a/04-missing.Rmd +++ b/04-missing.Rmd @@ -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) ``` diff --git a/05-results.Rmd b/05-results.Rmd index 6e6b2f1..586ff8b 100644 --- a/05-results.Rmd +++ b/05-results.Rmd @@ -1,5 +1,22 @@ # 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() + @@ -7,32 +24,137 @@ ggplot(df.close1, aes(price)) + 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. diff --git a/06-interactive.Rmd b/06-interactive.Rmd index 4187070..4d8a60a 100644 --- a/06-interactive.Rmd +++ b/06-interactive.Rmd @@ -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} diff --git a/07-conclusion.Rmd b/07-conclusion.Rmd index 63ae4f8..f107a66 100644 --- a/07-conclusion.Rmd +++ b/07-conclusion.Rmd @@ -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. diff --git a/README.md b/README.md index 95739de..119240d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-18-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-18-1.png new file mode 100644 index 0000000..85843d7 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-21-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-21-1.png new file mode 100644 index 0000000..615a822 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-21-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-22-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-22-1.png new file mode 100644 index 0000000..59b8c5e Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-22-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-23-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-23-1.png new file mode 100644 index 0000000..86e8e31 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-23-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-24-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-24-1.png new file mode 100644 index 0000000..6e28983 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-24-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-25-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-25-1.png new file mode 100644 index 0000000..a511d7b Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-25-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-26-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-26-1.png new file mode 100644 index 0000000..55918c5 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-26-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-27-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-27-1.png new file mode 100644 index 0000000..e4d9333 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-27-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-28-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-28-1.png new file mode 100644 index 0000000..5c4f5a4 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-28-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-29-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-29-1.png new file mode 100644 index 0000000..7f1b4a7 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-29-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-30-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-30-1.png new file mode 100644 index 0000000..fd06257 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-30-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-31-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-31-1.png new file mode 100644 index 0000000..5bde113 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-31-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-32-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-32-1.png new file mode 100644 index 0000000..2247a5c Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-32-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-33-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-33-1.png new file mode 100644 index 0000000..487dc53 Binary files /dev/null and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-33-1.png differ diff --git a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-5-1.png b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-5-1.png index c82cc97..aad3c2a 100644 Binary files a/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-5-1.png and b/_bookdown_files/finalproj_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/_output.yml b/_output.yml index eb6727b..4237e8e 100644 --- a/_output.yml +++ b/_output.yml @@ -3,6 +3,6 @@ bookdown::gitbook: config: toc: before: | -
  • SHORT TITLE HERE
  • +
  • Crypto
  • after: |
  • Published with bookdown
  • diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..f5182e2 Binary files /dev/null and b/data/.DS_Store differ diff --git a/docs/404.html b/docs/404.html index c52d7a3..a5c682d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -23,7 +23,7 @@ - + @@ -52,6 +52,13 @@ + + + + + + + @@ -69,13 +76,13 @@