Moving average
A moving average (also called a running average) for a numeric time series is another time series whose values are averages of progressive sections of values from the original series. It is a smoothing mechanism to provide a more general view of the trends of the original series.
For example, the three-element moving average of the series (20, 25, 21, 26, 28, 27, 29, 31) is the series (22, 24, 25, 27, 28, 29). This is because 22 is the average of (20, 25, 21), 24 is the average of (25, 21, 26), 25 is the average of (21, 26, 28), and so on. Notice that the moving average series is smoother than the original, and yet still shows the same general trend. Also note that the moving average series has six elements, while the original series had eight. In general, the length of the moving average series will be n – m + 1, where n is the length of the original series and m is the length of the segments being averaged; in this case, 8 – 3 + 1 = 6.
Listing 3-5 shows a test program for...