Final Post – A Framework for Creating an AI Trading Model

I have mentioned it before – if accurately predicting cyrpto currency price data was as simple as predicting the weather with Neural Network models – then I would be a very wealthy author. However, these past weeks I have come up with a general approach to creating a trading bot:

  1. Connecting to an exchange
    • First off is choosing an exchange. Obviously, this exchange must allow for an API in order to apply programmatic trading. For now – we are using the Binance API. However, even this is becoming ever more limited. In the US, only the Binance.US domain is accessible – and recently there have been reports that US banking transactions will be halted with Binance.
  2. Training a Model
    • Once data can be queried from an exchange programmatically – the next step is to train a model to predict future outcomes. We used TensorFlow – by far the most challenging aspect will be formatting the data correctly to train a viable model. All of these models distilled to their core amount to an ungodly amount of linear algebra (remember eigenvalues?). Thankfully, you won’t necessarily need to go that deep into the data structuring. There are excellent sources on how to develop and train AI models that specialize in time-series forecasting (hint – trading data is time-series data): https://www.tensorflow.org/tutorials/structured_data/time_series. In our case – we are exploring 1D Convolutional and Recurrent Neural Network models.
  3. Evaluating a Model
    • Without going into too much detail, a there a many ways structure models – such as number of layers or layer types or nodes in each layer. I will defer to the tensorflow tutorial link above to describe the different combinations. The most popular approach to evaluation is two-fold after splitting the training data into training, validation, and test datasets. First – train a model and track the validation loss – you want to minimize this value. Next, evaluate it against the test dataset. If the model is well trained, it will generalize but not overfit (i.e. just memorize the training data exactly) the training data. Evaluating against the test data set (totally unseen data) will act as the canary in the coalmine to confirm that the validation loss results are valid. If losses are sufficiently minimized, save the model and move on to executing the model.
  4. Deploying a Trained Model
    • This is currently where are group is out. So you trained a model and it looks alright using the training data – now what? There’s a few things to consider:
      • First – you want to create a bot that constantly looks at new data and make decisions. So to start – making a while loop that queries some timeframe of trading data every X seconds, minutes, hours etc. will give you data to make a prediction againt.
      • Next – load the trained model, and make a prediction in the future based on the queried input data.
      • Next – You know how to make a prediction. Time to deploy a trading strategy. The simplest would be to see if the predicted price is expected to be higher – then execute a buy. Vice versa – execute a sell. A smarter approach might to be to use a threshold – where if the price isn’t expected to move up or down by X% – do nothing. This will stop the model from being oversensitive.
      • Last – Program in protections. What if some time has gone by? – maybe it’s time to retrain the model so that predictions are based on recent activity. What if prices are moving way beyond thresholds? – this could indicate a major shift in trading conditions. Perhaps a rule to tell the model to wait X amount of time and then retrain can help the model stay relevant. Once these rules have been made – final step would be to make the model wait on a schedule to make routine predictions and see if any of the checks are triggered to force a retrain. For each prediction – execute a buy/sell/or do nothing according to the trading strategy you chose. Continue until rich.
Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *