Smoothing using a moving average. Smoothing time series using simple moving averages

One of the most simple ways To solve this problem, use the moving averages method.

The moving average method allows the trader to smooth out and quickly determine the direction of the current trend.

Types of moving averages

There are three different types moving averages, which differ in calculation algorithms, but they are all interpreted in the same way. The difference in the calculations lies in the weight given to the prices. In one case, all prices may have equal weight; in another, more recent data has more weight.

The three most common types of moving averages are:

  1. simple
  2. linear weighted
  3. exponential

Simple Moving Average (SMA, Simple Moving Average)

This is the most common method for calculating moving average prices. You just need to take the sum of the closing prices for a certain period and divide by the number of prices used for the calculation. That is, this is the calculation of a simple arithmetic mean.

For example, for a ten-day simple moving average, we would take the closing prices of the last 10 days, add them together and divide by 10.

As you can see in the picture below, a trader can make moving averages smoother by simply increasing the number of days (hours, minutes) used for calculation. A long period for calculating a moving average is usually used to show a long-term trend.

Many people doubt the advisability of using simple moving average prices, since each point has same value. Critics of this calculation method believe that more recent data should have more weight. It is arguments like this that led to the creation of other types of moving averages.

Weighted moving average (WMA, Linear Weighted Average)

This version of the moving average price is the least used indicator of the three. Initially, it was supposed to combat the shortcomings of calculating a simple moving average. To build a weighted moving average, you need to take the sum of closing prices for a certain period, multiplied by a serial number, and divide the resulting number by the number of factors.

For example, to calculate a five-day weighted moving average, you would take today's closing price and multiply it by five, then take yesterday's closing price and multiply it by four, and continue until the end of the period. Then these values ​​must be added and divided by the sum of the factors.

Exponential Moving Average (EMA)

This type of moving average represents a "smoothed" version of the WMA, where more weight is given to recent data. This formula is considered more effective than the one used to calculate the weighted moving average.

You don't need to fully understand how all types of moving averages are calculated. Any modern trading terminal will build you this indicator with any settings.

The formula for calculating the exponential moving average is as follows:

EMA = (closing price – EMA (previous period) * multiplier + EMA (previous period)

The most important thing you should know about the exponential moving average is that it is more responsive to new data compared to the simple moving average. This is a key factor why exponential calculation is more popular and is used by most traders today.

As you can see in the image below, an EMA with a period of 15 reacts faster to price changes than an SMA with the same period. At first glance, the difference does not seem significant, but this impression is deceptive. This difference can play a key role during real trading.

Determining the trend using moving averages

Moving averages are used to determine the current trend and when it will reverse, as well as to find resistance and support levels.

Moving averages allow you to very quickly understand which way to go. this moment the trend is directed.

Look at the image below. Obviously, when the moving average moves below the price chart, we can confidently say that the trend is upward. Conversely, when the moving average is above the price chart, the trend is considered downward.

Another way to determine trend direction is to use two moving averages with different periods for calculation. When the short-term average is above the long-term average, the trend is considered upward. Conversely, when the short-term average is below the long-term average, the trend is considered downward.

Determining trend reversal using moving averages

Trend reversals using moving averages are determined in two ways.

The first is when the average crosses the price chart. For example, when a 50-period moving average crosses the price chart, as in the image below, it often means a change in trend from up to down.

Another option for receiving signals about possible trend reversals is to monitor the intersection of moving averages, short-term and long-term.

For example, in the image below you can see how the moving average with a calculation period of 15 crosses the moving average with a period of 50 from the bottom up, which signals the beginning of an uptrend.

If the periods used to calculate the averages are relatively short (for example, 15 and 35), then their intersections will signal short-term trend reversals. On the other hand, to track long-term trends, much longer periods are used, such as 50 and 200.

Moving averages as support and resistance levels

Another fairly common way to use moving averages is to determine support and resistance levels. For this, moving averages with long periods are usually used.

When the price approaches the support or resistance line, the probability of it “bouncing” from this level is quite high, as can be seen in the image below. If the price breaks the long-term moving average, then there is a high probability that the price will continue to move in the same direction.

Conclusion

Moving averages in technical analysis are one of the most powerful and at the same time simple tools for market analysis. They allow the trader to quickly determine the direction of long-term and short-term trends, as well as support and resistance levels.

Each trader uses his own settings to calculate moving averages. Much depends on the trading style and on what financial market they are used (market, currency exchange, etc.).

Moving averages help technical analysts remove the so-called “noise” of daily price fluctuations from the chart. Traditionally, moving averages are called trend indicators.

.
Moving average belongs to the class of trend-following indicators, 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 smoothing factor) in large quantities others technical indicators. Sometimes called a trend line.

