PipJumpCutOffCalculatorService implements PipJumpCutOffCalculator<T> { @SuppressWarnings("unchecked") @Override public Double calculatePipJumpCutOff(TradeableInstrument<T> instrument) { Double refInstrumentPrice = this.offsetCache.getIfPresent(refInstrument); Double instrumentPrice = this.offsetCache.getIfPresent(instrument); if (refInstrumentPrice == null && instrumentPrice == null) { Map<TradeableInstrument<T>, Price<T>> priceMap = this.currentPriceInfoProvider .getCurrentPricesForInstruments(Lists.newArrayList(refInstrument, instrument)); Price<T> refPrice = priceMap.get(refInstrument); refInstrumentPrice = (refPrice.getAskPrice() + refPrice.getBidPrice()) / 2; Price<T> price = priceMap.get(instrument); instrumentPrice = (price.getAskPrice() + price.getBidPrice()) / 2; Lock writeLock = this.lock.writeLock(); try { writeLock.lock(); this.offsetCache.put(refInstrument, refInstrumentPrice); this.offsetCache.put(instrument, instrumentPrice); } finally { writeLock.unlock(); } } else if (refInstrumentPrice == null && instrumentPrice != null) { refInstrumentPrice = fetchSingleInstrumentPrice(refInstrument); } else if (instrumentPrice == null && refInstrumentPrice != null) { instrumentPrice = fetchSingleInstrumentPrice(instrument); } double pipRef = this.instrumentService.getPipForInstrument(refInstrument); double pip = this.instrumentService.getPipForInstrument(instrument); return ((instrumentPrice * pipRef) / (refInstrumentPrice * pip)) * refInstrumentPip; } PipJumpCutOffCalculatorService(TradeableInstrument<T> refInstrument,
			CurrentPriceInfoProvider<T> currentPriceInfoProvider, Double refInstrumentPip,
			InstrumentService<T> instrumentService); @SuppressWarnings("unchecked") @Override Double calculatePipJumpCutOff(TradeableInstrument<T> instrument);  }
@SuppressWarnings("unchecked") @Test public void foo() { final double pip1 = 0.0001; final double pip2 = 0.01; CurrentPriceInfoProvider<String> currentPriceInfoProvider = mock(CurrentPriceInfoProvider.class); InstrumentService<String> instrumentService = mock(InstrumentService.class); DateTime now = DateTime.now(); TradeableInstrument<String> eurusd = new TradeableInstrument<>("EUR_USD"); Price<String> eurusdPrice = new Price<>(eurusd, 1.11905, 1.11915, now); TradeableInstrument<String> nzdchf = new TradeableInstrument<>("NZD_CHF"); Price<String> nzdchfPrice = new Price<>(nzdchf, 0.65382, 0.65402, now); TradeableInstrument<String> gbpjpy = new TradeableInstrument<>("GBP_JPY"); Price<String> gbpjpyPrice = new Price<>(gbpjpy, 166.506, 166.524, now); TradeableInstrument<String> gbpnzd = new TradeableInstrument<>("GBP_NZD"); Price<String> gbpnzdPrice = new Price<>(gbpnzd, 2.17625, 2.17671, now); final double basePip = 45.0; PipJumpCutOffCalculator<String> pipCalculator = new PipJumpCutOffCalculatorService<>(eurusd, currentPriceInfoProvider, basePip, instrumentService); Map<TradeableInstrument<String>, Price<String>> eurusdnzdchfMap = Maps.newHashMap(); eurusdnzdchfMap.put(eurusd, eurusdPrice); eurusdnzdchfMap.put(nzdchf, nzdchfPrice); Map<TradeableInstrument<String>, Price<String>> gbpnzdMap = Maps.newHashMap(); gbpnzdMap.put(gbpnzd, gbpnzdPrice); Map<TradeableInstrument<String>, Price<String>> gbpjpyMap = Maps.newHashMap(); gbpjpyMap.put(gbpjpy, gbpjpyPrice); when(currentPriceInfoProvider.getCurrentPricesForInstruments(eq(Lists.newArrayList(eurusd, nzdchf)))) .thenReturn(eurusdnzdchfMap); when(currentPriceInfoProvider.getCurrentPricesForInstruments(eq(Lists.newArrayList(gbpnzd)))) .thenReturn(gbpnzdMap); when(currentPriceInfoProvider.getCurrentPricesForInstruments(eq(Lists.newArrayList(gbpjpy)))) .thenReturn(gbpjpyMap); when(instrumentService.getPipForInstrument(eurusd)).thenReturn(pip1); when(instrumentService.getPipForInstrument(gbpnzd)).thenReturn(pip1); when(instrumentService.getPipForInstrument(gbpjpy)).thenReturn(pip2); when(instrumentService.getPipForInstrument(nzdchf)).thenReturn(pip1); double v = pipCalculator.calculatePipJumpCutOff(nzdchf); assertEquals(26.2947, v, TradingTestConstants.precision); v = pipCalculator.calculatePipJumpCutOff(gbpjpy); assertEquals(66.9571, v, TradingTestConstants.precision); v = pipCalculator.calculatePipJumpCutOff(gbpnzd); assertEquals(87.5181, v, TradingTestConstants.precision); v = pipCalculator.calculatePipJumpCutOff(nzdchf); v = pipCalculator.calculatePipJumpCutOff(gbpjpy); verify(currentPriceInfoProvider, times(3)).getCurrentPricesForInstruments(any(Collection.class)); }