Thanks for pointing out the error in pctgain. Sorry about that. Is this OK:
pctgain:= ((b1-b)/abs(b+.0000001))*100; //abs((b1/b)-1);
If so, the scan will be:
//Slope formula by Bob Jagow //Back-testing version by Roy Yorgensen output = "linregslope.lst"; input="portfoli.lst"; issuetype common; //Daystoload = 50; //needed for R2 bug!!! integer i,j, S, Sx, Sxx; float b,b1, Sxy, Sy, pctgain;
b1:=0; // only initialized first time for j = 0 to -10 step -1 do // reset all variables at stat of next loop S := 21; Sx := 0; Sxx := 0; Sxy := 0; Sy := 0; for i = j+(1 - S) to j do Sx := Sx + i; Sy := Sy + close(i); //kills println wo d2ld Sxx := Sxx + i*i; Sxy := Sxy + i*close(i); //kills println wo d2ld //Sxy := Sxy + i*close(0); next i; b := (S*Sxy - Sx*Sy)/(S*Sxx - Sx*Sx);
if j<0 and // eliminate first pass thru loop b< b1 then pctgain:= ((b1-b)/abs(b+.0000001))*100; //abs((b1/b)-1); endif;
if j<0 // eliminate first pass thru loop and b< b1 then println symbol,",", date(i),",",close(0):6:3,","," B: ", b:4:3,","," B1: ", b1:4:3,","," Pctgain: ", pctgain:4:2; b1:=b; // save current for next test else b1:=b; // must alway set ot last day's val endif; next j; |