Analysing the Cryptocurrency of May 2021 | Python for Finance basics

Prateek Majumder Last Updated : 27 Oct, 2024
8 min read

This article was published as a part of the Data Science Blogathon

Introduction

Cryptocurrency serves as a digital asset and is a medium of exchange between individuals where coin ownership records are stored in a secure computerized database. They are named as such because complicated cryptography helps in creating and processing these digital currencies and transactions across decentralized systems.

Note: The article is written at the end of May 2021. Current conditions will be different.

Overview of Cryptocurrencies

Cryptocurrencies do not belong to any nation or so. Traditional currencies are usually related to the central banks of nations or the government, India has Indian Rupee, the USA has US Dollar, Japan has Yen, the EU has Euro and the list goes on.

cryptocurrency overview

(Image Source: https://www.dnaindia.com/analysis/report-understanding-the-concept-of-cryptocurrency-2820473)

Cryptocurrencies are designed to be free from the control of any Government or Central bank. The Crypto market has always been highly unstable and erratic and a variety of factors determine the overall direction.

Crypto Fall of May 2021

The Crypto market was on the rise in the pandemic season. Since mid-2020, almost all cryptocurrencies were on the rise. The social media was all buzzed up on bitcoin and the other cryptocurrencies.

cryptocurrency fall may 2021

Memes spread all over social media regarding the rise of cryptocurrencies. One of the major factors about the cryptocurrency trends was Elon Musk. In February 2021, Tesla bought $1.5 billion in bitcoin, and Elon musk even mentioned that Tesla would accept cryptocurrency as payment.

In early February 2021, the bitcoin price was about 32000 USD, and by February end, it had crossed 50000 INR. Elon Musk also added the hashtag #bitcoin to his Twitter bio, which did help in the rise of cryptocurrency prices.

The cryptocurrency had become the new “cool” thing among youngsters and people wanted to buy as much crypto as possible.

Dogecoin

Similarly, Dogecoin was another cryptocurrency that rose to fame was Dogecoin. In February 2021, when Elon Musk and many other celebrities tweeted about Dogecoin, the value of the coin shot up suddenly. And Dogecoin, unlike Bitcoin or Ethereum has technically no use. It is a meme cryptocurrency.

Dogecoin

In 2013, a Japanese Shiba Inu dog was immensely viral and Dogecoin was started, as a joke. And it was just a fun experiment.

On 1st April 2021, Elon Musk tweeted that SpaceX will put a literal Dogecoin on the moon. This immediately became an internet meme, and the price of Dogecoin suddenly soared.

Dogecoin to the moon

( Image Source: https://techvivi.com/elon-musk-is-sending-dogecoin-to-the-moon/)

Images like this spread all over the internet. The world might have been physically apart due to the Covid19 pandemic, but through the internet, everyone was together. Bitcoin and Dogecoin gained the limelight and this ultimately pushed the prices of most other cryptocurrencies. People got hyped up that crypto is the new future and will replace traditional currencies soon.

Musk then tweeted SpaceX’snew satellite will be called Doge-1. In an unexpected move, it was also said that the entire mission will be paid in DogeCoin. This meant Doge would be the first cryptocurrency to contribute to space exploration and also be the first meme in space.

All this social media hype and jokes lead to an increase in prices in the whole crypto market.

The Great Crash:

On 13th May 2021, Elon Musk announced that Tesla will suspend Vehicle purchases using Bitcoin.

elon musk on cryptocurrency

So what are these climate concerns?

Well, Bitcoin mining involves using high-powered computers to solve complex algorithms. This involves multiple computers and involves high electricity and bandwidth consumption.

On the other hand, China banned financial institutions and payment companies from providing services to buy/sell cryptocurrency or provide any other services. Investors were also warned against crypto trading.

A report from JP Morgan also mentioned that investors were moving away from Crypto and back to Gold. Many other factors also contributed, and suddenly the massive fall in cryptocurrency prices wiped out $1 trillion of wealth.

Let us try to look at the data of some important cryptocurrencies and have a look at what really happened.

Getting started with Python for Finance:

We will extract various crypto prices from Yahoo finance. Let us get started by importing the libraries.

import warnings
warnings.filterwarnings('ignore')  # Hide warnings
import datetime as dt
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import matplotlib.dates as mdates
import plotly.express as px
start = dt.datetime(2021, 1, 1)
end = dt.datetime(2021,5,29)

We set the starting and ending dates of the data.

Python Code:

import warnings
warnings.filterwarnings('ignore')  # Hide warnings
import datetime as dt
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import matplotlib.dates as mdates


import plotly.express as px
start = dt.datetime(2021, 1, 1)
end = dt.datetime(2021,5,29)

btc = web.DataReader("BTC-USD", 'yahoo', start, end)  # Collects data
btc.reset_index(inplace=True)

Bitcoin

“BTC-USD” indicates Bitcoin prices in US dollars. So we extract bitcoin prices.

#bitcoin

crypto= btc[['Date','Adj Close']]
crypto= crypto.rename(columns = {'Adj Close':'BTC'})
# 7 day moving average

crypto[ 'BTC_7DAY_MA' ] = crypto.BTC.rolling( 7).mean()

A rolling average or moving average is a way to analyze data points by creating a series of averages of the data already present in the data. Here we calculate average prices based on the previous 7 days’ data of Bitcoin price. Moving averages are often used in technical analysis.

To read more on moving averages, visit this link.

Ethereum

Next, we try Ethereum. Ethereum is the 2nd largest cryptocurrency by market cap, after bitcoin. Ethereum went live on 30 July 2015 with 72 million coins.

#Ethereum

eth = web.DataReader("ETH-USD", 'yahoo', start, end)  # Collects data
eth.reset_index(inplace=True)
crypto["ETH"]= eth["Adj Close"]

# 7 day moving average
crypto[ 'ETH_7DAY_MA' ] = crypto.ETH.rolling( 7).mean()

Dogecoin

Next up is Dogecoin. We already discussed Dogecoin. It was introduced on Dec 6, 2013.

#doge coin

doge = web.DataReader("DOGE-USD", 'yahoo', start, end)  # Collects data
doge.reset_index(inplace=True)
crypto["DOGE"]= doge["Adj Close"]

# 7 day moving average
crypto[ 'DOGE_7DAY_MA' ] = crypto.DOGE.rolling( 7).mean()

BinanceCoin

Next, we proceed with Binance Coin. Binance was launched in July 2017 and is based on the Ethereum network. But Binance has its own blockchain, the Binance chain.

#BinanceCoin 

bnb = web.DataReader("BNB-USD", 'yahoo', start, end)  # Collects data
bnb.reset_index(inplace=True)
crypto["BNB"]= bnb["Adj Close"]

# 7 day moving average
crypto[ 'BNB_7DAY_MA' ] = crypto.BNB.rolling( 7).mean()

Cardano

Next, we take Cardano. Cardano is a public blockchain platform and peer-to-peer transactions are facilitated by its cryptocurrency ADA. It was launched in September 2017.

#Cardano

ada = web.DataReader("ADA-USD", 'yahoo', start, end)  # Collects data
ada.reset_index(inplace=True)
crypto["ADA"]= ada["Adj Close"]


# 7 day moving average
crypto[ 'ADA_7DAY_MA' ] = crypto.ADA.rolling( 7).mean()

Ripple is a payment system and currency exchange platform that can be used to process transactions all over the globe. XRP is deducted as a small fee, whenever users make a transaction using Ripple.

#XRP

xrp = web.DataReader("XRP-USD", 'yahoo', start, end)  # Collects data
xrp.reset_index(inplace=True)
crypto["XRP"]= xrp["Adj Close"]

# 7 day moving average
crypto[ 'XRP_7DAY_MA' ] = crypto.XRP.rolling( 7).mean()

Dash

Dash is an open-source cryptocurrency. It was forked from the Bitcoin protocol. It was launched in January 2014.

#Dash

dash = web.DataReader("DASH-USD", 'yahoo', start, end)  # Collects data
dash.reset_index(inplace=True)
crypto["DASH"]= dash["Adj Close"]

# 7 day moving average

crypto[ ‘DASH_7DAY_MA’ ] = crypto.DASH.rolling( 7).mean()

Now, with the data at hand, we format the dates.

#getting the dates 

crypto.set_index("Date", inplace=True)

Now, let us have a look at the data.

crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].head()
cryptocurrency data

As we can see all the data has been properly extracted.

Now, let us check the correlation between the data.

crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].corr()
cryptocurrency corelation

