Financial Modeling Blog #2 Increasing BTC holdings using a RNN for short term forecasts
Code available on github
Introduction
I started developing neural networks to predict BTC price moves about two weeks ago. My previous post looked at my initial thoughts and attempts using a simple neural network. Since then I've implemented Tensorflow's LSTM and RNN (Recurrent Neural Network) modules to generate more accurate predictions, but this time using hourly data.
How the RNN (with LSTM cell) works
The RNN takes the previous week's hourly trading data (average price and volume for each hour) and outputs a prediction for the price and volume of the next hour. This is then fed back into the network 24 times to predict the daily price and volume. The R in RNN stands for recurrent meaning that the prediction for each hour is calculated by the network being given the previous hour's data and also information from the network its self after it processed the hour before's data. RNN's are quite complicated, but it is quite straight forward to use Tensorflow's built in classes.
Implementation
I decided to refactor the code from before, wrapping the Tensorflow code in a class called TimeSeriesForcaster which makes writing the code that uses the RNN much simpler and also creating a separate functions file to hold all the data manipulation (reading files, scaling data etc) functions cleaned up the code a lot. This means its quite straightforward to write scripts to use the RNN, where as before everything was done in one file and so altering what the NN predicted was difficult as I didn't want to lose functionality when editing the code.
Results - Trading strategy
The neural network seems to do a good job of predicting daily changes in price. The above price shows the value of a $1000 investment over period of 240 days if once a day I was to run the neural network, see if the price will increase and then buy / sell based on that predicted price. This is just a basic last minute test to evaluate the neural network, and it seems to do well on average, especially around the ATH. The period on the graph is the previous 200 days. The neural network was not trained on this data. If this was used with decent technical analysis then I am confident that the RNN could be used effectively to increase one's bitcoin investments substantially over the period of a year. The simulation does not account for trading fees.
Things to work on
The python code uses the RNN and the assumption that it's errors are normally distributed to generate a distribution of possible prices. This information is much more detailed than whether the price will increase or decrease and so could be used to develop a more complicated strategy - in particular, if I was able to forecast other the prices of other crypto currencies, techniques in artificial intelligence and genetic programming could be used to train agents to make better than human trading decisions.