Smooth the series using the moving average method. Smoothing time series using simple moving averages

Smooth the series using the moving average method.  Smoothing time series using simple moving averages
Smooth the series using the moving average method. Smoothing time series using simple moving averages

Moving average method a method of studying in the ranks of the dynamics of the main trend of the development of the phenomenon.

The essence of the moving average method is that the average level is calculated from a certain number of the first in the order of the levels of the series, then  the average level from the same number of levels, starting from the second, then  starting from the third, etc. Thus, when calculating average level, as it were, "slide" along a number of dynamics from its beginning to the end, each time dropping one level at the beginning and adding one next.

The middle of an odd number of levels refers to the middle of the interval. If the smoothing interval is even, then referring the average to a specific time is impossible, it refers to the middle between the dates. In order to correctly assign the average of an even number of levels, centering is applied, that is, finding the average of the average, which is already attributed to a certain date.

Let's show the application of the moving average in the following example. Example 3.1. Based on data on the yield of grain crops on the farm for 1989-2003. let's smooth the series using the moving average method.

The dynamics of the yield of grain crops in the economy for 1989-2003. and calculation of moving averages

1 ... Let's calculate three-year rolling amounts. We find the sum of the yield for 1989–1991: 19.5  23.4  25.0  67.9 and write this value in 1991. Then from this sum we subtract the value of the indicator for 1989 and add the indicator for 1992 .: 67.9 - 19.5  22.4  70.8 and we write this value in 1992, etc.

2 ... Let's define three-year moving averages using the simple arithmetic mean formula:

We write the resulting value in 1990. Then we take the following three-year moving average and find the three-year moving average: 70.8: 3  23.6, we write the resulting value in 1991, etc.

Four-year rolling amounts are calculated in a similar manner. Their values ​​are presented in column 4 of the table of this example.

Four-year moving averages are determined using the simple arithmetic mean formula:

This value will be assigned between the two years 1990 and 1991, i.e., in the middle of the smoothing interval. In order to find four-year centered moving averages, you need to find the average of two adjacent moving averages:

This average will be referred to 1991. The rest of the centered averages are calculated in a similar way; their values ​​are recorded in column 6 of the table of this example.

4. Analytical alignment method

The straight line equation for analytical alignment of a number of dynamics is as follows:

where - aligned (average) level of the time series; a 0 , a 1 - parameters of the required straight line;t- time designation.

The least squares method gives a system of two normal equations for finding the parameters a 0 and a 1:

where at initial level a number of dynamics ; n the number of members of the series.

The system of equations is simplified if the values t select so that their sum is equal to zero, that is, the beginning of time is transferred to the middle of the period under consideration.

If then

Research of the dynamics of social and economic. phenomena and the establishment of the main development trend provide a basis for forecasting (extrapolation)  determining the future size of the level of the economic phenomenon. The following extrapolation methods are used:

average absolute growth  s / indicator calculated to express the average rate of growth (decline) social-eq. process. Determined by the formula:

■ average growth rate;

extrapolation based on alignment according to any analytical formula. The method of analytical alignment is a method of researching the dynamics of social-economic. phenomena, allowing to establish the main trends in their development.

Consider the application of the analytical straight line alignment method to express the main trend onExample 4.1... Initial and calculated data for determining the parameters of the equation of the straight line:

2.3.1. Exercise*

The first two columns of Table 17 provide data reflecting the demand for a certain product over an eight-year period. Carry out data smoothing using the moving average method with a smoothing window k=3.

2.3.2. Completing the assignment

The moving average is calculated using the AVERAGE function. The calculation results are presented in the third column of Table 16 and illustrated in Figure 8.

Table 17. Product demand

2.4. Isolation of the trend and cyclical components of the time series **

Exercise 1

Table 18 provides data on the volume y energy consumption over four years (time t measured in quarters). Smooth the time series using the moving average method, choosing the size yourself k anti-aliasing windows.

2.4.2. Completing task 1

