Adaptive Moving Average – Trading Strategy Backtest (Does it work?)
Last Updated on September 19, 2022 by Quantified Trading
Adaptive moving average strategy backtest (Kaufman’s adaptive moving average)
We know that traditional moving averages smoothen price series to reduce noise and show the trend. However, when price makes a temporary but significant leap, it can still give the appearance of a false trend. This is why Perry J. Kaufman invented the adaptive moving average. But what is it? Can we make profitable adaptive moving average strategies in the markets?
Yes, adaptive moving average strategies do work. Our backtests show that an adaptive moving average can be used profitably for both mean-reversion and trend-following strategies on stocks.
The adaptive moving average (KAMA) is a moving average designed to account for changes in market volatility. The indicator closely follows prices when the price swings are relatively small (less volatility or noise) and adjusts to follow the prices less closely when the price swings widen. In essence, the adaptive moving average works like a slow-moving average, as it reduces the influence of outliers, without sacrificing the sensitivity.
Table of contents:
Adaptive moving average strategy backtest and best settingss
Before we go on to explain what an adaptive moving average is and how you can calculate it, we go straight to the essence of what this website is all about: quantified backtests.
Our hypothesis is simple:
Does an adaptive moving average strategy work? Can you make money by using adaptive moving averages strategies?
We look at the most traded instrument in the world: the S&P 500. We test on SPDR S&P 500 Trust ETF which has the ticker code SPY.
All in all, we do four different backtests:
- Strategy 1: When the close of SPY crosses BELOW the N-day moving average, we buy SPY at the close. We sell when SPY’s closes ABOVE the same average. We use CAGR as the performance metric.
- Strategy 2: Opposite, when the close of SPY crosses ABOVE the N-day moving average, we buy SPY at the close. We sell when SPY’s closes BELOW the same average. We use CAGR as the performance metric.
- Strategy 3: When the close of SPY crosses BELOW the N-day moving average, we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
- Strategy 4: When the close of SPY crosses ABOVE the N-day moving average, we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
The results of the first two backtests look like this:
Strategy 1
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
8.53 |
8.09 |
5.39 |
7.44 |
5.08 |
3.66 |
MDD |
-32.25 |
-36.21 |
-45.62 |
-48.05 |
-50.57 |
-50.7 |
Strategy 2
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
1.09 |
1.6 |
4.02 |
2.08 |
4.36 |
5.61 |
MDD |
-62.39 |
-56.77 |
-33.47 |
-54.55 |
-55.61 |
-43.64 |
The results from the backtests are pretty revealing: in the short run, the stock market shows tendencies to mean-reversion. In the long run, it is better to use trend-following strategies.
Why do we reach that conclusion?
Because if we use a short moving average, the best strategy is to buy when stocks drop below the average and sell when it turns around and closes above the moving average (buy on weakness and sell on strength). This can clearly be seen in the first test above for the 5-day moving average in the first table. The 5-day moving average returns a CAGR of 8.53%, which is almost as good as buy and hold even though the time spent in the market is substantially lower.
When we buy on strength and sell on weakness, in the second test in the table above, the best strategy is to use many days in the average. The longer the average is, the better. The 200-day moving average returns 5.61%, which is pretty decent. Keep in mind that our backtest doesn’t include reinvested dividends.
The result from backtests 3 and 4 looks like this (the results are not CAGR, but average gains per trade):
Strategy 3
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.25 |
0.55 |
1.01 |
2.4 |
4.3 |
8.01 |
10 |
0.17 |
0.4 |
0.93 |
1.96 |
4.19 |
8.95 |
25 |
0.45 |
0.68 |
1.35 |
2.68 |
5.15 |
10.08 |
50 |
0.52 |
0.83 |
1.59 |
2.81 |
5.94 |
9.79 |
100 |
0.53 |
0.85 |
1.72 |
2.55 |
4.63 |
7.77 |
200 |
0.61 |
0.79 |
1.49 |
2.21 |
6.12 |
10.52 |
Strategy 4
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.13 |
0.19 |
0.61 |
2.23 |
4.18 |
8.66 |
10 |
0.12 |
0.03 |
0.8 |
1.67 |
4.12 |
8.45 |
25 |
0.12 |
0.3 |
0.52 |
2.17 |
4.41 |
8.85 |
50 |
0.22 |
0.42 |
0.88 |
1.09 |
4.82 |
8.29 |
100 |
0.34 |
0.63 |
1.33 |
1.85 |
4.23 |
6.92 |
200 |
0.29 |
0.51 |
1.09 |
1.5 |
5.4 |
9.62 |
As expected, the longer you are in the stock market, the better returns you get. This is because of the tailwind in the form of inflation and productivity gains.
However, be aware that we have tested just four strategies of the moving average. There are basically unlimited ways you can use a moving average and your imagination is probably the most restricting factor!
What is Kaufman’s adaptive moving average (KAMA)?
Developed by American quantitative financial theorist Perry J. Kaufman in 1998, the adaptive moving average (KAMA) is a moving average designed to account for market noise, aka volatility. The indicator closely follows prices when the price swings are relatively small and the noise is low but adjusts when the price swings widen and follow prices from a greater distance.
In essence, the adaptive moving average works like a slow-moving average, as it reduces the influence of outliers, without sacrificing the sensitivity. It is a trend-following indicator that can be used to identify the overall trend, time turning points, and filter price movements. Although the technique began in 1972, it was Kaufman who officially presented it to the public many years later through his book: “Trading Systems and Methods.”
Unlike other moving averages, the adaptive moving average accounts not only for price action but also for market volatility. In another book titled, “Smarter Trading”, Kaufman offers some interesting adaptations of the trend-following approaches. He believes that trend following should be a safe and conservative approach to the markets, so traders need to be able to separate the trend from the random noise of the market at any given time.
The adaptive moving average is based on the idea that a noisy market requires a longer trend than one with less noise. As you know, noise is the erratic up-and-down price movement that can be seen within a trend or during a sideways period.
According to Kaufman, while longer trends are the most dependable, they respond very slowly to changing market circumstances. Since slower moving averages barely reflect forceful, short-term price movements, by the time they generate their signals, the price move may have been completed. So, the solution should be an adaptive method for trend following — one that speeds up entry when the markets are moving and does nothing when the markets are going sideways. This is why Kaufman created an adaptive moving average that can adjust to market volatility.
How to calculate the Kaufman adaptive moving average
There are several steps involved in calculating the Kaufman adaptive moving average. Perry Kaufman recommended keeping the settings at 10, 2, and 30. That is, when calculating Kaufman’s Adaptive Moving Average, do the following:
- Keep the number of periods for the efficiency ratio at 10
- Set the number of periods for the fastest exponential moving average at 2
- Set the number of periods for the slowest exponential moving average at 30
The first thing to calculate when creating KAMA is the value of the efficiency ratio and the smoothing constant. Let’s take a look at them.
Step 1: Calculating the efficiency ratio (ER)
To define the current market state, Kaufman introduced the notion of Efficiency Ratio to show the efficiency of price changes. The ER fluctuates between 1 and 0. When the price remains unchanged over 10 periods, the ER is zero, but if the price moves up or down 10 consecutive periods, the ER moves to 1. The ER is calculated by dividing the absolute difference between the current price and the price at the beginning of the period by the sum of the absolute difference between each pair of closes during the period. The formula for calculating ER is given thus:
ER = Change/volatility
Where:
Change = Absolute Value [Close – Close (past 10 periods)]
Volatility Sum = 10 periods (Close – Prior Close)
Step 2: Calculating the smoothing constant (SC)
The next step is to calculate the smoothing constant. This is done for each period, and it uses the value obtained for the efficiency ratio and two smoothing constants. The formula is given as follows:
SC= [ER x (Fastest SC – Slowest SC) + Slowest SC]2
Which translates to this:
SC= [ER x (2/ (2+1) – 2/(30+1)) +2/ (30+1)]2
From the above equation above, (2/30+1) is the smoothing constant for the recommended 30-period EMA. So, the slowest smoothing constant is the SC for the slowest 30-period EMA, and the fastest smoothing constant is the SC for shorter 2-period EMA.
Step 3: Calculating the Kaufman’s Adaptive Moving Average (KAMA)
When you have gotten the values of the efficiency function and smoothing constant, the next thing is to calculate the values of Kaufman’s Adaptive Moving Average indicator. The formula is as follows:
KAMAi = KAMAi-1 + SC x (Price – KAMA i-1)
Where:
KAMAi = the value of the current period
KAMAi-1 = the value of KAMA for the period preceding the period being calculated.
Price = the price data for the period being calculated.
While it is important to know how the indicator is derived, you don’t need to do the calculation yourself. Some trading platforms have the indicator, so the computer does the calculation.
How does the adaptive moving average work?
The adaptive moving average is designed to show the trend while putting the existing market condition into consideration. It aims to show the fastest trend possible using the shortest calculation interval for the existing market conditions, and its changes the speed of the trend by using an exponential smoothing while varying the smoothing constant each period.
The key assumption is that during a volatile period, the trend line has to lag further behind to avoid being violated by the erratic price movements, which would prematurely signal the end of a trend or the beginning of a new one. But during a period of less volatility, the trend line can be moved closer to the underlying price direction. To successfully identify the beginning of a trend the moving average should be as short as possible.
In essence, the adaptive moving average works like a slow-moving average in that it reduces the influence of outliers, without sacrificing the sensitivity. It has to be as long as necessary to avoid whipsaw losses and as short as possible to follow the price closely during periods of low volatility.
Let’s look at it this way: there are situations you want the moving average to be fast and at other times, you want it slow. But frequently adjusting your indicator yourself can be exhausting or even make things messed up. It becomes necessary to have a system that automatically adjusts the moving average when volatility changes, to adapt it to the new market condition. This is what the adaptive moving average does.
An adaptive moving average automatically adjusts itself to suit the prevailing market condition. It uses a continuously variable exponential moving average smoothing constant that increases as the price trend slope approaches the 90 degrees angle and decreases as the price trend slope nears zero. In other words, it operates like the Bollinger bands, which expand or contract in line with the prevailing market condition. But while the Bollinger bands indicator uses standard deviation to assess volatility, the adaptive moving average uses the efficiency ratio and smoothening constant.
The smoothing constant is used because it allows for a full range of trends, represented as percentages, compared to the simple moving average, which is limited in its selection. The exponential moving average period length grows shorter and more responsive when the trend is steep and accelerating, but when the price trend flattens, the period length grows longer and less responsive.
Interpreting the adaptive moving average
The KAMA indicator helps traders to get a clear picture of the market’s behavior. It can easily be applied to a chart, and traders can customize it by specifying its parameters in the properties dialog box. The main customizable parameters are the calculation periods and the appearance of the indicator. You can specify the number of periods to apply in the indicator calculation. The default number of periods is 14, but you can select any value between 2 and 1000.
Although the indicator uses historical data to obtain the final values, you can use it to make a trading decision based on the theory that trends tend to continue in the same direction until something significant happens. Traders use the KAMA indicator to analyze the behavior of a market and predict future price movement.
The indicator can be used to identify existing trends, indications of a possible impending trend change, and market reversal points that can be used for trade entries or exits. So, you can use KAMA like any other trend-following indicator, like the simple moving average indicator. See the chart below:
When using the indicator, look for price crosses, directional changes, and filtered signals. A cross above or below the KAMA indicator could mean directional changes in prices. As with any moving average, the indicator can show a lot of false signals and lots of whipsaws, but you can reduce whipsaws by applying a price or time filter to the crossovers. Some traders want to see the price to hold the cross for a set number of days or wait for the indicator cross to exceed KAMA by a set percentage.
The advantage of Kaufman’s adaptive moving average
Normally, one of the disadvantages of the usual moving average indicators is that accidental price leaps can result in the appearance of false trend signals, and on the other hand, excessive price smoothing can lead to the unavoidable lag of a signal about trend stop or change. The KAMA indicator was developed to address these two disadvantages.
When market volatility is low, the KAMA indicator remains near the current market price, but when volatility increases, it will lag to avoid being violated by exaggerated price swings. That is, the KAMA indicator tries to filter out “market noise” while maintaining its representation of the real trend. So, the KAMA indicator seeks to lessen the frequency of false signals by not responding to short-term, insignificant price movements, which makes it better than the traditional moving average methods.
How to use the adaptive moving average
As we have stated earlier, one of the uses of the KAMA indicator is to identify the general trend of current market price action — when the KAMA indicator line is moving downward, especially with the price lying mostly below it, it indicates the existence of a downtrend. On the other hand, when the KAMA line is moving upward, it shows a potential uptrend. When compared to the simple moving average indicator, the KAMA indicator is less likely to generate false signals that may cause a trader to incur losses.
With that said, here’s how you can use the KAMA indicator in your trading:
- Combine it with price action analysis: Use the KAMA to identify the direction of the market, and then use reversal candlestick patterns at support or resistance levels to indicate trade entry.
- Use two KAMA indicators: you can use them to spot the beginning of new trends and pinpoint trend reversal points: You can do this by plotting two KAMA lines on a chart — one with a more short-term moving average (faster) and another with a longer-term moving average (slower). The faster KAMA line crossing above the slower KAMA line implies a change from a downtrend to an uptrend. When this happens, you can take a long position and close the trade when the faster MA line crosses back below the slower MA line.
- Use the price crossing the indicator to generate signals: When the price crosses from below to above the KAMA line, you have a bullish (buy) signal. On the other hand, when the price falls from above the KAMA line to below it, you may have a bearish (sell) signal.
However, no matter what you do, you must always backtest your trading ideas. What looks good by using anecdotal evidence might not be so good when you test on longer time frames.
Relevant articles about moving averages strategies and backtests
Moving averages have been around in the trading markets for a long time. Most likely, moving average strategies were the start of the systematic and automated trading strategies developed in the 1970s, for example by Ed Seykota. We believe it’s safe to assume moving averages were a much better trading indicator before the 1990s due to the rise of the personal computer. The most low-hanging fruit has been “arbed away”.
That said, our backtests clearly show that you can develop profitable trading strategies based on moving averages but mainly based on short-term mean-reversion and longer trend-following. Furthermore, there exist many different moving averages and you can use a moving average differently/creatively, or you can combine moving averages with other parameters.
For your convenience, we have covered all moving averages with both detailed descriptions and backtests. This is our list:
- Moving average trading strategies
- Simple moving average (backtest strategy)
- Exponential moving average (backtest strategy)
- Hull moving average (backtest strategy)
- Linear-weighted moving average (backtest strategy)
- Smoothed moving average (backtest strategy)
- Variable moving average (backtest strategy)
- Weighted moving average (backtest strategy)
- Zero lag exponential moving average (backtest strategy)
- Volume weighted moving average (backtest strategy)
- Triple exponential moving average TEMA (backtest strategy)
- Variable Index Dynamic Average (backtest strategy)
- Triangular moving average (backtest strategy)
- Guppy multiple moving average (backtest strategy)
- McGinley Dynamic (backtest strategy)
- Geometric moving average GMA (backtest strategy)
- Fractal adaptive moving average FRAMA (backtest strategy)
- Fibonacci moving averages (backtest strategy)
- Double exponential moving average (backtest strategy)
- Moving average slope (backtest strategy)
We have also published relevant trading moving average strategies:
- The 200-day moving average strategy
- Trend-following system/strategy in gold (12-month moving average)
- Trend following strategies Treasuries
- Is Meb Faber’s momentum/trend-following strategy in gold, stocks, and bonds still working?
- Trend following strategies and systems explained (including strategies)
- Does trend following work? Why does it work?
- A simple trend-following system/strategy on the S&P 500 (By Meb Faber and Paul Tudor Jones)
- Conclusions about trend-following the S&P 500
- Why arithmetic and geometric averages differ in trading and investing
Adaptive (Kaufman) moving average – takeaways
Our takeaway from the backtests is that adaptive moving average strategies work well if you buy on weakness (a close below the moving average) and sell on strength (a close above the moving average) when you use a short number of days. Opposite, it’s best to buy on strength (a close above the moving average) when you use a longer moving average.