[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: R Squared Code



PureBytes Links

Trading Reference Links

I use the formula below

Regards
Jonas Vikstrom

------------------------------------------------------------
Function name: rmR2
Inputs: Price(NumericSeries), Len(NumericSimple), Smth(NumericSimple);
Vars: Ctr(0), RegSlope(0), RegValue(0), Avg(0), RegRes(0), YRes(0), r2(0);

RegRes = 0;
YRes = 0;
Ctr = 0;

Avg = Average(Price, Len);
RegSlope = LinearRegSlope(Price, Len);
RegValue = LinearRegValue(Price, Len, 0);

for Ctr = 0 to Len - 1 begin
	RegRes = RegRes + Square((RegValue - (Ctr * RegSlope)) - Avg);
	YRes = YRes + Square(Price[Ctr] - Avg);
end;	

if YRes <> 0 then 
	r2 = RegRes / YRes
else
	r2 = 0;

rmR2 = Average(r2, Smth);


> -----Original Message-----
> From: Jimmy56@xxxxxxx [mailto:Jimmy56@xxxxxxx]
> Sent: den 28 april 1999 10:56
> To: omega-list@xxxxxxxxxx
> Subject: R Squared Code
> 
> 
> I'm trying to use R squared as a trend indicator, but I don't 
> think I'm 
> coding it right.  I've pasted the code I'm using below.  Does 
> anyone know if 
> this is correct?  Thanks.
> 
> Plot1(LinearRegSlope(C, Length), "LinearReg");
> 
> Jim
> 
>