How to Build a Simple Bitcoin Trading Bot, Part 2
In part one of “How to Build a Simple Bitcoin Trading Bot,” we covered what algorithmic trading is and how to recognize and analyze market inefficiencies. In part two of this series, we will cover the six steps to developing an algorithm.
This is a guest post by Izak Fritz, a software contractor for Stably Blockchain Labs. Izak is a computer science student at the University of Michigan and interested in how cryptography can be used to make the internet more robust and secure. He enjoys trading cryptocurrencies and also writing algorithms that trade for him.
Developing an Algorithm
We can break down the process of developing an algorithm into six steps:
- Observation
- Coding
- Backtesting
- Backtest Analysis
- Walk Forward Test
- Automation
1. Observation
This first step will build the technical foundation for the rest of the algorithm. We first need to find out what kind of market we will be trading – i.e., a bear or bull market.
Once we discover a market that has inefficiencies, we can begin designing the algorithm to trade it. There is no systematic way to identify these opportunities – it takes an intuitive trader to find different patterns and there is no way to avoid the necessary research.
For instance, by trading Bitcoin against a stablecoin, this allows us to hedge when we are not in a position. We have realized that the market tends to follow a lot of momentum cycles so we want to implement a momentum strategy.
Trading the Bitcoin to StableUSD market will allow us to both long and short because when we are long we have our portfolio in Bitcoin, and when we are short, we have our portfolio in StableUSD.
2. Coding
Coding the algorithm is the most energy-intensive step, especially if you are not a programmer. There are multiple platforms that allow you to integrate your algorithm into backtesting data and use a simple programming language to create it. This step may seem daunting, but if you are willing to put in the work, it will be deeply rewarding.
3. Backtesting
Backtesting is where you put the algorithm to the test against the market. This step involves simulating the market over a time period and analyzing how the algorithm would trade against it.
It is recommended that the algorithm is tested against both a bear market and a bull market. Testing during both of these situations will help you make a better decision on whether or not you want to use the algorithm. For example, if an algorithm only performs well in a bear market, you can probably avoid using it in a bull market.
In our example, we want to test the Bitcoin vs. USD market for the past five years. Since StableUSD has a 1:1 ratio with the dollar, its price will remain $1 and so we can use the Bitcoin vs. USD market as a proxy.
4. Backtest Analysis
Backtest analysis involves monitoring at the performance of your algorithm and evaluating it quantitatively. There are a few factors to take into consideration – first, profit and loss ratio is the most immediate metric to evaluate. If the algorithm doesn’t make money, then it’s probably worth modifying.
Next, you can look at the Sharpe ratio which provides an idea of the risk-to-return. A Sharpe ratio above 2 is great – that means the average return divided by the average risk is greater than 2. You can also look at how the algorithm would have performed against the market as a whole.
For example, let’s say we discovered the algorithm outperformed the buy and hold strategy for the past five years and that it also has a high Sharpe ratio. In this case, we would be confident about starting a test on a live order book.
5. Walk Forward Test
Once you have tested the algorithm against the past market, you can begin testing it on the present market. This can involve paper trading or some other form of simulated trading. As it is the most important step in determining the usability of the algorithm, it also gives you an idea of how the algorithm would perform if used in the present.
In our example, let’s assume that we find the algorithm can trade Bitcoin much better than we could by hand. This is excellent news, we can now begin implementing it on an exchange.
6. Automation
The algorithm works and is ready to be thrown into the market. You can now connect the algorithm to an exchange and have it execute orders on your behalf. There are various platforms and services that allow you to do this easily – TradingView and AutoView are two examples.
Conclusion
Algorithmic trading is a rewarding endeavor to pursue. It involves discovering interesting and creative models for markets, and a neverending pursuit to find edges. The fun of algorithmic trading is found in the challenge of always adapting to the market.
There are always new players and new strategies trying to outsmart the market. Of course, in the cryptocurrency world, nothing stays the same and no strategy will always win. As a result, the thrill of developing a tested and successful algorithm can often be worth the hard work.
Disclaimer: The information and analysis in this article are provided for informational purposes only. Nothing herein should be interpreted as personalized investment advice. Under no circumstances does this information represent a recommendation to buy, sell, or hold any cryptocurrency. Past performance is not necessarily indicative of future results and all investments involve risk. My strategies may not be appropriate for all investors and all investors should carefully consider the potential risks of all investors should carefully consider before investing in any strategy.
None of the information in this presentation is guaranteed to be correct and anything written here should be subject to independent verification. You, and you alone are solely responsible for all investment and trading decisions that you make. I am invested in the cryptocurrencies mentioned in this article and gain monetarily from the market. Additionally, I am a software contractor for Stably Blockchain Labs, the company mentioned above.