An attempt at algorithmic crypto trading
It was the aftermath of cryptomarket’s bubble peak in January of 2018, and bitcoin’s price was falling:
In these desperate times, with a small group of guys (Niko https://twitter.com/nikovaananen and Eero https://twitter.com/bulabaloo) and we decided to try using bots for trading bitcoin. This is the introduction to our experiments. I did most of the programming for the project, while the others were researching investing strategies.
We begun by doing simulations. For coding I used standard tools, Python as our programming language of choice, with Numpy, Pandas etc. Python libraries. I also used quandl to pull bitcoin price history. I decided not to use any pre-existing trading software, because I wanted to keep the code as easily expandable as possible.
Our first strategy was pretty straightforward, it calculated the simple moving average of bitcoin price history over 3 and 15 days, and if the price was over both of those averages the bot would send a “buy” signal, and “sell” signal if the price was under both of them.
This strategy seemed to generate some nice returns in our simulation:
However that simulation was a bit too good. For the base price, it used averaged (and weighted) price history data over a couple of exchanges, and so the price history was much smoother than it really is (causing the calculated 3 and 15 days moving averages to be even smoother). It meant that the investment strategy worked much better than with actual exchange data, for example from Bitstamp.
So to advance in our project, I had to abandon the pre-existing, nice API of quandl, and I had to start pulling data from the actual exchange. This had some problems, because I needed to find single-trade level historical data from the exchange to do simulations for our trading strategy. Thankfully bitcoincharts had that data: http://api.bitcoincharts.com/v1/csv/ (1GB CSV uncompressed, Bitstamp usd).
To make the whole thing work, I needed a database. I did a simple MySQL database with a few tables. After that, I did a Python script to listen to Bitstamp’s Websocket api and add all the incoming trades to the database. I put the script to run in screen (ugly, I know), but it was fast to implement and test.
After all the technical hurdles, we got back to simulating again. We planned to make a bot that trades once every hour. I also wanted to make the bot more technically adept, so I began to use Talib for Python to access some technical analysis functions. Our shortBot strategy after simulations and testing consisted of rules based on exponential moving averages, RSI, and trend recognition:
The simulations looked well, and the bot seemed somewhat promising. So we decided to implement this bot to make trades with real money.
I coded the necessary parts for the bot to interact with Bitstamp and to make real live trades (using some light weight limit trading trickery).
Sadly, we managed to hit the worst possible time for the bot to go live in astonishing degree (around Feb 18):
After learning a lesson about over fitting a strategy to recent history, it was time to go back to the drawing board (there also was a bug with the bot which caused it to erroneously sell in the middle of price upsurge, which cost us some money). In upcoming posts I will tell about our tinkering with machine learning, walk forward optimization and our current bot.
Originally posted: https://medium.com/@jarno.varis/an-attempt-at-algorithmic-crypto-trading-cf5a97e6e275
✅ @levelbot, congratulations on making your first post! I gave you a $.05 vote!
Please take a moment to read this post regarding commenting and spam. (tl;dr - if you spam, you will be flagged!)
Congratulations @levelbot! You received a personal award!
Click here to view your Board
Congratulations @levelbot! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!