Simple moving average formula:

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

N - main parameter - smoothing length or period(number of prices included in the moving average calculation). Sometimes this parameter is called order of the moving average.

Moving average example:
with parameter 5.

Description:
The simple is the usual arithmetic average of prices over a certain period. represents 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 shorter the period for which the equilibrium is taken. When averaging prices, it always follows with a certain lag main trend market, filtering out small fluctuations. The smaller the parameter (they say shorter), the faster it determines 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 occur.

Usage:
Application of moving averages quite simple. Moving averages will not predict changes in the trend, but will only signal an already emerging trend. Since moving averages follow indicators, they are best used during periods of trend, and when 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 a trade using a moving average. If it is directed upwards, then you make only purchases, if downwards, then only sales. In this case, entry and exit points from the market are determined based on other moving average methods(including based on a faster moving average).
  2. A reversal from bottom to top with a positive slope of the price itself is considered as a signal to buy, a reversal from top to bottom with a negative slope of the price itself is considered as a signal to sell.
  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 signal to sell, the price crossing its moving average from bottom to top (with a positive slope of both) is considered a buy signal.
  4. The crossing of a long one by a short one from the bottom up is considered a signal to buy and vice versa.
  5. Moving averages with round periods(50, 100, 200) are sometimes considered as moving levels and resistances.
  6. Based on which moving averages are directed upwards and which ones are downward, they determine which ones are upward and which are downward (short-term, medium-term, long-term).
  7. Moments of greatest divergence between two averages different parameters understood as a signal for a possible change in trend.

Disadvantages of the moving average method:

  1. Using method for trading The lag at the input and output is usually very significant, so in most cases most of the movement is lost.
  2. In and especially in the side 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 for entering a trend.
  3. When entering the price calculation, it differs greatly from the price level on the market. When this price leaves the moving average, 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 that is closer to the current moment.

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

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

Risk Warning: We do not recommend using any indicators on live accounts without first testing them on a demo account or testing them as a trading strategy. Anyone, even the most best indicator If used incorrectly, it gives many false signals and, as a result, can cause significant losses in the trading process.

Extrapolation - this is the method scientific research, which is based on the dissemination of past and present trends, patterns, connections to the future development of the forecast object. Extrapolation methods include moving average method, exponential smoothing method, least squares method.

Moving average method is one of the widely known methods smoothing time series. Using this method, it is possible to eliminate random fluctuations and obtain values ​​that correspond to the influence of the main factors.

Smoothing using moving averages is based on the fact that random deviations in average values ​​cancel each other out. This occurs due to the replacement of the initial levels of the time series with an arithmetic average within the selected time interval. The resulting value refers to the middle of the selected time interval (period).

Then the period is shifted by one observation, and the calculation of the average is repeated. In this case, the periods for determining the average are taken to be the same all the time. Thus, in each case considered, the average is centered, i.e. is referred to the midpoint of the smoothing interval and represents the level for this point.

When smoothing a time series with moving averages, all levels of the series are involved in the calculations. The wider the smoothing interval, the smoother the trend. The smoothed series is shorter than the original by (n–1) observations, where n is the value of the smoothing interval.

At large values ​​of n, the variability of the smoothed series is significantly reduced. At the same time, the number of observations is noticeably reduced, which creates difficulties.

The choice of smoothing interval depends on the objectives of the study. In this case, one should be guided by the period of time in which the action takes place, and, consequently, the elimination of the influence of random factors.

This method used in short-term forecasting. Its working formula:

An example of using the moving average method to develop a forecast

Task . There are data characterizing the unemployment rate in the region, %

  • Construct a forecast of the unemployment rate in the region for November, December, January using the following methods: moving average, exponential smoothing, least squares.
  • Calculate the errors in the resulting forecasts using each method.
  • Compare the results and draw conclusions.

Solution using the moving average method

