July 8, 2026

Should you be trading Bitcoin? – The Programming Prodigy

Should you be trading Bitcoin? – The Programming Prodigy

Many of you may remember the cryptocurrency boom in 2017, sending the prices of various virtual coins soaring to unexplainable prices. Looking historically at the price of some cryptocurrencies, there is high volatility[1], hence the asset tends to fluctuate quite often. This is of course quite beneficial for investors, as a short term investment, large sums of profit can be made from trading these assets.

The trading of cryptocurrencies involves the exchange between a cryptocurrency and a token value such as BTC to USDT. USDT is a Tether, which is a blockchain-based cryptocurrency whose crypto coins in circulation are backed by an equivalent amount of traditional fiat currencies. 1 USDT = 1 US Dollar. To gain a profit whilst trading would involve the purchasing of an asset when it is low in price and selling it at a higher price and to do this efficiently and effectively, one has to implement a trading strategy. It is important to note that when choosing an asset to trade, a high trading volume is crucial [2] as it means that there are people willing to trade with you, and therefore you can obtain your desired position at a low cost.

A trading strategy is an algorithmic plan that aims to create a profitable return. There are a range of strategies that can be used, however, this article will investigate whether mean reversion would be suitable and if not, what would be more optimal. Before I explain what mean reversion is, I’d like to outline a few key definitions. Mean is the average price of a given set of data, and the standard deviation is how far the data spreads from the mean. Mean Reversion is the assumption that the price of an asset will fluctuate around the mean, tending to move to an average price over time; suggesting that if a price is a number of standard deviations away, it is expected to return to the mean price at that point. Hence, the asset is purchased when below the mean, and sold when above the mean, at these standard deviations [3]. Conversely, an asset might mean avert, which suggests the price keeps rising or dropping at the point where it is expected to be returning to the mean. This may be due to the overreaction or fear of investors, during periods such as a boom, or surge of investors into an asset [4]. If an asset possesses mean averting properties, a momentum strategy can be implemented as the suggestion that an asset will keep rising for a longer period can be used to generate returns. Doing some background research, there is evidence to suggest that the price of bitcoin does not mean revert, but in fact mean averts [5]. There is evidence that during World War II and the Depression, assets experienced mean reversion, however, it is suggested that evidence for mean reversion is an overstatement, as taking into account these periods are inaccurate [6].

Utilizing Python and its various statistical libraries I aim to experiment and model the trading of BTC and ETH, which are 2 of the most popular and high volume traded cryptocurrencies. Data obtained from Binance, one of the largest cryptocurrency trading platforms, would be used when testing my hypothesis, during the periods of 2017, 2018 and 2019. Initially, the Augmented Dicky-Fuller Test (ADFT) would be used to test for mean reversion. ADFT tests the null hypothesis that a unit root is present, and the alternative hypothesis being there is no unit root, suggesting the time series is stationary. A time series is stationary if a single shift in time doesn’t change the time series statistical properties, in which case a unit root does not exist [7]. If the P-value given by the test is below the significance level, we can reject the null hypothesis, as the is insufficient evidence to suggest a unit root is present. This test can easily identify where a data set experiences mean reversion, as a stationary time series will be mean reverting, hence have no unit-roots. If there is evidence to suggest mean reversion, a strategy based on this principle, using the concept mentioned earlier would be ideal; purchasing the asset when it is a number of standard deviations below the mean, and selling the asset when it is above the mean.

Alternatively, if the ADFT suggest that there is sufficient evidence to accept the null hypothesis, that would mean that the asset is experiencing mean averting properties. If this is the case then a strategy based on the momentum principle would be ideal. This is because there is evidence that the asset’s price will continue rising/falling, even when several standard deviations away. This means that for a given period of time, days or hours if the price of an asset is above the rolling mean it is considered attractive for purchase, and when it is below the mean, it is unattractive hence should be sold; as we would be expecting a further drop at this point.

Whist testing, the data will be split into two groups. Group 1 will be the fit data or historical data, used to create a strategy and fit it to the data. Group 2 will be the out of sample data, which the strategy will be tested on to see if it gives positive or negative results. The out of sample data simulates what would happen when deploying the strategy in real life. Sometimes a strategy may be overfitted to the historical data, meaning it works amazingly with historical data giving large returns, however, it works so perfectly with the historical data, that it no longer works with the out of sample data [8]. The fit data or historical data is used to create, test and optimise the strategy, to gain a profitable return.

