import pandas as pd import time import seaborn as sns import matplotlib.pyplot as plt import datetime import numpy as np # get market info for bitcoin from the start of 2016 to the current day bitcoin_market_info = pd.read_html("https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end="+time.strftime("%Y%m%d"))[0] # convert the date string to the correct date format bitcoin_market_info = bitcoin_market_info.assign(Date=pd.to_datetime(bitcoin_market_info['Date'])) # when Volume is equal to '-' convert it to 0 bitcoin_market_info.loc[bitcoin_market_info['Volume']=="-",'Volume']=0 # convert to int bitcoin_market_info['Volume'] = bitcoin_market_info['Volume'].astype('int64') # look at the first few rows bitcoin_market_info.head() from keras.models import Sequential from keras.layers import Activation, Dense from keras.layers import LSTM from keras.layers import Dropout def build_model(inputs, output_size, neurons, activ_func = "linear", dropout =0.25, loss="mae", optimizer="adam"): model = Sequential() model.add(LSTM(neurons, input_shape=(inputs.shape[1], inputs.shape[2]))) model.add(Dropout(dropout)) model.add(Dense(units=output_size)) model.add(Activation(activ_func)) model.compile(loss=loss, optimizer=optimizer) return model # random seed for reproducibility np.random.seed(202) # initialise model architecture eth_model = build_model(LSTM_training_inputs, output_size=1, neurons = 20) # model output is next price normalised to 10th previous closing price LSTM_training_outputs = (training_set['eth_Close'][window_len:].values/training_set['eth_Close'][:-window_len].values)-1 # train model on data # note: eth_history contains information on the training error per epoch eth_history = eth_model.fit(LSTM_training_inputs, LSTM_training_outputs, epochs=50, batch_size=1, verbose=2, shuffle=True) #eth_preds = np.loadtxt('eth_preds.txt')