Skip to content
tezvyn:
Menu

Moving Average: Smoothing Out the Noise in Data

Source: Wikipedia: Moving averageEasyHow cards are made

Moving Average: Smoothing Out the Noise in Data

A moving average smooths out noisy data by replacing each point with the average of its neighbors, revealing the underlying trend. It's used to track stock prices or server metrics without overreacting to short spikes.

The mental model

A moving average acts like a filter for noisy data, smoothing out short-term fluctuations to reveal the underlying trend. Imagine squinting to see the general shape of a jagged line; the moving average is the mathematical equivalent of that action, turning volatile data into a smoother, more interpretable signal.

How it works

The most common type is the Simple Moving Average (SMA). To calculate an N-day SMA, you take the data points for the last N days, sum them up, and divide by N. Then you slide the window forward one day and repeat. For example, with daily temperatures [70, 75, 72, 68, 71] and a 3-day window, the first average is (70+75+72)/3 = 72.3. The next is (75+72+68)/3 = 71.7. This creates a new, smoother time series. Other forms exist, like a weighted moving average that gives more importance to recent data, or a cumulative average that includes all data up to the current point.

When to use it

Use a moving average when you need to understand the long-term trend in volatile time-series data. It's ideal for financial charts to see if a stock is trending up or down over months, for monitoring systems to track average CPU load without getting alerted by brief spikes, or for analyzing weekly sales figures to see seasonal patterns.

When not to use it

Avoid moving averages when individual data points are critical. For example, in fraud detection, a single anomalous transaction is important and should not be averaged away. It also introduces lag; the average always trails the most recent data. Therefore, it's unsuitable for systems that require instantaneous, real-time responses to every data point.

One canonical example

In stock market analysis, traders use the 50-day and 200-day moving averages as key indicators. When the shorter-term 50-day average crosses above the longer-term 200-day average (a "golden cross"), it's often interpreted as a bullish signal for a long-term upward trend. The opposite is a "death cross."

Interview question

Which of the following is a known limitation of using a moving average?

  • a.It requires a fixed number of data points, making it inflexible for varying data streams.
  • b.It is only effective for data with a very low level of noise.
  • c.It exaggerates individual data spikes, making the underlying trend less clear.
  • d.It introduces a lag, causing it to trail the most recent data and delay real-time responses.Correct
Why?

The card states that a moving average 'introduces lag; the average always trails the most recent data,' making it 'unsuitable for systems that require instantaneous, real-time responses.' Its primary purpose is to smooth out noise, not to exaggerate spikes or require already clean data.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on analytics — each one lists the topics its interview covers.

See open roles