DefaultHistoricalPnLFXConverterFn implements HistoricalPnLFXConverterFn { @Override public Result<LocalDateDoubleTimeSeries> convertToSpotRate(Environment env, CurrencyPair currencyPair, LocalDateDoubleTimeSeries hts) { LocalDateRange fxDateRange = getDateRange(hts); s_logger.debug("Sourcing {} fx rates for period {}.", currencyPair, fxDateRange); Result<LocalDateDoubleTimeSeries> ccyPairHtsResult = _historicalMarketDataFn.getFxRates(env, currencyPair, fxDateRange); Result<FXMatrix> fxMatrixResult = _fxMatrixFn.getFXMatrix(env, ImmutableSet.of(currencyPair.getBase(), currencyPair.getCounter())); if (!Result.allSuccessful(fxMatrixResult, ccyPairHtsResult)) { return Result.failure(fxMatrixResult, ccyPairHtsResult); } FXMatrix fxMatrix = fxMatrixResult.getValue(); LocalDateDoubleTimeSeries ccyPairHts = rollIfRequired(currencyPair, ccyPairHtsResult.getValue().reciprocal()); double envFxRate = fxMatrix.getFxRate(currencyPair.getBase(), currencyPair.getCounter()); LocalDateDoubleTimeSeries resultHts = hts.multiply(ccyPairHts).divide(envFxRate); return Result.success(resultHts); } DefaultHistoricalPnLFXConverterFn(FXMatrixFn fxMatrixFn, HistoricalMarketDataFn historicalMarketDataFn, PnLPeriodBound periodBound); @Override Result<LocalDateDoubleTimeSeries> convertToSpotRate(Environment env, CurrencyPair currencyPair, LocalDateDoubleTimeSeries hts);  }
@Test public void convertToSpotEnd() { HistoricalPnLFXConverterFn fn = new DefaultHistoricalPnLFXConverterFn(_fxMatrixFn, _mdFn, PnLPeriodBound.END); when(_mdFn.getFxRates(env, _ccyPair, _range)).thenReturn(Result.success(_reciprocalFxRates)); Result<LocalDateDoubleTimeSeries> result = fn.convertToSpotRate(env, _ccyPair, _inputPnL); assertTrue(result.isSuccess()); assertEquals("Expected size of series to remain the same", _inputPnL.size(), result.getValue().size()); assertTrue("Converted PnL did not match expected results.", checkResult(result, EXPECTED_PNL_WITH_END_FX)); }
@Test public void convertToSpotStart() { HistoricalPnLFXConverterFn fn = new DefaultHistoricalPnLFXConverterFn(_fxMatrixFn, _mdFn, PnLPeriodBound.START); when(_mdFn.getFxRates(env, _ccyPair, _adjustedRange)).thenReturn(Result.success(_reciprocalFxRates)); Result<LocalDateDoubleTimeSeries> result = fn.convertToSpotRate(env, _ccyPair, _inputPnL); assertEquals("Expected size of series to remain the same", _inputPnL.size(), result.getValue().size()); assertTrue("Converted PnL did not match expected results.", checkResult(result, EXPECTED_PNL_WITH_START_FX)); }