This function returns the moving average of adjacent ranges [i-nb, i+nf], for a point i. The part of range beyond the input vector is dropped.
The adjacent average at point i with iback backward offset and iforw forward offset is:
vector movavg(vector vx, int back, int forward[,int missing])
vx
back
forward
missing
Return the adjacent average vector.
Example 1
// Col(2) will be filled with adjacent value at each point. Note that // col(2)[9] = (col(1)[9]+col(1)[10])/2 and col(1)[10] = col(2)[10] for(ii=1;ii<=10;ii++) col(1)[ii] = ii; col(2)=movavg(col(1),0, 2);
Example 2
// The subrange [10:20] in col(2) will be filled with adjacent average // of the given subrange [10:20] in col(1). range aa=col(1)[10:20]; range bb=col(2)[10:20]; bb = movavg(aa, 3, 3);
Example 3
newbook; col(A) = {4,8,6,-1,NAN,-3,-1, 3, 4, 5}; col(B) = movavg(col(A),3,0,0); //returns [4 6 6 4.25 4.33333 0.66667 -1.66667 -0.33333 0.75 2.75] col(C) = movavg(col(A),3,0,1); //returns [4 6 6 4.25 -- -- -- -- 0.75 2.75] col(D) = movavg(col(A),3,0,2); //returns [4 6 6 4.25 -- 0.66667 -1.66667 -0.33333 0.75 2.75]