Bitcoin is a very particular asset. Its price is sensible to demand and supply rather than external factors, so it may highly depend on perceived trends rather than perceived information. For this category of problems, pattern recognition may prove incredibly useful.
Because this problem is very big, from beginning to end, I will begin with the first part of the article by Mining Bitcoin Data.
In the second part, I will be setting up LSTM to predict the upcoming Bitcoin price. Because the necessary computing power to run the code won’t be enough for a regular notebook, I will be renting computing power from Q Blocks. In the next article, I will reserve a full part on how to connect to their notebook to speed up your performances using peer to peer distributed GPU.
After having set everything to run on the Q Blocks platform, I will be explaining in detail how the LSTM model works and estimate the accuracy of the final model.
import json
import urllib.request
import pandas as pd
With the following functions I will be able to decode UTF-8 data and group the data into chunks (weeks, specifically). For now, I won’t be entering into details, but with further code will require the use of those two main functions.
def group_chunks(df, id_loc, value_loc): #df, 0, 1
def average(list1):
sum1 = 0
for _ in list1:
sum1 += _
return sum1/len(list1)
#convert DataFrame into a dict with a unique value per timestamp
mydict = {}
for x in range(len(df)):
currentid = df.iloc[x,id_loc]
currentvalue = df.iloc[x,value_loc]
mydict.setdefault(currentid, [])
mydict[currentid].append(currentvalue)
mydict
#convert dict into a list
dictlist = list()
for key, value in mydict.items():
temp = [key,value]
dictlist.append(temp)
#convert to DataFrame
dictlist = pd.DataFrame(dictlist)
dictlist
#average of multiple values
dictlist[1] = dictlist[1].apply(lambda x : average(x))
return dictlist
The only manual intervention you will have to do in this code is to specify when the weeks have to be counted. Because I am downloading data for the last 5 years, I will specify 2015 as the initial date.
#mining #artificial-intelligence #recurrent-neural-network #machine-learning #bitcoin #deep learning