Bitcoin Price Prediction from OrderBook Data

Rani Khalil
4 min readMay 28, 2020

--

Who wouldn’t want to predict the future price of an asset?

With a correct prediction of the price change in future timestamps, it provides traders an idea of the price movement going forward and whether is could be used to initiate a profitable trade.

The use of such a predictive system could easily be wrapped within a trading bot for automated use, if able of consistently producing reliable predictions.

When trading any asset one should be aware of the general sentiment around that asset; that is generally obtainable through news outlets as well as some further investigation into the general market and dependant factors. After coming to the decision on the expected performance a trader can then implement some technical analysis (short term/long term analysis on the chart) to determine whether to buy/sell and at what price he would be looking to buy/sell.

Types of orders:

When trading on a specific exchange there exists two main order types a trader can set:

1- Market Orders: These are orders that are settled immediately at the current market price.

Example: BTC is trading at 9800USD setting a maket order of 0.2 BTC is settled immediately at a cost of (9800*0.2)1960USD in exchange for 0.2 BTC

2- Limit Orders: Include orders that are set to trigger at specific price levels to either buy/sell an asset.

Example: BTC is trading at 9800USD setting a limit order of 0.2 BTC at 9700USD is settled when/if the price were to drop to 9700 at which the tranasction is settled at a cost of (9700*0.2)1940USD for 0.2 BTC

People don’t generally wait by the computer to initiate their ideal trade, but rather put in limit orders that help automate this step ensuring you buy or sell at your chosen price even if you are not behind the computer. Of course for your computer to execute that trade on your behalf it needs to be pre-funded and that amount held in the case this trade executes.

Orderbook:

All the limit orders placed by all the traders on the market are stored in what is called an orderbook. In other terms all trader’s sentiment around the asset are now digitalised in numeric form and include the following key features: Buy(bid) or Sell(ask)? How much of the asset (amount)? At what price level (price)?

Orderbook visualisation from cryptowat.ch

But what is the current price?

Sounds like a weird question to ask but just in case. If you are a buyer the current price is the least priced ask on the market when the trade is settled . Otherwise, if you are a seller you would be selling at the highest bid at that time.

Orderbook Visualisation:

Using this data the prediction of the price movement can be monitored and predicted through changes in the orderbook reflecting buying support or selling resistance.

Visualisation from tensorcharts.com

The above chart is a clear visualisation of the orderbook data layered above the actual price data. As a quick walkthrough the horizontal lines on the chart show the price levels were limit orders have been set:

Above the price → Sell orders

Below the price → Buy orders

Using this data a trader can make more informed decisions about the price level and the general sentiment of the market, as well as some key price levels other traders are interested in. Put that together and the price value can be now be analysed for a better understanding of the future movement of the price.

Modelling:

After the data was binned in percentage increments in roughly the same layout as the chart shown before the data was run through several models to attempt price movement. Data source: Kaiko

Baseline: The baseline model that was run was a logistic regression that aimed to classify the data into a binary value of Up/Down 1 time-step into the future (approx. 30s).

The baseline model scored a validation accuracy of just under 54%. Which to be honest is just a little better than a coin flip answer

Neural Networks: Other data modelling involved neural network classifications but this time split into three categories: Buy/Hold/Sell the data was given a safety factor and aimed at predicting 15 time-steps into the future (approx. 2 mins).

  • The first NN model attempted was a Sequential Dense layered network that was capable of achieving a high training accuracy of 0.96 which was a clear sign of overfitting since the validation accuracy was 0.71 (some adjustments would have included lower epoch number or smaller bin arrangements)
  • The second NN model was a (Long Short Term Memory) LSTM model also attempting the three category classification returned much better results: training accuracy was 0.76 and a validation accuracy of 0.80

When finally set on the LSTM as a final model and with some minor parameter optimisation the final test accuracy of the model was 0.80, further confirming the previous results obtained.

Future work:

  • Combination of executed trades alongside the orderbook data (since the orders located within the orderbook can be cancelled and not executed; in other words sometimes they are used to effect the way traders look at the market).
  • Amending some of the factors which might include the safety factor on the target classifier.
  • Some other bug fixes if present.

Hopefully you know understand a bit more about orderbook data and how it could be used in predicting the general trend of an asset’s price for future observations.

Please feel free to access the project on github here!

--

--