I did Cumulated Moving Average in a hard way. Can anyone modify my code by using "while" or "fold" iterated loops?
CMA (X, N, M);
formula:
Y = (M*X + (N-M) * Y1) / N; --- Y1 is last period of Y, N must be > M;
assume N = 7; M = 1;
here is the hard way of the code:
def a1 = X[6];
def a2 = (X[5] + a1)/2;
def a3 = (X[4] + 2*a2)/3;
def a4 = (X[3] + 3*a3)/4;
def a5 = (X[2] + 4*a4)/5;
def a6 = (X[1] + 5*a5)/6;
def Y = (X + 6*a6)/7;
CMA (X, N, M);
formula:
Y = (M*X + (N-M) * Y1) / N; --- Y1 is last period of Y, N must be > M;
assume N = 7; M = 1;
here is the hard way of the code:
def a1 = X[6];
def a2 = (X[5] + a1)/2;
def a3 = (X[4] + 2*a2)/3;
def a4 = (X[3] + 3*a3)/4;
def a5 = (X[2] + 4*a4)/5;
def a6 = (X[1] + 5*a5)/6;
def Y = (X + 6*a6)/7;