Moving average - definition and purpose

Lecture



Moving average (moving average, MA) — a general name for a family of functions whose values at each point of definition are equal to the average value of the original function over the preceding period. Moving averages are usually used with time series data to smooth out short-term fluctuations and highlight underlying trends or cycles[1][2]. Mathematically, a moving average is a type of convolution.

Applications

Moving averages are used:

  • In statistics and economics for smoothing numerical series (primarily time series). For example, for estimating GDP, employment indicators, or other macroeconomic indicators.
  • In engineering, in signal processing, and systems analysis. See Moving average (filter).
  • In technical analysis, as an independent technical indicator or as part of other tools, see Moving average (indicator).

Etymology

Since when calculating a moving average, the value of the function is recalculated each time[2], taking into account a finite significant[3] set of preceding values, the moving average «moves» (shifts), as if «sliding» along the time series.

Types of moving averages

General case

In the general case, weighted moving averages are calculated using the formula[2]:

Moving average - definition and purpose (WWMA 1)

where Moving average - definition and purpose — the value of the weighted moving average at point {\displaystyle t}Moving average - definition and purpose; {\displaystyle n}Moving average - definition and purpose — the number of values of the original function used to calculate the moving average; {\displaystyle w_{t-i}}Moving average - definition and purpose — the normalized weight (weighting coefficient) of the {\displaystyle t-i}Moving average - definition and purpose-th value of the original function; {\displaystyle p_{t-i}}Moving average - definition and purpose — the value of the original function at a moment in time removed from the current one by {\displaystyle i}Moving average - definition and purpose intervals.

Normalization of the weighting coefficients means that[2]:

Moving average - definition and purpose

The above formula with arbitrary values of the weighting coefficients can be rewritten as:

Moving average - definition and purpose (WWMA 2)

where Moving average - definition and purpose — the value of the weighted moving average at point Moving average - definition and purpose, Moving average - definition and purpose — the number of values of the original function used to calculate the moving average, Moving average - definition and purpose — the weight (weighting coefficient) of the Moving average - definition and purpose-th value of the original function, Moving average - definition and purpose — the value of the original function at a moment in time removed from the current one by }Moving average - definition and purpose intervals.

The weighting coefficients in formulas (WWMA 1) and (WWMA 2) are related as follows:

Moving average - definition and purpose

Often, either 1 is used as the weight (for a simple moving average — SMA), or a formal series, such as an arithmetic progression (WMA) or an exponential function (EMA). But the values of a related time series can also serve as the weighting coefficient. For example, to weight exchange prices by trade volume (VMA), the value {\displaystyle p_{t-i}}Moving average - definition and purpose should be regarded as the transaction price of the instrument, and {\displaystyle W_{t-i}=V_{t-i}}Moving average - definition and purpose — as the volume at time {\displaystyle t-i}Moving average - definition and purpose:

{\displaystyle {\textit {VMA}}_{t}={\frac {\sum _{i=0}^{n-1}V_{t-i}\cdot p_{t-i}}{\sum _{i=0}^{n-1}V_{t-i}}}.}Moving average - definition and purpose

Simple moving average

Moving average - definition and purpose

The original function and its simple moving averages over four values (n = 4).
Green line — centered at the middle of the interval (true position).
Red line — graph shifted right to the last value of the window.

Simple moving average, or arithmetic moving average (simple moving average, SMA) is numerically equal to the arithmetic mean of the values of the original function over the established period[1] and is calculated using the formula[2]:

Moving average - definition and purpose

where {\displaystyle {\textit {SMA}}_{t}}Moving average - definition and purpose — the value of the simple moving average at point {\displaystyle t}Moving average - definition and purpose; {\displaystyle n}Moving average - definition and purpose — the number of values of the original function used to calculate the moving average (the smoothing interval[1]); the wider the smoothing interval, the smoother the resulting graph of the function[1]; {\displaystyle p_{t-i}}Moving average - definition and purpose — the value of the original function at point {\displaystyle t-i}Moving average - definition and purpose.

The resulting value of the simple moving average refers to the middle of the selected interval[1], however, it is traditionally assigned to the last point of the interval[2].

From its previous value, the simple moving average can be obtained using the following recurrence formula[2]:

Moving average - definition and purpose

