How to do ROC calculation

Hi experts,

I am trying to compute return for different periods per the attached simple AFL. I know I must have made some basic mistake regarding calculating ROC. R2 and R2a are supposed to give the same answer but they did not. Could you please help me understand what are the differences.

Thanks,

//parameter
winsize = int(StrToNum( ParamStr("window.size", "25")));
winnum = int(StrToNum( ParamStr("no.of.window", "3")));
wl = ParamStr("watchlist", "sectors");

r1=ROC(C,winsize);
r2=ROC(Ref(C, -1*winsize+1),winsize);
r2a=100*( Ref(C, -1*winsize+1) - Ref(C,-2*winsize+1) )/Ref(C,-1*winsize+1);
r3=ROC(Ref(C, -2*winsize+1),winsize);
r3a= 100*( Ref(C, -2*winsize+1) - Ref(C,-3*winsize+1) )/Ref(C,-2*winsize+1);
rtot=ROC(C,3*winsize);

AddtextColumn(fullName(), "ticker");
AddColumn(r1,"win01"); 
AddColumn(r2,"win02"); 
AddColumn(r2a,"win02a"); 
AddColumn(r3,"win03"); 
AddColumn(r3a,"win03a");
AddColumn(rtot,"total ret");

1 Like

Sorry folks. Found the problem. The denominator should be
Ref(C,-2*winsize+1);

May be the administrator can consider deleting this post.

jimmy