During the fit-data testing, two factors were altered: commission fees and the rolling mean window, to generate a number of tables for daily and hourly data for the cryptocurrencies being investigated. Altering the rolling-mean window changes the number of previous prices we use for constructing the moving average. Different cryptocurrency trading platforms have different commission fees, hence by investigating the results at a range of fee levels, this will simulate a more realistic scenario. I aim to experiment with fee levels of (0.01, 0.05, 0.1, 0.5,1%) [9] and rolling windows of (2,5,7,10,15,20,24) days or hours. Identifying the best performing parameters on the historical data (2017–2017), it would then be used and attempted on the out of sample data (2019).

Testing with the ADFT on data from 2017 and 2018, at the 1,5 and 10% significance levels, the P-value was greater than all the values given at the significance levels. This suggests that there is sufficient evidence to accept the null hypothesis which states that there is a unit root. As mentioned before, the presence of a unit root means the data is not a stationary time series, hence suggesting it doesn’t experience mean-reverting behaviours. This is most likely due to the number of spikes in 2017 and 2018 that were caused by the crypto-boom, where lots of people were investing in the currencies to try to make profits. However, what this does identify is that the prices of cryptocurrencies tend to continue going in the same direction once they move, rather than returning to the mean. As a result, it would be more appropriate to use a momentum-based strategy.

A momentum-based strategy is based on the assumption that once an asset’s price has moved in a certain direction, it will keep moving in the same direction for a period of time. If the price of an asset is above the mean then we can expect it to keep rising, and so we would purchase the asset with the aim of selling it at a high price later. The opposite being done if the price of an asset is below the mean. In addition, it is possible to limit the number of tokens at any given time, e.g. to a maximum of 5 to reduce the amount of risk being held. For example, if we had 100 tokens, this poses a high risk as a sudden drop in price can cause our overall loss to be increased to a very significant amount.

At the green circles, we would purchase the asset, and at the red circles, we would sell the asset. Utilizing this principle, this strategy will be run on historical hourly data, during 2017 and 2018, for the trade of BTC for USDT; generating a table of profit and loss, by varying the parameters of rolling windows for the moving average (2, 5, 7, 10, 15, 20, 24 hours) and different fee levels (0.01, 0.05, 0.1, 0.5, 1 %).

Running the strategy we obtain these tables below, containing profit and loss values (PNL) for BTC/USDT and running the same strategy on ETH/USDT (Ethereum).

Analysing both tables we can see that a profitable return is consistently made for both cryptocurrencies at fee levels of 0.0001 to 0.001 and with moving average windows of 20 or 24 hours. However, we can see that Ethereum begins to be profitable at a much lower window, 5 hours, compared to BTC, which only becomes profitable at a window of 15 hours. The graphs below show the profit growth (PNL) at 0.0001 fee level and MA of 24 hours for bitcoin and 20 hours for Etherum, respectively.

In addition, if we run the same strategy for BTC/USDT and ETH/USDT for daily data during 2017 and 2018, we obtain the following results.

Analysing both of these tables we once a gains see a similar pattern, both cryptocurrencies delivering a profitable return at a moving average window of 20 or 24 days, however gaining profit at all fee levels. It is even more important to note that Bitcoin is only becoming profitable at a window of 5 days, however, Ethereum is profitable all across the board. The graphs below show the profit growth at 0.0001 fee level and MA of 24 days for bitcoin and 20 days for Etherum, respectively.

Whilst analysing the fit-data during 2017 and 2018 for BTC/USD the window with the most profit is the 24-hour window however it stops being profitable at fees of 0.005 and 0.01. With ETH/USDT the ideal window is the 20-hour window, however, also stops being profitable at fees of 0.005 and 0.01. It is evident that neither cryptocurrencies are profitable above these fee levels hence such a strategy should be used on a trading platform that offers low fees, such as binance[9].

The above tables show the profit of both cryptocurrencies at their best window and fee levels when looking at performance during 2019. This is being done on the out of sample data to test whether the strategy made on the earlier fit-data (historical) can be viable for forecasting on new data. This simulates what would happen if the strategy were run in real life.

Both cryptocurrencies return a high profit during our out of sample testing; with bitcoin performing better, giving larger profits, compared to Ethereum.

Doing the same for both cryptocurrencies on our daily out-of-sample data, the below table can be obtained showing the profits at the ideal daily windows for each cryptocurrency, respectively.

Looking at the tables, the strategy simulates that in 2019, we would be profitable with Bitcoin using a 24-day moving average, up to a fee level of 0.001. However, it would appear that Ethereum although profitable across the board during 2017 and 2018, our strategy does not deliver high profits during 2019.

