0% found this document useful (0 votes)
34 views2 pages

Moving Average

The document discusses different types of moving averages used to smooth data including simple moving averages, exponential moving averages, and approximate rolling averages. Simple moving averages average past data points over a given period. Exponential moving averages apply weighting factors that decrease exponentially. Approximate rolling averages apply a weighted average to the input stream without storing all past values.

Uploaded by

Can Ilica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Moving Average

The document discusses different types of moving averages used to smooth data including simple moving averages, exponential moving averages, and approximate rolling averages. Simple moving averages average past data points over a given period. Exponential moving averages apply weighting factors that decrease exponentially. Approximate rolling averages apply a weighted average to the input stream without storing all past values.

Uploaded by

Can Ilica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Moving, Rolling and Running (Average)

A Finite Impulse Response Filter, or Moving Average is an example of a low-pass filter typically used in signal
processing. In its most basic form it’s simply used to smooth data. Its true purpose is to smooth out short-term
fluctuations and highlight longer-term trends or cycles. When used without any specific connection to time, a
moving average filters out the higher frequency components.

//no error checking is performed on exceeding the bounds of data

float SimpleMovingAverage(float data[], int index, int period) {

float sample;

sample = 0.0;

for (i=(index–period+1); i<=index; i++)

sample += data[i];

return (sample/period);

The period selected depends on the type of movement of interest, such as short, intermediate, or long term. If
the data is 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.

An exponential moving average, or exponentially weighted moving average, is a type of impulse response filter
that applies weighting factors which decrease exponentially.

float accumulator;

const float alpha = 1.0; //0 to 1

float ExponentialMovingAverage(float new_value) {

accumulator += alpha*(new_value - accumulator);

return(accumulator);

}
In this example, we use an “accumulator” variable, which, as each sample is evaluated is updated with the new
value. The function requires a constant “alpha” that is between 0 and 1, where the effect of a given sample only
lasts for the requisite period.

Finally, you can approximate a rolling average by applying a weighted average on your input stream. This way,
you don’t need to maintain a large array of values. However, since it’s an approximation, it’s value will not
exactly match a true rolling average.

float sma;

int period;

float ApproximateSimpleMovingAverage(float new_value) {

sma *= (period – 1);

sma += vew_value;

sma /= period;

return sma;

The following chart demonstrates the 3 types of moving averages on a sample data set. The SMA has a period
of 7, the exponential average uses an alpha of 0.4, and the approximate-rolling average uses a period of 5.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy