// System.out.println(new Date(openTime)+" -> "+new Date(time)+" quantity "+quantity+" gain "+totalCost+" price "+openPrice+" to "+price);
} else {
if (quantity==0 && totalQuantity==0) {
throw new C2ServiceException("Can not open position in "+symbol+" of zero quantity", false);
}
//if (Math.abs(totalCost.doubleValue()) > 1000000) {
// throw new C2ServiceException(totalCost+" bad cost "+price+" "+quantity+" "+commission,false );
//}
openTime = time;
if (BigDecimal.ZERO.compareTo(price)>=0 && quantity>0) {
//this can really happen but it would be expected to be rare, confirm this with a secondary source
logger.warn("Lost 100% of position due to zero price data for "+symbol+" on "+new Date(time));
}
//logger.trace("open new {} position of {} existing "+totalQuantity,symbol,quantity);
}
totalQuantity = totalQuantity + quantity;
//TODO:off while testing for optimals
// //watch for big loss/gain
// BigDecimal pctFlag = new BigDecimal(".5"); //NOTE: hardcoded to only look for losses now
// if (0==totalQuantity.intValue() && totalCost.doubleValue()<0 && totalCost.abs().compareTo(initialCost.abs().multiply(pctFlag))>0) {
// System.err.println("LARGE CHANGE:"+symbol+" Gain:"+totalCost+" Invest:"+initialCost+" closing:"+isClosing+" price:"+price+" quantity:"+quantity+" commission:"+commission+" DATE:"+new Date(time)+" openPrice: "+openPrice+" openDate:"+new Date(openTime));
// }
// if (verbose) {
// System.err.println(new Date(time)+" update portfolio "+symbol +" quantity:"+totalQuantity+" gain:"+totalCost+" flow:"+adj+" "+isClosing);
// }
simplePortfolio.updatePortfolio(symbol, totalQuantity, totalCost, totalSellPrice, this, isClosing, duration);
if ((0 == totalQuantity.intValue()) || null == openPrice) {
openPrice = price;
}
//TODO: no transactions should ever be this big must track down how this happened.
if (Math.abs(totalCost.doubleValue()) > 1000000) {
throw new C2ServiceException(totalCost+" bad cost "+price+" "+quantity+" "+commission+" init "+initialCost+" totalSale "+totalSellPrice+" date "+new Date(time),false );
}
/*
* WARNING: stats gathering
com.collective2.signalEntry.C2ServiceException: -1661142.6100 bad cost 39.7200 706 10.00 init -1633090.2900 totalSale -28052.3200 date Tue Mar 18 15:00:00 CDT 2008
at com.collective2.signalEntry.adapter.dynamicSimulator.portfolio.SimplePosition.addTransaction(SimplePosition.java:127)