Moving average

Thus in signal processing it is viewed as a low-pass finite impulse response filter.

Given a series of numbers and a fixed subset size, the first element of the moving average is obtained by taking the average of the initial fixed subset of the number series.

A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer-term trends or cycles - in this case the calculation is sometimes called a time average.

The threshold between short-term and long-term depends on the application, and the parameters of the moving average will be set accordingly.

It is also used in economics to examine gross domestic product, employment or other macroeconomic time series.

When used with non-time series data, a moving average filters higher frequency components without any specific connection to time, although typically some kind of ordering is implied.

In financial applications a simple moving average (SMA) is the unweighted mean of the previous

However, in science and engineering, the mean is normally taken from an equal number of data on either side of a central value.

This means that the moving average filter can be computed quite cheaply on real time data with a FIFO / circular buffer and only 3 arithmetic steps.

During the initial filling of the FIFO / circular buffer the sampling window is equal to the data-set size thus

) depends on the type of movement of interest, such as short, intermediate, or long-term.

If the data used are not centered around the mean, a simple moving average lags behind the latest datum by half the sample width.

[2] For a number of applications, it is advantageous to avoid the shifting induced by using only "past" data.

Hence a central moving average can be computed, using data equally spaced on either side of the point in the series where the mean is calculated.

A major drawback of the SMA is that it lets through a significant amount of the signal shorter than the window length.

[citation needed] This can lead to unexpected artifacts, such as peaks in the smoothed result appearing where there were troughs in the data.

It also leads to the result being less smooth than expected since some of the higher frequencies are not properly removed.

Its frequency response is a type of low-pass filter called sinc-in-frequency.

Thus the current cumulative average for a new datum is equal to the previous cumulative average, times n, plus the latest datum, all divided by the number of points received so far, n+1.

This is also known as Anti-aliasing [citation needed] In the financial field, and more specifically in the analyses of financial data, a weighted moving average (WMA) has the specific meaning of weights that decrease in arithmetical progression.

Its symmetric weight coefficients are [−3, −6, −5, 3, 21, 46, 67, 74, 67, 46, 21, 3, −5, −6, −3], which factors as ⁠[1, 1, 1, 1]×[1, 1, 1, 1]×[1, 1, 1, 1, 1]×[−3, 3, 4, 3, −3]/320⁠ and leaves samples of any quadratic or cubic polynomial unchanged.

[9][10] Outside the world of finance, weighted running means have many forms and applications.

On this point, the French version of this article discusses the spectral effects of 3 kinds of means (cumulative, exponential, Gaussian).

From a statistical point of view, the moving average, when used to estimate the underlying trend in a time series, is susceptible to rare events such as rapid shocks or other anomalies.

A more robust estimate of the trend is the simple moving median over n time points:

For larger values of n, the median can be efficiently computed by updating an indexable skiplist.

However, the normal distribution does not place high probability on very large deviations from the trend which explains why such deviations will have a disproportionately large effect on the trend estimate.

It can be shown that if the fluctuations are instead assumed to be Laplace distributed, then the moving median is statistically optimal.

This is because, for a given variance, the Laplace distribution, which the Moving Median assumes, places higher probability on rare events than the normal distribution that the Moving Average assumes.

Those two concepts are often confused due to their name, but while they share many similarities, they represent distinct methods and are used in very different contexts.

Smoothing of a noisy sine (blue curve) with a moving average (red curve).
WMA weights n = 15