Exponential smoothing

Exponential smoothing theory

This page exists due to the efforts of the following people:

Timur

Timur

cruelity0_0

khajit_94

Created: 2015-11-07 09:09:28, Last updated: 2022-10-28 07:39:50
Creative Commons Attribution/Share-Alike License 3.0 (Unported)

This content is licensed under Creative Commons Attribution/Share-Alike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work https://planetcalc.com/587/. Also, please do not modify any references to the original work (if any) contained in this content.

I would write an article about technical indicators and tell you about exponential moving average. However, it turned out that by studying the theory of this indicator, I came across some interesting things more related to statistics than to the stock market or forex.

Since statistics already been mentioned on this site, I've decided to write a separate article about it - the article about exponential smoothing in time series analysis.

This topic was raised in the article Seasonal fluctuations. Seasonal indices. Method of simple averages. The calculation of average seasonality indexes of average mean methods could be mainly applied to time series where there were no upward/downward trends, or they are negligible. In other words, the observed value fluctuates around some permanent value._

What does that mean? It means that the average is constant, and because of that, it can not capture the trend.
Let's illustrate it with a graph

PLANETCALC, Constant average - graph

Constant average - graph

Constant average
The file is very large. Browser slowdown may occur during loading and creation.

Time series

Items per page:

Generally speaking, all methods of averaging are intended to eliminate "noise" from the random scatter of the data that allows identifying the trend more clearly or the seasonal or cyclic changes, that is, the internal structure of the data, seemingly random, and use it to build the model, followed by analysis and forecasting of future values - but as we see, the simple averaging method does not work if there is a pronounced trend. We cannot predict anything with its help.
We must be able to receive not only one average but average series. And the most popular (and simple) method to obtain those series is exponential smoothing.

It can be described as follows - When forecasting, newer values of observed values are given the greater weight comparing with older values. At the same time, older values are given exponentially decreasing weights.

Now we describe the definition with formulas.
Traditionally denote the observed value as y, and smoothed average as S.
Then,
S_1 undefined
S_2 = y_1
S_3 = \alpha y_2 + (1-\alpha)S_2

and, generalized

S_t = \alpha y_{t-1} + (1-\alpha)S_{t-1}

where \alpha takes the value from the range [0;1)

Why it is called exponential? Let's expand several previous values:

S_t = \alpha y_{t-1} + (1-\alpha)S_{t-1} \\= \alpha y_{t-1} + (1-\alpha)[\alpha y_{t-2} + (1-\alpha)S_{t-2}] \\= \alpha y_{t-1} + (1-\alpha)[\alpha y_{t-2} + (1-\alpha)[\alpha y_{t-3} + (1-\alpha)S_{t-3}]] \\S_t = \alpha y_{t-1} + \alpha(1-\alpha)y_{t-2} + \alpha(1-\alpha)^{2}y_{t-3} + (1-\alpha)^{3}S_{t-3}

and, generalized
S_t=\alpha\sum_{i=1}^{t-2}(1-\alpha)^{i-1}y_{t-i} + (1-\alpha)^{t-2}S_2, for t > 2

Thus, the weight before y - is an infinitely decreasing geometric progression with multiplier 1-\alpha
And the farther S, the less it is affected by the initial values.

Let's assume that y_1=1000 and see how its contribution changes for the various S.

PLANETCALC, Weight values change for exponential smoothing

Weight values change for exponential smoothing

Digits after the decimal point: 4
y1 value
 
Weight values change for exponential smoothing
The file is very large. Browser slowdown may occur during loading and creation.

For S2, it is taken as it is, but in S3 with a coefficient alpha of 0.5, the contribution of y1 is only 250, in S4 - 125, and so on.

Simultaneously, the choice of the coefficient \alpha is important. If you play around with the parameter "a" in the calculator (see. Above), it is clear that the higher the value, the faster the countdown actually ceases to affect the smoothed average, and vice versa - the lower, the longer it retains its influence.

Accordingly, for small \alpha, the method of obtaining S2 has a great influence on the result. Assignment S_2=y_1 is just one of the methods. As an alternative, the initial value may be a simple average of the first few values of y, for example.

But how do you choose \alpha? Which index is most suitable for the simulation of the dynamics of this series? There is no mathematical formulas for calculating exact \alpha. This indicator is most often chosen by selection or by the "trials and errors" method.
The method consists in the fact that you take multiple values \alpha then, among them, select the best one. What is the criterion of "best" in our case?

That criterion is to minimize the mean of squared errors. Error - is the deviation of the actual value of the forecast. For each S value, it is squared to get rid of the sign's influence and then calculate the average of all values. That index\alpha, for which the average value and the minimum are the best of several.

Now a few words about the prediction.

The next value of the series is predicted directly from the formula
S_{fcst} = \alpha y_{last} + (1-\alpha)S_{last}

If it is necessary to get a forecast for a larger number of samples, the technique called bootstrapping is used. The last known value of "y" is taken as a constant and is used in the recursive formula.

S_{fcst+n} = \alpha y_{origin} + (1-\alpha)S_{fcst+n-1}

Now apply this knowledge when calculating the smoothed average for the graph shown at the beginning of this article. To make this more interesting, we calculate the smoothed average for the three values at once \alpha, and at the same time calculate the mean square error.

The graph shows for reference the following predicted value, i.e., moving average extended for one count further than actual data.

PLANETCALC, Calculation of exponentially smoothed average

Calculation of exponentially smoothed average

Time series

Items per page:

Digits after the decimal point: 2
Root mean square error 1
 
Root mean square error 2
 
Root mean square error 3
 
Exponential Smoothing
The file is very large. Browser slowdown may occur during loading and creation.

By the way, I should note that the best default value for the calculator above \alpha will be 0.7
With \alpha equals 1, smoothing degenerates into a repeat of penultimate values that under significant variation neighboring values do not always give a minimum mean square error.

URL copied to clipboard
PLANETCALC, Exponential smoothing

Comments