To: Bob Jagow who wrote (5244 ) 7/7/1998 4:52:00 PM From: TechTrader42 Read Replies (1) | Respond to of 11149
Slope enthusiasts (philanslopists?): Bob Jagow has solved the dizzying d by z problem in the slope formula when percentage gain is added as a condition. Here's his new formulation of the formula (for moolah?): 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),",",close(0):6:3,","," B: ", b:4:3,","," B1: ", b1:4:3,","," Pctgain: ", pctgain:4:2; endif; endif; b1:=b; // must alway set to last day's val next j; Note this line: b := .000001+(S*Sxy - Sx*Sy)/(S*Sxx - Sx*Sx); Kills z bugs every time. If you put "i" in date() instead of "j," you get the date of the move up (B1). With j in the date, you get the previous date (the date of B). B1 or B: That is now the question. You can change this line: if pctgain > 1 then to get the percentage change you want. Of course, you're going to get greater percentage changes if you use a shorter period for slope. Instead of using 21 days for the period, for example, you could use 3 days. Change this line to do that: S := 21; What more could a slopephiliac desire? Brooke