### Question:
BulletPaymentTradeCalculationFunction implements CalculationFunction<BulletPaymentTrade> { @Override public Map<Measure, Result<?>> calculate( BulletPaymentTrade trade, Set<Measure> measures, CalculationParameters parameters, ScenarioMarketData scenarioMarketData, ReferenceData refData) { ResolvedBulletPaymentTrade resolved = trade.resolve(refData); RatesMarketDataLookup ratesLookup = parameters.getParameter(RatesMarketDataLookup.class); RatesScenarioMarketData marketData = ratesLookup.marketDataView(scenarioMarketData); Map<Measure, Result<?>> results = new HashMap<>(); for (Measure measure : measures) { results.put(measure, calculate(measure, resolved, marketData)); } return results; } BulletPaymentTradeCalculationFunction(); @Override Class<BulletPaymentTrade> targetType(); @Override Set<Measure> supportedMeasures(); @Override Optional<String> identifier(BulletPaymentTrade target); @Override Currency naturalCurrency(BulletPaymentTrade trade, ReferenceData refData); @Override FunctionRequirements requirements(
      BulletPaymentTrade trade,
      Set<Measure> measures,
      CalculationParameters parameters,
      ReferenceData refData); @Override Map<Measure, Result<?>> calculate(
      BulletPaymentTrade trade,
      Set<Measure> measures,
      CalculationParameters parameters,
      ScenarioMarketData scenarioMarketData,
      ReferenceData refData);  }### Answer:
@Test public void test_simpleMeasures() { BulletPaymentTradeCalculationFunction function = new BulletPaymentTradeCalculationFunction(); ScenarioMarketData md = marketData(); RatesProvider provider = RATES_LOOKUP.ratesProvider(md.scenario(0)); DiscountingPaymentPricer pricer = DiscountingPaymentPricer.DEFAULT; Payment payment = RTRADE.getProduct().getPayment(); CurrencyAmount expectedPv = pricer.presentValue(payment, provider); CashFlows expectedCashFlows = pricer.cashFlows(payment, provider); Set<Measure> measures = ImmutableSet.of( Measures.PRESENT_VALUE, Measures.CASH_FLOWS, Measures.RESOLVED_TARGET); assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)) .containsEntry( Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))) .containsEntry( Measures.CASH_FLOWS, Result.success(ScenarioArray.of(ImmutableList.of(expectedCashFlows)))) .containsEntry( Measures.RESOLVED_TARGET, Result.success(RTRADE)); }
@Test public void test_pv01() { BulletPaymentTradeCalculationFunction function = new BulletPaymentTradeCalculationFunction(); ScenarioMarketData md = marketData(); RatesProvider provider = RATES_LOOKUP.ratesProvider(md.scenario(0)); DiscountingPaymentPricer pricer = DiscountingPaymentPricer.DEFAULT; Payment payment = RTRADE.getProduct().getPayment(); PointSensitivities pvPointSens = pricer.presentValueSensitivity(payment, provider).build(); CurrencyParameterSensitivities pvParamSens = provider.parameterSensitivity(pvPointSens); MultiCurrencyAmount expectedPv01 = pvParamSens.total().multipliedBy(1e-4); CurrencyParameterSensitivities expectedBucketedPv01 = pvParamSens.multipliedBy(1e-4); Set<Measure> measures = ImmutableSet.of( Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED); assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)) .containsEntry( Measures.PV01_CALIBRATED_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01)))) .containsEntry( Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedBucketedPv01)))); }