First call to ShannonGain always returns -1.#IND00.
Observe.
Code:
function run() {
StartDate = 20140401;
EndDate = 20140515;
BarPeriod = 30;
LookBack = 501;
asset("GBP/USD");
vars Price = series(price());
var shan = ShannonGain(Price, 250);
static int i = 0;
printf("\nAt bar %d ind=%f", Bar, shan);
i += 1;
if (i >= 5) {
quit();
}
}
Logs
Code:
shannon_bug compiling................
At bar 0 ind=-1.#IND00
BackTest: shannon_bug GBP/USD 2014
At bar 139 ind=-1.#IND00
At bar 140 ind=-0.000001
At bar 141 ind=-0.000002
At bar 142 ind=-0.000000
Cancelled
Last edited by GPEngine; 06/18/1406:20.
Re: First call to ShannonGain always returns -1.#IND00
[Re: GPEngine]
#442320 06/18/1406:0706/18/1406:07
The problem comes when part of the series is a flatline. Then, G=log(1)=0 sumx2=0 rmsx=sqrt(sumx2/Period) =sqrt(0/Period) =0 P = ((avgx / rmsx) + 1) / 2.0; // shannon probability = ((avgx / 0.0 + 1) / 2.0
kaboom.
Re: First call to ShannonGain always returns -1.#IND00
[Re: GPEngine]
#442329 06/18/1408:3206/18/1408:32