Now, we have some interesting revelations. All the data points have a high correlation with each other. Let us just compare bitcoin to the others, even the lowest correlation with DOGE is 0.237, which is quite a good value. Dash being forked from BTC, has the highest correlation with BTC at 0.77.

Looking at other data points, BNB and XRP have a high correlation of 0.93 which is extremely high. It is as if, they are the same value.

Now let us understand why? Well, it is simple. The crypto market follows trends. When Bitcoin and Dogecoin were rising, other coins also increased in value. This was mainly due to public sentiment regarding crypto. Who doesn’t want to look cool in front of friends saying that they brought cryptocurrency?

And similarly, when the values of BTC and DOGE fell, others also fell. It was like a chain reaction.

Let us look at the correlation heatmap.

#heatmap

plt.figure(figsize = (10,10))
sns.heatmap(crypto[['BTC','ETH','DOGE','BNB','ADA','XRP','DASH']].corr(),annot=True, cmap='Blues')
heatmap

The heatmap clearly shows the high correlation between the prices of all cryptocurrencies.

Let us plot the data using Plotly express.

fig = px.line(crypto, y=["BTC",'ETH','DOGE','BNB','ADA','XRP','DASH'] )
fig.show()
plot data

Well, only the BTC crash in mid-May 2021 is clear. But let us have a look at BTC 7 day moving average values.

