Warning: This is going to be an extremely long post. One day I will be able to write and explain my ideas in a more concise manner. Today is not that day. Consider yourself warned. There's a summary at the end that contains all the important bits, feel free to skip the rest.IntroductionThe following test of different EMA strategies was based on a few simple assumptions that can be summarized as follows:
(1) Recent performance (i.e. the result of back-testing on recent historical data) is a much greater factor in determining future profits than performance on older historical data.
(2) The simple parameter search we employ seems to favor curve fitting, which makes future performance of the parameters doubtful. Therefore, we need to back-test across different time segments to confirm results found in recent history.
(3) Trading is more expensive than previously assumed. It is necessary to take into account not only the rather high trading fees itself, but also slippage while executing a trade, and possibly even the delay between the EMA method signaling a trade and the trader executing it, which tends to cut into profits.
MethodologyThe obvious parts: I'm using Gekko for back-testing, performing a search for optimal parameters for EMA crossover methods, yadda yadda yadday. All of the following is based on mtgox data.
I didn't perform an exhaustive search across those main EMA parameters, but only plugged in those values that had been previously established as profitable in this thread. In particular, I need to thank ErebusBat for his August 10 post, highlighting the profitable parameter ranges.
I only tested *hourly* and *daily* variants of the EMA method. A very sloppy test on 12h interval gave pretty bad results. I suspect that a 2h version of EMA crossovers (with different parameters of course) might peform quite well. I chose '1 hour' and '1 day' because I wanted to see results from the usable range of time periods: faster than 1h is almost certainly too sensitive, slower than 1d probably is too slow for the pretty volatile btc market.
Time period(s)Like I said above, I believe it makes sense to put more weight on recent performance when trying to find optimal parameters for an EMA crossover trading strategy. The reason is simple: say a method performed spectacularly well during 2011 and 2012, but fails to generate any profit in the current year. It would be rather naive to simply look at the aggregate profit and conclude that the method will perform with that (aggregate) profit on average in the *future*. Basically, it would be nice if our method would have generated money not only in the distant past but also the last few months, right?
I decided to start the primary backtest after the April 10 peak, for the reason that the (double?) exponential growth during the weeks before April was unusual, even for the fast bitcoin price movement. So post-peak it is. I based the decision where to start exactly after the peak on Bollinger Bandwidth (2h interval). Volatility around and immediately after the April 10 peak was extremely high, only around May 4th it went back to normal. Well, "bitcoin normal". So "recent history" is 2013-05-04 to 2013-08-22 (110 days). Almost 4 months, enough data to chew on in my opinion.
In addition, I needed another period to backtest the backtesting results on. For that I chose approximately a time period going back 1 year from, so the "entire history" is: 2012-10-22 to 2013-08-22 (304 days).
BenchmarkWe need something to compare our results again, right? "Buy & hold" (from now on: B&H) is the obvious candidate. However, B&H is problematic. Why? You'll notice that when proponents of B&H on this forum talk about its profits, they assume you bought in at a really low price point, like in early January, or at the lowest point after the bubble burst in April. Which is bullshit of course. That's not "B&H", that's "magically knowing the local minimum", and if you can do that, you don't need trading advice anyway, you're already the richest person on Earth.
So let's define B&H for our purposes: B&H profit is calculated as the volume weighted 12h price in the middle of the last day of our testing period, divided by the price halfway through the first day of the testing period.
Gekko settingsAs I said, I think most parameter searches in here assumed slightly too low trading costs. An actual trading fee of 0.5% is quite normal on mtgox as far as I know. Also, some slippage usually occurs (unless you buy or sell only minimal amounts). Finally,unless you have a trading bot, there will be a delay between the EMA method signalling a trade and the trade being executed, which often reduces profits. So I decided to set the "fee" value to 1%, which includes all profit reducing factors mentioned above. Note that setting this value higher favors B&H on the one hand, and "slower" EMA methods (i.e. methods that react slower to trends, and yields less trade signals) on the other.
The intial history setting defines the number of candles at the beginning of the data that are reserved to calculate the EMA methods initial average values. Default is 100, but this is a bad value for our purposes: the EMA methods would include all the volatile data for the initial history that I carefully exluded. So candles is set to 1, which essentially means the EMA method buys immediately. Which is good, because that's what B&H, our benchmark, does as well, so they start on equal grounds.
ResultsFinally.
Anyone still reading this?
Congratulations. You must be really bored.
Hourly intervalsThe list starts with the classical EMA20/10, since that's how Goomboo's thread started. You will notice it performs pretty bad.
The only other parameters I list below are the ones that performed best during backtesting. In particular, if a parameter combination didn't manage to outperform the B&H benchmark on the recent data (May to August), I immediately dismissed it (except for EMA20/10), based on my initial assumption that performance on recent data matters most.
Results are ranked by profit on recent history (h1), followed by profit on the entire history (h2), the 'long' and 'short' average parameter, the optimal 'treshold' values and finally, number of trades executed.
time periods
------------
h1: 2013-05-04 to 2013-08-22 (110 days)
h2: 2012-10-22 to 2013-08-22 (304 days)
EMA results
-----------
* 1h EMA20+10, -0.3/0.3
h1: +2.5%, 41 trades
* 1h EMA24+15, -0.4/0.4
h1: +32%, 19 trades
h2: +518%
* 1h EMA29+18, -0.25/0.25
h1: +38%, 23 trades
h2: +850%
* 1h EMA28+18, -0.4/0.4
h1: +42%, 15 trades
h2: +823%
benchmark
---------
recent history (h1): 2013-05-04 to 2013-08-22 (110 days), B&H profit: +9.9%
entire history (h2): 2012-10-22 to 2013-08-22 (304 days), B&H profit: +945%
Pretty good recent profits for the hourly methods, huh? But did you notice that I didn't find a single hourly EMA method that outperforms B&H on recent data AND on the entire history? Some come close though, EMA29+18 gives +850% on h2 vs. B&H 945% on h2.
But as I said several times, I don't think performance on the older data is equally important. It mainly serves as a sanity check, to protect us from too much curve fitting. Here's an example of such curve fitting: I found some combinations that perform *even better* when set to some very high treshold value, like -1.8/1.8, or some odd combination of treshold, like -0.2/1.8. If you test those parameters on the older history (h2) however, you'll see that it falls apart. That's a pretty good indicator that those parameters where the result of curve fitting.
In conclusion, several hourly parameter combinations drastically outperform B&H during h1, even with the rather high trading fee I chose. Those methods perform well enough on the entire history as well, so I expect them to be reasonably generalized and perform well enough in the (near) future.
Daily intervalsTresholds were 0 for all of the daily results. The daily EMA crossover method is "cautious" enough already and doesn't benefit from tresholds, it seems.
EMA results
-----------
* 1d EMA21+20
h1: +4%, 3 trades
h2: +826%
* 1d EMA37+5
h1: +6%, 5 trades
h2: +288%
* 1d EMA24+15
h1: +7%, 3 trades
h2: +826%
* 1d EMA21+18
h1: +9%, 3 trades
h2: +847%
* 1d EMA29+12
h1: +12%, 3 trades
h2: +827%
* 1d EMA20+10
h1: +17%, 3 trades
h2: +366%
* 1d EMA5+1
h1: +20%, 19 trades
h2: +1339%
* 1d EMA20+1
h1: +23%, 9 trades
h2: +878%
* 1d EMA23+3
h1: +24%, 5 trades
h2: +564%
* 1d EMA24+2
h1: +24%, 5 trades
h2: +727%
* 1d EMA20+6
h1: +32%, 3 trades
h2: +676%
* 1d EMA16+4
h1: +32%, 3 trades
h2: +639%
benchmark
---------
recent history (h1): 2013-05-04 to 2013-08-22 (110 days), B&H profit: +9.9%
entire history (h2): 2012-10-22 to 2013-08-22 (304 days), B&H profit: +945%
As you can see, daily method profits on recent history are somewhat lower than those of the hourly variant, but the number of trades is much lower as well.
Also, I think I found the answer to a question that came up earlier in this thread. Marcus Antonius reported that daily EMA20+21 generated a spectacular 3533% profit over the entire history of trading. The h2 profit of that parameter in my own test confirm this, it is rather high at +826%. Applying this parameter to the recent data h1 however is much less spectacular, only +4% profit. It's up to you to decide of course, but I wouldn't trust a method, that once upon a time performed extremely well, but in the past months failed to generate any serious profits.
On to the better parameters: 20+6 for example performs very well on recent data (+32%) and reasonably well on the entire history (+676%, vs. B&H 945%).
One strange beast showed up in my search: EMA5+1 is a rather fast version of the daily method, compared to the other parameter combinations (see the high number of trades). It performs relatively well on recent data, and *extremely* well on the old data. I'm not sure what to make of it, but I suggest to watch how this combination performs in the future.
Summary / Conclusions- There's a trade-off between "historical" performance and "recent" performance. My assumption was that recent performance is more important for future performance, but we also need to look at performance in the more distant past to check how consistently profitable the found parameters really are.
- EMA20+10 is dead. At least with hourly interval size.
- Hourly EMA crossovers absolutely need treshold values to be profitable, especially if we assume relatively high cost of trading (fees+slippage).
- One of the best *hourly* parameters I found during my search: EMA28+18, treshold -0.4/0.4. Profit May to August: +42% (vs. B&H profit +9.9%). Parameters hold up well in the "historical" back-test as well.
- Good *daily* parameters: EMA20+6, EMA16+4. Both generate +32% profit on recent data. Note that those profits were generated with very few trades (3), which could be important if you want to trade as seldom as possible, and if your trading volume is large enough that your profits are reduced by large slippage.
- Another profitable *daily* combination: EMA20+1. Profit May to August is +23% (less than the ones above), but still outperforms B&H during recent history. Note that this combination performed better on historical data, and it generated the recent history profit with a total of 9 trades, more than the parameters above, which increases the chance that future results are somewhat in line with historic results.
- Which interval is better, hourly or daily? Hourly EMA methods can generate higher total profits in principle, but there's a trade-off: hourly requires a much higher number of trades to reach this profit, which means more work for the trader, more fees, more chance for slippage and more room to make mistakes. Personally, I would recommend using methods with daily interval size.
- Here's my attempt to answer the recurring question "Can a simple strategy like EMA crossover actually beat B&H?". Answer: it depends. If you have (a) enough time to trade often, and more importantly: trade as soon as you receive a crossover signal, and (b) trade with a relatively small volume so that slippage stays manageable, then the crossover method beats B&H by a significant margin. On the other hand, if your goal is to trade as little as possible, or your trading volume is large enough that it causes significant slippage on your exchange, then B&H might be the better choice. But even if you use B&H, I would still suggest to use one of the daily EMA crossovers to determine at which point to *buy in*, e.g. to avoid buying in in the middle of a big correction/downtrend.
- Another caveat: there's always the risk that past performance and future performance diverge. As we've seen, testing different EMA parameters on different partitions of the historical data yields very different results. There is always the possibility that the EMA parameters you choose now, based on back-testing, will actually generate a loss in the future. In practice this means you should probably define a limit up to which you trust your method: if the parameters you chose are unprofitable for, say, 2 or 3 months in a row, it might be time to look for new parameters.