MAMA-FAMA Crossover: The Mother of all Crossover Strategies? (Python)
Screenshot: QuantConnect Strategy results
While browsing the QuantConnect forum I stumbled across a post with the intriguing title “Daydreaming: 10K to 1 million (in 10 years)” that caught my attention. The gist of this post by a user called “JB P" is that he implemented a crossover strategy of the MESA Adaptive Moving Average (MAMA) and Following Adaptive Moving Average (FAMA), which he backtested using Apple stock and pulled off a stunning 11,000% total return in 10 years.🙄
In this post I wanted to take a closer look at the strategy he implemented see if I could reproduce these results.
This story is solely for general information purposes, and should not be relied upon for trading recommendations or financial advice. Source code and information is provided for educational purposes only, and should not be relied upon to make an investment decision. Please review my full cautionary guidance before continuing.
What is the MESA Adaptive Moving Average (MAMA)?
The MESA Adaptive Moving Average (MAMA) is a technical indicator based on the price of a security that uses a special method to adapt to price movements, similar to the Exponential Moving Average (EMA). The indicator was developed by John Ehlers, president of MESA Software), in this paper.
Although Ehlers didn’t publish the exact formula for this indicator, he did describe it in words and post the code to calculate it MESA EasyLanguage code.
From what I understand, the core of idea for MAMA is based on the concept of the EMA, which blends a portion of the current price with a portion of the previous EMA value. The EMA becomes more responsive to current price changes as the weighting factor (α) increases. To make the EMA adaptive, MAMA varies the weighting factor (α) based on the phase rate of change, as determined by the cycle period and the Hilbert Transform Discriminator.
So basically when the cycle period is short (indicating a faster rate of change in the market), MAMA becomes more sensitive to price changes. During longer cycle periods, which often occur in trending markets, MAMA becomes less sensitive, helping to avoid unnecessary trades during these periods.
The calculation - which is quite complex - involves determining the phase of the market cycle using the arctangent of the ratio of two components (Quadrature and InPhase) derived from the price data. This phase helps to adjust the EMA weighting factor (α) dynamically, with MAMA moving quickly to adapt to price changes and then holding its value until the next cycle phase adjustment.
In the implementation section you can see the complete calculation in C#, the translation into Python script, and using the TA-Lib MAMA/FRAMA indicators.