Cryptocurrencies heatmap correlation graph
Get live data from the web and compute data viz and analysis about different cryptocurrencies.
Tags: #cryptocurrency #eth #btc #heatmap #finance #trading
Author: Carlo Occhiena

Input

Install and import libraries

1
import datetime as dt
2
import matplotlib.pyplot as plt
3
try:
4
import seaborn as sns
5
except:
6
!pip install seaborn
7
import seaborn as sns
8
try:
9
import yfinance as yfin
10
except:
11
!pip install yfinance
12
import yfinance as yfin
Copied!

Setup your variables

1
# user settings (modify accordingly to Yahoo Finance parameters)
2
currency = "USD"
3
metric = "Close"
4
5
# Date
6
start = dt.datetime(2018,1,1)
7
end = dt.datetime.now()
Copied!
👉 Insert a range of cryptocurrencies; here you'll have correlation and heatmap
1
# pick your favorite list of cryptocurrencies
2
crypto = ['BTC', 'ETH', 'LTC', 'XRP', 'DASH', 'SC']
Copied!

Model

Get combined data

1
yfin.pdr_override()
2
3
colnames = []
4
5
first = True
6
7
for ticker in crypto:
8
data = yfin.download(f"{ticker}-{currency}", start, end)
9
if first:
10
combined = data[[metric]].copy()
11
colnames.append(ticker)
12
combined.columns = colnames
13
first = False
14
else:
15
combined = combined.join(data[metric])
16
colnames.append(ticker)
17
combined.columns = colnames
18
19
combined
Copied!

Output

Show heatmap and correlation

1
plt.yscale('log') # first show linear
2
for ticker in crypto:
3
plt.plot(combined[ticker], label=ticker)
4
5
plt.tick_params(axis="x", width = 2)
6
plt.xticks(rotation = "vertical", )
7
plt.margins(0.01)
8
plt.subplots_adjust(bottom = 0.15)
9
plt.legend(loc='lower center', bbox_to_anchor=(0.5, 1.05),
10
ncol=6, fancybox=True, shadow=False)
11
plt.show()
12
13
# Correlation Heat Map
14
combined = combined.pct_change().corr(method='pearson')
15
16
sns.heatmap(combined, annot=True, cmap="coolwarm")
17
plt.show()
18
print(combined)
Copied!
Copy link
Edit on GitHub