Analysing the Cryptocurrency of May 2021 | Python for Finance basics

Prateek Majumder 24 Jun, 2022 • 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:

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 Majumder 24 Jun 2022

Prateek is a final year engineering student from Institute of Engineering and Management, Kolkata. He likes to code, study about analytics and Data Science and watch Science Fiction movies. His favourite Sci-Fi franchise is Star Wars. He is also an active Kaggler and part of many student communities in College.

Frequently Asked Questions

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Responses From Readers

Clear

Jim Parshall
Jim Parshall 02 Jun, 2021

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

krizz
krizz 02 Jun, 2021

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 03 Jun, 2021

I want too know about this

Henry ogigi
Henry ogigi 03 Jun, 2021

Really want too know more about this

helen
helen 25 Jun, 2021

Hello there, I am glad today cos i have finally found a true and reliable trader. Haven lost over $10,000 in an attempt to get a trustworthy trader until I was finally introduced to Alex Meyer by a friend. When I contacted him he told me about trust and transparency and I was a little skeptical and decided to start my trade with just $1,000 and in less than 7 days I got a profit of $3,000 and I reinvested another $5,000 and I made a whooping interest and since then he has been my path way to financial freedom. If you are in need of a diligent and trustworthy trader, seek no further contact Email : [email protected] Whatsapp : +1 (213) 542 0660

Badrul
Badrul 14 Jul, 2021

Yahoo finance API has now changed, causing issued (see https://365datascience.com/question/remotedataerror-unable-to-read-url-for-yahoo-using-pandas-datareader/)

Victoria ChangeNOW
Victoria ChangeNOW 23 Jul, 2021

Indeed, crypto market is extremely volatile. It can be affected by literally one tweet from one person. I honestly doubt it can ever be accurately predicted, but it's very interesting to see various methods applied to data analyzing.

Binance Kapatma
Binance Kapatma 25 Nov, 2021

You have prepared a great coin content. thanks.

Hannah
Hannah 06 Feb, 2022

Hello there, as a newbie to crypto currency trading, I lost a lot of money trying to navigate the market on my own. In my search for a genuine and trusted trader, i came across David Benjamin who guided and helped me make so much profit up to the tune of $40,000. I made my first investment with $1,000 and got a ROI of $9,400 in less than 8 days. You can contact this expert trader via email [email protected] or on WhatsApp +1 408 500 0775 and be ready to share your own testimony

Alisha Russell
Alisha Russell 22 Apr, 2022

It will be bad to keep this to myself. I came across the best binary expert Crypto who really helped me to invest, he is very honest and diligent in his work. All I did was invest $1500 and within 7 days he made $15000 profit for me. Contact him via email: [email protected]

Petter
Petter 09 Dec, 2023

Best written article nice sharing...

Petter
Petter 09 Dec, 2023

Osam written and article nice sharing...

Time Series
Become a full stack data scientist