Post by Admin/YBB on Oct 23, 2023 8:55:52 GMT -6
Moving Averages – Simple MA & Exponential EMA
GENERAL BACKGROUND
Note – Due to website limitations, data points are Xi (i th value), moving averages are simple MAi, exponential EMAi, period is n days or weeks, smoothing factor is “a”. This is the best possible web presentation for quantities with subscripts (upper-caps for most variables, lower-caps for subscripts).
RECURSION for Simple n-dMA
MAi = MAi-1 + (Xi – Xi-n)/n
Recursion starts with the longhand calculation of MAo. Elsewhere, it is also noted that from this recursion it follows that StockCharts parameter ROC(n) (%change over n periods) is proportional to the slope of the n-dMA curve. Keep in mind that StockCharts default values are adjusted-prices and it has the effect of incorporating the distributions; _TICKERS must be used for actual-prices.
ybbpersonalfinance.proboards.com/thread/321/ma-slope-roc
RECURSION for Exponential EMA
EMAi = EMAi-1 + 2*(Xi – EMAi-1)/(n + 1)
When written as follows, one can see exponential smoothing,
EMAi = [1 – 2/(n + 1)]*EMAi-1 + [2/(n + 1)]*Xi
or, EMAi = (1 – a)*EMAi-1 + a*Xi
Here, a = [2/(n+1)] is the smoothing factor (0 < a < 1). Note how the most recent data are weighted more prominently. Recursion is seeded with the longhand calculation of MAo.
By repeated substitutions, it can be seen that the older data points Xi are weighted progressively less as powers of (1 – a) appear in their weights; this is why “exponential” is in the name (powers are the discrete analog of exponentials). The pattern of weights with exponential decay is:
a, a(1 – a), a(1 – a)^2, a(1-a)^3,….,a(1 – a)^(n-1); a < 1.
For n = 50, the 1 st weight is a = 0.0392,…, the 50 th weight is 0.0055.
Compare this to the uniform weights for MA; for n = 50, the weights are 0.02, 0.02,…, 0.02.
So, compared to simple MA, the 1st term of exponential EMA is overweighted by a factor of 2n/(n+1), or by slightly less than 2. Then, the exponential decay in EMA weights follows.
In principle, infinite data points (if available) are (effectively) used for the EMA, but powers of (1 – a) make the contributions of the older data negligible, so, only the first several data points dominate (but that is an indeterminate number).
Basically, the exponential EMA moves a bit faster than the simple MA. As the smoothing factor “a” depends on the EMA period n (smaller “a” for larger n), the EMA should be used for low values of n ( < 50); of course, one can change the smoothing factor “a” in DIY programming. Differences in MA & EMA are more pronounced for smaller periods n < 50. The crossover points for 50-dMA & 200-dMA would be different than those for 50-dEMA & 200-dEMA, and so would be lot of the related technical analysis (TA). Generalizations as double-exponential and triple-exponential smoothing are also available. Lot of the related work is driven by the similarity in the analysis of data points in general (statistics, markets, business, economics, etc) and electronic signal processing (and the related sensors/hardware and software).
MA, Wiki en.wikipedia.org/wiki/Moving_average
EMA, Wiki en.wikipedia.org/wiki/Exponential_smoothing
MA & EMA, StockCharts school.stockcharts.com/doku.php?id=technical_indicators:moving_averages
ROC, StockCharts
school.stockcharts.com/doku.php?id=technical_indicators:rate_of_change_roc_and_momentum
MA-Slope & ROC, YBB Link ybbpersonalfinance.proboards.com/thread/321/ma-slope-roc
EXAMPLES with StockCharts
Using very volatile $VIX, links below show 14-, 20-, 50-, 200- dMA and dEMA. One should get a feel for differences in MA & EMA as they may matter in some situations, but not in others.
20-dMA, 50-dMA, 200-dMA (period dependence for MA)
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=1&mn=0&dy=0&id=p82309342225
20-dEMA, 50-dEMA, 200-dEMA (period dependence for EMA)
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=1&mn=0&dy=0&id=p76358252389
Comparisons of MA vs EMA
14-dMA vs 14-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p70012887472
20-dMA vs 20-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p77551581768
50-dMA vs 50-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p36452343260
200-dMA vs 200-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p41150890190
The exponential EMA is faster than the simple MA, and so is the simple MA for lesser periods. I tried to see if I could approximate the EMA with the MA for a slightly lower period n. The answer was negative – the patterns of MA (with equal weights for all data used) and EMA (with progressively decreasing weights for the older data) are just different. So, the MA and EMA should be seen as fundamentally different concepts although their differences may be small in many situations.
Edit/Add
Exponential decay (1 – a)^k, a = [2/(n+1)], k = 1, 2, 3,…,n-1; n = 50:
0.9608, 0.9231, 0.8869, 0.8521, 0.8187, 0.7866, 0.7558, 0.7261, 0.6976, 0.6703, 0.6440, 0.6187, 0.5945, 0.5712, 0.5488, 0.5272, 0.5066 (half-life point at k = 17),…,0.1408 (k = 49).
In general, the half-life point in exponential decay is at (integer) m = Ln0.5 / Ln(1 – a).
The half-life points are at m = 5 (for n = 14), 7 (for n = 20); 17 (for n = 50, above); 69 (for n = 200). These are seen well before the middle of the data set, or m < n/2.
GENERAL BACKGROUND
Note – Due to website limitations, data points are Xi (i th value), moving averages are simple MAi, exponential EMAi, period is n days or weeks, smoothing factor is “a”. This is the best possible web presentation for quantities with subscripts (upper-caps for most variables, lower-caps for subscripts).
RECURSION for Simple n-dMA
MAi = MAi-1 + (Xi – Xi-n)/n
Recursion starts with the longhand calculation of MAo. Elsewhere, it is also noted that from this recursion it follows that StockCharts parameter ROC(n) (%change over n periods) is proportional to the slope of the n-dMA curve. Keep in mind that StockCharts default values are adjusted-prices and it has the effect of incorporating the distributions; _TICKERS must be used for actual-prices.
ybbpersonalfinance.proboards.com/thread/321/ma-slope-roc
RECURSION for Exponential EMA
EMAi = EMAi-1 + 2*(Xi – EMAi-1)/(n + 1)
When written as follows, one can see exponential smoothing,
EMAi = [1 – 2/(n + 1)]*EMAi-1 + [2/(n + 1)]*Xi
or, EMAi = (1 – a)*EMAi-1 + a*Xi
Here, a = [2/(n+1)] is the smoothing factor (0 < a < 1). Note how the most recent data are weighted more prominently. Recursion is seeded with the longhand calculation of MAo.
By repeated substitutions, it can be seen that the older data points Xi are weighted progressively less as powers of (1 – a) appear in their weights; this is why “exponential” is in the name (powers are the discrete analog of exponentials). The pattern of weights with exponential decay is:
a, a(1 – a), a(1 – a)^2, a(1-a)^3,….,a(1 – a)^(n-1); a < 1.
For n = 50, the 1 st weight is a = 0.0392,…, the 50 th weight is 0.0055.
Compare this to the uniform weights for MA; for n = 50, the weights are 0.02, 0.02,…, 0.02.
So, compared to simple MA, the 1st term of exponential EMA is overweighted by a factor of 2n/(n+1), or by slightly less than 2. Then, the exponential decay in EMA weights follows.
In principle, infinite data points (if available) are (effectively) used for the EMA, but powers of (1 – a) make the contributions of the older data negligible, so, only the first several data points dominate (but that is an indeterminate number).
Basically, the exponential EMA moves a bit faster than the simple MA. As the smoothing factor “a” depends on the EMA period n (smaller “a” for larger n), the EMA should be used for low values of n ( < 50); of course, one can change the smoothing factor “a” in DIY programming. Differences in MA & EMA are more pronounced for smaller periods n < 50. The crossover points for 50-dMA & 200-dMA would be different than those for 50-dEMA & 200-dEMA, and so would be lot of the related technical analysis (TA). Generalizations as double-exponential and triple-exponential smoothing are also available. Lot of the related work is driven by the similarity in the analysis of data points in general (statistics, markets, business, economics, etc) and electronic signal processing (and the related sensors/hardware and software).
MA, Wiki en.wikipedia.org/wiki/Moving_average
EMA, Wiki en.wikipedia.org/wiki/Exponential_smoothing
MA & EMA, StockCharts school.stockcharts.com/doku.php?id=technical_indicators:moving_averages
ROC, StockCharts
school.stockcharts.com/doku.php?id=technical_indicators:rate_of_change_roc_and_momentum
MA-Slope & ROC, YBB Link ybbpersonalfinance.proboards.com/thread/321/ma-slope-roc
EXAMPLES with StockCharts
Using very volatile $VIX, links below show 14-, 20-, 50-, 200- dMA and dEMA. One should get a feel for differences in MA & EMA as they may matter in some situations, but not in others.
20-dMA, 50-dMA, 200-dMA (period dependence for MA)
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=1&mn=0&dy=0&id=p82309342225
20-dEMA, 50-dEMA, 200-dEMA (period dependence for EMA)
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=1&mn=0&dy=0&id=p76358252389
Comparisons of MA vs EMA
14-dMA vs 14-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p70012887472
20-dMA vs 20-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p77551581768
50-dMA vs 50-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p36452343260
200-dMA vs 200-dEMA
stockcharts.com/h-sc/ui?s=%24VIX&p=D&yr=0&mn=6&dy=0&id=p41150890190
The exponential EMA is faster than the simple MA, and so is the simple MA for lesser periods. I tried to see if I could approximate the EMA with the MA for a slightly lower period n. The answer was negative – the patterns of MA (with equal weights for all data used) and EMA (with progressively decreasing weights for the older data) are just different. So, the MA and EMA should be seen as fundamentally different concepts although their differences may be small in many situations.
Edit/Add
Exponential decay (1 – a)^k, a = [2/(n+1)], k = 1, 2, 3,…,n-1; n = 50:
0.9608, 0.9231, 0.8869, 0.8521, 0.8187, 0.7866, 0.7558, 0.7261, 0.6976, 0.6703, 0.6440, 0.6187, 0.5945, 0.5712, 0.5488, 0.5272, 0.5066 (half-life point at k = 17),…,0.1408 (k = 49).
In general, the half-life point in exponential decay is at (integer) m = Ln0.5 / Ln(1 – a).
The half-life points are at m = 5 (for n = 14), 7 (for n = 20); 17 (for n = 50, above); 69 (for n = 200). These are seen well before the middle of the data set, or m < n/2.