Adaptive Moving Average with some pseudo-code

David Varadi at CSS made an interesting post about using an adaptive MA that uses the square of a percentile of drawdowns to adjust his MA. The methodology looks interesting and it seems to pass the smell test. Unfortunately, at least for me, his pseudocode is quite vague. Anyone want to help me take a stab at it?
This is the discussion:
The first step is to create a series of drawdowns from all-time highs (it isn’t critical to choose all-time, 1-year highs work well too). Then find the empirical distribution of such drawdowns using some lookback using a percentile ranking over the past 6 months (again not critical can use longer or shorter or a combination). I use the square of this value for the simple reason that we want to ignore small drawdowns and focus on larger drawdowns to make lookback length adjustments (remember corrections require long-term lookbacks and rebounds after large drawdowns require short-term lookbacks). Next choose a short-term trend-following lookback and a long-term lookback. In this case I chose 50 and 200 which are often followed by market participants via their respective moving averages but again the parameter choice is not critical. One practical point is that it is inefficient to use a really short-term lookback for tactical trading such as 20 days. We can calculate the optimal alpha of a moving average using the exponential moving average framework as follows:

Percentile Ranking of Drawdowns ^ 2 (squared) = P

Short- Term Alpha= ST

Long-Term Alpha= LT

Optimal Alpha= P*ST+(1-P)*LT

link is here: https://cssanalytics.wordpress.com/2020/12/23/how-should-trend-followers-adjust-to-the-modern-environment-enter-adaptive-momentum/#respond

1 Like

@TonyR it is pretty late here and I'm probably too sleepy and shouldn't post this until I've double checked it but I have taken a stab at it. Hopefully this will get you started and you can post improvements.

HH252 = HHV( H, 252);
EQ = C;
// DD = 100 * ( Eq - HH252 ) / HH252; // usually I think of DD as a negative number
// no, for this calculation we need the DD to be a positive number
DD = 100 * ( HH252 - Eq ) / HH252;

// consider parameterizing or optimizing these lookback periods
// in david's blog post it appears that he (not suprisingly) has examined different periods
ST = 50; // he suggests 50 day 
LT = 200; // and 200 day ema's

ST_alpha = 2/(ST + 1);
LT_alpha = 2/(LT + 1);

// rank for about 6 months suggested
prDD = PercentRank(DD, 126)/100; // i think we need a number from  0 to 1.0, so not a 0 to 100%
P 	 = prDD*prDD;

OptimalAlpha = P*ST_alpha + (1-P)*LT_alpha;

VaradiAMA = AMA( close, OptimalAlpha );

Produces a plot that looks pretty similar to the blog post.
image

14 Likes

Larry, thank you very much! I truly appreciate it! Now to dig in and see if and how it can be used. Again thank you! I was getting caught up at the decimalization of prDD which you caught right away.
Kindest Regards!
Tony R

2 Likes

If anyone is interested I found the WEEKLY time frame to show promise. As Larry noted, the ST and LT variables are easily optimized. I'm just running some general tickers like SPY and it looks compelling as a market filter for other purposes. Thanks again to @portfoliobuilder!
Tony

3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.