Bob Jagow suggests changing "date(j)" to "date(j+1)" if you want the date to be the day when the slope moved up (not the day before). I'm not channeling Bob or reading his mind -- he's been answering some of my probing e-mail inquiries (such as "Huh?" or "Duh?"). Here's the whole scan again (for positively the last time, as that indefatigable troupe in "Nicholas Nickleby" said):
//Slope formula by Bob Jagow //Back-testing version by Roy Yorgensen output = "linregslope.lst"; input="portfoli.lst"; //issuetype common; integer first, i, j, S, Sx; float b,b1, Sxx, Sxy, Sy, pctgain; first:= -10; Daystoload = 50 -first; DaysRequired = 22 - first; S := 21; // set here b1 := 0; // only initialized first time for j = 0 to first step -1 do //why 0 to -10? // reset all variables at start of loop Sx := 0; Sxx := 0; Sxy := 0; Sy := 0; for i = j+(1 - S) to j do Sx := Sx + i; Sy := Sy + close(i); Sxx := Sxx + i*i; Sxy := Sxy + i*close(i); next i; b := .000001+(S*Sxy - Sx*Sy)/(S*Sxx - Sx*Sx); if b = 0 then print symbol,"b was zero with j: ",j; endif; pctgain := abs((b1/b) -1); //gives div by 0 -- strange? if j < 0 // eliminate first pass thru loop -- clumsy and b < b1 then //pctgain := abs((b1/b)-1); // not % and constrained to be > 0 ;) if pctgain > 1 then println symbol,",", date(j+1),",",close(0):6:3,","," B: ", b:4:3,","," B1: ", b1:4:3,","," Percent gain: ", pctgain:4:2; endif; endif; b1:=b; // must alway set to last day's val next j; |