Applying machine learning to cryptocurrency trading Paweł Duda


okay so hello everyone this is my second
presentation about Cryptocurrency trading month ago I covered the Elixir
part which was the API that communicated with exchange today I’ll talk a little
bit about how I applied the machine learning to improve the accuracy of my
classifier that trades crypto currencies so firstly I would like to say that at
the time of making this experiment I knew nothing about machine learning
skills I knew nothing about trading cryptocurrencies and I only have about 15 minutes to tell you all this so yeah hopefully it will work out somehow
and first I would like to start with a very simple thing a very simple example
of classification problem let’s say that we want to train a classifier that
recognizes geometric figures based on amount of sides so for example we want to recognize triangles quadrilaterals and pentagons this is
fairly simple I don’t think it can get any easier than that so on the left side
we have so-called features and on the right side the names that the
corresponding names of figures that we want to be recognized those are called
classes and we can also extract more features if we want to if the problem
gets more complex and we want to be able to recognize more complex patterns
so well in this case all that we have on the left side of this table is
called feature vector this this is a single data set that we can simply put
into array and on the right side we need to pre-fill the data set
with whatever we want to be recognized so this is the code in Python this is my
“Hello World” of machine learning and this all it takes to train this classifier firstly we have two data sets only one data set X
is the array of feature vectors in our case it’s only sides and Y is array of the classes that are corresponding so this is our training
dataset the next lines where we instantiate the classifier and we simply
fit our data and then we can test we have another data set usually you don’t want to test the data set on the same thing as you trained it and
in our case as we can see below the this is 100 percent correct and we also
get correct we can recognize the geometric figures correctly so this is
very simple example this is basically the first thing I made in machine
learning and unfortunately in my case the trading problem that I wanted to
solve this a little bit more complex I wanted to create a classifier that could
give me some trading signals based on following rules when there was some
price change it would at first it would only take the price from 5 minutes ago
and current price and if there was a significant increase it was a buy signal
for it and likewise when the market is when the price decrease a lot by lot I
mean more than a transaction fee would cost it was a sell signal for my bot
otherwise it would recommend to hold the money and do nothing so what I did I
gathered some historical data actually a lot of historical data it was a few
years of data for about 70 different bitcoin and altcoin markets and in the
in the beginning I only used the closing price as you can see there is a lot more
but it will come in handy later and so the simulation was I prepared some
simulation to verify whether the results were ok so I trained this
classifier using data from one single market then I prepared simulations on remaining markets and I went manually through those results I
also assumed that the fee was always the highest possible on
that exchange and I also gave the bot during the simulation I assume that it
has $10 worth of Bitcoin to train it so those are some selected results of the
first simulations for example let me explain what’s going on here
so there are two charts the upper chart is the price market over time this is
Digibyte cryptocurrency and there are as you can
see there is a lot of black lines on this chart
I used it to so that I could see when my bot decided to make a buy or sell
call whenever a line appears above the chart it’s a buy signal and whenever
it’s below the chart it’s a sell signal and on the bottom chart this is the
simulated portfolio over time that the bots owned so in this case the problem was that the bot would simply make too many unprofitable trades and as you can see it
basically ended up losing the whole money that it starts with another
example is this one it would make a lot not well it would actually make a
very few trades over many years because this is data from from like two years
from over two years and it would not despite increasing the portfolio by a
bit it’s still not enough to – it’s not the significant enough over two years so
those were usually the two most common problems that I struggled with initially
so I did some things to improve the model first I extracted more features
from my data set so called technical analysis indicators I tried different
classifiers algorithms and parameters basically it was I didn’t know really
what I was doing so I was sort of following my gut and I was brute-forcing
through different possible combinations and then comparing results if they were
getting better than yeah it was okay so let’s
talk a little bit explain quickly what technical analysis so in finance
technical analysis is an analysis methodology for forecasting the
direction of prices through the study of past market data primarily price and
volume this is the definition from Wikipedia basically some people would
say that it’s a complete bullshit they don’t think that technical
analysis works but there is also some people we will tell you that it’s very
useful in predicting stock price movements I personally think that the truth is somewhere in between and I decided to give it a try
for my classifier and yeah there are like hundreds of different technical
analysis indicators that are available and I was able to compute to calculate most of
them having the data the historical data but I picked those because I went
through some research papers that covered the topic of automatic trades
and applying machine learning to it and this is the list that I computed but I
don’t really understand what most of those do so don’t ask me and I also tried different algorithms to tune up the
accuracy of the classifier luckily with scikit-learn library in Python it’s
really easy to switch between one and another because you just simply if it
gives you so many tools that are ready to use you simply import them and call
field on them finally the best algorithm that ended up working the best for me was AdaBoost this is the definition of the boost is exactly like human specialization gets person (weak learner) A to learn problem X whatever
part of X . A is not true that gets person B to learn that subset whatever A and B
are not good at, get C to learn that and so on each learner specializes in
the weakest area that needs the most
improvement this is a nice definition that helped me understand what’s going
on at least on the surface and what happened with my simulations after I done all those improvements so this is like I decided
to pick this example so the despite not making a lot of trades it gains a lot of
bitcoins over few years so it starts with like ten dollars and it
exits with hundreds bitcoins which is like I’m okay with this and another
example is this is my favorite it’s it seems to do nothing because I think
that’s because of the incorrect scale on the bottom chart but suddenly as you can see it’s like you can see the number up there so that’s not even possible in the real market so but I liked it because I had like a lot of
charts like this and at the point I was very hyped to test it in production and
also one more example is this one there are not many trades but I like how this
one shows that the classifier manages to capture when the market trend is turning then when it’s trending upwards it’s it’s trading a lot
but as soon as the trend turns it is suddenly trading a lot less so I
personally liked this one despite only give only returning one Bitcoin and like
I said before at this time I was very hyped to try it out in production and
because I knew that somewhere I had to make some mistake in my
assumptions and calculations so that’s when I quickly develop the elixir API
that I talked about on my previous presentation and then how it went in
production so yeah simulation is not reality it turned out that I made quite a lot of bad assumptions so the bot was trading but it was slowly
losing money over time which was expected to be honest then I made a few
tweaks that fix some initial problems it still kept losing money but I noticed
that sometimes it can make small profits but it was still not enough to – it was
still not enough for me to know whether it was lucky or whether it was
working okay because I only tested it for like I only managed to test it for
about two weeks because then the exchange that I was using suddenly
experienced a huge increase of user base and it was lagging a lot it was often
going down and then they reacted by making more stricter API rate limits so
which basically made my API bot useless and I would have to rewrite it to
continue my tests or move to different exchange which I had no time for so the
pre-alpha version certainly does not look good but to be honest I expected it
to lose the money a lot quicker so to summarize the time frame for this
project was about six weeks I lost about ten dollars so far which is about three
Grander Texas burgers and so the good parts are that I learned a lot
about machine learning that was my first like successful project and when it
comes to machine learning and I also managed to not only get into the machine
learning I also managed to improve the initial simulation which actually they
are still not perfect but I think it was very nice given how little time I spent on this and this that was like one of the most exciting projects
that I have been working on since ever and there are it’s still not done although it’s a bit stalled recently I still see a lot of ideas how I could improve accuracy of the bot I could tweak the API in elixir
apply different trading strategies or move into different exchange since the
old one is unusable currently yes so basically I would also like to recommend
the scikit – learn library to anyone who would like to try machine learning in
Python it’s it has a lot of tools that you would otherwise have to prepare
yourself it can pre-process your data it has lots of classifiers and other models
and it has even ready data sets that you can import and learn those are very
popular data sets that are widely used by people who are trying to improve
their skills in machine learning and it’s all available in this one
library so I would highly recommend trying this out if anyone wants to get
in [did you compare it with tensor flow or something] to be honest I haven’t tried the tensor flow but the tensor flow is more focused on making neural networks as far as I know correct me if I’m wrong and the upside of tensor flow is that it can utilize your GPU this library won’t so the computations will be significantly slower but it depends on your problem to be honest I don’t want to assume anything here but I think 90% of if you just want to try something out I would recommend this one it’s really simple as you saw in the example that I
showed in the beginning it’s just few lines of code and you already get some
results out of it any more questions yes [there are some nice visualization tools for this library did you use it] I used for the charts that you saw
earlier I used I think math log lib or something like that [I saw that the tools offer machine learning use often display the result by the plots] yeah [because how it hits out backend or not] I’m not sure if it has any built-in tools for visualizing the data but if the
library itself does not then you have a lot of options in Python there are so
many tools that you will surely find something okay any questions [do you plan on continuing your experiment] yes someday I plan to when I get
more time because like I said before there are a lot of possibilities for improvement there it’s definitely not finished and I was kind of it was kind of unfortunate that the exchange blocked API requests and I was unable to continue mostly because of this ok so I think that’s all thank you

One thought on “Applying machine learning to cryptocurrency trading Paweł Duda”

  1. Did you miss the bitcoin boom!!!! I always advice people to
    create a wallet with various different cryptocurrencies. And
    Firstcoin is a good one to have. But what makes Firstcoin
    even more interesting is the firstcoin club where you can
    get up to 8% monthly interest on top of the value rise.have
    you guys heard of firstcoin yet?
    https://www.youtube.com/watch?v=5cfZ5sygILI

Leave a Reply

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