Lately, I study time series to see something more out the limit of my experience. I decide to use what I learn in cryptocurrency price predictions with a hunch of being rich. Kidding? Or not :). As I see more about the intricacies of the problem I got deeper and I got a new challenge out of this. Now, I am in a process of creating something new using traditional machine learning to latest reinforcement learning achievements.

So the story aside, I like to see if an AI bot trading without manual help is possible or is a luring dream. Lately, I read a lot about the topic from traditional financial technical analysis to latest ML solutions. What I see at the ML front is many people claim to use lazy ML with success and sell deceitful dreams.What I call lazy ML is, downloading data , training the model and done. We are rich!! What I really experience is they have false conclusion induced by false interpretations. And the bad side of this, many other people try to replicate their results (aka beginner me) and waste a lot of time. Here, I like to show a particular mistake in those works with a accompanying code helping us to realize the problem better off.

Briefly, this work illustrates a simple supervised setting where a model predicts the next Bitcoin move given the current state. Here is the full Notebook and to see more advance set of experiments check out the repo. Hope you like that.

Before we start, lets lay down two main assumptions generally deemed true in market literature.

• All information describing the market is hidden under the price values.

• We go Semi-Markovian, meaning each prediction only depends on the present state.

Now, what we do here is very simple. Given the state as High, Low, Open, Closeprice values of the present step we like to predict the price direction at the next step which is categorized as Up, Down or Same.

First, we read Bitcoin price history downloaded from here into a Pandas dataframe, convert any row to a difference from the previous time step and drop None rows. That is, each row is a difference btw the time t and time (t-1) for each columns.

Split the datainto train and test by taking the date 2017-7-1 is the split point. So we use the market data after 2017-7-1 as the test set. That gives us 262541 steps for training and 53319 steps for testing.

Compute labels at each time step (t) as Up, Down or Same. If the label is Up, the price is predicted to increase at time (t+1).

Let’s define the magic box with Keras. This is a basic 4 layers fully connected network. You can play around the architecture as you like for your run.

Train the model and enjoy the progress bar ðŸ™‚

This is where I stop the learning. You should also see similar values.

Before we see the model performance, first we measure the baseline values. Considering the Bitcoin craze, If wealways predict UPwe already get ~0.22 accuracy.

Random prediction also obtains~0.41 accuracy. Now measure the model performance and see if we get something better.

We obtain 0.47 accuracy which is better than random and shows our model is keen to learn something. Most of the people stop here and believe that things gonna work out when you stream the real data. No!! it is not done yet.

Let’s plot the predictions and see what actually goes wrong. What we see here is the color coding of our prediction at each time step.Green is Up, blue is Same and red is Down.

The broken thing here, if we look carefully, the model only predicts what we have at the previous time step. If price stayed the same, it predicts Blue. If price was up before, it predicts Green and so on. With a model like this, it is normal to measure good accuracy since it is natural to expect Up move, if it went Up previously. It is a good catch for a Kaggler but not a trader.

That I can say, trained model is not generalizing the knowledge to help us but memorizing basic rules which makes it useless in a real-life.

I like to keep it brief. What I aim to pin here is not that ML is useless for this problem. ML is definitely helpful with more advance constructs. Just don’t expect to download data, train the model and be rich :).

If you are really interested in using ML in trading, I suggest you to start from the rudiments. Initially use ML for creating helping signals. It might merely use traditional financial indicators and signal certain complex conditions. However, do not rely on ML from the start and use it as a side-kick.

Note that, I try to keep things simple here but you might like to include many other features like financial indicators using the great library TA-Lib. Also, you might use other basic ML models. Or you can type a regression problem and predict the real price changes. I assure you the result will be the same. Some of such experiments are on the repo as well.

What about RNN? I should also point out that RNN (or LSTM, GRU) has far worse memorization problem. If youtrain RNN for regressing the relative price change, what it does is predicting a small variance over a previous time step price. Again, this gives satisfying model performance as Mean Squared Error is the concern but has no real use. Although this is a solution proposed by many blog posts, I once again assure you that RNN does not work too.

Last remarks, I believe ML has a huge playground at the nascent Crypto market for two main reasons. The first, since many people are just new in trading, they tightly follow well studied buy/sell patterns with no cannier selections. So this means a pattern and can be learned by ML. The second, cryto market is a wild game. Things are so volatile. Things go up 100% or down 200% over a night. It is great opportunity for good traders but it is not possible to eye all the crazy volatile market. So this is just a great reason to use AI to help us and expand the horizon we anticipate.

Pls let me know what you think. Also feel free to ping me if you have something new or you like the notion of AI based trading. I personally start to use ML to do what I propose above. We could enjoy it together. Best!!