Simple Moving Average Crossover Strategy Backtest for Bitcoin Five Minute Data

In this article I will optimize and backtest the simple moving average crossover strategy for Bitcoin hourly data. So if you were a daytrader, how would you do using this strategy is the question we are attempting to answer. First, I will do the analyses for the period of January 1st 2012 – Math 5th 2021 hourly historical price data for Bitcoin using Backtesting.py and optimize the moving average periods. Then I will use 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 of 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.

Backtest Optimization Results

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

n1   n2 
105  235    7.813418e+08
110  235    6.022125e+08
115  235    5.832279e+08
80   235    4.380330e+08
70   235    4.070184e+08
105  230    3.819659e+08
110  230    3.817126e+08
     225    3.716279e+08
95   235    3.523545e+08
75   235    3.480299e+08

So the short period moving average is 105 x 5 minutes and long one is 235 x 5 minutes according to our backtest results, we will call this (105,235). Let’s visualize all possibilities with the heatmap. We are looking for the yellow zones. Perhaps we should have searched for longer periods.

Bitcoin 5 minute data Simple Moving Average (SMA) crossover strategy parameter optimization heatmap

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

Start                     2011-12-31 09:50:00
End                       2021-05-06 23:55:00
Duration                   3414 days 14:05:00
Exposure Time [%]                   54.636339
Equity Final [$]             781341830.770001
Equity Peak [$]              1114451669.30594
Return [%]                       78034.183077
Buy & Hold Return [%]          1285717.539863
Return (Ann.) [%]                  103.921387
Volatility (Ann.) [%]               141.64505
Sharpe Ratio                         0.733675
Sortino Ratio                        2.817505
Calmar Ratio                         1.432162
Max. Drawdown [%]                  -72.562602
Avg. Drawdown [%]                   -2.211365
Max. Drawdown Duration     1177 days 18:55:00
Avg. Drawdown Duration        3 days 11:42:00
# Trades                                 2139
Win Rate [%]                        34.642356
Best Trade [%]                      65.704043
Worst Trade [%]                    -22.590114
Avg. Trade [%]                       0.311896
Max. Trade Duration          35 days 15:45:00
Avg. Trade Duration           0 days 21:00:00
Profit Factor                        1.429233
Expectancy [%]                       0.407582
SQN                                  1.710645

Disappointing isn’t it. Only 78,034%. 19 million percent versus 1.3 million percent of buy and hold. It looks good. When we traded daily we could see 2,7 million percent returns. This time we were only exposed 58% of the time, reducing our risk. But look at our win rate it is only about 34%, could you have handle loosing 2 out of 3 trades you made. Many trades now, 2139 trades in 3414 days, that’s almost trading daily. But we surely overfit, 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 six months back how would our optimized strategy perform, using (15,155) x 5 minute moving average crossover strategy.

Start                     2020-11-01 00:00:00                                                   
End                       2021-05-06 23:55:00
Duration                    186 days 23:55:00
Exposure Time [%]                   57.255594
Equity Final [$]                2257410.30348
Equity Peak [$]                  3206024.6753
Return [%]                          125.74103
Buy & Hold Return [%]              308.150001
Return (Ann.) [%]                  390.007039
Volatility (Ann.) [%]              320.425732
Sharpe Ratio                         1.217153
Sortino Ratio                        12.30408
Calmar Ratio                        11.737125
Max. Drawdown [%]                  -33.228499
Avg. Drawdown [%]                   -1.905366
Max. Drawdown Duration       57 days 01:45:00
Avg. Drawdown Duration        0 days 23:47:00
# Trades                                  132
Win Rate [%]                        37.121212
Best Trade [%]                      21.078695
Worst Trade [%]                       -6.0479
Avg. Trade [%]                       0.620907
Max. Trade Duration           3 days 12:00:00
Avg. Trade Duration           0 days 19:23:00
Profit Factor                        1.696033
Expectancy [%]                       0.709469
SQN                                  1.334331

This time we are below buy and hold return almost by half, but our exposure time is 57% and we only made 132 trades and 37% are winning trades. We made 125% returns, where buy and hold return was 308%. What if we optimized only for this period? The best parameters were 80 and 230. Here are the results.

Start                     2020-11-01 00:00:00
End                       2021-05-06 23:55:00
Duration                    186 days 23:55:00
Exposure Time [%]                   57.225884
Equity Final [$]                2996083.88592
Equity Peak [$]                 3694657.26674
Return [%]                         199.608389
Buy & Hold Return [%]              308.150001
Return (Ann.) [%]                   756.43368
Volatility (Ann.) [%]              569.249969
Sharpe Ratio                         1.328825
Sortino Ratio                       25.143781
Calmar Ratio                        27.567776
Max. Drawdown [%]                  -27.439053
Avg. Drawdown [%]                   -1.730988
Max. Drawdown Duration       49 days 20:45:00
Avg. Drawdown Duration        0 days 20:42:00
# Trades                                  132
Win Rate [%]                        43.181818
Best Trade [%]                      22.125803
Worst Trade [%]                     -6.059373
Avg. Trade [%]                       0.843642
Max. Trade Duration           3 days 13:10:00
Avg. Trade Duration           0 days 19:23:00
Profit Factor                        1.978148
Expectancy [%]                       0.938291
SQN                                  1.964724

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

n1  n2 
80  230    2.996084e+06
    235    2.928764e+06
85  235    2.882026e+06
80  195    2.864463e+06
85  185    2.848370e+06
75  210    2.813827e+06
    225    2.788240e+06
    235    2.785790e+06
85  230    2.783143e+06
80  200    2.732565e+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 parameters for SMA optimization with 5 minute Bitcoin historical price data

Making Sense of Backtests

Similar to the results we obtained with daily, four hourly, and hourly Bitcoin simple moving average crossover backtests, for 5 minute 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. 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.