Best technical indicators for Bitcoin from TA-lib

Berend
Coinmonks
Published in
5 min readMar 11, 2022

--

This article is written by Berend Gort & Bruce Yang, core team members of the Open-Source project AI4Finance. This project is an open-source community sharing AI tools for finance, and a part of the Columbia University in New York. GitHub link:

Introduction

This story is based on my previous article, and summarizes my personal results:

A pipeline was constructed which allows for feature importance measurements and neural network design for deep reinforcement learning. After working with my own pipeline for a week, we have identified the best features from TA-lib (technical indicator library).

TA-lib overview

The following few figures show which technical indicators we tested. We have not focused yet on pattern recognition indicators as they require special attention.

https://mrjbq7.github.io/ta-lib/

Adding these features to the Binance Processor

Compared to the old processor from my previous article, we changed the class method add_technical_indicators(), line 47.

I added a new function in a separate cell called get_features_for_each_coin()

That function is now a special function to download all technical indicators from TA-lib, and looks like the code in the next snippet.

Note that not all of them are there as we already did some feature selection on the complete list of technical indicators present in TA-lib. In the next section we will explain what we did.

High correlation filter

A high correlation filter is quite simple to apply, but very necessary in order to have a good performance on the predictability of your target. Imagine every feature is highly correlated to the other feature, or even completely identical, why would you add that feature? It contains almost the same information as the feature you already had.

That is why we need to remove these highly correlated features.

Example of current DF with 40 features

First from the original data we drop the target again

Then we plot a heatmap:

The result looks as follows:

Crypto features heatmap

In this figure, first take a look at the diagonal axis. Here every color corresponds to fully correlated, or 1. That is, for example, the open feature is completely correlated to the open feature itself, as they contain exactly the same information.

Also, it is important to note the negative correlations (in red) as well; for example the feature minus_di is completely negatively correlated to the macd. Therefore, we can remove either of the two.

Now, lets say we want to drop all features with a (positive or negative) correlation higher then X. We can do that by computing the correlation matrix first:

Note that the correlation matrix will be mirrored around the diagonal, with all diagonal components equal to 1. So, whether we choose the upper triangular or lower triangular section of the correlation matrix, the diagonal elements should not be included. As a result, we’ve chosen the upper triangular. The following code does that:

Now we got our upper triangular matrix containing the residual information required to drop certain features which are highly correlated. So we are selecting the columns which are having absolute correlation greater than 0.95 and making a list of those columns named dropping_these_features:

The result looks as follows:

Then we have features which are not highly correlated and thus contain there own valuable information. We can now start the training process on these features.

Neural network design

After a trial and error process, we ended up with the following neural network. Compared to the original one (see my previous article).

The main difference is more complexity (extra layers), a higher state dimension (29 corresponding to the amount of features) and most importantly : dropout.

Dropout prevents overfitting by regularization. It is explained in detail in the following video:

The final train result looks as follows, and amounts to 75% accuracy on the test set:

Feature importance

Below the result of the importance of each feature is listed, based on the method described in my previous article:

The new features have a massive effect on importance as the error greatly went up went shuffling any columns. If you want a smaller model, you can always drop for example the last 10 features from this importance list and retrain.

Conclusion

These new features, and the new neural network, we improved the predictability of the price direction from 38% to 75%; a fine improvement. Now it’s time to implement all of this in our DRL!

Thanks for getting to the bottom of “best technical indicators for Bitcoin from TA-lib”!

~ Berend & Bruce

--

--