In statistics, a moving average (also rolling average, running average, moving mean, or rolling mean) is a calculation to analyze data points by creating a series of averages of different selections of the full data set. Variations include: simple, cumulative, or weighted forms. Mathematically, a moving average is a type of convolution. Thus in signal processing it is viewed as a low-pass finite impulse response filter. Because the boxcar function outlines its filter coefficients, it is called a boxcar filter. It is sometimes followed by downsampling. 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. Then the subset is modified by "shifting forward"; that is, excluding the first number of the series and including the next value in the 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. Viewed simplistically it can be regarded as smoothing the data.
History The technique of moving averages was invented by the Bank of England in 1833 to conceal the state of its bullion reserves.
Simple moving average
In financial applications a simple moving average (SMA) is the unweighted mean of the previous k data-points. However, in science and engineering, the mean is normally taken from an equal number of data on either side of a central value. This ensures that variations in the mean are aligned with the variations in the data rather than being shifted in time. An example of a simple equally weighted running mean is the mean over the last k entries of a data-set containing n entries. Let those data-points be p1,p2,…,pn. This could be closing prices of a stock. The mean over the last k data-points (days in this example) is denoted as 𝑆𝑀𝐴k and calculated as: 𝑆𝑀𝐴k=pn−k+1+pn−k+2+⋯+pnk=1k∑i=n−k+1npi When calculating the next mean 𝑆𝑀𝐴k,next with the same sampling width k the range from n−k+2 to n+1 is considered. A new value pn+1 comes into the sum and the oldest value pn−k+1 drops out. This simplifies the calculations by reusing the previous mean 𝑆𝑀𝐴k,prev. 𝑆𝑀𝐴k,next=1k∑i=n−k+2n+1pi=1k(pn−k+2+pn−k+3+⋯+pn+pn+1⏟∑i=n−k+2n+1pi+pn−k+1−pn−k+1⏟=0)=1k(pn−k+1+pn−k+2+⋯+pn)⏟=𝑆𝑀𝐴k,prev−pn−k+1k+pn+1k=𝑆𝑀𝐴k,prev+1k(pn+1−pn−k+1) 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 k=n and the average calculation is performed as a cumulative moving average. The period selected (k) 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. An SMA can also be disproportionately influenced by old data dropping out or new data coming in. One characteristic of the SMA is that if the data have a periodic fluctuation, then applying an SMA of that period will eliminate that variation (the average always containing one complete cycle). But a perfectly regular cycle is rarely encountered. 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. This requires using an odd number of points in the sample window. A major drawback of the SMA is that it lets through a significant amount of the signal shorter than the window length. 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 (or, in discrete time, is a Dirichlet kernel).
Continuous moving average The continuous moving average of an integrable function f:ℝ→ℝ is defined via integration as:
Mf,ε:ℝ→ℝx↦12ε∫x−εx+εf(t)dt where the ε environment [x−ε,x+ε] around x defines the intensity of smoothing of the graph of the integrable function. A larger ε>0 smooths the source graph of the function (blue) f more. The animations below show the moving average as animation in dependency of different values for ε>0. The fraction 12ε is used, because 2ε is the interval width for the integral. Naturally, limε→0Mf, ε=f by fundamental theorem of calculus and L'Hôpital's rule.
… excerpt ends here. Continue reading the full article.





