Thursday, November 3, 2011

The Moving Average


From Technical Analysis in the Foreign Exchange Market: A Layman’s Guide, by Christopher J. Neely:

A second variety of mechanical trading rule is the “moving average” class. Like trendlines and filter rules, moving averages bypass the short-run zigs and zags of the exchange rate to permit the technician to examine trends in the series. A moving average is the average closing price of the exchange rate over a given number of previous trading days. The length of the moving average “window”—the number of days in the moving average—governs whether the moving average reflects long- or short-run trends.

"A moving average is the average ... over a given number of previous ... days."

I assume that's typical. Figure the average for a chunk of years, and show the result on a graph at the last year of the chunk. I guess that's good if you want to make decisions today based on past trends.

But it seems to me that sometimes you might want to plot the result at the middle year of the chunk. Using the middle year would give a better picture of "what happened when". And I see I'm not the only person to think of that. Well, good.

I suppose it just depends what you're trying to do.


Below is the Excel graph from a previous post, but with a different trendline. This time the red trendline is a 10-period moving average:

Graph #1
Near the start, before Event 50,  the blue peaks are less than 10 years apart. So the moving average adds two or more peaks together, and the red line shows brief high values.

After Event 64, the blue peaks are 11 or more years apart, so the moving average falls to zero for increasingly longer periods.

Toward the right, the non-zeros of the moving average grow increasingly far apart. But more disturbing, to me, is that those red non-zeros come at or after the blue peaks. The red line shows an average of what happened during the previous ten events. The average is displaced, offset to the right from the blue spike. If the blue peaks were significant events, this graph might fool us into thinking that the event took place later than it really did.


Graph #2 shows the Federal Funds interest rate in blue. The numbers are from FRED. In Excel, I added a 10-year moving average in red. The moving average makes it look as if the peak of interest rates occurred in the late 1980s. That is certainly a false read.

Graph #2
Besides that, the red peak looks like the flat-topped mountain from the movie E.T. Close Encounters. In addition, the red trendline, for both the increase and the decline seem somehow to be too far to the right. Because they are.

Graph #3, below, is similar to Graph #2 but shows a 5-year moving average.

Graph #3
This graph shows a shorter moving average, so it shows more variation than the red line on Graph #2, and it starts five years nearer to the start of the blue line. Also the red peak is a little higher and not as flat or broad. However, the red peak is again delayed because the average for each 5-year period is shown at the end of the five-year period, not in the middle of it. The blue interest rate falls a good 6 points or more before the red line starts to show the downward trend!

Graph #4, below, is similar to Graph #3 but shows the five-year average centered in the five-year period.

Graph #4

Now the red peak lines up dead-center on the blue peak. The red line does not lag the blue at the peak, or on the uptrend, or on the downtrend. To me, this is what a moving average should look like, when you want a peek at the past.

3 comments:

Jazzbumpa said...

A moving average is backward looking and ALWAYS is plotted along with the most recent data point.

Again, your graph 1 is of a dataset for which a moving average is meaningless - because there is no trend.

Look at graph 2. The utility of a M.A. is as a comparator to the current value. Is it above or below the M.A? How is it trending?

Note how, except at extreme points, the data set is quasi-consistently above or below the M.A.

Since the M.A. is retarded, you miss the initial big drop. A long M.A has this shortcoming. OTOH, a short M.A. can have too many cross-overs.

No single trading tool is either complete or perfect.

Cheers!
JzB

jim said...

Hi Art,
In digital signal processing (DSP) the moving average is classified as a low pass filter (tends to attenuate high frequency components in the data). The moving average is sometimes called a "boxcar" filter.

In DSP the issue of where you reference the input and output time stamp is referred to as causality. If you only use the most recent past input data points to create the current output data point the filter is causal. If you use data points ahead of the current output it is not causal.

If the output current sample point is the middle of the input sample points the frequency response of the filter is said to be "zero phase".

-jim

The Arthurian said...

Jazz -- "Note how, except at extreme points, the data set is quasi-consistently above or below the M.A."

Sure, because the M.A. is shifted 5 years to the right, relative to the actual data.

jim -- thanks. Causality, yeah that's what I was fishing for.