PureBytes Links
Trading Reference Links
|
{
*******************************************************************
Study : sve.lr
Last Edit : 8:16 PM 7/2/2004
Provided By : Sergey Efremov
Description : Calculates the slope and intercept of
the
linear regression of Price2 with respect to Price1.
Outputs the current value of the regression together
with
Intercept and Slope:
Price2[k]=Intercept+Slope*Price1[k]
********************************************************************}
Inputs : Price1(NumericSeries), {numeric series x}
Price2(NumericSeries), {numeric series y}
Length(NumericSimple), {length of the series}
Intercept(NumericRef),
Slope(NumericRef);
vars: a11(0), a12(0), a21(0), a22(0), x1(0), x2(0);
vars: k(0);
a11 = 0;
a12 = 0;
a21 = 0;
a22 = 0;
x1 = 0;
x2 = 0;
for k = 0 to Length - 1 begin
a11=a11+1;
a12=a12+Price1[k];
a21=a12;
a22=a22+Price1[k]*Price2[k];
x1=x1+Price2[k];
x2=x2+Price2[k]*Price2[k];
end;
intercept = (a22*x1-a12*x2)/(a11*a22-a21*a12);
slope = (a21*x1-a11*x2)/(a12*a21-a11*a22);
sve.lr = intercept + slope * Price1;
|