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

Hurst Exponent



PureBytes Links

Trading Reference Links

This is the code for the Hurst exponent (in case anyone wants it and doesn't have it ) .. the problem is that I keep getting an error that it is apparently trying to feed a zero value to a log function .. when I think I've fixed that it then tells me that I am trying to divide by zero .. Does anyone see what needs to be done to correct the code??

Inputs: Len(Numeric);
Vars: Mean(0), j(0), k(1.253314), SumSqr(0), Scale(0), MaxY(0),
   MinY(0), Rng(0);
Arrays: X[100](0), Y[100](0);

Mean = Average(C, Len);
SumSqr = 0;
for j = 0 to Len - 1 begin
   X[j] = C[j] - Mean;
   SumSqr = SumSqr + X[j] * X[j];
end;
Scale = SquareRoot(SumSqr / Len);
Y[0] = X[0];
MaxY = X[0];
MinY = X[0];
for j = 1 to Len - 1 begin
   Y[j] = Y[j - 1] + X[j];
   if Y[j] > MaxY then MaxY = Y[j];
   if Y[j] < MinY then MinY = Y[j];
end;
Rng = MaxY - MinY;
Hurst = Log(Rng/(k * Scale)) / Log(Len);