6.2 Moving averages | Forecasting: Principles and Practice (2nd ed) (2024)

6.2 Moving averages

The classical method of time series decomposition originated in the 1920s and was widely used until the 1950s. It still forms the basis of many time series decomposition methods, so it is important to understand how it works. The first step in a classical decomposition is to use a moving average method to estimate the trend-cycle, so we begin by discussing moving averages.

Moving average smoothing

A moving average of order \(m\) can be written as\[\begin{equation} \hat{T}_{t} = \frac{1}{m} \sum_{j=-k}^k y_{t+j}, \tag{6.1}\end{equation}\]where \(m=2k+1\). That is, the estimate of the trend-cycle at time \(t\) is obtained by averaging values of the time series within \(k\) periods of \(t\). Observations that are nearby in time are also likely to be close in value. Therefore, the average eliminates some of the randomness in the data, leaving a smooth trend-cycle component. We call this an \(m\)-MA, meaning a moving average of order \(m\).

autoplot(elecsales) + xlab("Year") + ylab("GWh") + ggtitle("Annual electricity sales: South Australia")

6.2 Moving averages | Forecasting: PrinciplesandPractice (2nded) (1)

Figure 6.4: Residential electricity sales (excluding hot water) for South Australia: 1989–2008.

For example, consider Figure 6.4 which shows the volume of electricity sold to residential customers in South Australia each year from 1989 to 2008 (hot water sales have been excluded). The data are also shown in Table 6.1.

Table 6.1: Annual electricity sales to residential customers in South Australia. 1989–2008.
YearSales (GWh)5-MA
19892354.34
19902379.71
19912318.522381.53
19922468.992424.56
19932386.092463.76
19942569.472552.60
19952575.722627.70
19962762.722750.62
19972844.502858.35
19983000.703014.70
19993108.103077.30
20003357.503144.52
20013075.703188.70
20023180.603202.32
20033221.603216.94
20043176.203307.30
20053430.603398.75
20063527.483485.43
20073637.89
20083655.00

In the last column of this table, a moving average of order 5 is shown, providing an estimate of the trend-cycle. The first value in this column is the average of the first five observations (1989–1993); the second value in the 5-MA column is the average of the values for 1990–1994; and so on. Each value in the 5-MA column is the average of the observations in the five year window centred on the corresponding year. In the notation of Equation (6.1), column 5-MA contains the values of \(\hat{T}_{t}\) with \(k=2\) and \(m=2k+1=5\). This is easily computed using

ma(elecsales, 5)

There are no values for either the first two years or the last two years, because we do not have two observations on either side. Later we will use more sophisticated methods of trend-cycle estimation which do allow estimates near the endpoints.

To see what the trend-cycle estimate looks like, we plot it along with the original data in Figure 6.5.

autoplot(elecsales, series="Data") + autolayer(ma(elecsales,5), series="5-MA") + xlab("Year") + ylab("GWh") + ggtitle("Annual electricity sales: South Australia") + scale_colour_manual(values=c("Data"="grey50","5-MA"="red"), breaks=c("Data","5-MA"))

6.2 Moving averages | Forecasting: PrinciplesandPractice (2nded) (2)

Figure 6.5: Residential electricity sales (black) along with the 5-MA estimate of the trend-cycle (red).

Notice that the trend-cycle (in red) is smoother than the original data and captures the main movement of the time series without all of the minor fluctuations. The order of the moving average determines the smoothness of the trend-cycle estimate. In general, a larger order means a smoother curve. Figure 6.6 shows the effect of changing the order of the moving average for the residential electricity sales data.

6.2 Moving averages | Forecasting: PrinciplesandPractice (2nded) (3)

Figure 6.6: Different moving averages applied to the residential electricity sales data.

Simple moving averages such as these are usually of an odd order (e.g., 3, 5, 7, etc.). This is so they are symmetric: in a moving average of order \(m=2k+1\), the middle observation, and \(k\) observations on either side, are averaged. But if \(m\) was even, it would no longer be symmetric.

Moving averages of moving averages

It is possible to apply a moving average to a moving average. One reason for doing this is to make an even-order moving average symmetric.

For example, we might take a moving average of order 4, and then apply another moving average of order 2 to the results. In the following table, this has been done for the first few years of the Australian quarterly beer production data.

