Arnaud Legoux Moving Average

The Arnaud Legoux Moving Average (ALMA) of Arnaud Legoux and Dimitris Kouzis-Loukas (2009) weights the prices of the window with a Gaussian curve whose peak can be moved towards the latest price, which balances smoothness against lag.

The formula for the Arnaud Legoux Moving Average first places the peak m of the curve at a fraction o of the window of n periods, rounded down to a whole period, and sets the width s of the curve so that sigma widths fit in the window:

\[m = \left\lfloor o \cdot (n - 1)\right\rfloor\] \[s = \frac{n}{\sigma}\]

Each price of the window gets the weight \(w_{i}\) of the Gaussian curve at its position, and the average weights each closing price \(\text{Close}_{i}\) with it:

\[w_{i} = \exp\left(-\frac{(i - m)^{2}}{2 \cdot s^{2}}\right)\] \[\text{ALMA} = \frac{\sum_{i=0}^{n - 1} w_{i} \cdot \text{Close}_{i}}{\sum_{i=0}^{n - 1} w_{i}}\]

Where i runs from 0 for the oldest to n - 1 for the latest price. An offset o close to 1 puts the weight on the latest prices and makes the ALMA quick; close to 0, it puts it on the oldest and makes the ALMA smooth. A larger sigma narrows the curve. The authors’ settings are \(n = 9\), \(o = 0.85\) and \(\sigma = 6\).

A moving average smooths the price by averaging it over the last n periods, so that the trend shows through the noise of single periods. It is the oldest and most widely used trend indicator: the direction of the average shows the direction of the trend, the price above (below) it an uptrend (downtrend), and other indicators, from the MACD to the Bollinger Bands, are built on it. Every moving average trades smoothness against lag: the more periods it averages, the smoother it is and the later it turns after the price. The averages differ in how they weight the prices within the window and whether they adapt their speed to the market, each a different answer to that trade-off.

Also known as: ALMA.

In the Finance Toolkit this is get_moving_average with method="arnaud_legoux", the same function as Moving Average.

Example · ^GSPC · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_moving_average:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["^GSPC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_moving_average(method="arnaud_legoux", window=50)

Which returns:

References

  • Paper Legoux, A. & Kouzis-Loukas, D. (2009). “ALMA: Arnaud Legoux Moving Average.” arnaudlegoux.com.
  • Library Referenced against TA-Lib’s ALMA (Arnaud Legoux Moving Average)
  • Library Referenced against pandas-ta-classic’s alma (Arnaud Legoux Moving Average)
Share