Jump to content

Moving Average/Simple Moving Average

From Wikiversity

Simple moving average - discrete

[edit | edit source]

In financial applications a simple moving average (SMA) is the unweighted mean of the previous n data. 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 for a n-day sample of closing price is the mean of the previous n days' closing prices.

p0(0)=p0(−1)=…=p0(−(n−1))=1n

and p0(x)=0 for x∉{−n+1,…,−1,0} with V=ℤ as additive group.

Let C(t) be the cost/price of product at time t∈V. If those prices are C(0),C(1),…,C(97),C(98),C(99),C(100),C(101),… and we want to create a simple moving average at day t=100 and looking back for time span of n=5 days then the formula is

SMA(100)=15⋅C(100)+15⋅C(99)+15⋅C(98)+15⋅C(97)+15⋅C(96)=15∑i=04C(100−i)=∑i=0n−1p100(100−i)⋅C(100−i)

When calculating successive values for other days/time t∈V=ℤ, a new value comes into the sum and an old value drops out, meaning a full summation each time is unnecessary for this simple case,

SMA(101)=15⋅C(101)+15⋅C(100)+15⋅C(99)+15⋅C(98)+15⋅C(97)


𝑆𝑀𝐴(t)=1n∑i=0n−1C(t−i)=∑i=0n−1pt(t−i)⋅C(t−i)=∑i=0n−1p0(−i)⋅C(t−i)

The period selected depends on the type of movement of interest, such as short, intermediate, or long-term. In financial terms moving-average levels can be interpreted as support in a falling market, or resistance in a rising market. If you draw a graph for 𝑆𝑀𝐴(t) and cost function C(t), you will identify, that the graph of 𝑆𝑀𝐴 runs smoother in the time t∈V

If the data used are not centered around the mean, a simple moving average lags behind the latest datum point by half the sample width. An SMA can also be disproportionately influenced by old datum points 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.[1]

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.[2] This requires using an odd number of datum points in the sample window.

p0(−n)=p0(−n+1)=…=p0(−1)=p0(0)=p0(1)=⋯=p0(n−1)=p0(n)=12n+1

and p0(x)=0 for x∉{−n,…,−1,0,1,…,n} with V=ℤ as additive group.

𝑆𝑀𝐴(t)=12n+1∑i=−nnC(t+i)=∑i=−nnpt(t+i)⋅C(t+i)=∑i=−nnp0(i)⋅C(t+i)

A major drawback of the SMA is that it lets through a significant amount of the signal shorter than the window length. Worse, it actually inverts it. 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.

Simple moving average - continuous

[edit | edit source]

If we consider a continous measurement of value e.g. a force f(t) at time t. The objective is to smooth the values f(t) with a continous simple moving average. We look a time span s>0 in the past. As probability distribution we use a uniform distribution (mathematics) for the intervall [−n,0]. The density function is:

p0(x)={1nfor −n≤x≤0,0for x<n or x>0 and pt(x):=p0(x−t)

Application on the moving average definition for continuous probability distriubtions we get:

SMA(t):=∫ℝpt(x)⋅f(x)dx=∫t−ntp0(x−t)⋅f(x)dx=1n∫t−ntf(x)dx
  1. ↑ Statistical Analysis, Ya-lun Chou, Holt International, 1975, ISBN 0-03-089422-0, section 17.9.
  2. ↑ The derivation and properties of the simple central moving average are given in full at Savitzky–Golay filter