Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Moving average
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Simple moving average== [[File: Moving Average Types comparison - Simple and Exponential.png|thumb]] In financial applications a '''simple moving average''' ('''SMA''') is the unweighted [[arithmetic mean|mean]] of the previous <math>k</math> 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. {{Anchor|algorithm}}An example of a simple equally weighted running mean is the mean over the last <math>k</math> entries of a data-set containing <math>n</math> entries. Let those data-points be <math>p_1, p_2, \dots, p_n</math>. This could be closing prices of a stock. The mean over the last <math>k</math> data-points (days in this example) is denoted as <math>\textit{SMA}_{k}</math> and calculated as: <math display="block">\begin{align} \textit{SMA}_{k} &= \frac{p_{n-k+1} + p_{n-k+2} + \cdots + p_{n}}{k} \\ &= \frac{1}{k} \sum_{i=n-k+1}^{n} p_{i} \end{align}</math> When calculating the next mean <math>\textit{SMA}_{k,\text{next}}</math> with the same sampling width <math>k</math> the range from <math> n - k + 2 </math> to <math> n+1 </math> is considered. A new value <math>p_{n+1}</math> comes into the sum and the oldest value <math>p_{n-k+1}</math> drops out. This simplifies the calculations by reusing the previous mean <math>\textit{SMA}_{k,\text{prev}}</math>. <math display="block"> \begin{align} \textit{SMA}_{k, \text{next}} &= \frac{1}{k} \sum_{i=n-k+2}^{n+1} p_{i} \\ &= \frac{1}{k} \Big( \underbrace{ p_{n-k+2} + p_{n-k+3} + \dots + p_{n} + p_{n+1} }_{ \sum_{i=n-k+2}^{n+1} p_{i} } + \underbrace{ p_{n-k+1} - p_{n-k+1} }_{= 0} \Big) \\ &= \underbrace{ \frac{1}{k} \Big( p_{n-k+1} + p_{n-k+2} + \dots + p_{n} \Big) }_{= \textit{SMA}_{k, \text{prev}}} - \frac{p_{n-k+1}}{k} + \frac{p_{n+1}}{k} \\ &= \textit{SMA}_{k, \text{prev}} + \frac{1}{k} \Big( p_{n+1} - p_{n-k+1} \Big) \end{align} </math> 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 <math> k = n </math> and the average calculation is performed as a [[#Cumulative average|cumulative moving average]]. The period selected (<math>k</math>) 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 has 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.<ref>''Statistical Analysis'', Ya-lun Chou, Holt International, 1975, {{ISBN|0-03-089422-0}}, section 17.9.</ref> 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.<ref>The derivation and properties of the simple central moving average are given in full at [[Savitzky–Golay filter]].</ref> 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 filter#Frequency-domain sinc|sinc-in-frequency]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)