How To Calculate Exponential Moving Averages

Stock analysts use moving averages to help filter out noise and identify trends. They're not used to predict prices – but the trend information gleaned from graphs of moving averages, especially several moving averages overlaid atop one another, can help identify points of resistance and support, and trigger decisions to buy or sell. There are two types of moving averages: simple moving averages and exponential moving averages, with the latter responding more quickly to changes in trends.

Advertisement

TL;DR (Too Long; Didn't Read)

The exponential moving average formula is:

EMA = (closing price − previous day's EMA) × smoothing constant + previous day's EMA

where the smoothing constant is:

2 ÷ (number of time periods + 1)

How to Calculate a Simple Moving Average

Before you can start calculating exponential moving averages, you must be able to calculate a simple moving average or SMA. Both SMAs and EMAs are usually based on stock closing prices.

To find a simple moving average, you calculate the mathematical mean. In other words, you sum all the closing prices in your SMA, and then divide by the number of closing prices. For example, if you're computing a 10-day SMA, you'd first add up all the closing prices from the last 10 days, and then divide by 10. So if the closing prices over a 10-day period are $12, $12, $13, $15, $18, $17, $18, $20, $21 and $24, the SMA would be:

Advertisement

\(12 + 12 + 13 + 15 + 18 + 17 + 18 + 20 + 21 + 24 = 170\)
\(\frac{170}{10} = 17\)

So the average closing price for that 10-day time period is $17. But in order for the SMA to be useful you must calculate a number of SMAs and graph them, and because each SMA only deals with the previous 10 days' worth of data, old values will "drop out" out of the equation as you add new data points. That's what allows the graph of the average to "move" and adjust to the changes in price over time, although the stabilizing effect of that old data means there is a lag period before price changes are really reflected in your simple moving average.

For example: The next day, your stock closes at $24 again. This time when you calculate the SMA you add the newest data point to your equation, but also "lose" the oldest data point – that first $12 closing price. So now your 10-day simple moving average is:

Advertisement

\(12 + 13 + 15 + 18 + 17 + 18 + 20 + 21 + 24 + 24 = 182\)
\(\frac{182}{10} = 18.2\)

You'd do the same process daily, calculating a new SMA for every day that you want represented on your graph.

The Lag Period in Moving Averages

The lag period before your SMA catches up to actual price changes isn't necessarily a bad thing; that "lag" is what smoothes out the variance in day-to-day prices. If the moving average rises, you know that prices are generally increasing, despite periodic dips. Likewise, if a moving average starts to drop, it means prices are generally decreasing despite periodic dips.

Advertisement

Second, the longer the time period for your moving average (five-day versus 10-day versus 100-day, and so on), the more slowly it adjusts to reflect current trends. So the behavior of a long-term moving average gives you a window into long-term trends, while a shorter moving average reflects the behavior of more short-term trends.

The Exponential Moving Average Formula

The key difference between a simple moving average (SMA) and the exponential moving average (EMA) is that in the EMA calculation, the most recent data is weighted to have more of an impact. That makes EMAs quicker than SMAs to adjust and reflect trends. On the downside, an EMA requires a lot more data to be reasonably accurate.

Advertisement

In order to calculate the EMA of a set of data, you must do three things:

1. Find the Initial EMA Value

The EMA formula is based on the previous day's EMA value. Since you have to start your calculations somewhere, the initial value for your first EMA calculation will actually be an SMA. For example, if you want to calculate a 100-day EMA for the last year of tracking a certain stock, you'll start with the SMA of the first 100 data points in that year.

Advertisement

That's too many numbers to add here, so instead let's demonstrate the five-day EMA of a data set that started a year ago. If the first five closing prices of the year were $14, $13, $14, $12 and $13, your SMA is:

\(14 + 13 + 14 + 12 + 13 = 66\)
\(\frac{66}{5} = 13.2\)

So the SMA, which becomes your initial EMA value, is 13.2.

2. Calculate the Weighting Multiplier (Smoothing Constant)

The weighting multiplier or smoothing constant is what emphasizes the most recent data, and its value depends on the time period of your EMA. The formula for your smoothing constant is:

\(\frac{2}{\text{number of time periods } + 1}\)

So if you're calculating a five-day EMA, that calculation becomes:

\(\frac{2}{5 + 1} = \frac{2}{6} = 0.3333\)

or, if you express it as a percentage, 33.33%.

Advertisement

TL;DR (Too Long; Didn't Read)

Note that an EMA may be referred to by its time period (in this case, a five-day EMA) or by its percentage value (in this case, a 33.33% EMA). Also, the shorter the time period, the more heavily the most recently data will be weighted.

3. Input That Information in the EMA Formula

Finally, calculate a separate EMA for every day between the initial value (the SMA you calculated in Step 1) and today. You do that by inputting the information from Steps 1 and 2 into the EMA formula:

\(\text{EMA} = (\text{closing price } – \text{ previous day's EMA}) × \text{ smoothing constant as a decimal } + \text{ previous day's EMA}\)

Remember, the "previous day's EMA" for your first calculation will be the SMA you found in Step 1, which is 13.2. Since that SMA covered the first five days worth of data, the first EMA value you calculate will apply to the next day, which is day six. Using the data from Steps 1 and 2 in the EMA formula, you have:

\(\begin{aligned}\)
\(\text{EMA } &= (12 – 13.2) × 0.3333 + 13.2\)
\(&= 12.80\)
\(\end{aligned}\)

So the EMA value for day six is 12.80.

If the closing value on day seven was $11, you'd repeat the process, using day six's value of 12.80 as the new "previous day's EMA." So the calculation for day seven is as follows:

Advertisement

\(\begin{aligned}\)
\(\text{EMA } &= (11 – 12.8) × 0.3333 + 12.8 \
&= 12.20\)
\(\end{aligned}\)

Getting an Accurate EMA

If you recall that the original example said you'd calculate the stock's five-day EMA for a whole year's worth of data, that means you have several hundred calculations yet to do – because you have to calculate one day at a time. Obviously, this is much faster and easier with a computer program or script to crunch the numbers for you.

Advertisement

If you really want the most accurate EMA possible, you should start your calculations with data from the very first day the stock was available. Although that's often impractical, it also reinforces the fact that EMAs are used to reflect and analyze trends – so if you graphed the EMA starting from day one of the stock you'd see how, after a lag period, the graph curve shifts to follow the actual stock prices. If you also draw an SMA for the same time period on the same graph, you'd also see that an EMA adjusts to changes in price more quickly than an SMA does.

Cite This Article

MLA

Maloney, Lisa. "How To Calculate Exponential Moving Averages" sciencing.com, https://www.sciencing.com/calculate-exponential-moving-averages-8221813/. 22 December 2020.

APA

Maloney, Lisa. (2020, December 22). How To Calculate Exponential Moving Averages. sciencing.com. Retrieved from https://www.sciencing.com/calculate-exponential-moving-averages-8221813/

Chicago

Maloney, Lisa. How To Calculate Exponential Moving Averages last modified March 24, 2022. https://www.sciencing.com/calculate-exponential-moving-averages-8221813/

Recommended

Advertisement