> It's actually a mystery to me why the averageBalance would ever be
> NaN. I'd expect 0 when market data stops. I'll investigate before
> making a permanent fix.

I figured the NaN probably comes from these three lines:

double balance = 100.0d * (cumulativeBid - cumulativeAsk) /
totalDepth;
balances.add(balance);
midPointPrice = (bids.getFirst().getPrice() +
asks.getFirst().getPrice()) / 2;

When the trading stops and limit book becomes empty, all the bid and
ask level sizes become zero, so the totalDepth is also zero, which
results into division by 0.

The fix is simply this:

if (totalDepth != 0) {
    double balance = 100.0d * (cumulativeBid - cumulativeAsk) /
totalDepth;
    balances.add(balance);
    midPointPrice = (bids.getFirst().getPrice() +
asks.getFirst().getPrice()) / 2;
}

If my theory is true, it's becomes unnecessary to check for NaN, as
in:

if (Double.isNaN(averageBalance)) {
    averageBalance = 0;
    return null;
}

I'll test this today.


-- 
You received this message because you are subscribed to the Google Groups 
"JBookTrader" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jbooktrader?hl=en.

Reply via email to