Comparing both Bitcoin and Etherum, from our results and analysis, it would be ideal to trade on hourly data rather than daily data as both give high profits as well as provide evidence to suggest that our model is well suited.

In conclusion, all the evidence collected suggests that Bitcoin and Etherum mean averts, as highlighted by the ADFT, during 2017 and 2018. As a result, a momentum strategy is more appropriate when attempting to forecast when to buy and sell crypto. Overall the simulation shows the strategy is suitable for predicting when a cryptocurrency should be purchased or sold, as there is plenty of evidence to show this can be done profitably.

Looking at improving and adapted for other scenarios, there are different factors that can be taken into account to make a better simulation. In my strategy, I limited the total number of coins that I can have at any given moment and the total number of tokens I can short, to 5. This allowed me to minimise the risk of having too many assets if the number of coins being held is too high, this poses a risk of a large loss if for some reason the price of the asset were to drastically drop. One factor that was ignored in the strategy was slippage. Slippage is where the trading participant receives an execution price that is a percentage higher or lower than the intended number. For example, the execution price when buying the asset might be 2% higher than the actual price. This is usually a result of a small number of people trading, however as I picked currencies with a high trading volume, slippage can be ignored as it will be so small. This assumption is further supported by the evidence presented by these two articles [10][11]. Nonetheless, if an asset has a low trading volume then slippage would be a factor that should be taken into account to ensure that the simulation is more accurate.

Another factor that can be investigated further is the moving average window. The windows being investigated were: 2,5,7,10,15,20,24 days or hours. By using a larger range of windows, such as 30 days and 90 days, more data can be acquired to test for a better return.

Furthermore, it would be interesting to test this strategy on other cryptocurrencies such as Ripple (XRP), to see whether or not there is evidence to suggest that the strategy works other cryptocurrencies on the market.

[1](9 August 2016) Can volume predict Bitcoin returns and volatility? A quantiles-based approach https://www.sciencedirect.com/science/article/abs/pii/S0264999317304558

[2] Karpoff, J. (1987). The Relation between Price Changes and Trading Volume: A Survey. Journal of Financial and Quantitative Analysis, 22(1), 109–126. doi:10.2307/2330874

https://www.cambridge.org/core/journals/journal-of-financial-and-quantitative-analysis/article/relation-between-price-changes-and-trading-volume-a-survey/DBE2C70FA41E390EB8FA418BBFFD76C8

[3]Mean Reversion Definition REVIEWED BY JAMES CHEN Updated May 15, 2019 https://www.investopedia.com/terms/m/meanreversion.asp

[4]The Journal of Investing Winter 2009, 18 (4) 57–71 https://joi.pm-research.com/content/18/4/57.abstract

[5]Testing for mean reversion in Bitcoin returns with Gibbs-sampling-augmented randomization https://www.sciencedirect.com/science/article/abs/pii/S1544612319306415

[6]McQueen, G. (1992). Long-Horizon Mean-Reverting Stock Prices Revisited. Journal of Financial and Quantitative Analysis, 27(1), 1–18. doi:10.2307/2331295 https://www.cambridge.org/core/journals/journal-of-financial-and-quantitative-analysis/article/longhorizon-meanreverting-stock-prices-revisited/9E5B50277CCDE2451639A1B87E05AAFD

[7]Augmented Dickey-Fuller Test in Python 11/20/2018 http://www.insightsbot.com/blog/1MH61d/augmented-dickey-fuller-test-in-python

[8] J. Chem. Inf. Comput. Sci. 2004, 44, 1, 1–12 Publication Date:December 2, 2003 https://pubs.acs.org/doi/abs/10.1021/ci0342472

[9 ]https://www.binance.com/en/fee/schedule

[10]Xie, Anthony. An Analysis of Slippage on the Binance Exchange, HodlBlog, 16/11/19, https://www.hodlbot.io/blog/an-analysis-of-slippage-on-the-binance-exchange.

[11]Getting slippage even with small market orders, GitHub, 16/11/19, https://github.com/sammchardy/python-binance/issues/142

Published at Mon, 18 Nov 2019 23:14:06 +0000

{flickr|100|campaign}

Previous Article

Make No Mistake, Crypto is Still Hated by Beijing Despite Bullish Blockchain Pivot

Next Article

Ford’s Electric Mustang Mach-E Is Terrible News for Tesla

You might be interested in …