|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | + |
| 4 | +# load data of various cryptos from kaggle datasets: |
| 5 | +# https://www.kaggle.com/sudalairajkumar/cryptocurrencypricehistory/downloads/cryptocurrencypricehistory.zip |
| 6 | + |
| 7 | +# if you run in jupyter, simply make sure that all CSV files are in the same folder as the (.ipynb) notebook file |
| 8 | +# other IDEs should load the CSV filepath accordingly |
| 9 | + |
| 10 | + |
| 11 | +def create_csv(name): |
| 12 | + file_path = f'{name}_price.csv' |
| 13 | + return pd.read_csv(file_path, parse_dates=True, index_col='Date') |
| 14 | + |
| 15 | + |
| 16 | +dataset_to_create = ['bitcoin', 'bitcoin_cash', 'dash', 'ethereum_classic', |
| 17 | + 'bitconnect', 'litecoin', 'monero', 'nem', |
| 18 | + 'neo', 'numeraire', 'omisego', |
| 19 | + 'qtum', 'ripple', 'stratis', 'waves'] |
| 20 | + |
| 21 | +cryptos = [create_csv(currency) for currency in dataset_to_create] |
| 22 | + |
| 23 | +bitcoin = cryptos[0] |
| 24 | +bitcoin_cash = cryptos[1] |
| 25 | +dash = cryptos[2] |
| 26 | +ethereum_classic = cryptos[3] |
| 27 | +bitconnect = cryptos[4] |
| 28 | +litecoin = cryptos[5] |
| 29 | +monero = cryptos[6] |
| 30 | +nem = cryptos[7] |
| 31 | +neo = cryptos[8] |
| 32 | +numeraire = cryptos[9] |
| 33 | +omisego = cryptos[10] |
| 34 | +qtum = cryptos[11] |
| 35 | +ripple = cryptos[12] |
| 36 | +stratis = cryptos[13] |
| 37 | +waves = cryptos[14] |
| 38 | + |
| 39 | +dataset = [bitcoin, bitcoin_cash, dash, |
| 40 | + ethereum_classic, bitconnect, |
| 41 | + litecoin, monero, nem, neo, |
| 42 | + numeraire, omisego, qtum, |
| 43 | + ripple,stratis, waves] |
| 44 | + |
| 45 | +for item in dataset: |
| 46 | + item.sort_index(inplace=True) |
| 47 | + item['30_day_mean'] = item['Close'].rolling(window=20).mean() |
| 48 | + item['30_day_volatility'] = item['Close'].rolling(window=20).std() |
| 49 | + |
| 50 | +ethereum_classic[['Close','30_day_mean', '30_day_volatility']].plot(figsize=(10,8)); |
| 51 | +plt.title('Ethereum Closing Price with 30 Day Mean & Volatility') |
| 52 | +plt.ylabel('Price') |
| 53 | +plt.show() |
| 54 | + |
| 55 | +print(bitcoin['Close'].resample('A').mean()) |
| 56 | +print(bitcoin['Close'].resample('A').apply(lambda x: x[-1])) |
0 commit comments