-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_correlations_2.py
50 lines (39 loc) · 1.43 KB
/
crypto_correlations_2.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
47
48
49
50
import pandas as pd
import pandas_datareader as web
import mplfinance as mpf
import datetime as dt
import matplotlib.pyplot as plt
import seaborn as sns
import requests
pd.set_option('display.max_columns', 30)
req = requests.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=25'
'&page=1&sparkline=false')
dataj = req.json()
li = [item.get('symbol').upper() for item in dataj]
ignore_usd = [x for x in li if not (x.endswith('USD') | x.startswith('USD'))]
list1 = ['WBTC', 'UST', 'DAI', 'STETH', 'CETH']
filtered = [x for x in ignore_usd if all(y not in x for y in list1)]
print(filtered)
currency = "USD"
metric = "Close"
start = dt.datetime(2021, 1, 12)
end = dt.datetime.now()
# crypto = ['BTC', 'ETH', 'BNB', 'ADA', 'DOT', 'LUNA', 'AVAX', 'LTC', 'XRP', 'SOL', 'MATIC', 'LINK']
colnames = []
first = True
for ticker in filtered:
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
# # Correlation Heat Map
print(combined)
combined = combined.pct_change().corr(method='pearson')
sns.heatmap(combined, annot=True, cmap="coolwarm")
plt.show()