To calculate the forecast value using the moving average method, you must:

1. Determine the value of the smoothing interval, for example equal to 3 (n = 3).

2. Calculate the moving average for the first three periods
m Feb = (Jan + Ufev + U March)/ 3 = (2.99+2.66+2.63)/3 = 2.76
We enter the resulting value into the table in the middle of the period taken.
Next, we calculate m for the next three periods: February, March, April.
m March = (Ufev + Umart + Uapr)/ 3 = (2.66+2.63+2.56)/3 = 2.62
Next, by analogy, we calculate m for every three adjacent periods and enter the results into the table.

3. Having calculated the moving average for all periods, we build a forecast for November using the formula:

where t + 1 – forecast period; t – period preceding the forecast period (year, month, etc.); Уt+1 – predicted indicator; mt-1 – moving average for two periods before the forecast; n – number of levels included in the smoothing interval; Уt – actual value of the phenomenon under study for the previous period; Уt-1 – the actual value of the phenomenon under study for two periods preceding the forecast one.

U November = 1.57 + 1/3 (1.42 – 1.56) = 1.57 – 0.05 = 1.52
We determine the moving average m for October.
m = (1.56+1.42+1.52) /3 = 1.5
We are making a forecast for December.
U December = 1.5 + 1/3 (1.52 – 1.42) = 1.53
We determine the moving average m for November.
m = (1.42+1.52+1.53) /3 = 1.49
We are making a forecast for January.
Y January = 1.49 + 1/3 (1.53 – 1.52) = 1.49
We enter the obtained result into the table.

We calculate the average relative error using the formula:

ε = 9.01/8 = 1.13% forecast accuracy high.

Next, we will solve this problem using methods exponential smoothing And least squares . Let's draw conclusions.

In-depth analysis of time series requires the use of more complex methods of mathematical statistics. If there is a significant random error (noise) in the time series, one of two simple techniques is used - smoothing or leveling by enlarging the intervals and calculating group averages. This method allows you to increase the visibility of the series if most of the “noise” components are located within the intervals. However, if the “noise” is not consistent with the periodicity, the distribution of indicator levels becomes coarse, which limits the possibility of a detailed analysis of changes in the phenomenon over time.

More exact specifications are obtained if moving averages are used - a widely used method for smoothing the indicators of the average series. It is based on the transition from the initial values ​​of the series to the average in a certain time interval. In this case, the time interval when calculating each subsequent indicator seems to slide along the time series.

The use of a moving average is useful when the trends in the time series are uncertain or when there is a strong impact on the performance of cyclically recurring outliers (outliers or intervention).

The larger the smoothing interval, the smoother the moving average chart looks. When choosing the value of the smoothing interval, it is necessary to proceed from the value of the time series and the meaningful meaning of the reflected dynamics. Large value of time series with a large number of source points allows the use of larger smoothing time intervals (5, 7, 10, etc.). If the moving average procedure is used to smooth a non-seasonal series, then most often the smoothing interval is taken equal to 3 or 5. https://tvoipolet.ru/iz-moskvi-v-nyu-jork/ - an excellent opportunity to choose an airline for a flight from Moscow to New York

Let's give an example of calculating the moving average number of farms with high yields (more than 30 c/ha) (Table 10.3).

Table 10.3 Smoothing a time series by enlarging intervals with a moving average

Accounting year

Number of farms with high yields

Amounts for three years

Three year rolling

Moving averages

90,0

89,7

1984

88,7

87,3

87,3

87,0

86,7

83,0

83,0

82,3

82,3

82,6

82,7

82,7

Examples of moving average calculations:

1982(84 + 94 + 92) / 3 = 90.0;

1983 (94 + 92 + 83) / 3 = 89.7;

1984(92 + 83 + 91) / 3 = 88.7;

1985(83 + 91 + 88) / 3 = 87.3.

A schedule is drawn up. The years are indicated on the abscissa axis, and the number of farms with high yields is indicated on the ordinate axis. The coordinates of the number of farms on the graph are indicated and the resulting points are connected by a broken line. Then the coordinates of the moving average by year are indicated on the graph and the points are connected by a smooth bold line.

A more complex and effective method is smoothing (leveling) the dynamics series using various approximation functions. They allow you to form a smooth level of the general trend and the main axis of dynamics.