beer2 <- window(ausbeer,start=1992)ma4 <- ma(beer2, order=4, centre=FALSE)ma2x4 <- ma(beer2, order=4, centre=TRUE)
Table 6.2: A moving average of order 4 applied to the quarterly beer data, followed by a moving average of order 2.
YearQuarterObservation4-MA2x4-MA
1992Q1443
1992Q2410451.25
1992Q3420448.75450.00
1992Q4532451.50450.12
1993Q1433449.00450.25
1993Q2421444.00446.50
1993Q3410448.00446.00
1993Q4512438.00443.00
1994Q1449441.25439.62
1994Q2381446.00443.62
1994Q3423440.25443.12
1994Q4531447.00443.62
1995Q1426445.25446.12
1995Q2408442.50443.88
1995Q3416438.25440.38
1995Q4520435.75437.00
1996Q1409431.25433.50
1996Q2398428.00429.62
1996Q3398433.75430.88
1996Q4507433.75433.75

The notation “\(2\times4\)-MA” in the last column means a 4-MA followed by a 2-MA. The values in the last column are obtained by taking a moving average of order 2 of the values in the previous column. For example, the first two values in the 4-MA column are451.25=(443+410+420+532)/4and448.75=(410+420+532+433)/4.The first value in the 2x4-MA column is the average of these two:450.00=(451.25+448.75)/2.

When a 2-MA follows a moving average of an even order (such as 4), it is called a “centred moving average of order 4”. This is because the results are now symmetric. To see that this is the case, we can write the \(2\times4\)-MA as follows:\[\begin{align*} \hat{T}_{t} &= \frac{1}{2}\Big[ \frac{1}{4} (y_{t-2}+y_{t-1}+y_{t}+y_{t+1}) + \frac{1}{4} (y_{t-1}+y_{t}+y_{t+1}+y_{t+2})\Big] \\ &= \frac{1}{8}y_{t-2}+\frac14y_{t-1} + \frac14y_{t}+\frac14y_{t+1}+\frac18y_{t+2}.\end{align*}\]It is now a weighted average of observations that is symmetric. By default, the ma() function in R will return a centred moving average for even orders (unless center=FALSE is specified).

Other combinations of moving averages are also possible. For example, a \(3\times3\)-MA is often used, and consists of a moving average of order 3 followed by another moving average of order 3. In general, an even order MA should be followed by an even order MA to make it symmetric. Similarly, an odd order MA should be followed by an odd order MA.

Estimating the trend-cycle with seasonal data

The most common use of centred moving averages is for estimating the trend-cycle from seasonal data. Consider the \(2\times4\)-MA:\[ \hat{T}_{t} = \frac{1}{8}y_{t-2} + \frac14y_{t-1} + \frac14y_{t} + \frac14y_{t+1} + \frac18y_{t+2}.\]When applied to quarterly data, each quarter of the year is given equal weight as the first and last terms apply to the same quarter in consecutive years. Consequently, the seasonal variation will be averaged out and the resulting values of \(\hat{T}_t\) will have little or no seasonal variation remaining. A similar effect would be obtained using a \(2\times 8\)-MA or a \(2\times 12\)-MA to quarterly data.

In general, a \(2\times m\)-MA is equivalent to a weighted moving average of order \(m+1\) where all observations take the weight \(1/m\), except for the first and last terms which take weights \(1/(2m)\). So, if the seasonal period is even and of order \(m\), we use a \(2\times m\)-MA to estimate the trend-cycle. If the seasonal period is odd and of order \(m\), we use a \(m\)-MA to estimate the trend-cycle. For example, a \(2\times 12\)-MA can be used to estimate the trend-cycle of monthly data and a 7-MA can be used to estimate the trend-cycle of daily data with a weekly seasonality.

Other choices for the order of the MA will usually result in trend-cycle estimates being contaminated by the seasonality in the data.

Example: Electrical equipment manufacturing

autoplot(elecequip, series="Data") + autolayer(ma(elecequip, 12), series="12-MA") + xlab("Year") + ylab("New orders index") + ggtitle("Electrical equipment manufacturing (Euro area)") + scale_colour_manual(values=c("Data"="grey","12-MA"="red"), breaks=c("Data","12-MA"))

6.2 Moving averages | Forecasting: PrinciplesandPractice (2nded) (4)

Figure 6.7: A 2x12-MA applied to the electrical equipment orders index.

Figure 6.7 shows a \(2\times12\)-MA applied to the electrical equipment orders index. Notice that the smooth line shows no seasonality; it is almost the same as the trend-cycle shown in Figure 6.1, which was estimated using a much more sophisticated method than a moving average. Any other choice for the order of the moving average (except for 24, 36, etc.) would have resulted in a smooth line that showed some seasonal fluctuations.

Weighted moving averages

Combinations of moving averages result in weighted moving averages. For example, the \(2\times4\)-MA discussed above is equivalent to a weighted 5-MA with weights given by\(\left[\frac{1}{8},\frac{1}{4},\frac{1}{4},\frac{1}{4},\frac{1}{8}\right]\). In general, a weighted \(m\)-MA can be written as\[ \hat{T}_t = \sum_{j=-k}^k a_j y_{t+j},\]where \(k=(m-1)/2\), and the weights are given by \(\left[a_{-k},\dots,a_k\right]\). It is important that the weights all sum to one and that they are symmetric so that \(a_j = a_{-j}\). The simple \(m\)-MA is a special case where all of the weights are equal to \(1/m\).

