Moving Average

MOVING AVERAGE
The Mean

When dealing with time series data, a moving average smooths out short-term fluctuations. It also highlights long-term trends. Practical applications of the moving average would be in the analyses of technical data like trade volumes, stock prices, gross domestic product (GDP), employment, and other time-series data.

Simple Moving Average

The term simply means the unweighted mean of the previous n data points.
Example: Computing for a 10-day simple moving average of price is the mean of the previous 10 day prices. If the prices are pM, pM-1 , … , pM-9 then the formula is
SMA = { pM + pM-1 + … + p_{M-9} / 10 }
When dealing with successive values, a new value is used and an old value is removed.
SMAtoday = SMAyesterday – {p(M-n) / n} + {p(M) /n}
Moving average levels may be used to show support in a rising market or resistance in a falling market. The moving average always lags behind the most recent data point. Old data points may also affect the average in a negative manner. To address this concern, weighted and exponential moving averages may be used.

If the data have periodic fluctuations, applying a simple moving average on that time period will remove that variation.

Cumulative Moving Average

If an investor wants to look at more data points, he might want to use the cumulative moving average (CMA). This is the average of all the data points up to the current time. For example, the CMA price of stock A from January 1 to March 8 is the average of all the prices of stock A from January 1 to March 8. On March 9, there is a new CMA price since the March 9 price is now going to be added in the computations.

In equation form, the CMA is the unweighted average of the sequence of i values x1, …, xi up to the current time:
CAi = {{x1 + … + xi} / i}
To update the cumulative average if a new datum xi+1 arrives, this formula is used:
CAi+1 = {{xi+1 + i CAi} / {i+1}}, where CA0 can be taken to be equal to 0.

Weighted Moving Average

The simple moving average and cumulative moving average does not take into account the weights. The weighted moving average (WMA) has weights that decrease. Given n days, the latest day has n as its weight, the second latest has n-1, and so on, until zero. The formula is:

WMAM = { n pM + (n-1) pM-1 + … + 2 pM-n+2 + pM-n+1 / n + (n-1) + … + 2 + 1}
Note: the denominator can be computed using the formula [n(n+1)/2].

Exponential Moving Average

The exponential moving average applies weights that exponentially decreases. The later data gets heavier weights as compared to the earlier data points.
1. The decrease in the weights is expressed as a constant smoothing factor α, a number between 0 and 1.This factor can be expressed as a percentage, so a value of 20% is equivalent to α = 0.2.If there is a higher α, the older observations are decreased faster.The α may also be expressed in terms of N time periods, where α = 2/(N+1).For example, N = 9 is equivalent to α = 0.2.The half-life of the weights is approximately N/2.8854 and is within 1% if N > 5.
2. The observation at a time period t is designated Yt, and the value of the EMA at any time period t is designated St.
Note: The half-life of the weights is the interval over which the weights decrease by a factor of two
The S1 is undefined. S2 is commonly set to Y1, or one may also set S2 to be the average of the first 4 or 5 observations. Smaller α values make the S2 choice relatively more important as compared to larger α values.

The Formula:
The formula for calculating the EMA at time periods t > 2 is as follows,
St = α * Yt-1 + (1-α) * St-1
This is according to Hunter (1986). The weights will obey α(1 − α)x Yt − (x + 1). An alternate approach by Roberts (1959) uses Yt instead of Yt−1:
St,alternate = α * Y_t + (1-alpha) times S_{t-1}
It can also be expressed as follows:
EMAtoday = EMA yesterday + α * (price today – EMAyesterday)
Expanding out EMA {yesterday} each time will result in the power series, expressed below:
EMA = α * (p1 + (1-α) p2 + (1-α)2 p3 + (1-α)3 p4 + … )
The one above is an infinite sum with decreasing terms.
In an N-day EMA, the N periods only specify the α factor. For sufficiently large N, The first N data points represent 86% of the total weight in the calculations:
α * {1 + (1-α)+(1-α)2 + … +(1-α)N} / {α * { 1 + (1-α)+(1-α)2 + … +(1-α)∞} = 1 – { 1 – (2 / N+1 ) } N+1
i.e. lim N to ∞ [ 1 – (1 – (2 / N+1) )N+1] ,… tends to 1-e-2 = 0.8647

The formula above gives a starting value for a particular day. After which, the successive days formula shown first could be applied. How far back to go for an initial value depends on the data. If one assumes that prices don’t vary too much, then he can just consider the weighting. The weight omitted by stopping after k terms is found as follows:
α * [ (1-α)k + (1-α)k+1 + (1-α)^k+2 + … ],
which is
α * (1-α)k * (1 + (1-α) + (1-α)2 + … ]
i.e. a fraction
(1 – α)k
out of the total weight.
As an example, to have 99.9% of the weight,
k = log (0.001) / log (1-α)
terms must be used. Since log,(1-α) approaches -2 / N+1 as N increases, this can then be simplified to approximate
k = 3.45(N+1)
for this example (99.9% weight).

Modified Moving Average:
This is also called running moving average (RMA), or smoothed moving average.
MMAtoday = (N – 1) * MMA yesterday + price / N
This is therefore an EMA, with α = 1 / N.