StatTimeSerAnalysis.MovingAverage Method

Double MovingAverage(TVec Y, Int32 N, TVec M, ref Int32 Index, Boolean Centered)

Single moving average.

#NameDescription
1YSample data.
2NNumber of elements in period.
3MSmoothed data.
4IndexIndex of first value in smoothed data.
5CenteredIf true, a centered moving average is perfomed.

Returns: Double - MSE.

Remarks:

Performs single moving average smoothing on data Y. General equation for moving average smoothing is:

M[i]=1N(X[i]+X[i1]++X[iN+1]),N1iX.LengthM[i] =\cfrac{1}{N} \left(X[i]+X[i-1]+\cdots+X[i-N+1] \right) \quad , \quad N-1\leq i \leq X.Length

where N indicates number of points in period and X.Length data sample size. When using single moving average smoothing, bear in mind that when used as forecasts for the next period, single moving average is not able to cope with a significant trend.

Examples
using Dew.Math;
using Dew.Stats;
using Dew.Stats.Units;
using Steema.TeeChart;
namespace Dew.Examples
{
    private void Example(Styles.Line line1, Styles.Line line2)
    {
        Vector ts = new Vector(0);
        Vector Mv = new Vector(0);
        int FirstIndex;
        ts.LoadFromFile("testdata.vec");
        MtxVecTee.DrawValues(ts,line1,0.0,1.0); // draw original time series
        StatTimeSerAnalysis.MovingAverage(ts,12,Mv,out FirstIndex,true);
        MtxVecTee.DrawValues(Mv,line2,FirstIndex,1.0); // draw MA over original time series
    }
}