private void openTrade(final int i) { openBarIndex = i; final double openPrice = timeSeries.getBar(i).getOpenPrice().doubleValue(); openContracts = tradeStrategyFactory.getContracts(portfolioValue, i); final double positionSize = openPrice * openContracts; if(positionSize > portfolioValue) { throw new IllegalArgumentException("Unable to open a trade with position size: " + positionSize + " portfolio size: " + positionSize); } calculateFees(openPrice); }