From the dependency graph y(t) (see Fig. 9), it can be seen that the time series contains a cyclic component with a period T n = 4. Having calculated the selective autocorrelation coefficient using the CORREL function r(1, t) (see Table 19) and building a correlogram (using the diagram wizard - see Fig. 10), we find that the maximum of the autocorrelation coefficient takes place at values ​​of t that are multiples of four; this confirms (see §1.2) that T n = 4. The smoothing window should be chosen equal (see §1.5) to the period of the cyclic component: k = T n = 4. Then the result of smoothing will be an approximate trend (for the period, positive and negative values ​​of the cyclical component will compensate each other).

The third column of Table 18 shows the results of calculating the moving average u 1 (t) for k= 4. Midpoint t cp of the smoothing window is between the second and third times of the window. So, for example, for the first window (containing the moments of time t=1, 2, 3, 4) t cf = 2.5; there is no such moment in time in our data, and we assign the average value of observations over the window to the moment t= 2. For the second window t cp = 3.5, and the average value of observations for the second window will be assigned to the moment t= 3. Similarly, we will assign the average value of observations for each next sliding window to the second time instant of this window.

To set the correspondence between the average value of observations over the window and the middle of the window t cp needs to be applied to u 1 (t) moving average method with a smoothing window equal to two: u 2 (t)=[u 1 (t-1)+u 1 (t)] / 2. The calculation results are shown in Table 18 (fourth column). Recall (see also §1.5) that the calculation u 2 is needed only in case of even k... For odd k midpoint of the anti-aliasing window t Wed coincides with one of the points in time available in the table.


Table 18. Calculation of the trend and cyclical component

t y u 1 u 2 S 1 = y-u 2 S 2 S 3 S T + E=Y-S T E
0,581 5,419 5,902 -0,483
4,4 6,100 -1,977 6,377 6,088 0,289
6,400 6,250 -1,250 -1,275 -1,294 -1,294 6,294 6,275 0,019
6,500 6,450 2,550 2,708 2,690 2,690 6,310 6,461 -0,151
7,2 6,750 6,625 0,575 0,600 0,581 0,581 6,619 6,648 -0,029
4,8 7,000 6,875 -2,075 -1,958 -1,977 -1,977 6,777 6,834 -0,057
7,200 7,100 -1,100 -1,294 7,294 7,020 0,273
7,400 7,300 2,700 2,690 7,310 7,207 0,104
7,500 7,450 0,550 0,581 7,419 7,393 0,026
5,6 7,750 7,625 -2,025 -1,977 7,577 7,580 -0,003
6,4 8,000 7,875 -1,475 -1,294 7,694 7,766 -0,072
8,250 8,125 2,875 2,690 8,310 7,952 0,358
8,400 8,325 0,675 0,581 8,419 8,139 0,280
6,6 8,350 8,375 -1,775 -1,977 8,577 8,325 0,252
Sum 0,075 0,000 -1,294 8,294 8,512 -0,218
10,8 The average 0,019 0,000 2,690 8,110 8,698 -0,588

Assignment 2

Calculate the values ​​of the cyclic component of the time series according to the data in Table 18. Record the results in the same table.

2.4.4. Completing task 2

The considered time series is described by an additive model, since the amplitude of oscillations of the levels of the series is practically independent of time (see Fig. 9). By formula (43) (taking into account that T» u 2) counting S

The values S 2 are obtained by averaging S 1 by periods. Since the average value of the cyclic component over the period for the additive model of the series should be equal to zero, then we align the values S 2: S 3 =S 2 -S 2 Wed, where after S 2 sr indicates the average value S S obtained by copying S 3 for all periods.

Having received the cyclical component, we calculate the next approximation of the trend under the assumption that the trend is linear. Let's calculate the noisy trend values: T+E=Y-S(see formula (40)). Applying OLS to these values ​​(using the LINEST function), we get the following formula: T(t)=0,186t+5.72. Using this formula, we calculate the trend values, and then, taking into account that E=Y-T-S, Are the values ​​of the random component E.

In fig. 9 the components of the range are shown graphically. Since the random component is significantly less than the other components of the series, it can be assumed that the obtained estimates of the trend and the cyclical component are quite acceptable.

Assignment 3

The first two columns of Table 20 show the quarterly data on the company's profit (in conventional units) for the last four years. Determine the trend, cyclical and random components of the time series.

2.4.6. Completion of task 3