Most effective method smoothing using mathematical functions is simple exponential smoothing. This method takes into account all previous observations of the series according to the formula:

S t = α∙X t + (1 - α ) ∙S t - 1 ,

where S t - each new smoothing at time t; S t - 1 - smoothed value at the previous time t -1; X t - actual value of the series at time t; α is the smoothing parameter.

If α = 1, then previous observations are completely ignored; when α = 0, current observations are ignored; α values ​​between 0 and 1 give intermediate results. By changing the values ​​of this parameter, you can select the most appropriate alignment option. The selection of the optimal value of α is carried out by analyzing the resulting graphic images of the original and aligned curves, or by taking into account the sum of squared errors (errors) of the calculated points. Practical use This method should be carried out using a computer in MS Excel. Mathematical expression Patterns of data dynamics can be obtained using the exponential smoothing function.

§ 2.1. Main indicators of the dynamics of economic phenomena

To quantify the dynamics of phenomena, statistical indicators are used: absolute increases, growth rates, growth rates, and they can be divided into chain, basic and average.

The calculation of these dynamics indicators is based on a comparison of the levels of the time series. If the comparison is carried out with the same level taken as the basis of comparison, then these indicators are called basic. If the comparison is carried out with a variable base, and each subsequent level is compared with the previous one, then the indicators calculated in this way are called chain indicators.

Absolute increase equal to the difference between the two compared levels.

The growth rate T characterizes the ratio of the two compared levels of the series, expressed as a percentage.

The growth rate K characterizes the absolute growth in relative values. The growth rate defined in % shows how many percent the compared level has changed relative to the level taken as the basis of comparison. In table 2.1. expressions are given for calculating basic and chain increments, growth rates, growth rates. The following notations are used:

Table 2.1.

Key dynamics indicators

Growth

Growth rate

Growth rate

Chain

Basic

Average

To obtain general indicators of development dynamics, average values ​​are determined: average absolute growth, average growth and increment rates.

The description of the dynamics of a series using average growth corresponds to its representation in the form of a straight line drawn through two extreme points. In this case, to get a forecast one step ahead, it is enough to add the value of the average absolute increase to the last observation.

(2.1.),

Where y n - actual value at the last nth point of the series;

Predictive estimate of the level value at point n+1;

Average increase value calculated for time series .

Obviously, this approach to obtaining a forecast value is correct if the nature of development is close to linear. Such a uniform nature of development can be indicated by approximately the same values ​​of chain absolute increases.

The use of the average growth rate (and the average growth rate) to describe the dynamics of a series corresponds to its presentation in the form of an exponential or exponential curve drawn through two extreme points. Therefore, using this indicator as a general one is advisable for those processes whose dynamics change at an approximately constant growth rate. In this case, the forecast value for i steps ahead can be obtained using the formula:

(2.2.),

where is the forecast estimate of the level value at point n+i;

Actual value at the last nth point of the series;

Average growth rate calculated for the series (not in % terms).

The disadvantages of average growth and average growth rate include the fact that they take into account only the final and entry levels series, exclude the influence of intermediate levels. However, these indicators have a very wide scope of application, which is explained by the extreme simplicity of their calculation. They can be used as approximate, simplest methods of forecasting, preceding a more in-depth quantitative and qualitative analysis.


§ 2.2. Smoothing Time Series Using a Moving Average

A common technique for identifying development trends is smoothing the time series. The essence of various smoothing techniques comes down to replacing actual levels of a time series with calculated levels, which are subject to fluctuations to a lesser extent. This contributes to a clearer manifestation of the development trend. Sometimes smoothing is used as a preliminary step before using other trend identification methods (for example, those discussed in the third chapter).

Moving averages make it possible to smooth out both random and periodic fluctuations, to identify an existing trend in the development of a process, and therefore are an important tool for filtering components of a time series.

The smoothing algorithm using a simple moving average can be represented as the following sequence of steps:

