Can Neural Networks Predict Price Movements?

A Preliminary Investigation

Victor Hogrefe
8 min readJun 19, 2018

Much is being said about using artificial intelligence to assist in trading, both on wall street and in the cryptocurrency game. However, there is a suspicious lack of actual data supporting one trading algorithm or another, or delivering substantial evidence that these automated trading bots are able to outperform the markets. Trading gurus such as Anton Kreil argue that algorithms have made short-term human trading a waste of time in the stock market, so the question becomes whether the same holds true for cryptocurrency? One of the major differences is that there is far less reliable information for algorithms to hold on to, and much more volatility, which could make trend prediction especially tricky.

In fact, the topic of artificial intelligence and market analysis is so vast that we decided to dedicate an entire research paper on building a complex machine learning model over the next few months, in partnership with talented data scientists (stay tuned for that). Curiosity, however, has motivated me to construct my own simple neural network here just to test the viability of the entire project, and to learn a thing or two about making predictions.

The major question I have, personally, is whether data from within the market is enough to predict its next move. Is pure technical analysis enough to consistently be right about the future, or do factors outside the market, such as politics, fundamentals, headlines and regulations override any market internal analysis?

The Setup

This implementation of a neural network is not aimed at maximizing profits, nor does it claim to be sophisticated in any way. It exists merely to falsify our null hypotheses, or at least give us some indication that they could be falsified:

H0a: Neural Networks cannot reliably predict the next opening bitcoin price.

H0b: Neural Networks cannot reliably predict the next closing bitcoin price.

H0c: Neural Networks cannot reliably predict bitcoin prices, two or three days in the future.

We choose Bitcoin here because it’s data is most easily available over larger timespans, curtesy of coinmarketcap.

Methodology

We constructed a regression neural network (NN) using R’s helpful neuralnet library. The goal of this NN is to make the simplest possible prediction, namely to correctly predict the next day’s opening price, given previous opening, closing, high and low prices, as well as trading volumes, of the last 13 days. The NN was then trained using a one year data set, and then tested on 253 previous opening days. The NN employed a relatively standard resilient back-propagation method, as well as using a “sum of squared errors” function to calculate its errors in the training phase.

Because Bitcoin is a continuously traded token, the time difference between a previous day’s closing data, and the next day’s opening data is extremely small. In our training data set, the average difference between closing and next day opening prices is just $1.02. This means that predicting the opening price is one of the simplest possible tasks. Presumably, upward or downward trends can easily be extrapolated a couple of minutes into the future.

For this reason, we have elected to test three distinct null hypotheses, each making claims about the predictability of prices further in the future. If we can detect that the NN is progressively worse at predicting events further removed in time, this could be a valuable tool for arguing against the soundness of our market-data-only approach.

All data is normalized, using the min-max scaling method. That is, all price data is transformed into a number on the interval [0,1]. This allows the NN to converge much faster and is common practice.

Training Phase

Given our 65 inputs and four hidden layers, the NN settles for the below distribution of weights, which will ideally predict the next opening price with sufficient accuracy.

If we plot predicted opening prices in our training data against true prices, we can easily see that the NN did very well. Even though there is some heteroscedasticity on the upper end of the distribution, a simple linear regression analysis tells us that the p-value, the probability that this correlation is due to chance, is almost zero. All this tells us is that our NN was successfully trained on our given dataset.

The greater variance at the top end of the distribution could be due to several factors. First, there is clearly less data available to the network at higher price levels, since Bitcoin only spent a few weeks above the $15 thousand mark. Second, during the dramatic spike in prices, we saw much faster price movements of greater magnitude, which our NN may not be able to comfortably predict.

The test data ranges from the 14th of August 2016 to the 23rd of April 2017. If we apply this data to the NN so that it can predict the next opening price, an interesting pattern emerges:

We can see that the inaccuracy at the upper end of prices has been dramatically exacerbated, showing that our NN struggles to predict the next opening price. In addition, our NN seems to consistently predict more conservative price changes. I find this bias towards lower price prediction difficult to explain. In fact, we should expect an opposite bias, because our training data included the bitcoin bubble of 2017, while our test data sees much less dramatic price movement. If the NN is over-fitted, it should be making more aggressive predictions than it does, showing some other factor is possibly overpowering that particular effect.

If we now attempt to test our NN on how far it can see into the future, we can challenge it to predict the next closing price. In our test data, the average difference between today’s closing price, and next day’s closing price is $2.50, more than twice as much as in our first set.

Pushing it even further, we may attempt to predict the closing price three days from now, which leads to a very confused looking NN.

In this version, we find that the average difference between predicted and real closing prices is $590, which, given this particular dataset means up to 46% error at the higher end of prices.

Discussion

It seems clear that our NN cannot really foresee price movements, either because there are no larger patterns in the data that can be learned, or because our NN is too simple to find them. However, it is able to make more or less accurate guesses about prices in the very near future, which is likely a result of a simple extrapolation of upward and downward trends. That is, if the price is already moving down, it is more likely to keep moving down at approximately the same rate, than it is to pivot and suddenly go up. Perhaps our NN even found some general rule about how long these upward and downward trends last, and when to expect a price reversal.

When we try to understand which patterns our NN has detected, or which patterns it is capable of foreseeing, we can also understand its limitations. Instead of giving it historical price data to test its accuracy, we can learn about its inner functioning by feeding it its own previously computed result. That is, next day’s price, as calculated by the NN, will now be considered today’s price, and so on. If we iterate this process many times, and record all newly predicted prices, the pattern inscribed in its neural pathways emerges.

This data shows that the NN is capable of more than just trend recognition. It does not simply keep going up or down, depending on the previous week’s direction, but has learned to pivot and reverse the trend given some unknown indicator. Feeding upon itself it seems to converge around some price in the future, as the waves of upward and downward price movement begin to become entirely composed of previous predictions instead of historical data.

The NN does not rest at this seeming equilibrium, but starts to confuse itself with this violent oscillation around some hypothetical limit, eventually diverging and falling into a state of permanent, yet uniform chaos. Even though this teaches us very little about Bitcoin prices, I thought this result was too cool to exclude.

Conclusion

The price of Bitcoin is determined by many factors, including previous prices and patterns. The problem is that our NN only has access to five types of data from within the market, and none from outside. Thus, the forces of crowd psychology, consumer confidence, good or bad headlines, political or regulatory decisions, the size of the Bitcoin network, the number of users, and merchant adoption are completely invisible to it. It may simply be the case that internal market data alone is not sufficient to make any kind of long term predictions, or foresee short term price fluctuations.

This is not to say that NNs as a whole are unable to predict the future or beat the markets. If a more sophisticated network manages to include and properly weigh these other factors, it is conceivable that it could vastly outperform other traders and simpler algorithms. Given these initial findings, we are motivated to move forward with our more serious machine learning model, and to hopefully learn more in the process. Stay tuned.

More where this came from

This story is published in Noteworthy, where thousands come every day to learn about the people & ideas shaping the products we love.

Follow our publication to see more stories featured by the Journal team.

--

--

Victor Hogrefe

Tech Entrepreneur, here to share thoughts on technology, politics and other philosophical musings.