### Question:
CashFlowEquivalentCalculator { public static ResolvedSwapLeg cashFlowEquivalentSwap(ResolvedSwap swap, RatesProvider ratesProvider) { validateSwap(swap); ResolvedSwapLeg cfFixed = cashFlowEquivalentFixedLeg(swap.getLegs(SwapLegType.FIXED).get(0), ratesProvider); ResolvedSwapLeg cfIbor = cashFlowEquivalentIborLeg(swap.getLegs(SwapLegType.IBOR).get(0), ratesProvider); ResolvedSwapLeg leg = ResolvedSwapLeg.builder() .paymentEvents( Stream.concat(cfFixed.getPaymentEvents().stream(), cfIbor.getPaymentEvents().stream()).collect(Collectors.toList())) .payReceive(PayReceive.RECEIVE) .type(SwapLegType.OTHER) .build(); return leg; } private  CashFlowEquivalentCalculator(); static ResolvedSwapLeg cashFlowEquivalentSwap(ResolvedSwap swap, RatesProvider ratesProvider); static ResolvedSwapLeg cashFlowEquivalentIborLeg(ResolvedSwapLeg iborLeg, RatesProvider ratesProvider); static ResolvedSwapLeg cashFlowEquivalentFixedLeg(ResolvedSwapLeg fixedLeg, RatesProvider ratesProvider); static ImmutableMap<Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivitySwap(
      ResolvedSwap swap,
      RatesProvider ratesProvider); static ImmutableMap<Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivityIborLeg(
      ResolvedSwapLeg iborLeg,
      RatesProvider ratesProvider); static ImmutableMap<Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivityFixedLeg(
      ResolvedSwapLeg fixedLeg,
      RatesProvider ratesProvider);  }### Answer:
@Test public void test_cashFlowEquivalent_pv() { ResolvedSwap swap = ResolvedSwap.of(IBOR_LEG, FIXED_LEG); ResolvedSwapLeg cfe = CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap, PROVIDER); DiscountingSwapLegPricer pricerLeg = DiscountingSwapLegPricer.DEFAULT; DiscountingSwapProductPricer pricerSwap = DiscountingSwapProductPricer.DEFAULT; CurrencyAmount pvCfe = pricerLeg.presentValue(cfe, PROVIDER); MultiCurrencyAmount pvSwap = pricerSwap.presentValue(swap, PROVIDER); assertThat(pvCfe.getAmount()).isCloseTo(pvSwap.getAmount(GBP).getAmount(), offset(TOLERANCE_PV)); }
@Test public void test_cashFlowEquivalent_compounding() { RatePaymentPeriod iborCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(IBOR1, IBOR2) .dayCount(ACT_365F) .currency(GBP) .notional(-NOTIONAL) .build(); ResolvedSwapLeg iborLegCmp = ResolvedSwapLeg.builder() .type(IBOR) .payReceive(PAY) .paymentPeriods(iborCmp) .build(); ResolvedSwap swap1 = ResolvedSwap.of(iborLegCmp, FIXED_LEG); assertThatIllegalArgumentException() .isThrownBy(() -> CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap1, PROVIDER)); RatePaymentPeriod fixedCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(FIXED1, FIXED2) .dayCount(ACT_365F) .currency(GBP) .notional(NOTIONAL) .build(); ResolvedSwapLeg fixedLegCmp = ResolvedSwapLeg.builder() .type(FIXED) .payReceive(RECEIVE) .paymentPeriods(fixedCmp) .build(); ResolvedSwap swap2 = ResolvedSwap.of(IBOR_LEG, fixedLegCmp); assertThatIllegalArgumentException() .isThrownBy(() -> CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap2, PROVIDER)); }