How to Calculate Exponential Moving Averages

••• wutwhanfoto/iStock/GettyImages

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.

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:

12 + 12 + 13 + 15 + 18 + 17 + 18 + 20 + 21 + 24 = 170; 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:

12 + 13 + 15 + 18 + 17 + 18 + 20 + 21 + 24 + 24 = 182; 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.

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.

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

  1. Find the Initial EMA Value

  2. 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.

    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; 66 ÷ 5 = 13.2

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

  3. Calculate the Weighting Multiplier (Smoothing Constant)

  4. 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:

    2 ÷ (number of time periods + 1)

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

    2 ÷ (5 + 1) = 2 ÷ 6 = 0.3333 or, if you express it as a percentage, 33.33%.

    Tips

    • 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.

  5. Input That Information in the EMA Formula

  6. 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:

    EMA = (closing price - previous day's EMA) × smoothing constant as a decimal + 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:

    EMA = (12 - 13.2) × 0.3333 + 13.2

    EMA = 12.80

    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:

    EMA = (11 - 12.8) × 0.3333 + 12.8

    EMA = 12.20

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.

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.

References

About the Author

Lisa studied mathematics at the University of Alaska, Anchorage, and spent several years tutoring high school and university students through scary -- but fun! -- math subjects like algebra and calculus.

Dont Go!

We Have More Great Sciencing Articles!