Last active
April 22, 2020 18:42
-
-
Save KenoLeon/a95cc575f741c15cbd3c5e46dbd45b88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| from tabulate import tabulate | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| import matplotlib.dates as mdates | |
| import matplotlib as mpl | |
| import matplotlib.dates as mdates | |
| ytdETH = 'pythonDev/ETHYTD.csv' | |
| ytdNMR = 'pythonDev/NMRYTD.csv' | |
| ytdBTC = 'pythonDev/BTCYTD.csv' | |
| # Notes: You need to copy paste from your browser the historical data from CMC into Excel and save as csv. | |
| # This is part of a bigger script, but also works in standalone mode, disregard the bottom chart. | |
| # Prettify the resulting chart in photoshop. | |
| def main(verbose = 1): | |
| # BTC | |
| df_BTC = pd.read_csv( | |
| ytdBTC, header=0, parse_dates=[0], index_col=0, squeeze=True, thousands=',') | |
| # REMOVE COLUMNS | |
| df_BTC.drop( | |
| columns=['Volume', 'Market Cap', 'Open*', 'High', 'Low'], | |
| axis=1, | |
| inplace=True) | |
| df_BTC = df_BTC.rename(columns={'Close**': 'Close'}) | |
| # REVERSE SORT | |
| df_BTC = df_BTC[::-1] | |
| # Calculate Index | |
| firstVal_BTC = df_BTC['Close'].iloc[0] | |
| df_BTC['index_BTC'] = (((df_BTC['Close']/firstVal_BTC)-1)*100) | |
| # ETH | |
| df_ETH = pd.read_csv( | |
| ytdETH, header=0, parse_dates=[0], index_col=0, squeeze=True, thousands=',') | |
| # REMOVE COLUMNS | |
| df_ETH.drop( | |
| columns=['Volume', 'Market Cap', 'Open*', 'High', 'Low'], | |
| axis=1, | |
| inplace=True) | |
| df_ETH = df_ETH.rename(columns={'Close**': 'Close'}) | |
| # REVERSE SORT | |
| df_ETH = df_ETH[::-1] | |
| # Calculate Index | |
| firstVal_ETH = df_ETH['Close'].iloc[0] | |
| df_ETH['index_ETH'] = (((df_ETH['Close']/firstVal_ETH)-1)*100) | |
| # NMR | |
| df_NMR = pd.read_csv( | |
| ytdNMR, header=0, parse_dates=[0], index_col=0, squeeze=True, thousands=',') | |
| # REMOVE COLUMNS | |
| df_NMR.drop( | |
| columns=['Volume', 'Market Cap', 'Open*', 'High', 'Low'], | |
| axis=1, | |
| inplace=True) | |
| df_NMR = df_NMR.rename(columns={'Close**': 'Close'}) | |
| # REVERSE SORT | |
| df_NMR = df_NMR[::-1] | |
| # Calculate Index | |
| firstVal_NMR = df_NMR['Close'].iloc[0] | |
| df_NMR['index_NMR'] = (((df_NMR['Close']/firstVal_NMR)-1)*100) | |
| # new Dataframe with indexes | |
| df_Spreads = pd.concat([df_BTC['index_BTC'], df_ETH['index_ETH'], df_NMR['index_NMR']], axis=1, keys=['index_BTC', 'index_ETH','index_NMR']) | |
| # Calculate spread | |
| df_Spreads['Spread BTC ETH'] = df_Spreads['index_BTC'] - df_Spreads['index_ETH'] | |
| sns.set(rc={'figure.figsize':(11, 6)}) | |
| plt.style.use('fivethirtyeight') | |
| plt.subplot(211) | |
| df_Spreads['index_BTC'].plot(linewidth=2) | |
| df_Spreads['index_ETH'].plot(linewidth=2) | |
| df_Spreads['index_NMR'].plot(linewidth=2) | |
| # print(df_Spreads.head()) | |
| plt.title('Index BTC ETH NMR') | |
| frame = plt.gca() | |
| frame.set_xlabel('') | |
| plt.legend() | |
| plt.subplot(212) | |
| ax = df_Spreads['Spread BTC ETH'].plot(kind='bar',width=1) | |
| ax.axhline(y=df_Spreads['Spread BTC ETH'].mean(), color='dimgray', lw = 1) | |
| ax.xaxis.set_major_locator(plt.MaxNLocator(6)) | |
| plt.title('Spread BTC ETH') | |
| frame = plt.gca() | |
| frame.set_xlabel('') | |
| plt.legend() | |
| plt.tight_layout() | |
| plt.savefig('pythonDev/img/spreadBTCETHNMR_2.png') | |
| if verbose != 0: | |
| print(df_Spreads['Spread BTC ETH'].mean()) | |
| plt.show() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment