Predicting Cryptocurrency Price With Tensorflow and Keras
5 stars based on
74 reviews
If you haven't read that, I would highly recommend checking it out to get to grips with the basics of LSTM neural networks from a simple non-mathematical angle. As anyone who's been on a date with me knows; I find small talk boring, so let's just jump right into it!
The first thing we will need is the data. Luckily, Kaggle have a fun dataset of minute-by-minute historical data set from Bitcoin which includes 7 factors. We will however need to normalise this dataset before feeding it into our network of LSTMs. We will do this as per the previous article where we take a sliding window of size N across the data and re-base to data to be returns from 0 where.
Now this being a multidimensional approach, we are going to be doing this sliding window approach across all of our github bitcoin price prediction. Normally, this would be a pain in the ass. We can represent each window as a Pandas dataframe and we can then perform the normalisation operation across the whole dataframe i.
The other thing you will notice with this dataset is that especially at the beginning, the data is not very clean. Whilst we're here, let's make these functions into a self contained class called ETL extract, transform, load and save it as etl. See the first time I tried to do this, github bitcoin price prediction machine shuddered to a halt and gave me a memory error.
The github bitcoin price prediction, you see, comes from the fact that the Bitcoin dataset, being a minute-by-minute dataset, is quite large. When normalised it is around 1 million data windows. In a nutshell; a generator iterates over data of unknown and potentially infinite length, only passing out the next piece every time it is called.
Technically speaking, if you made the windows small enough you could even train this model on your IoT toaster machine if you really wanted to! On its github bitcoin price prediction this was acceptable as it took around mins to get through the training data batches. However, if I wanted to tweak the model and re-run it, it would github bitcoin price prediction an awful long time to re-train it again. What can we do? Well, how about pre-normalising it then saving the normalised numpy arrays of windows to a file, hopefully one that preserves the structure and is super-fast to access?
HDF5 to the rescue! Through the use of the h5py library we can easily save the clean and normalised data windows as a list of numpy arrays that takes a fraction of a second IO time to access. The only extra thing we need to add in when predicting our test set is a generator function that iterates the generator and splits out the x and y outputs.
We then do the same but rather than predict on a a step-by-step basis we initialise a window of size 50 with the first prediction, and then keep sliding the window along the new predictions taking them as true data, so we slowly start predicting on the predictions and hence are forecasting the next 50 steps forward. Finally, we save the test set predictions and test set true y values in a HDF5 file again so we can easily access them in the future without re-running everything, should the model turn out to be useful.
We then plot the results on 2 matplotlib charts. One showing the daily 1-step-ahead predictions, the other showing steps ahead predictions. We then go for the forecasting of Bitcon price!
As per my last article, we will try and do two types of forecasts:. Here is the results of point-by-point predictions:. The results of this look like:. What can we see? Well, we can see that when predicting 1 github bitcoin price prediction ahead it's doing a very reasonable job.
Occasionally it's out, but in general it follows the true data quite well. However, the predictions do appear far more volatile than the true data. Without doing more tests it's hard to ascertain why this might be and if a model re-parameterisation github bitcoin price prediction fix this. When predicting the trend however this model starts to fall a bit on its face.
The trend doesn't seem particularly accurate to model and is inconsistent at times. What is interesting is the size of the predicted trend line does seem to correlate with the size of the price moves volatility. I am going to use this section to take off my AI hat and github bitcoin price prediction on my investment manager hat to explain a few key truths The main github bitcoin price prediction one should realise is that predicting returns is a pretty futile exercise.
I mean sure, it's the holy grail of forecasting to be able to predict returns, and whilst some top end hedge funds do try to do just that by finding new alpha indicators in truth it's a pretty github bitcoin price prediction thing to do due to the huge swaths of external influences that push github bitcoin price prediction asset price.
In real terms it's comparable to trying to predict the next step of a random walk. However, all is not lost and our exercise isn't completely pointless. See, whilst with limited time series data, even with multiple dimensions it's hard to predict returns, what we can see, especially from the second chart, is that there is an avenue there to predicting volatility.
And not just volatility, but we could also expand that to predict market environments in a way allowing us to know what type of market environment we are currently in. Why would this be useful? Well a lot of different strategies which I won't go into here work well in different market environments respectively. A momentum strategy might work well in a low vol, strongly trending environment whilst an arbitrage strategy might be more successful in producing high returns in a high vol environment.
We can see that by knowing our current market environment and predicting the future market environments are key to allocating the correct strategy to the market at any given time.
Whilst this is more of a general investment approach for traditional markets, the github bitcoin price prediction would apply to the Bitcoin market. So as you can see, predicting longer-term Bitcoin prices is currently as with all types of stock markets pretty hard and nobody can claim to do so from just the technical time-series data github bitcoin price prediction there are a lot more factors that go into the price changes.
Another issue which is worth touching on with the use of LSTM neural networks across a dataset like this is the fact that we are taking the whole time series data github bitcoin price prediction as a stationary time series. Github bitcoin price prediction is to say, the properties of the time series are assumed unchanged throughout time.
There is work that can be done help with this github bitcoin price prediction issue, the leading edge research of this currently focuses on using Bayesian methods alongside of LSTMs to overcome the issue of time series non-stationarity.
But that's far out of scope for this short article. I may make another post in the future detailing the implementation of this. In the meantime, feel free to browse the full code for this project on my GitHub page: About Articles CV Contact.
Dataset Time The first thing we will need is the data. Restrict yielding until we have enough in our batch. File filename, 'r' as hf: As per my last article, we will try and do two types of forecasts: Here is the results of point-by-point predictions: The results of this look like: Conclusion I am going to use this section to take off my AI hat and put on my investment manager hat to explain a few key truths