fig = px.line(crypto, y=['BTC_7DAY_MA'] )
fig.show()
btc 7 day moving average

An interesting thing about Plotly is that we can interact with the Plot and get the exact values, kind of like we can do in Power BI.

Here, it is clearly visible that the BTC price suddenly increased in Feb 2021 after all those tweets and social media buzz. And suddenly in May 2021, everything came crashing.

Let us try Ethereum.

fig = px.line(crypto, y=['ETH'] )
fig.show()
cryptocurrency ethereum

And, it is clear that ETH also follows a similar pattern. In April 2021 end, everyone saw the sudden rise in prices of BTC and DOGE and bought ETH. This led to a sudden increase in the price of ETH as well.

Moving Average values:

fig = px.line(crypto, y=['ETH_7DAY_MA'] )
fig.show()
cryptocurrency moving average ethereum

The mountain fell down as quickly as it rose. People who bought at the high faced enormous losses.

DOGE:

fig = px.line(crypto, y=['DOGE'] )
fig.show()
doge

The rise and fall of DOGE is also interesting. In Jan 2021, DOGE was nothing, and in early May 2021, it had risen a lot. And its fall was also sudden.

Moving Average Values:

fig = px.line(crypto, y=['DOGE_7DAY_MA'] )
fig.show()
moving average dogecoin

The code for plotting all the other data is pretty much the same. I will leave a link to the Kaggle notebook where I coded all this in the end.

Conclusion

We now pretty much understand what caused the crash. The entire crypto market seems to related to each other. People see someone buying BTC, they go buy ETH. Someone sells DOGE, they also sell their BTC. It is all interrelated.

The crypto market is highly volatile, various factors lead to the frenzied selloff. One of the largest cryptocurrency exchanges in the world, Coinbase faced service disruptions during this selloff. Many Crypto investors had invested because they thought Tesla and Elon musk was into Bitcoin and thought of it as the next thing in finance and currency.

Many critics have said that this lack of regulation and price manipulation makes Crypto risky for new investors, and many people lost their money this fall.

Code Link: Analyzing the Crypto Crash of May 2021

About me:

Prateek Majumder

Data Science and Analytics | Digital Marketing Specialist | SEO | Content Creation

Connect with me on Linkedin.

Thank You.

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.

Prateek is a dynamic professional with a strong foundation in Artificial Intelligence and Data Science, currently pursuing his PGP at Jio Institute. He holds a Bachelor's degree in Electrical Engineering and has hands-on experience as a System Engineer at TCS Digital, where he excelled in API management and data integration. Prateek also has a background in product marketing and analytics from his time with start-ups like AppleX and Milkie Way, Inc., where he was involved in growth campaigns and technical blog management. Recognized for his structured thinking and problem-solving abilities, he has received accolades like the Dr. Sudarshan Chakraborty Award for Best Student Performance. Fluent in multiple languages and passionate about technology, Prateek continues to expand his expertise in the rapidly evolving AI and tech landscape.

Responses From Readers

Clear

Jim Parshall
Jim Parshall

Thanks a lot. Great tutorial! Lots of good infos and a great intro to analyzing your own data from crypto.

krizz
krizz

Good to see the data, this data help to understand the crypto industry. very informative content. thank you for sharing this.

Henry ogigi
Henry ogigi

I want too know about this

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details