Bitcoin Hourly Simple Moving Average Crossover Strategy Backtest

In this article I will optimize and backtest the simple moving average crossover strategy for Bitcoin hourly data. I did the analyses for the period of January 1st 2012 – May 5th 2021 hourly historical price data for Bitcoin using Backtesting.py and optimize the moving average periods. Afterwards I used the backtest results to see how they performed in the last six months. For the conceptual background of the simple average crossover strategy and the python code please read the first article in the series in which similar analyses are made for daily data. I have to remind that this is an educational article, it is not investment or trading advice, backtesting may not be reliable.

Backtest Optimization Results

Let’s see which two numbers are maximizing our returns.

n1  n2 
15  155    1.938680e+11
    160    1.728041e+11
    150    1.687099e+11
10  165    1.470637e+11
    175    1.313821e+11
15  180    1.310179e+11
    185    1.305704e+11
    175    1.290040e+11
10  170    1.237129e+11
    160    1.116725e+11

So the short period moving average is 15 hours and long one is 155 according to our backtest results, we will call this (15,155). Let’s visualize all possibilities with the heatmap. We are looking for the yellow zones.

Bitcoin hourly data optimization for SMA parameters for almost 10 years

So how do the actual results look like for (15,155):

Start                     2011-12-31 09:00:00
End                       2021-05-06 23:00:00
Duration                   3414 days 14:00:00
Exposure Time [%]                   58.261812
Equity Final [$]          193868024868.845459
Equity Peak [$]            208891713676.42807
Return [%]                    19386702.486885
Buy & Hold Return [%]          1285717.539863
Return (Ann.) [%]                  267.818009
Volatility (Ann.) [%]              237.705807
Sharpe Ratio                         1.126678
Sortino Ratio                        8.064977
Calmar Ratio                         5.404598
Max. Drawdown [%]                  -49.553737
Avg. Drawdown [%]                   -3.101874
Max. Drawdown Duration      654 days 03:00:00
Avg. Drawdown Duration        4 days 23:00:00
# Trades                                  370
Win Rate [%]                        32.972973
Best Trade [%]                     393.626379
Worst Trade [%]                    -12.416737
Avg. Trade [%]                        3.34526
Max. Trade Duration          63 days 15:00:00
Avg. Trade Duration           5 days 07:00:00
Profit Factor                        4.399904
Expectancy [%]                       5.217638
SQN                                  2.108866

Unbelievable. 19,386,702%. 19 million percent, compare this to 1.3 million percent of buy and hold. It looks good. When we traded daily we could only see 2,7 million percent returns and when we used four hourly data we obtained 11.6 million percent. This time we were only exposed 58% of the time, reducing our risk. But look at our win rate it is only about 33%, could you have handle loosing 2 out of 3 trades you made. Only 370 trades in 3414 days, that’s almost one trade every 9 days. Could you wait that long if you were a day trader? But we surely curve fit, didn’t we? Let’s check to see if we did by using these parameters for the last 6 months.

Backtesting for the last six months

Let’s only look 6 months back this time. Not include the data before. Had we entered the Bitcoin market last year how would our optimized strategy perform, using (15,155) hourly moving average crossover strategy.

Start                     2020-11-01 00:00:00                                                   
End                       2021-05-06 23:00:00
Duration                    186 days 23:00:00
Exposure Time [%]                   61.898396
Equity Final [$]                2428866.41374
Equity Peak [$]                 2717607.20868
Return [%]                         142.886641
Buy & Hold Return [%]              307.571211
Return (Ann.) [%]                  465.273233
Volatility (Ann.) [%]               369.92888
Sharpe Ratio                         1.257737
Sortino Ratio                       13.029614
Calmar Ratio                        25.941468
Max. Drawdown [%]                  -17.935501
Avg. Drawdown [%]                   -3.192582
Max. Drawdown Duration       54 days 00:00:00
Avg. Drawdown Duration        2 days 20:00:00
# Trades                                   34
Win Rate [%]                        44.117647
Best Trade [%]                      23.347799
Worst Trade [%]                     -6.189641
Avg. Trade [%]                       2.675659
Max. Trade Duration           9 days 10:00:00
Avg. Trade Duration           3 days 09:00:00
Profit Factor                        3.179813
Expectancy [%]                       2.911525
SQN                                  2.162449

This time we are below buy and hold return almost by half, but our exposure time is 62% and we only made 34 trades and 44% are winning trades. This doesn’t look as amazing as the previous run does it? What if we optimized only for this period? The best parameters were 10 and 125. Here are the results.

Start                     2020-11-01 00:00:00
End                       2021-05-06 23:00:00
Duration                    186 days 23:00:00
Exposure Time [%]                     63.5918
Equity Final [$]                3494285.27992
Equity Peak [$]                 3693813.69762
Return [%]                         249.428528
Buy & Hold Return [%]              307.571211
Return (Ann.) [%]                 1049.650362
Volatility (Ann.) [%]              818.845853
Sharpe Ratio                         1.281866
Sortino Ratio                       30.762862
Calmar Ratio                        55.647357
Max. Drawdown [%]                  -18.862537
Avg. Drawdown [%]                   -2.732061
Max. Drawdown Duration       31 days 00:00:00
Avg. Drawdown Duration        2 days 03:00:00
# Trades                                   23
Win Rate [%]                        47.826087
Best Trade [%]                      58.308743
Worst Trade [%]                     -5.456185
Avg. Trade [%]                        5.64439
Max. Trade Duration          21 days 12:00:00
Avg. Trade Duration           5 days 04:00:00
Profit Factor                        6.475452
Expectancy [%]                       6.719754
SQN                                  1.804575

Better than the original optimization but we are still below buy and hold. And the top ten combinations are:

n1   n2 
10   125    3.494285e+06
     120    3.430349e+06
     115    3.274591e+06
5    120    3.246864e+06
     125    3.200323e+06
110  190    3.180469e+06
5    65     3.180198e+06
     130    3.158930e+06
10   105    3.136170e+06
     130    3.126782e+06

n1 = 15 and n= 155 is not even in the top 10. Also none of the strategies outperformed buy and hold returns. Let’s look at the heatmap.

Heatmap of optimization parameters for six monts

Making Sense of Backtests

Similar to the results we obtained with daily Bitcoin simple moving average crossover backtest, for hourly backtests we found that optimization is not an exact science. It may or may not be better than a simple buy and hold. The strategy you develop may not necessarily be as successful in upcoming periods. You may want to continue reading the 5 minute data backtest results for bitcoin. Let me finish this again with the warning: this is not investment or trading advice.

References

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.