rolandp@tekgds.UUCP (Roland E. Parenteau) (09/23/83)
I am posting this article to net.math because it describes a mathematical problem I would like an explanation for. I am also posting it to net.invest because the problem is related to a procedure commonly used by investors: taking a moving average of an array of figures. The way I learned to take an N-period moving average was the obvious way: add up the first N figures in the data, and divide by N to get the first value of the moving average. Then, drop the 1st data element from the total, add the N+1th data element, and divide by N to get the second value of the moving average. Continue in this manner until all the data values are used up. This method is simple enough, but if you are keeping track of, say, 100 weekly stock prices, that involves a lot of keypunching, especially if you don't own a personal computer (yes, there are still a few of us left...) and are doing all this on your calculator. Luckily, there's a better way to achieve the same result. The documentation for the "Technical Indicator Program", produced by Investment Software of Chatsworth, CA for the HP-41C, says that an N-day moving average can be approximated by multiplying the previous value of the moving average by a factor K1, multiplying the next data element by K2 (always equal to 1 - K1), and adding the results. Here's how K1 and K2 relate to N (from Table 2 of their documentation): N K1 K2 10 .82 .18 18 .90 .10 36 .95 .05 40 .955 .045 90 .98 .02 180 .99 .01 A little diddling with the figures revealed that the formula for determining K2 from N is: K2 = 2/(N+N/9) Tests with sets of non-random data (e.g., the DJIA, cumulative advance decline line, and a 1000-element sine wave with random increments or decrements at each point) have convinced me that this formula is quite useful for my purposes (keeping a 5-week, 15-week, and 40-week moving average on various stocks and technical indicators). In fact, for the data I've tried, this method produces values that seldom fluctuate from the "true" moving average by more than 1.5 %. My question is: why does this method work so well at approximating the moving average? I can see that the method weights "old" values less than "new" values as time goes on. But I don't see why the fit is so close. In addition, I don't understand why my (empirically derived) formula should work, but it seems to. Anyway, for all you technical investment analysts out there who confine your investment activities to your calculator at home, here's a new method that may ease your burden. Now would someone please explain to me by mail why it works? While you're at it, please tell me what kinds of data the method won't work for (intuitively, it would seem, this method wouldn't work for taking the moving average of a completely random array of data...but I haven't tried that yet, either...and there might be other cases where I should watch out). Thanks in advance, Roland Parenteau, decvax!tektronix!tekgds!rolandp
gear@uiuccsb.UUCP (09/27/83)
#R:tekgds:-141900:uiuccsb:15300008:000:825 uiuccsb!gear Sep 26 09:10:00 1983 This calculation gives an Exponentially Weighted Average. If you use P times the prior value plus 1-P times the new value, the result you get is (1-P)(sum from n=0 to infinity V(n)*P**n) where V(n) is the value n days ago. Since P is less than 1 (or it makes little sense), you weight older values at successively lower weights. Making P small increases the decay rate. If you make P = 1 - 1/M you get something close to an M-day average. For largish M, the value from any particular day is weighted about exp(-1) [ ~= .368] times one M days later. It is a useful indicator in its own right. It will differ seriously from an M-day average if all of the early values are one extreme, and all of the later ones are the other (i.e. if the stock falls or increases drastically near the midpoint of the average period).