where Moving average - definition and purpose — the value of the simple moving average at point {\displaystyle t}Moving average - definition and purpose, {\displaystyle {\textit {SMA}}_{t-1}}Moving average - definition and purpose — the previous value of the simple moving average, {\displaystyle p_{t-n}}Moving average - definition and purpose — the value of the original function at point {\displaystyle t-n}Moving average - definition and purpose (in the case of a time series, the «earliest» value of the original function used to calculate the previous moving average), {\displaystyle p_{t}}Moving average - definition and purpose — the value of the function under study at point {\displaystyle t}Moving average - definition and purpose (in the case of a time series, the current — last value). This formula is convenient for avoiding the regular summation of all values.

For example, the simple moving average for a time series with a number of periods equal to 10 is calculated as:

Moving average - definition and purpose

where {\displaystyle {\textit {SMA}}_{t}}Moving average - definition and purpose — the value of the simple moving average at point {\displaystyle t}Moving average - definition and purpose, {\displaystyle p_{t-i}}Moving average - definition and purpose — the value of the original function at a moment in time removed from the current one by {\displaystyle i}Moving average - definition and purpose intervals.

The following disadvantages of the simple moving average are noted[2]:

  1. Equality of the weighting coefficient to 1.
  2. Double reaction to each value (see the recurrence formula): at the moment of entering the calculation window and at the moment of leaving it.

Weighted moving averages

General provisions

Sometimes, when constructing a moving average, it is advisable to make certain values of the original function more significant. For example, if it is assumed that a nonlinear trend exists within the smoothing interval[1], or in the case of time series, where the most recent — more relevant data may carry more weight than earlier data.

It happens that the original function is multidimensional, that is, represented by several related series at once. In this case, there may be a need to combine all the obtained data into a single resulting moving average function. For example, time series of exchange prices are usually represented, for each moment in time, by at least two values — the transaction price and its volume. A tool is needed to calculate the volume-weighted moving average price.

In these and similar cases, weighted moving averages are applied.

Weighted moving average

Moving average - definition and purpose

Weights of the values of the original function when calculating WMA with n = 15

Weighted moving average (weighted moving average — WMA), more precisely linearly weighted moving average — a moving average in which the weight of each term of the original function, starting from the smallest, is equal to the corresponding term of an arithmetic progression. That is, when calculating the WMA for a time series, we consider the most recent values of the original function to be more significant than the preceding ones, with the significance function decreasing linearly.

For example, for an arithmetic progression with an initial value and a step equal to 1, the formula for calculating the moving average takes the form[2]:

Moving average - definition and purpose

where Moving average - definition and purpose — the value of the weighted moving average at point Moving average - definition and purpose, }Moving average - definition and purpose — the number of values of the original function used to calculate the moving average, Moving average - definition and purpose — the value of the original function at a moment in time removed from the current one by {\displaystyle i}Moving average - definition and purpose intervals.

It is easy to see that the denominator of the function, in this case, is equal to a triangular number — the sum of the terms of an arithmetic progression with initial term and step equal to 1:

Moving average - definition and purpose

