public virtual void test_cashFlowEquivalentAndSensitivity_wrongSwap()
        {
            ResolvedSwap swap1 = ResolvedSwap.of(IBOR_LEG, FIXED_LEG, IBOR_LEG);

            assertThrowsIllegalArg(() => CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap1, PROVIDER));
            ResolvedSwap swap2 = ResolvedSwap.of(FIXED_LEG, FIXED_LEG);

            assertThrowsIllegalArg(() => CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap2, PROVIDER));
            ResolvedSwap swap3 = ResolvedSwap.of(FIXED_LEG, CashFlowEquivalentCalculator.cashFlowEquivalentIborLeg(IBOR_LEG, PROVIDER));

            assertThrowsIllegalArg(() => CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap3, PROVIDER));
        }
        public virtual void test_cashFlowEquivalent()
        {
            ResolvedSwap    swap             = ResolvedSwap.of(IBOR_LEG, FIXED_LEG);
            ResolvedSwapLeg computed         = CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap, PROVIDER);
            ResolvedSwapLeg computedIborLeg  = CashFlowEquivalentCalculator.cashFlowEquivalentIborLeg(IBOR_LEG, PROVIDER);
            ResolvedSwapLeg computedFixedLeg = CashFlowEquivalentCalculator.cashFlowEquivalentFixedLeg(FIXED_LEG, PROVIDER);

            assertEquals(computedFixedLeg.PaymentEvents, computed.PaymentEvents.subList(0, 2));
            assertEquals(computedIborLeg.PaymentEvents, computed.PaymentEvents.subList(2, 6));

            // expected payments from fixed leg
            NotionalExchange fixedPayment1 = NotionalExchange.of(CurrencyAmount.of(GBP, NOTIONAL * RATE * PAY_YC1), PAYMENT1);
            NotionalExchange fixedPayment2 = NotionalExchange.of(CurrencyAmount.of(GBP, NOTIONAL * RATE * PAY_YC2), PAYMENT2);
            // expected payments from ibor leg
            LocalDate        fixingSTART1       = GBP_LIBOR_3M.calculateEffectiveFromFixing(FIXING1, REF_DATA);
            double           fixedYearFraction1 = GBP_LIBOR_3M.DayCount.relativeYearFraction(fixingSTART1, GBP_LIBOR_3M.calculateMaturityFromEffective(fixingSTART1, REF_DATA));
            double           beta1              = (1d + fixedYearFraction1 * PROVIDER.iborIndexRates(GBP_LIBOR_3M).rate(GBP_LIBOR_3M_COMP1.Observation)) * PROVIDER.discountFactor(GBP, PAYMENT1) / PROVIDER.discountFactor(GBP, fixingSTART1);
            NotionalExchange iborPayment11      = NotionalExchange.of(CurrencyAmount.of(GBP, -NOTIONAL * beta1 * PAY_YC1 / fixedYearFraction1), fixingSTART1);
            NotionalExchange iborPayment12      = NotionalExchange.of(CurrencyAmount.of(GBP, NOTIONAL * PAY_YC1 / fixedYearFraction1), PAYMENT1);
            LocalDate        fixingSTART2       = GBP_LIBOR_3M.calculateEffectiveFromFixing(FIXING2, REF_DATA);
            double           fixedYearFraction2 = GBP_LIBOR_3M.DayCount.relativeYearFraction(fixingSTART2, GBP_LIBOR_3M.calculateMaturityFromEffective(fixingSTART2, REF_DATA));
            double           beta2              = (1d + fixedYearFraction2 * PROVIDER.iborIndexRates(GBP_LIBOR_3M).rate(GBP_LIBOR_3M_COMP2.Observation)) * PROVIDER.discountFactor(GBP, PAYMENT2) / PROVIDER.discountFactor(GBP, fixingSTART2);
            NotionalExchange iborPayment21      = NotionalExchange.of(CurrencyAmount.of(GBP, -NOTIONAL * beta2 * PAY_YC2 / fixedYearFraction2), fixingSTART2);
            NotionalExchange iborPayment22      = NotionalExchange.of(CurrencyAmount.of(GBP, NOTIONAL * PAY_YC2 / fixedYearFraction2), PAYMENT2);

            ResolvedSwapLeg expected = ResolvedSwapLeg.builder().type(OTHER).payReceive(RECEIVE).paymentEvents(fixedPayment1, fixedPayment2, iborPayment11, iborPayment12, iborPayment21, iborPayment22).build();

            double eps = 1.0e-12;

            assertEquals(computed.PaymentEvents.size(), expected.PaymentEvents.size());
            for (int i = 0; i < 6; ++i)
            {
                NotionalExchange payCmp = (NotionalExchange)computed.PaymentEvents.get(i);
                NotionalExchange payExp = (NotionalExchange)expected.PaymentEvents.get(i);
                assertEquals(payCmp.Currency, payExp.Currency);
                assertEquals(payCmp.PaymentDate, payExp.PaymentDate);
                assertTrue(DoubleMath.fuzzyEquals(payCmp.PaymentAmount.Amount, payExp.PaymentAmount.Amount, NOTIONAL * eps));
            }
        }