Which combination of moving averages is the best?

Which combination of moving averages is the best?

The moving average strategy should be a strategy we heard when we first entered the stock market, and the dual moving average strategy, as the name suggests, is two moving averages: short-term moving average and long-term moving average. Buy when the short-term moving average crosses the long-term moving average (golden cross), and sell when the short-term moving average crosses the long-term moving average (die cross). This is the core idea of ​​the double moving average strategy.

In the figure below, the yellow line represents the 30-day moving average, and the white line represents the 5-day moving average. It can be seen that when the 5-day moving average crosses the 30-day moving average, a dead cross is formed, and the stock price becomes a bearish trend; When the 30-day moving average was crossed, a golden cross was formed, and the stock price has been rising since then. Of course, this is a necessary and insufficient condition. What we want to study is the estimation of the probability of rising and falling of Jin Cha and Si Cha.


1. let’s talk about moving averages. There are two calculation methods for moving averages: MA (Moving Average) and EMA (Exponential Moving Average)

MA is a simple moving average. When doing an arithmetic average, the weight of the new and old data is the same.

EMA is an exponential moving average, and the newer the data, the greater the weight.

Among them, α is the smoothing index, generally taken as 2/(N+1). When calculating the MACD indicator, the N in the EMA calculation is generally selected for 12 and 26 days, so α is 2/13 and 2/27 respectively. Where EMA1 can be calculated using MA.

The above EMA formula can be derived as follows:

Continue to iterate EMA_{yesterday} according to the formula to get:

Among them, p1 represents today's price, and p2 represents yesterday's price.

From this formula, we can see the characteristics of EMA weighted average more clearly. In the EMA indicator, the weight coefficient of daily price is reduced in the form of exponential ratio. The closer the time is to the present moment, the greater its weight, indicating that the EMA function strengthens the weight ratio of recent prices, and can reflect recent price fluctuations in a timely manner.

Back-testing the dual moving average strategy can be divided into direct back-testing on the index or back-testing on multiple stocks. When backtesting the index, directly use the ma5 and ma30 of the index to judge, buy when the golden cross, and sell when the cross is dead.

When the stock pool is back-tested, the situation of each stock's golden fork is judged every day. It is also bought at golden fork and sold at dead fork. The position of each stock is controlled by the total amount of funds.

The picture below shows the results of the backtest of the index. The average annual return is more than 10%. This is the return of the manager after the plunge in 2015 and the one-year bear market in 2018. It seems not bad. It can also be seen from the figure that the double moving average strategy almost must have passed the plunge and bear market. This also gives us a reminder that if you make your own investment and do not rely on procedures, it is still necessary to clear the position below the 30 (or 60) daily moving average.

Then there is still a question, why do we take the 5-day moving average and the 30-day moving average? This is a good question, and it seems that our answer can only be: This is an experience value. Is this value really the optimal value? Is there any other moving average combination that works better?

The following content refers to "Research on Medium and Low Frequency Quantitative Trading Strategies".

Let’s do further research. It’s very simple. Test all the parameter combinations (1 day moving average and 2 day moving average combination, 1 day moving average and 3 day moving average combination, 2 day moving average and 3 day moving average combination...), you know where. One kind of combination is optimal from the historical data. This method is also called grid search. But such a violent method is intuitively a bit too time-consuming and laborious, and theoretically speaking, the greater the length of the two adjacent moving averages, the smaller the difference, such as the difference between a 2-day moving average and a 3-day moving average. It is much larger than the difference between the 100-day moving average and the 101-day moving average. The difference between the latter two is actually very small due to the difference of one trading day. In this way, if all possible moving averages starting from 1 to the end of a certain length are involved in the search, then the moving average with a small length will change quickly, and the search will be biased towards the long-term moving average with little change, which will cause computational redundancy. (Refer to "Research on Medium and Low Frequency Quantitative Trading Strategy")

Therefore, we use the Fibonacci sequence to deal with the search range of the moving average. The sequence has no special meaning here, and readers can also change to other combinations by themselves.

The Fibonacci sequence has the form [1,2,3,5,8,13,21,34,55,89,144,...], that is to say, the simple optimization of the moving average trend strategy will use the 1-day moving average ①, 2 Daily moving average, 3-day moving average, 5-day moving average, etc. until the 144-day moving average, a total of 11 long and short combinations of moving averages are searched to find the combination with the best profitability to determine the optimal moving average trend strategy form. The short-term moving average is limited to the 34-day moving average, and the long-term moving average starts searching from the last one of the short-term moving average to the end of the 144-day moving average.

The following table shows the annualized rate of return of all short-term and long-term moving average combinations under the moving average trend strategy. In the entire table, there are a total of 47 moving average trend strategies with a positive annualized rate of return, and only 5 ones with a negative annualized rate of return. Therefore, purely from an optimization perspective, the moving average trend strategy is a relatively stable strategy. . The worst-performing strategy for yields is a combination of trends with a short-term moving average of a 3-day moving average and a long-term moving average of a 5-day moving average, with an annualized rate of return of -12.77%. One strategy with the best yield performance is a trend combination of the short-term moving average of the 3-day moving average and the long-term moving average of the 21-day moving average, with an annualized return of 25.51%. It is worth noting that the short-term moving averages in these two moving average combinations are both 3-day moving averages. That is to say, when the short-term moving average formed by the 3-day moving average is used, the profit performance of the moving average trend strategy has a relatively large range of change. The grid search is not a good phenomenon. But at the same time, the long-term moving average is the 21-day moving average. The six moving average trend strategies have relatively high and relatively stable returns. The lowest annualized return rate has reached 18.13%. On the whole, the short-term moving average selected by the principle of optimal returns is the 3-day moving average and the long-term moving average is the 21-day moving average trend strategy. The area in which it is located should be considered relatively stable.

Of course, there is no back-testing of the 5-day moving average and 30-day moving average in the book. Those who are interested can try it by themselves. When looking at the returns on the 5th and 34th, the possibility that the combination of the 5th and 30th can exceed the combination of the 3rd and 21st is relatively small.

Therefore, when we use the moving average strategy in the future, we can use the best combination ma3 and ma21.

Reference: https://cloud.tencent.com/developer/article/1653013 Which moving average combination is the best? -Cloud + Community-Tencent Cloud