Wanna know more about data science? Make sure to check out my events and my webinar What it's like to be a data scientist and What’s the best way to become a data scientist !
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.
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?
“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:
- 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.
- 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.
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.
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.