1. Determine the length of the smoothing interval g, which includes g successive levels of the series (g cancel out fluctuations, and the development trend is smoother and smoother. The stronger the fluctuations, the wider the smoothing interval should be.

2. The entire observation period is divided into sections, with the smoothing interval sliding along the series with a step equal to 1.

3. Arithmetic averages are calculated from the levels of the series that form each section.

4. Replace the actual values ​​of the series located in the center of each section with the corresponding average values.

In this case, it is convenient to take the length of the smoothing interval g in the form of an odd number: g=2p+1, because in this case, the resulting moving average values ​​fall on the middle term of the interval.

The observations that are taken to calculate the average are called the active smoothing region.

For an odd value of g, all levels of the active site can be represented as:

A the moving average is determined by the formula:

(2.3.),

Where - actual value of the i-th level;

Moving average value at the moment t ;

2p+1 - length of the smoothing interval.

The smoothing procedure leads to the complete elimination of periodic oscillations in a time series if the length of the smoothing interval is taken equal to or a multiple of the cycle, the period of oscillations.

To eliminate seasonal fluctuations, it would be desirable to use four- and twelve-term moving averages, but in this case the condition of oddity of the length of the smoothing interval will not be met. Therefore, with an even number of levels, it is customary to take the first and last observation in the active section with half the weights:

(2.4.)

Then, to smooth out seasonal fluctuations when working with time series of quarterly or monthly dynamics, you can use the following moving averages:

(2.5.)

(2.6.)

When using a moving average with the length of the active section g=2p+1, the first and last p levels of the series cannot be smoothed, their values ​​are lost.Obviously, the loss of the values ​​of the last points is a significant drawback, because For the researcher, the latest “fresh” data has the greatest information value. Let's consider one of the techniques that allows you to restore lost values ​​of a time series. To do this you need:

1) Calculate the average increase in the last active section

,

Where g is the length of the active section;

The value of the last level in the active section;

The value of the first level in the active section;

Average absolute increase.

2) Obtain P smoothed values ​​at the end of the time series by sequentially adding the average absolute increase to the last smoothed value.

A similar procedure can be implemented to estimate the first levels of a time series.

The simple moving average method is applicable if the graphical representation of a time series resembles a straight line. When the trend of the aligned series has bends, and it is desirable for the researcher to preserve small waves, the use of a simple moving average is inappropriate.

If the process is characterized by nonlinear development, then a simple moving average can lead to significant distortions. In these cases, using a weighted moving average is more reliable.

When smoothing using a weighted moving average, in each section the alignment is carried out using polynomials of low orders. The most commonly used polynomials are 2nd and 3rd order. Since with a simple moving average the alignment on each active section is carried out along a straight line (a first-order polynomial), the simple moving average method can be considered as a special case of the weighted moving average method. A simple moving average takes into account all levels of a series included in the active smoothing section with equal weights, and a weighted average assigns a weight to each level depending on the removal of this level to the level in the middle of the active section.

Alignment using a weighted moving average is carried out as follows.

For each active area, a polynomial of the form is selected

,

optionswhich are estimated using the least squares method. In this case, the reference point is transferred to the middle of the active section. For example, for the length of the smoothing interval g=5, the indices of the levels of the active section will be the following i: -2, -1, 0, 1, 2.

Then the smoothed value for the level located in the middle of the active section will be the value of parameter a 0 of the selected polynomial.

There is no need to recalculate the weighting coefficients each time for the series levels included in the active smoothing section, because they will be the same for each active site. Moreover, when smoothing using a polynomial whoa odd degree, the weighting coefficients will be the same as when smoothing by a polynomial (k-1) degree. In table 2.2. Weighting coefficients for smoothing using a 2nd or 3rd order polynomial are presented (depending on the length of the smoothing interval).

Since the weights are symmetrical with respect to the central level, a symbolic notation is used in the table: weights are given for half the levels of the active section; the weight related to the level located in the center of the smoothing area is allocated. For the remaining levels, weights are not given, since they can be reflected symmetrically.

For example, let's illustrate the use of the table for smoothing along a 2nd order parabola over a 5-term weighted moving average. Then the central value at each active site , will be estimated using the formula:

Let us note the important properties of the given scales:

1) They are symmetrical relative to the central level.

2) The sum of the weights, taking into account the common factor taken out of brackets, is equal to one.

3) The presence of both positive and negative weights allows the smoothed curve to preserve the various bends of the trend curve.

There are techniques that allow, with the help of additional calculations, to obtain smoothed values ​​for P of the initial and final levels of the series with the length of the smoothing interval g=2p+1.

Views