Moving averages is often used in analyzing time series data. It is widely applied in finance, particularly in technical analysis.
It can also be used as a generic smoothing operation, in which case the data need not be a time series.
A moving average series can be calculated for any time series. In finance it is most often applied to stock prices,
returns, or trading volumes. Moving averages are used to smooth out shortterm fluctuations, thus highlighting longerterm
trends or cycles.
A moving average smooths data by replacing each data point with the average of the neighboring data points defined within
the time span.
A simple moving average (SMA) is the mean value of the previous n data points. For example,
a 5day simple moving average of an opening price is the mean of the previous 5 days' opening prices. If those prices are
p_{0}, p_{1}, p_{2}, p_{3}, p_{4} then the moving average
is described by,
SMA = p_{0} + p_{1} + p_{2} + p_{3} + p_{4} / 5

In general, for nday moving average,
SMA = (p_{0} + p_{1} + p_{2} + p_{3} + p_{4} / n) = 1/n ∑_{i=0} p_{i}

When calculating successive values, a new value comes into the sum and an old value drops out, meaning a full summation each time
is unnecessary.
Technical analysis uses various popular values for n, like 10 days, 40 days, or 100 days. The period
selected depends on the kind of movement one is concentrating on, such as short, intermediate or long term.
Testing the Simple Average Moving Method
In order to test the Simple Average Moving Method as defined above, a new SimpleAverageMovingMethod()
static method has been added and executed. Supporting code and methods are not shown.
static void SimpleAverageMovingMethod();
{
ListBox1.Items.Clear();
double[] xarray = new double[] {t1, t2, t3, t4, t5, t6, t7, t8,
t9, t10, t11, t12, t13, t14, t15, t16,
t17, t18, t19, t20};
VectorR sma = CurveFitting.SimpleMovingAverage(data, 5);
ListBox1.Items.Add(" " + sma.ToString());
}
