-
Notifications
You must be signed in to change notification settings - Fork 0
/
correlation.py
46 lines (33 loc) · 981 Bytes
/
correlation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas_datareader as web
import mplfinance as mpf
import datetime as dt
import matplotlib.pyplot as plt
import seaborn as sns
currency = "USD"
metric = "Close"
start = dt.datetime(2020,1,1)
end = dt.datetime.now()
crypto = ['BTC', 'ETH', 'LTC', 'XRP', 'DASH', 'SC']
colnames = []
first = True
for ticker in crypto:
data = web.DataReader(f"{ticker}-{currency}", "yahoo", start, end)
if first:
combined = data[[metric]].copy()
colnames.append(ticker)
combined.columns = colnames
first = False
else:
combined = combined.join(data[metric])
colnames.append(ticker)
combined.columns = colnames
plt.yscale('log') # first show linear
for ticker in crypto:
plt.plot(combined[ticker], label=ticker)
plt.legend(loc="upper right")
plt.show()
# # Correlation Heat Map
print(combined)
combined = combined.pct_change().corr(method='pearson')
sns.heatmap(combined, annot=True, cmap="coolwarm")
plt.show()