Can we predict Bitcoin prices using machine learning?

Published by Dr. Stylianos Kampakis on

predicting bitcoin prices

Wanna become a data scientist within 3 months, and get a guaranteed job? Then you need to check this out !

Bitcoin and machine learning

Something that I’ve been asked a lot is whether it is possible to predict Bitcoin (or any other’s cryptocurrency’s prices) in order to make a profit. With the size of the cryptocurrency market right now being in the range of billions worth of dollars, it makes sense to ask this question.

Forecasting time series, financial or otherwise, is not an easy task. You have to integrate lots of different kinds of data, and in the case of cryptocurrencies, the system can suffer from random exogenous shocks. The markets are very emotional, and on this we have to add market manipulation and unexpected events, such as SEC trying to regulate crypto exchanges.

In the chart below you can see how Bitcoin’s price peaked at $20k on Bistamp, with it crashing a few days later. Around 55k transactions took place, with the majority of the traders selling Bitcoins in a panicked attempt to stop the losses.

bitcoin price chart

So, under such a volatile environment, can you predict Bitcoin prices? And what kind of information you need? It is easy to use the standard candlestick information (open-close-high-low-volume), but what about social media, and sentiment analysis, and tracking telegram groups and all these different sources of data?

Most traders go with either fundamental or technical analysis. A very good overview of the topic with regards to cryptocurrencies can be found here, quoting:

“While fundamental analysis is centered on calculating the underlying value of the coin, technical analysis is mostly unconcerned with a coin’s intrinsic value. Instead, technical analysis attempts to the predict the future price movement of an asset solely based on past trading data and market sentiment.”

Technical analysis is the way to go if you are interested in short term fluctuations in price. However, there are many different indicators and patterns, with different parameters and it is not always clear which one to choose. Some example indicators include the relative strength index, moving averages, head-and-shoulders, the stochastic oscillator and many more.  Also, the best parameters for each indicator might change over time, since the market reacts to different external signals (regulations for example). This is when using something more sophisticated, like machine learning can greatly help.

Bitcoin prices and reinforcement learning

I’ve done extensive research into the subject, mainly in collaboration with Innopolis University and a few private individuals. I’d like to make a big statement here. It is possible to predict Bitcoin prices to some extent. However, there are two things you need to keep in mind:

  1. Prediction do seem to be nearly impossible after a certain timespan. I believe it is very difficult to predict price more than a few days ahead.
  2. If you want to profit, maybe instead of trying to predict prices you should focus on creating an agent that can benefit off volatility. This is where reinforcement learning really shines.

So, here are two example graph from a model I developed, where I make hourly predictions about Bitcoin’s price. You can see that the model follows the trend pretty closely and that in most cases the true values fall between the 99% confidence interval (upper confidence interval is represented by the green line, the lower one by the red line). The algorithm is using over 60 indicators with different parameter settings which allows it to adapt to changes in the market.

bitcoin predictionbitcoin prediction

These predictions happen on an hourly  basis, so using this model it is possible to make up to 24-trades in a day. However, there is still some variance in the predictions which can reduce our margin significantly. This is where using a reinforcement learning agent can help us devise an optimal strategy.

DEEP Q-LEARNING for bitcoin algorithmic trading

I used deep q-learning to develop an agent that can understand the optimal positions to buy and sell. The ideal agent buys multiple times during a crash, and then sells when the price rises. A problem with reinforcement learning in this scenario, is that some agents end up holding a position for too long, because Bitcoin last year had a rising trend. For this reason, the agent is penalised if it is holding for too long. The results after many simulations is an agent with positive expectation in reward, even if the volatility in rewards can range from anything between 5% to 70% over the course of a month.

In the figure below you can see the agent performing multiple trades over the course of 45 days that also include the Bitcoin price crash. The expectation is still positive, mainly owing to the agent’s ability to perform multiple buys and sells, thus reducing risk by not betting into the long-term performance of Bitcoin.

reinforcement learning bitcoin trading

So, to answer the original question posed by the article, is it possible to predict Bitcoin prices? Yes, but if you are looking into making a profit through trading, maybe there are better ways to approach the problem, like using reinforcement learning. If you have any questions or comments, simply get in touch.

Wanna become a data scientist within 3 months, and get a guaranteed job? Then you need to check this out !

Dr. Stylianos Kampakis is the owner and author of The Data Scientist.


Thesaus · March 24, 2018 at 1:00 pm

Thanks – not to be critical but this is the trouble with approaching this from an academic standpoint or only running tests on historical data.

1. You state that the deep Q agent had a positive expected return despite volatility ranges of 5-70% over the course of the month. In reality if this was this case in a live trading environment then you could in theory get financial backing of 200K and only let your algorithm trade for one cryptocurrency and you would – in theory make money every month.
2. You also stated the deep Q agent held your currency for too long in some time periods – to it being trained in a period where the currency had a rising trend.

The behaviour pointed out in point (2) seems to suggest one could not realistically make money using deep Q learning run trading strategies alone. Perhaps in a small alocation in a well constructed portfolio but an agent holding too long during a significant decline in a equity/currency could wipe out your whole profits.

The problem with many of the academic papers in this area is that people do not trade with live money. Those who do trade with live money work for quant hedge funds and do not publish their ideas on portfolio construction for obvious reasons.

Dr. Stelios · March 24, 2018 at 7:55 pm

Hi Thesaus,

1. Yes, that is correct. The return in all simulations was positive, but I am working on improving convergence and reducing volatility.

2. This is not academic work, that’s why I omit most details. This is part of a work that is going into a trading fund.

Comments are closed.