Many investment strategies use the mean like an official parameter. However, this estimator can be considered non-robust, being easily affected by outliers. But if we take a look at almost any financial series, we will notice that outliers may appear more often than we might think.
Introduction
In this post, we will try to study what happens if we introduce a robust parameter (such as the median) in the known strategy, simple moving average.
The moving average strategy is a technical analysis strategy to find trends and take advantage of them.
How does it work?
We have two windows, one short and one long. Let’s say 20 days for the short and 40 for the long one. Having set these windows, we calculate the average price for the last 20 and 40 days. The idea then will be to buy /sell when the moving average with the short window (in this case 20 days) crosses and gets above/below the long window average (40 days in our case).
The following graph shows an example of how this strategy should be carried out.

Setting our environment
For our purpose, we will try to carry out this strategy using both the mean and the median in the foreign exchange market, a.k.a Forex market.
Since the results can vary depending on the windows introduced in the strategies, we are going to study the results using several windows and apply them in different currencies.
Thus, the windows to be used are:
- Short term: 5/10, 10/15, 20/30, 40/60.
- Long term: 40/80, 80/120, 80/160, 160/240.
As an example of the 5/10 parameter, we will have a fast window (5 days rolling average or median) and a slow window (10 days rolling average or median).
Some results…
As we can see in the graph below, the backtests have been carried out between 1992 and 2020 for more than 20 pair currencies and eight strategies for each pair (four short and four long). The results are very similar between the mean and the median estimates. Perhaps the are some differences between the minimum and maximum. Nevertheless, there is not a clear sign of who is the winner.

Taking a quick look at the distributions of the returns, we cannot see apparently any difference. We may think that the mean is more centered; with thinner tails. The average return for the moving average and the moving median is 17.7% and 15.7% respectively. This tells us that, on average, using the mean as an estimator, even though is not robust, gives us better results than a robust estimator, such as the median. At least for the simple moving average strategy.
Spreading results
After taking a look at the main differences between the two strategies, we proceed to see in detail where do these differences lay. In order to do so, we are going to divide the strategies into two main groups:
- Short-term strategies. Here you will find the strategies with small windows, such as 10/15, 20/30 or 40/60.
- Long-term strategies. Composed by strategies with bigger windows, such as 40/80, 80/160 and 160/240
Short term
For the short term, the median seems to have very similar results to the average, with very similar distributions.
The average return for each strategy is 17.3% for the moving average and 16.4% and for the moving median. Very similar in both cases, but again the mean has a slightly bigger advantage. This may be telling us that in the short term, both the mean and median appear to have the same capacity to catch trends.

Long term
For the long term, moving average outperforms the moving median. This time the moving average distribution appears to be slightly moved to the right. With average returns of 11.6% and 8.0% for each strategy respectively.
It seems that the moving average strategy works better for short term periods, rather than long term ones. Furthermore, the use of the median does not appear to have any benefits for the strategy.

Conclusions
We have used in this post the moving average strategy to test if robust estimators such as the median, work better than non-robust estimators.
It seems, at least for this strategy, that the median does not catch as many tendencies as the mean. Should we then use outliers in our strategies, rather than filtering them?
There are many other strategies where this test could be carried out, in order to answer one question: is it robustness our ally? For now, let’s keep using the mean.