Moving average
Moving average
In statistics, a moving average (rolling average or running average) is a calculation to analyze data points by creating a series of averages of different subsets of the full data set. It is also called a moving mean (MM) or rolling mean and is a type of finite impulse response filter. Variations include: simple, and cumulative, or weighted forms.
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 subset.
A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer-term trends or cycles. The threshold between short-term and long-term depends on the application, and the parameters of the moving average will be set accordingly.
Variations
- MA: moving average
- SMA: simple moving average
- LWMA: linearly weighted moving average
- EMA: exponential moving average
- DEMA: double exponential moving average
- TEMA: triple exponential moving average
- DMA: displaced moving average
Sample coding
EMA
1 | class ExponentialMovingAverage { |
Time windowed EMA
1 | /** |