function MovingAverage(const Y: TVec; const N: Integer; const M: TVec; out Index: Integer; const Centered: Boolean): Double;
Single moving average.
| # | Name | Description |
|---|---|---|
| 1 | Y | Sample data. |
| 2 | N | Number of elements in period. |
| 3 | M | Smoothed data. |
| 4 | Index | Index of first value in smoothed data. |
| 5 | Centered | If 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:
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
Uses MtxExpr, StatTimeSerAnalysis, Series, TeEngine;
procedure Example(Series1,Series2: TLineSeries);
var ts,Mv: Vector;
FirstIndex: Integer;
begin
ts.LoadFromFile('testdata.vec');
DrawValues(ts,Series1); // draw original time series
MovingAverage(ts,12,Mv,FirstIndex,True);
DrawValues(Mv,Series2,FirstIndex); // draw MA over original time series
end;