def Update_trends(self): # Change to data directory os.chdir(self.home_dir + '\\Data') # define date my_cryptory = Cryptory(from_date="2018-05-01") # pull data from google trends df = my_cryptory.get_google_trends(kw_list=["cryptokitties"]) # save as csv df.to_csv('trends.csv', index=0) print("\nUpdated google trends data, saved in trends.csv\n") # change directory back to original os.chdir(self.home_dir)
def Update_ETH_price(self): # Change to data directory os.chdir(self.home_dir + '\\Data') # define date to pull from my_cryptory = Cryptory(from_date="2018-05-01") # get historical ethereum prices from coinmarketcap df = my_cryptory.extract_coinmarketcap("ethereum") # save as csv df.to_csv('ETH_price.csv', index=0) print("\nUpdated Ethereum price data, saved in ETH_price.csv\n") # change directory back to original os.chdir(self.home_dir)
def __init__(self, date_from, date_to, days=None, bitinfo_list=None, google_list=None, prediction_ticker='ltc'): if bitinfo_list is None: bitinfo_list = ['btc', 'eth'] if google_list is None: google_list = ['Litecoin'] cryp_obj = Cryptory(from_date=date_from, to_date=date_to) fin_table = cryp_obj.extract_bitinfocharts(bitinfo_list[0]) if len(bitinfo_list) > 1: for i in range(1, len(bitinfo_list)): temp_table = cryp_obj.extract_bitinfocharts(bitinfo_list[i]) temp_table = temp_table.drop(columns='date') fin_table = pd.concat([fin_table, temp_table], axis=1, join_axes=[temp_table.index]) prediction_table = cryp_obj.extract_bitinfocharts(prediction_ticker) prediction_table = prediction_table.drop(columns='date') if google_list: google_table = cryp_obj.get_google_trends(google_list) self.final_table = pd.concat( [fin_table, google_table, prediction_table], axis=1, join_axes=[prediction_table.index]) else: self.final_table = pd.concat([fin_table, prediction_table], axis=1, join_axes=[prediction_table.index]) if days is not None: self.days_out = days
X_test = [] Y_test = [] def get_mean(): global Y_mean return Y_mean def get_std(): global Y_std return Y_std #####GET GOOGLE TRENDS##### my_cryptory = Cryptory(from_date="2015-08-25", to_date="2018-04-04") trend1 = my_cryptory.get_google_trends(kw_list=['bitcoin']) trend2 = my_cryptory.get_google_trends(kw_list=['ethereum']) def generatedata_v1(isTrain, batch_size): """ Return data regarding cyrptocurrencies. """ # window for encoder and decoder's predictions. seq_length = 40 global Y_train global X_train global X_test
import re import plotly.graph_objects as go import time # initialise object # pull data from start of 2017 to present day from_date = "2013-04-28" to_date = "2020-03-21" to_date_bitcoin = "2020-03-20" from_date_cmp = time.strptime(from_date, "%Y-%m-%d") to_date_cmp = time.strptime(to_date, "%Y-%m-%d") lowest_date = '' highest_date = '' my_cryptory = Cryptory(from_date=from_date, to_date=to_date, timeout=100) coin_col = False coin = "bitcoin" def extract_coinmarketcap(coin, coin_col=False): try: output = pd.read_html( "https://coinmarketcap.com/currencies/{}/historical-data/?start={}&end={}" .format(coin, from_date.replace("-", ""), to_date_bitcoin.replace("-", "")))[2] except: # future versions may split out the different exceptions (e.g. timeout) raise
Created on 4 mrt. 2020 @author: stan ''' # load package from cryptory import Cryptory import datetime import matplotlib.pyplot as plt import pandas as pd import numpy as np import re import plotly.graph_objects as go # initialise object # pull data from start of 2017 to present day my_cryptory = Cryptory(from_date="2015-12-31", to_date="2020-03-21") dates = list(reversed(my_cryptory.extract_bitinfocharts("btc")["date"])) #print(dates) priceBTC = list(reversed( my_cryptory.extract_bitinfocharts("btc")["btc_price"])) #print(my_cryptory.get_google_trends(kw_list=['bitcoin'])) GoogleTrends = list( reversed(my_cryptory.get_google_trends(kw_list=['bitcoin'])["bitcoin"])) #Subreddit RedditData = my_cryptory.extract_reddit_metrics( "bitcoin", "subscriber-growth-perc")["subscriber_growth_perc"] #print("Length dates: {} ".format(len(dates))) #print("Length priceBTC: {} ".format(len(priceBTC)))
# load package from cryptory import Cryptory # initialise object # pull data from start of 2017 to present day my_cryptory = Cryptory(from_date="2017-01-01") ######## Basic Usage # get historical bitcoin prices from coinmarketcap my_cryptory.extract_coinmarketcap("bitcoin") # get daily subscriber numbers to the bitcoin reddit page my_cryptory.extract_reddit_metrics(subreddit="bitcoin", metric="total-subscribers") # google trends- bitcoin search results my_cryptory.get_google_trends(kw_list=["bitcoin"]) # dow jones price (market code from yahoo finance) my_cryptory.get_stock_prices(market="%5EDJI") # USD/EUR exchange rate my_cryptory.get_exchange_rates(from_currency="USD", to_currency="EUR") # get historical commodity prices my_cryptory.get_metal_prices() ######## Advanced Usage # generate price correlation matrix
print('Ended portfolio in EUR: {}'.format( locale.currency(EUROS, grouping=True))) print('% Profit/Loss: {}%'.format( round(((EUROS - startingPortfolio) / startingPortfolio) * 100), 2)) #Plotting results y_axis_breakeven = [] for i in range(0, len(y_axis)): y_axis_breakeven.append(startingPortfolio) #date_1 = datetime.strptime(x_axis[0], "%Y-%m-%d") #modifiedDate = date_1 + timedelta(days=1) modifiedDate = x_axis[0] my_cryptory = Cryptory( from_date=modifiedDate, to_date=presentDate) # First element of x_axis = start date of data priceBTC = list(reversed( my_cryptory.extract_bitinfocharts("btc")["btc_price"])) print(my_cryptory.extract_bitinfocharts("btc")) print("Length Portfolio: {} ".format(len(y_axis))) print("Length BTC Pric: {} ".format(len(priceBTC))) print("Length Break-even: {} ".format(len(y_axis_breakeven))) print("Start date: {} ".format(x_axis[0])) print("Start date modified +1: {} ".format(modifiedDate)) #Create dataframe df = pd.DataFrame({'Portfolio': y_axis}) df['BTC Price'] = priceBTC df['Break-even'] = y_axis_breakeven
from cryptory import Cryptory import pandas as pd my_cryptory = Cryptory(from_date="2017-01-01") pd.options.display.max_rows = 6 all_coins_df = my_cryptory.extract_bitinfocharts("btc") bit_info_coins = ['btc', 'eth', 'xrp', 'bch', 'ltc'] for coin in bit_info_coins[1:]: all_coins_df = all_coins_df.merge(my_cryptory.extract_bitinfocharts(coin), on='date', bow='left') import seaborn as sns import matplotlib.pyplot as plt import datetime fig, ax1 = plt.subplots(1, 1, figsize=(10, 4)) ca = plt.get_cmap('gist_rainbow') print(my_cryptory.head()) # Help on class Cryptory in module cryptory.cryptory: my_cryptory.extract_poloniex(coin1="btc", coin2="eth")
from cryptory import Cryptory import pandas as pd from dtaidistance import dtw import matplotlib.pyplot as plt from dtaidistance import dtw_visualisation as dtwvis from dtw_btc.templates import HeadAndShouldersTop, HeadAndShouldersBottom, TripleTopReversal, \ DoubleTopReversal, FallingWedge, DoubleBottomReversal, RisingWedge, TripleBottomReversal, \ BumpAndRunReversal, SymmetricalTriangle from dtw_btc.utils import normalize, denormalize, normalize_function_paper cryptory_from_date = Cryptory(from_date="2020-05-01") history_price_btc = cryptory_from_date.extract_coinmarketcap( "bitcoin").sort_values(by=['date']) list_of_dates = list(history_price_btc['date']) list_of_closes = list(history_price_btc['close']) len_list_of_closes = len(list_of_closes) patterns = [ HeadAndShouldersTop(), HeadAndShouldersBottom(), TripleTopReversal(), DoubleTopReversal(), DoubleBottomReversal(), FallingWedge(), RisingWedge(), TripleBottomReversal(), BumpAndRunReversal(), SymmetricalTriangle()
from cryptory import Cryptory import matplotlib.dates as mdates import seaborn as sns import matplotlib.pyplot as plt import datetime my_cryptory = Cryptory(from_date="2017-01-01") # btc_google = my_cryptory.get_google_trends(kw_list=['bitcoin']).merge( # my_cryptory.extract_coinmarketcap('bitcoin')[['date','close']], on='date', how='inner') # eth_google = my_cryptory.get_google_trends(kw_list=['ethereum']).merge( # my_cryptory.extract_coinmarketcap('ethereum')[['date','close']], on='date', how='inner') ltc_google = my_cryptory.get_google_trends(kw_list=['litecoin']).merge( my_cryptory.extract_coinmarketcap('litecoin')[['date', 'close']], on='date', how='inner') iota_google = my_cryptory.get_google_trends(kw_list=['iota']).merge( my_cryptory.extract_coinmarketcap('iota')[['date', 'close']], on='date', how='inner') # ripple_google = my_cryptory.get_google_trends(kw_list=['ripple']).merge( # my_cryptory.extract_coinmarketcap('ripple')[['date','close']], on='date', how='inner') doge_google = my_cryptory.get_google_trends(kw_list=['Dogecoin']).merge( my_cryptory.extract_coinmarketcap('Dogecoin')[['date', 'close']], on='date', how='inner')
class MyDataManager(): def __init__(self, date): self.crypto_data = Cryptory(from_date = date) self.bitcoin_data = self.crypto_data.extract_coinmarketcap("bitcoin") self.sc = MinMaxScaler() # Cleans the data to keep only the open column def clean_data(self): for col in self.bitcoin_data.columns: if col != "open": del self.bitcoin_data[col] # Creates the train data set def create_train_data(self): self.clean_data() training_set = self.bitcoin_data; training_set = self.sc.fit_transform(training_set) train_data = training_set[365:] # around 80% of the data is used for training # Split the data into x and y x_train, y_train = train_data[:len(train_data)-1], train_data[1:] return self.format_to_3d(x_train), y_train # Creates the test data set def create_test_data(self): test_set = self.bitcoin_data test_set = self.sc.transform(test_set) test_data = test_set[:364] return test_data # Plots the graph def plot(self, real_value, model): input = real_value input = self.sc.fit_transform(input) input = np.reshape(input, (364, 1, 1)) predicted_result = model.predict(input) predicted_result = self.sc.inverse_transform(predicted_result) print(real_value) plt.plot(real_value, color='pink', label='Real Price') plt.plot(predicted_result, color='blue', label='Predicted Price') plt.title('Bitcoin Prediction') plt.xlabel('Time') plt.ylabel('Prices') plt.legend() plt.show() # Format a 2D np.array to a 3D array def format_to_3d(self, df_to_reshape): reshaped_df = np.array(df_to_reshape) return np.reshape(reshaped_df, (reshaped_df.shape[0], 1, reshaped_df.shape[1]))
def __init__(self, date): self.crypto_data = Cryptory(from_date = date) self.bitcoin_data = self.crypto_data.extract_coinmarketcap("bitcoin") self.sc = MinMaxScaler()
# generate price correlation matrix import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # load package from cryptory import Cryptory import datetime # initialise object # pull data from start of 2017 to present day my_cryptory = Cryptory(from_date="2016-01-01") # get historical bitcoin prices from coinmarketcap my_cryptory.extract_coinmarketcap("bitcoin") all_coins_df = my_cryptory.extract_bitinfocharts("btc") # coins of interest bitinfocoins = ["btc", "eth", "xrp", "bch", "ltc", "dash", "xmr", "doge"] for coin in bitinfocoins[1:]: all_coins_df = all_coins_df.merge(my_cryptory.extract_bitinfocharts(coin), on="date", how="left") # date column not need for upcoming calculations all_coins_df = all_coins_df.drop('date', axis=1) corr = all_coins_df.pct_change().corr(method='pearson') # fig, ax = plt.subplots(figsize=(7,5)) # sns.heatmap(corr, # xticklabels=[col.replace("_price", "") for col in corr.columns.values], # yticklabels=[col.replace("_price", "") for col in corr.columns.values], # annot_kws={"size": 16}) # plt.show()