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) { // revalue the former position. 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; }
public void process(PNLChangeEvent delta) { dataChanged = new AtomicBoolean(true); tsContainer.setValue(delta.getTradInstId(), delta.getTimeStamp(), delta.getChange()); double currentVal = 0.0; if (!currentValues.containsKey(delta.getTradInstId())) { // also add a new line chart. currentVal = delta.getChange(); currentValues.put(delta.getTradInstId(), currentVal); cumulatedTSContainer.setValue(delta.getTradInstId(), delta.getTimeStamp(), currentVal); } else { currentVal = currentValues.get(delta.getTradInstId()); currentVal += delta.getChange(); currentValues.put(delta.getTradInstId(), currentVal); cumulatedTSContainer.setValue(delta.getTradInstId(), delta.getTimeStamp(), currentVal); } Iterator<Entry<String, Double>> it = currentValues.entrySet().iterator(); double total = 0.0; while (it.hasNext()) { total += it.next().getValue(); } cumulatedTSContainer.setValue("TOTAL", delta.getTimeStamp(), total); }
/** * Called when a pnl change event arrived. * * @param pe */ public void process(PNLChangeEvent pe) { int row = getInstrumentTable().getRowIndexOfByTradeId( pe.getTradInstId()); getPositionTable().setValueAt(pe.getTotalPnl(), row, PositionTable.Columns.PNLATLIQUIDATION.colIdx()); getPositionTable().signalUpdate(); }
public PNLChangeEvent ce(long l, String id, Double val){ PNLChangeEvent p = new PNLChangeEvent(new TimeStamp(l), id, val, 0.0); return p; }