private PNLChangeEvent pnl(TimeStamp ts, String tid, double price, double posChange) {
PNLChangeEvent pce = null;
Double formerPos = positions.get(tid);
Double lastValuationPrice = lastValPrices.get(tid);
Double avgPrice = avgPrices.get(tid);
if (formerPos == null) {
formerPos = 0.0;
lastValuationPrice = 0.0;
}
Double newPos = formerPos + posChange;
if (formerPos != 0.0) {
double pnlChange = (price - lastValuationPrice) * formerPos;
double unrealizedPnl = (price - avgPrice) * formerPos;
if(newPos==0.0)
unrealizedPnl = 0.0;
pce = new PNLChangeEvent(ts, tid, pnlChange, unrealizedPnl);
try {
riskDataPublisher.send(pce);
} catch (Exception e) {
e.printStackTrace();
}
}
if(posChange!=0.0)
positions.put(tid, newPos);
lastValPrices.put(tid, price);
return pce;
}