Exponentially weighted moving average[

Moving average - definition and purpose

Weights of the values of the original function when calculating EMA with n = 15

Exponentially weighted moving average, exponential moving average (exponentially weighted moving average — EWMA, exponential moving average — EMA) — a type of weighted moving average whose weights decay exponentially and are never equal to zero[3]. Defined by the following formula[ :

Moving average - definition and purpose

where Moving average - definition and purpose — the value of the exponential moving average at point Moving average - definition and purpose (the last value, in the case of a time series), Moving average - definition and purpose — the value of the exponential moving average at point Moving average - definition and purpose (the previous value, in the case of a time series), Moving average - definition and purpose — the value of the original function at time {\displaystyle t}Moving average - definition and purpose (the last value, in the case of a time series), Moving average - definition and purpose (smoothing constant) — a coefficient characterizing the rate at which the weights decrease, taking a value from 0 to 1; the smaller its value, the greater the influence of previous values on the current mean.

The first value of the exponential moving average is usually taken to be equal to the first value of the original function:

Moving average - definition and purpose

The coefficient {\displaystyle \ \alpha }Moving average - definition and purpose can be chosen arbitrarily, within the range from 0 to 1. For example, it can be expressed through the size of the averaging window:

Moving average - definition and purpose

Exponential moving average of arbitrary order

Moving average - definition and purpose

Weights of the third-order exponentially weighted moving average — TMA with window n=10.

In an ordinary exponential moving average, the values of the original function are smoothed, however, the values of the resulting function can also be smoothed[2]. Therefore, some authors define the concept of the exponential moving average of arbitrary order[2], which is calculated using the formula:

Moving average - definition and purpose

where Moving average - definition and purpose — the value of the exponential moving average of order Moving average - definition and purpose at point Moving average - definition and purpose (the last value, in the case of a time series), Moving average - definition and purpose — the value of the exponential moving average of order Moving average - definition and purpose at point Moving average - definition and purpose (the previous value, in the case of a time series), Moving average - definition and purpose — the value of the exponential moving average of order {\displaystyle (n-1)}Moving average - definition and purpose at point {\displaystyle t}Moving average - definition and purpose (the last value, in the case of a time series), {\displaystyle \ \alpha }Moving average - definition and purpose — the smoothing constant.

Exponentially weighted moving averages of the second and third order are sometimes denoted respectively as Moving average - definition and purpose (from double exponential moving average) and Moving average - definition and purpose (from triple exponential moving average)[2]:

Moving average - definition and purpose

Moving average - definition and purpose

Modified moving average

Modified moving average (from modified moving average — MMA; sometimes called running moving average — RMA and smoothed moving average) is defined as:

Moving average - definition and purpose

where {\displaystyle {\textit {MMA}}_{t}}Moving average - definition and purpose — the value of the modified moving average at point {\displaystyle t}Moving average - definition and purpose (the last value, in the case of a time series),), {\displaystyle {\textit {MMA}}_{t-1}}Moving average - definition and purpose — the value of the modified moving average at point {\displaystyle t-1}Moving average - definition and purpose (the previous value, in the case of a time series), {\displaystyle n}Moving average - definition and purpose — the number of values of the original function used to calculate the moving average (the smoothing interval).

It is easy to see that the modified moving average is a special case of the exponential moving average, for which the smoothing constant is equal to the reciprocal of the smoothing interval:

Moving average - definition and purpose

Related functions

Moving averages based on other averaging functions

By analogy with moving averages built on the basis of the arithmetic mean, other averaging functions can also be used (power mean: root mean square, harmonic mean, etc.; geometric mean; median, etc.) and their weighted counterparts. The specific choice depends on the nature of the original function being studied.

Simple moving median

Simple moving median (simple moving median — SMM) — a function whose value at each point of definition is numerically equal to the median of the values of the original function over the established period:

{\displaystyle {\textit {SMM}}_{t}={\text{Median}}(p_{t},p_{t-1},\ldots ,p_{t-n+1}),}Moving average - definition and purpose

where {\displaystyle {\textit {SMM}}_{t}}Moving average - definition and purpose — the value of the simple moving median at point {\displaystyle t}Moving average - definition and purpose; {\displaystyle n}Moving average - definition and purpose — the number of values of the original function used to calculate the moving median (the smoothing interval); {\displaystyle p_{t-i}}Moving average - definition and purpose — the value of the original function at point {\displaystyle t-i}Moving average - definition and purpose.

Dynamic moving averages

In the 1990s, a number of moving averages with a dynamically variable window width (or smoothing coefficient) were proposed, see, for example, Kaufman's Adaptive Moving Average.

Cumulative moving average

Cumulative moving average (cumulative moving average) is numerically equal to the arithmetic mean of the values of the original function over the entire observation period:

Moving average - definition and purpose

where Moving average - definition and purpose — the cumulative moving average at time Moving average - definition and purpose, {\displaystyle t}Moving average - definition and purpose — the number of intervals available for calculation, {\displaystyle p_{i}}Moving average - definition and purpose — the value of the original function at point Moving average - definition and purpose.

In real-world calculations, when the previous value of the cumulative moving average is known, the following formulas are also applied:

Moving average - definition and purpose

where Moving average - definition and purpose — the cumulative moving average at time Moving average - definition and purpose, Moving average - definition and purpose — the cumulative moving average at time Moving average - definition and purpose (the previous value, in the case of a time series), Moving average - definition and purpose — the value of the original function at time Moving average - definition and purpose (in the case of a time series — the last value), {\displaystyle t}Moving average - definition and purpose — the number of intervals available for calculation. Moreover, Moving average - definition and purpose

Cumulative sum

The cumulative moving average should not be confused with the cumulative sum, which is calculated by summing all the values of the series on a running basis:

Moving average - definition and purpose

where {\displaystyle {\textit {Cumulative}}_{t},{\textit {Cumulative}}_{t-1}}Moving average - definition and purpose — the current and previous values of the cumulative sum, {\displaystyle p_{i}}Moving average - definition and purpose — the value of the original series at time {\displaystyle i}Moving average - definition and purpose.

See also

  • Autoregressive model: Autoregressive–moving-average model, Moving-average model
  • Window (weighting function)

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Probability theory. Mathematical Statistics and Stochastic Analysis"

Terms: Probability theory. Mathematical Statistics and Stochastic Analysis