Exponential Moving Average

The Exponential Moving Average (EMA) weights the prices with exponentially decaying weights, so the latest price weighs the most and older prices fade without ever dropping out abruptly.

The formula for the Exponential Moving Average first sets the smoothing factor alpha from the number of periods n:

\[\alpha = \frac{2}{n + 1}\]

Each EMA then moves the EMA of the period before a fraction alpha of the way to the latest close:

\[\text{EMA} = \alpha \cdot \text{Close} + (1 - \alpha) \cdot \text{EMA}_{t-1}\]

Where EMA(t-1) is the EMA of the period before. The EMA follows the price more closely than an SMA of the same length and turns earlier, at the cost of more false turns in a sideways market. It is read like the SMA: the direction of the average and the price above or below it give the trend.

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: EMA, exponentially weighted moving average, EWMA.

In the Finance Toolkit this is get_moving_average with method="exponential", 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="exponential", window=50)

Which returns:

References

  • Paper Murphy, J.J. (1999). “Technical Analysis of the Financial Markets.” New York Institute of Finance.
  • Paper Achelis, S.B. (2000). “Technical Analysis from A to Z.” 2nd edition, McGraw-Hill.
  • Library Referenced against TA-Lib’s EMA (Exponential Moving Average)
  • Library Referenced against TA-Lib’s DEMA (Double Exponential Moving Average)
  • Library Referenced against TA-Lib’s TEMA (Triple Exponential Moving Average)
  • Library Referenced against TA-Lib’s ZLEMA (Zero Lag Exponential Moving Average)
Share