From the dependency graph y(t) (see Fig. 11, a), it can be seen that the time series contains a cyclic component with a period T n = 4. By constructing a correlogram (which is not shown here), one can make sure that the maximum of the autocorrelation coefficient occurs at values ​​of t that are multiples of four; this confirms that T n = 4. Select the smoothing window equal (see §1.5) to the period of the cyclic component: k = T n = 4.

The third and fourth columns of Table 20 show the results of calculating the trend approximations u 1 (t) and u 2 (t), obtained in the same way as in table 18.

For the time series under consideration, a multiplicative model should be chosen, since the amplitude of fluctuations in the levels of the series changes in proportion to the trend (see Fig. 11, a). By formula (44) (taking into account that T» u 2) counting S 1 - the first approximation of the cyclic component of the series.

The values S 2 are obtained by averaging S 1 by periods. Since the average value of the cyclical component over the period for the multiplicative model should be equal to one, then from S 2, we pass to the next approximation of the cyclic component: S 3 =S 2 /S 2 Wed, where S 2 sr - average S 2. Cyclic component values S obtained by copying S 3 for all periods.

Next, we calculate the next approximation of the trend, assuming that the trend is linear. Let's calculate the noisy trend values: TE=Y/S(see formula (41)). Applying OLS to these values ​​(using the LINEST function), we get the formula for the trend: T(t)=-2,77t+90.57. Using this formula, we calculate the trend values, and then - the values ​​of the random component E(E=Y/(TS)). The absolute error of the model is calculated by the formula: Eabs=Y-TS.

In fig. 11 the components of the range are shown graphically. Note that the absolute error is significantly less than the series and trend levels. In addition, a random component for almost all values t is close to one. Therefore, estimates of the trend and cyclical component are quite acceptable.


Table 20. Company profit data

t y u 1 u 2 S 1 S 2 S 3 S T*E=Y/S T E Eabs
0,914 78,804 87,792 0,898 -8,212
81,5 1,202 83,182 85,019 0,978 -2,208
81,25 1,108 1,088 1,082 1,082 83,153 82,245 1,011 0,982
0,800 0,806 0,802 0,802 79,819 79,472 1,004 0,278
76,5 77,75 0,900 0,918 0,914 0,914 76,615 76,699 0,999 -0,077
75,75 1,215 1,208 1,202 1,202 76,527 73,926 1,035 3,127
1,081 1,082 73,914 71,152 1,039 2,989
71,5 0,811 0,802 72,336 68,379 1,058 3,173
68,5 0,905 0,914 67,859 65,606 1,034 2,059
64,5 65,75 1,217 1,202 66,545 62,833 1,059 4,463
63,25 1,075 1,082 62,827 60,059 1,046 2,995
59,5 0,807 0,802 59,865 57,286 1,045 2,067
52,5 54,75 0,950 0,914 56,914 54,513 1,044 2,194
50,25 1,194 1,202 49,909 51,740 0,965 -2,201
Sum 4,021 1,082 46,196 48,966 0,943 -2,998
The average 1,005 0,802 37,415 46,193 0,810 -7,038


3. Assignment for independent work

1. Table 21 * presents data on labor productivity Y for some enterprise from 1987 to 1996. Get equations and trend graphs: linear, logarithmic, power, polynomial, exponential. Choose from them the trend that most closely matches the observations (comparing the value R 2). For the chosen trend, test the hypothesis of the independence of the residuals using the Durbin-Watson test (for n=10 d n = 0.88 d b = 1.32). Why test this hypothesis?

2. Table 22 ** shows the average y eggs per layer for each month in the United States from 1938 to 1940 Required:

1) build a graph y(t) and a correlogram. Analyzing them, answer the questions: does the series contain a linear trend? Does the series contain a cyclical component? What is the period of the cyclic component Tts? Which model is suitable for describing a series - additive or multiplicative?

2) determine the components of the series.

Table 22. Average number y eggs per hen

3. Table 23 gives the levels of a certain series, time t measured in quarters. Conduct studies for these data, similar to paragraph 2.

Table 23. Row levels

t
y

Practical work No. 5. Using bogus
variables in solving econometrics problems

Theoretical part