A major advantage of weighted moving averages is that they yield a smoother estimate of the trend-cycle. Instead of observations entering and leaving the calculation at full weight, their weights slowly increase and then slowly decrease, resulting in a smoother curve.

6.2 Moving averages | Forecasting: Principles and Practice (2nd ed) (2024)

FAQs

What is the principle of moving average? ›

Understanding a Moving Average (MA)

Moving averages are calculated to identify the trend direction of a stock or to determine its support and resistance levels. It is a trend-following or lagging, indicator because it is based on past prices. The longer the period for the moving average, the greater the lag.

What is the formula for moving average? ›

A moving average is a technical indicator that investors and traders use to determine the trend direction of securities. It is calculated by adding up all the data points during a specific period and dividing the sum by the number of time periods. Moving averages help technical traders to generate trading signals.

What is the 4 moving average method? ›

Moving averages method is used in statistics to analyze data points, which are calculated by averaging several subsets of a larger dataset. A moving average is a measure of how well a piece of work is doing over a given period of time. The moving average method is a popular stock indicator in technical analysis (MA).

What are 4 point moving averages? ›

The first four observations are added together and then divided by four. The four-quarter moving average for the first four quarters is 322.50. Moving to the next four observations, gives an average of 327.50. We can then work out the mid-point of these two averages by adding them together and dividing by two.

What is the simple moving average rule? ›

To calculate a simple moving average, the number of prices within a time period is divided by the number of total periods.

What does the moving average tell you? ›

A simple moving average is a technical indicator, or tool, that tracks a security's price over a time period and plots it on a line. This essentially “smooths out” price fluctuations to give an investor a general idea where the trend is heading.

What is the best moving average strategy? ›

The best way to trade moving average is to use the crossover strategy, where a shorter-period moving average crossing above a longer-period moving average generates a bullish signal, and vice versa for a bearish signal. This method helps indicate potential changes in the market trend.

What is the simple moving average method? ›

SMA is the easiest moving average to construct. It is simply the average price over the specified period. The average is called "moving" because it is plotted on the chart bar by bar, forming a line that moves along the chart as the average value changes. SMAs are often used to determine trend direction.

What is an example of a moving average? ›

Example #1

Now, to calculate the MA for the 6th day, we need to exclude 150 and include 159. Therefore, Moving Average = ( 155 + 142 + 133 + 162 + 159 ) / 5 = 150.20 and we can continue doing this.

What 3 moving averages should I use? ›

Typical settings for moving averages:

Long-term trend: 200 days (200 being roughly the number of trading days in a year) Medium-term trend: 50 days (50 being roughly 2 months of trading) Short-term trend: 9, 10 and 20 days.

What are the most used moving averages? ›

Traders and market analysts commonly use several periods in creating moving averages to plot their charts. For identifying significant, long-term support and resistance levels and overall trends, the 50-day, 100-day, and 200-day moving averages are the most common.

What is the formula for the moving average cost method? ›

Moving average cost formula. The moving average cost formula divides your current inventory value by the number of units in your current inventory. Note that the moving average price formula is the same.

How to calculate moving averages? ›

Most moving averages are based on closing prices; for example, a 5-day simple moving average is the five-day sum of closing prices divided by five.

How do you predict moving averages? ›

How to calculate simple moving average
  1. Establish the time frame you want to review. ...
  2. Look at the highest price points for each time interval. ...
  3. Add each price point together. ...
  4. Divide the total by the number of time intervals established.
Jun 24, 2022

What are the best two moving averages? ›

The SMA is popular among traders as it is easy to understand and calculate. Exponential Moving Average (EMA): This type of moving average gives greater weight to recent prices and is more responsive to short-term price movements compared to the SMA.

How does the moving average technique work? ›

The moving average method is a forecasting technique used to analyze data and predict future trends. It works by taking the average of a certain number of past observations, such as a stock price over the past 6 months, and then extrapolating that figure into the future.

What is the rule of thumb for moving average? ›

The thumb rule for trading with a simple moving average is that a security trading above its simple moving average is in an uptrend whereas a security trading below its simple moving average is in a downtrend. For example, a security trading above its 20-day simple moving average is said to be in a short-term uptrend.

What is moving average model theory? ›

In time series analysis, the moving-average model (MA model), also known as moving-average process, is a common approach for modeling univariate time series. The moving-average model specifies that the output variable is cross-correlated with a non-identical to itself random-variable.

Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5724

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.