Moving averages are often used in analysis for two purposes.
Firstly, they are used to remove volatility from single point values. By including a number of prior observations, a smoother estimation of the volatile point is defined.
Secondly, they remove volatility and can provide the general (and expected) trend movement (just as any consecutive set of numbers are an indicator of trend). Since a daily value may include prior N periods, the value of N is often used to support long-term or short-term trends. For example, a trend based on 30 days may be considered a long-term trend, whereas a trend based on five days may be used to provide a short-term trend. This type of smoothing, and a mix of long- and short-term trends is often used in charting analysis for stock prices.
This recipe shows how to perform last N calculations over stock data. The data is from the Australian Stock Exchange between January 1993 and December 2006. There are approximately 2.5 million...