First, we will consider several of the simplest forecasting methods that do not take into account the presence of seasonality in the time series. Suppose that the RBC magazine contains a summary of the last 12 days (including today) prices for oranges at the close of the exchange. Using this data, you need to predict tomorrow's cocoa price (also at the close of the exchange). Let's look at several ways to do this.

    If the last (today's) value is the most significant compared to the rest, then it is the best forecast for tomorrow.

    Perhaps due to the rapid change in prices on the exchange, the first six values ​​are already outdated and not relevant, while the last six are significant and have equal value for the forecast. Then, as a forecast for tomorrow, you can take the average of the last six values.

    If all values ​​are significant, but today's 12th value is most significant, and the previous 11th, 10th, 9th, etc. are less and less significant, you should find the weighted average of all 12 values. Moreover, the weight coefficients for the latter values ​​must be greater than for the previous ones, and the sum of all weight coefficients must be equal to 1.

The first method is called "naive" forecasting and is fairly obvious. Let's take a closer look at the other methods.

Moving average method

One of the assumptions underlying this method is that a more accurate forecast for the future can be obtained if recent observations were used, and the “newer” the data, the greater their weight for the forecast should be. Surprisingly, this "naive" approach is extremely useful in practice. For example, many airlines use a private type of moving average to generate air travel demand forecasts, which in turn are used in sophisticated revenue management and optimization mechanisms. Moreover, almost all inventory management software packages contain modules that perform predictions based on some type of moving average.

Consider the following example. The marketer needs to predict the demand for the machines his company produces. The data on sales volumes for the last year of the company's operation are in the file "ЛР6. Example 1. Machines.xls".

Simple moving average... In this method, the average of a fixed number N of recent observations is used to estimate the next value of the time series. For example, using machine tool sales for the first three months of the year, the manager gets the value for April using the formula below:

The manager calculated the sales volume based on a simple moving average for 3 and 4 months. However, it is required to determine how many nodes give a more accurate prediction. To assess the accuracy of forecasts, use is made of mean of absolute deviations(CAO) and mean of relative errors, in percentage (SOOP), calculated by formulas (3) and (4).

where x i i-th real value of the variable in i-th moment of time, and x i i th predicted value of the variable in i-th moment in time, N is the number of predictions.

According to the results obtained on the sheet “Simple sk. average "of the workbook" ЛР6. Example 1. Machines.xls "(see Figure 56), the three-month moving average has a CAO value of 12.67 ( cell D16), while for a 4-month moving average, the CAO value is 15.59 ( cell F16). It can then be hypothesized that the use of more statistical data degrades rather than improves the accuracy of the moving average forecast.

Figure 56. Example 1 - Simple Moving Average Forecasting Results

On the graph (see Figure 57), built based on the results of observations and forecasts with an interval of 3 months, you can notice a number of features common to all applications of the moving average method.

Figure 57. Example 1 - Simple Moving Average Forecast Curve Graph and Real Sales Volume Graph

The forecast value obtained by the simple moving average method is always less than the actual value if the initial data monotonically increases, and more than the actual value if the initial data decreases monotonically. Therefore, if the data is monotonically increasing or decreasing, then using a simple moving average cannot provide accurate predictions. This method is best for data with small random deviations from some constant or slowly changing value.

The main disadvantage of the simple moving average method arises from the fact that in calculating the predicted value, the most recent observation has the same weight (i.e., significance) as the previous ones. This is because the weight of all N recent observations participating in the moving average calculation is 1 / N. Equal weighting goes against the intuition that, in many cases, the latest data can say more about what will happen in the near future than the previous ones.

Weighted Moving Average... The contribution of different points in time can be taken into account by entering a weight for each value of the indicator in a sliding interval. The result is a weighted moving average method that can be written mathematically like this:

where is the weight with which the indicator is used in the calculation.

Weight is always a positive number. In the case when all weights are the same, the simple moving average method degenerates.

The marketer can now use the 3 months weighted moving average method. But first you need to understand how to choose weights. Using the Solution Finder tool, you can determine the optimal node weights. To determine the weights of nodes using the Solution Finder tool that would have the minimum mean absolute deviations, follow these steps:

    Select Tools -> Find Solution.

    In the Find solution dialog box, set the target cell G16 (see sheet "Weights"), minimizing it.

    Change the cells to specify the range B1: B3.

    Set limits B4 = 1.0; В1: ВЗ ≥ 0; В1: В3 ≤ 1; B1 ≤ B2 and B2 ≤ B3.

    Run a search for a solution (the result displays).

Figure 58. Example 1 - the result of searching for weights of indicator values ​​when using the weighted moving average method

The results show that the optimal weight distribution is such that all the weight is concentrated on the most recent observation, while the mean absolute deviation is 7.56 (see also Figure 59). This result supports the assumption that later observations should carry more weight.

Figure 59. Example 1 - Weighted Moving Average Forecast Curve Graph and Real Sales Volume Graph

Will be able to find an option that allows you to select a calculation method. There are three options: SMA (simple), EMA (exponential) and WMA (weighted). This article is about considering weighted moving average.

What is the essence of a weighted average?

While the simple moving average is just the arithmetic average of the values ​​for the number of periods specified by the trader in the settings (the default is most often 20 periods), the weighted average takes into account that the values ​​of the last periods (that is, the most relevant data) are more important than the values ​​of the first ones. The use of such an indicator is especially appropriate if at the moment there is a clearly pronounced tendency to an increase or decrease in the value of an asset in the market. Visually, the formula for calculating WMA looks like this:

It is important to note that the exponential average (EMA) is also weighted to some extent - the principle of increasing the weight of the indicator over time remains. However, the calculation of the EMA is slightly different:

Weighted moving averages are popular among traders - they are considered to be much more flexible. The Simple Moving Average is a clumsy tool that is most often used as part of a more sophisticated indicator.

How is a weighted moving average calculated?

The following formula is used for the calculation:

The formula may look daunting, but it is surprisingly simple: the P value is the price of the asset in a certain period, the W value is the specific weight. It is not difficult to calculate the weighted average manually, which we will prove with the following example:

date

Asset price

It is necessary to determine the value of the weighted moving average on May 6 for the last 5 periods.

Substitute the values ​​into the formula:

It can be seen that the WMA value is higher, and this is a reflection of a pronounced trend towards an increase in values:

Naturally, in reality, for five periods, the average is not considered, since such an analysis gives a too subjective result. However, carrying out more massive calculations manually is problematic and simply takes a long time, so we can thank the computers for doing this work for us.

Advantages and Disadvantages of Weighted Means

The advantage of the weighted average has already been illustrated - this indicator reacts more flexibly to the latest trends in the price of an asset. The disadvantages include the following points:

  • The lag in entering and exiting a trend is still quite noticeable, albeit to a lesser extent than when using simple averages. By the way, to get rid of this drawback, it is recommended to use exponential EMA indicators, which are currently considered the most perfect moving average model.
  • The weighted average changes greatly when a false signal appears (since it is the last signal that is given special attention). In this regard, the simple moving average is more perfect.
  • WMA is ineffective for positional trading as it looks smoother due to low market noise. It is better to use such an average for medium and short-term trading. What tools to use when trading on large timeframes, this article will tell you -.

Weighted average trading strategy

To illustrate the work of moving averages, it is necessary to give an example of one of the strategies based on this indicator - called "Weighted Taylor".

The trading conditions are as follows:

  • The daily timeframe is selected - it is better if the asset is the currency EURUSD. If the margin of the deposit is not enough to trade on such large timeframes, you should not risk it - you should reduce the size of the transaction.
  • Set 5 weighted averages with periods of 5 (blue), 15 (orange), 30 (yellow), 60 (pink), 90 (red). The graph looks like this:

  • The RSI is set with a period of 5 and two levels (60 and 40).
  • MACD is set with the following parameters: fast EMA 5, slow EMA 13, simple SMA. Two red levels are also set: 0.005 and -0.005.

The whole picture looks like this:

You need to trade as follows: first of all, pay attention to the moving averages. Long-term weighted averages have a smoother appearance - as a rule, when short-term weighted averages cross them, this indicates the beginning of a trend. According to our example, it is clear that the market is calm, however, the blue (the shortest) has changed direction and tends to pink and red (the longest), so the trader should be on his guard.

Next, pay attention to the RSI indicator. If the green line is in the 40-60 corridor, it is not recommended to open a position (our example is exactly that), because this interval is characterized by a large level of market noise and false signals.

The MACD indicator is used to search for entry points on. At the same time, pay attention to the "red corridor" - the principle is the same as that of the RSI: no deals can be made... In our example, the indicator line is located exactly in this corridor.

So, you should open a position only when all 3 indicators give the same signal.

Keep up to date with all the important events of United Traders - subscribe to our

.
Moving average belongs to the class of indicators that follow the trend, it helps to determine the beginning of a new trend and its completion, by its angle of inclination, one can determine the strength (speed of movement), it is also used as a basis (or a smoothing factor) in a large number of other technical indicators. Sometimes referred to as a trend line.

Simple moving average formula:

Where Pi - Prices in the market (usually Close prices are taken, but sometimes Open, High, Low, Median Price, Typical Price are used).

N - main parameter - smoothing length or period(the number of prices included in the calculation of the moving one). This parameter is sometimes referred to as moving average order.

An example of a sliding average:
with parameter 5.

Description:
Prime is the usual arithmetic average of prices for a certain period. is a certain indicator of the equilibrium price (equilibrium of supply and demand in the market) for a certain period, the shorter the moving average, the less period the equilibrium is taken. Averaging prices, it always follows the main market trend with a certain lag, filtering out small fluctuations. The smaller the parameter (they say that it is shorter), the faster it detects a new trend, but at the same time makes more false fluctuations, and vice versa, the larger the parameter (they say long, the slower the new trend is determined, but fewer false fluctuations come in.)

Usage:
Using moving averages simple enough. Moving averages will not predict changes in the trend, but will only signal an already emerging trend. Since moving averages are following the indicator, they are best used during trend periods, and when they are not present in the market, they become completely ineffective. Therefore, before using these indicators, it is necessary to conduct a separate analysis of the properties of a particular currency pair. In its simplest form, we know several ways to use a moving average.

There are 7 basic moving average methods:

  1. Determining the side of the trade using the moving average. If it is directed upwards, then you make only purchases, if downwards, then only sells. In this case, the points of entry and exit from the market are determined on the basis of other moving average methods(including on the basis of a faster moving one).
  2. An upward reversal with a positive slope of the price itself is considered a buy signal, a downward reversal with a negative slope of the price itself is considered a sell signal.
  3. Moving average method, based on the price crossing its moving average from top to bottom (with a negative slope of both) is considered as a sell signal, the price crossing its moving average from the bottom up (with a positive slope of both) is considered a buy signal.
  4. The crossing of a long short from the bottom up is considered a buy signal and vice versa.
  5. Moving averages with round periods(50, 100, 200) are sometimes viewed as moving levels and resistances.
  6. Based on which moving averages are directed upwards and which ones are downward, determine which is ascending and which is descending (short-term, medium-term, long-term).
  7. The moments of the greatest divergence of two averages with different parameters are understood as a signal for a possible trend change.

Disadvantages of the moving average method:

  1. Using method for trading on the lag at the entrance and exit is usually very significant, so in most cases most of the movement is lost.
  2. In and especially in the sideways in the form of a saw, it gives a lot of false signals and leads to losses. At the same time, a trader trading on the basis of a simple moving average cannot miss these signals, since each of them is a potential signal to enter a trend.
  3. Upon entering the price calculation, the difference from the market price level changes greatly. When this price leaves the moving average calculation, a strong change occurs a second time. A. Elder called this effect "a bad dog barks twice".
  4. One of the most serious disadvantages of the moving average method, is that it gives equal weight to both newer prices and older prices, although it would be more logical to assume that new prices are more important, since they reflect a market situation closer to the current moment.

Note 1: The market is better able to use a shorter moving average, in the market it is better to use a longer moving average as it gives less false signals.

Note 2: it has quite a lot of more effective modern variations: exponential moving average, weighted moving average, there is also a series adaptive moving averages AMA, KAMA, Jurik MA, etc.

Risk warning: we do not recommend using any indicators on real accounts without first testing their work on a demo account or testing them as a trading strategy. Any, even the best indicator, used incorrectly, gives a lot of false signals and, as a result, can bring significant losses in the trading process.