Roy: I think you were right with "i" in the date() after all. I didn't understand what you were doing with "b" and "b1." You have "b" as the previous day and "b1" as the day of the date, or date(i) -- in other words, the day of the hit, when the condition is true. So for DELL, if I put "b" and "b1" in the output, the value of "b1" on 7/01 is .65. B is the value on the previous day.
DELL ,07/01/1998, 92.88, B: 0.61, B1: 0.65
Of course, that's why you have if b<b1 when you're looking for slope moving up. B is the first value, and B1 is the "next j."
So the scan should be the way you had it, with q<0 and date(i). I've just changed the output to show B1:
println symbol,",", date(i),",",close(0):6:2,","," B: ", b:4:2,","," B1: ", b1:4:2;
Here's the whole thing again:
//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; 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 //println symbol,",", date(i),",",close(0):8:2,",",b:8:4; println symbol,",", date(i),",",close(0):6:2,","," B: ", b:4:2,","," B1: ", b1:4:2; b1:=b; // save current for next test else b1:=b; // must alway set ot last day's val endif; next j;
Brooke |