public virtual void test_inflation_fixed()
        {
            BusinessDayAdjustment  bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule       accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_14_06_09).endDate(DATE_19_06_09).frequency(P12M).businessDayAdjustment(bda).build();
            PaymentSchedule        paymentSchedule  = PaymentSchedule.builder().paymentFrequency(Frequency.ofYears(5)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).compoundingMethod(STRAIGHT).build();
            FixedRateCalculation   rateCalc         = FixedRateCalculation.builder().rate(ValueSchedule.of(0.05)).dayCount(ONE_ONE).build();
            NotionalSchedule       notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg test             = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_14_06_09, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_19_06_09, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);
            RateAccrualPeriod rap0       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09, REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(1), REF_DATA)).unadjustedStartDate(DATE_14_06_09).unadjustedEndDate(DATE_14_06_09.plusYears(1)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap1       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(1), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(2), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(1)).unadjustedEndDate(DATE_14_06_09.plusYears(2)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap2       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(2), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(3), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(2)).unadjustedEndDate(DATE_14_06_09.plusYears(3)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap3       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(3), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(4), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(3)).unadjustedEndDate(DATE_14_06_09.plusYears(4)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap4       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(4), REF_DATA)).endDate(bda.adjust(DATE_19_06_09, REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(4)).unadjustedEndDate(DATE_19_06_09).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RatePaymentPeriod rpp        = RatePaymentPeriod.builder().paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)).accrualPeriods(rap0, rap1, rap2, rap3, rap4).compoundingMethod(STRAIGHT).dayCount(ONE_ONE).currency(GBP).notional(1000d).build();
            ResolvedSwapLeg   expected   = ResolvedSwapLeg.builder().paymentPeriods(rpp).payReceive(RECEIVE).type(SwapLegType.FIXED).build();
            ResolvedSwapLeg   testExpand = test.resolve(REF_DATA);

            assertEquals(testExpand, expected);
        }
示例#2
0
        public virtual void test_createTrade_withFee()
        {
            TenorCdsTemplate  base1      = TenorCdsTemplate.of(TENOR_10Y, CONV1);
            TenorCdsTemplate  base2      = TenorCdsTemplate.of(AccrualStart.NEXT_DAY, TENOR_2Y, CONV2);
            LocalDate         tradeDate  = LocalDate.of(2015, 5, 5);
            AdjustablePayment payment1   = AdjustablePayment.of(EUR, NOTIONAL_2M, CONV1.SettlementDateOffset.adjust(tradeDate, REF_DATA));
            AdjustablePayment payment2   = AdjustablePayment.of(USD, NOTIONAL_2M, CONV2.SettlementDateOffset.adjust(tradeDate, REF_DATA));
            LocalDate         startDate1 = date(2015, 3, 20);
            LocalDate         endDate1   = date(2025, 6, 20);
            LocalDate         startDate2 = date(2015, 5, 6);
            LocalDate         endDate2   = date(2017, 6, 20);
            CdsTrade          test1      = base1.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment1, REF_DATA);
            CdsTrade          test2      = base2.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment2, REF_DATA);
            Cds expected1         = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, startDate1, endDate1, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d);
            PeriodicSchedule sch1 = expected1.PaymentSchedule;

            expected1 = expected1.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build();
            Cds expected2         = Cds.of(BUY, LEGAL_ENTITY, CONV2.Currency, NOTIONAL_2M, startDate2, endDate2, Frequency.P3M, CONV2.SettlementDateOffset.Calendar, 0.05d);
            PeriodicSchedule sch2 = expected2.PaymentSchedule;

            expected2 = expected2.toBuilder().paymentSchedule(sch2.toBuilder().startDateBusinessDayAdjustment(sch2.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build();
            assertEquals(test1.Info.TradeDate, tradeDate);
            assertEquals(test1.UpfrontFee, payment1);
            assertEquals(test1.Product, expected1);
            assertEquals(test2.Info.TradeDate, tradeDate);
            assertEquals(test2.UpfrontFee, payment2);
            assertEquals(test2.Product, expected2);
        }
示例#3
0
        /// <summary>
        /// Create a pay leg.
        /// <para>
        /// The pay leg created is periodic fixed rate payments without compounding.
        /// The Ibor index is used to specify the payment frequency.
        ///
        /// </para>
        /// </summary>
        /// <param name="index">  the Ibor index </param>
        /// <param name="startDate">  the start date </param>
        /// <param name="endDate">  the end date </param>
        /// <param name="fixedRate">  the fixed rate </param>
        /// <param name="notional">  the notional </param>
        /// <param name="payRec">  pay or receive </param>
        /// <returns> the instance </returns>
        public static SwapLeg createFixedPayLegUnresolved(IborIndex index, LocalDate startDate, LocalDate endDate, double fixedRate, double notional, PayReceive payRec)
        {
            Frequency        frequency   = Frequency.of(index.Tenor.Period);
            PeriodicSchedule accSchedule = PeriodicSchedule.of(startDate, endDate, frequency, BUSINESS_ADJ, StubConvention.NONE, RollConventions.NONE);

            return(RateCalculationSwapLeg.builder().payReceive(payRec).accrualSchedule(accSchedule).calculation(FixedRateCalculation.of(fixedRate, ACT_360)).paymentSchedule(PaymentSchedule.builder().paymentFrequency(frequency).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(CurrencyAmount.of(EUR, notional))).build());
        }
        public virtual void test_inflation_interpolated()
        {
            BusinessDayAdjustment    bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule         accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_14_06_09).endDate(DATE_19_06_09).frequency(Frequency.ofYears(5)).businessDayAdjustment(bda).build();
            PaymentSchedule          paymentSchedule  = PaymentSchedule.builder().paymentFrequency(Frequency.ofYears(5)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            InflationRateCalculation rateCalc         = InflationRateCalculation.builder().index(GB_RPI).indexCalculationMethod(INTERPOLATED).lag(Period.ofMonths(3)).build();
            NotionalSchedule         notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg   test             = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_14_06_09, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_19_06_09, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);

            double            weight     = 1.0 - 9.0 / 30.0;
            RatePaymentPeriod rpp0       = RatePaymentPeriod.builder().paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)).accrualPeriods(RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09, REF_DATA)).endDate(bda.adjust(DATE_19_06_09, REF_DATA)).unadjustedStartDate(DATE_14_06_09).unadjustedEndDate(DATE_19_06_09).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(GB_RPI, YearMonth.from(bda.adjust(DATE_14_06_09, REF_DATA)).minusMonths(3), YearMonth.from(bda.adjust(DATE_19_06_09, REF_DATA)).minusMonths(3), weight)).build()).dayCount(ONE_ONE).currency(GBP).notional(1000d).build();
            ResolvedSwapLeg   expected   = ResolvedSwapLeg.builder().paymentPeriods(rpp0).payReceive(RECEIVE).type(SwapLegType.INFLATION).build();
            ResolvedSwapLeg   testExpand = test.resolve(REF_DATA);

            assertEquals(testExpand, expected);
        }
示例#5
0
        internal static FixedCouponBond sut2()
        {
            BusinessDayAdjustment adj  = BusinessDayAdjustment.of(MODIFIED_FOLLOWING, SAT_SUN);
            PeriodicSchedule      sche = PeriodicSchedule.of(START_DATE, END_DATE, Frequency.P12M, adj, StubConvention.SHORT_INITIAL, true);

            return(FixedCouponBond.builder().securityId(SECURITY_ID2).dayCount(DayCounts.ACT_360).fixedRate(0.005).legalEntityId(LegalEntityId.of("OG-Ticker", "BUN EUR 2")).currency(GBP).notional(1.0e6).accrualSchedule(sche).settlementDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).yieldConvention(FixedCouponBondYieldConvention.GB_BUMP_DMO).build());
        }
 static BondFutureTest()
 {
     for (int i = 0; i < NB_BOND; ++i)
     {
         LocalDate        endDate        = START_DATE[i].plus(BOND_TENOR[i]);
         PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE[i], endDate, Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, false);
         FixedCouponBond  product        = FixedCouponBond.builder().securityId(SecurityId.of("OG-Test", "Bond " + i)).dayCount(DAY_COUNT).fixedRate(RATE[i]).legalEntityId(ISSUER_ID).currency(USD).notional(NOTIONAL).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS).yieldConvention(YIELD_CONVENTION).exCouponPeriod(EX_COUPON).build();
         BOND_PRODUCT[i]    = product;
         RESOLVED_BASKET[i] = product.resolve(REF_DATA);
     }
 }
示例#7
0
        /// <summary>
        /// Creates an Ibor cap/floor leg.
        /// <para>
        /// The Ibor index should be {@code EUR_EURIBOR_3M} or {@code EUR_EURIBOR_6M} to match the availability of the curve
        /// data in <seealso cref="IborCapletFloorletDataSet"/>.
        ///
        /// </para>
        /// </summary>
        /// <param name="index">  the index </param>
        /// <param name="startDate">  the start date </param>
        /// <param name="endDate">  the end date </param>
        /// <param name="strikeSchedule">  the strike </param>
        /// <param name="notionalSchedule">  the notional </param>
        /// <param name="putCall">  cap or floor </param>
        /// <param name="payRec">  pay or receive </param>
        /// <returns> the instance </returns>
        public static IborCapFloorLeg createCapFloorLegUnresolved(IborIndex index, LocalDate startDate, LocalDate endDate, ValueSchedule strikeSchedule, ValueSchedule notionalSchedule, PutCall putCall, PayReceive payRec)
        {
            Frequency           frequency       = Frequency.of(index.Tenor.Period);
            PeriodicSchedule    paySchedule     = PeriodicSchedule.of(startDate, endDate, frequency, BUSINESS_ADJ, StubConvention.NONE, RollConventions.NONE);
            IborRateCalculation rateCalculation = IborRateCalculation.of(index);

            if (putCall.Call)
            {
                return(IborCapFloorLeg.builder().calculation(rateCalculation).capSchedule(strikeSchedule).notional(notionalSchedule).paymentSchedule(paySchedule).payReceive(payRec).build());
            }
            return(IborCapFloorLeg.builder().calculation(rateCalculation).floorSchedule(strikeSchedule).notional(notionalSchedule).paymentSchedule(paySchedule).payReceive(payRec).build());
        }
示例#8
0
        //-------------------------------------------------------------------------
        public virtual void test_createTrade()
        {
            DatesCdsTemplate @base     = DatesCdsTemplate.of(START, END, CONV1);
            LocalDate        tradeDate = LocalDate.of(2015, 5, 5);
            CdsTrade         test      = @base.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, REF_DATA);
            Cds expected          = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, START, END, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d);
            PeriodicSchedule sch1 = expected.PaymentSchedule;

            expected = expected.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build();
            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
            assertEquals(test.UpfrontFee, null);
        }
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            BusinessDayAdjustment bda             = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule      accrualSchedule = PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(bda).build();
            PaymentSchedule       paymentSchedule = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            ValueSchedule         amountSchedule  = ValueSchedule.of(123d);
            KnownAmountSwapLeg    test            = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).amount(amountSchedule).currency(GBP).build();

            assertEquals(test.PayReceive, PAY);
            assertEquals(test.StartDate, AdjustableDate.of(DATE_01_05, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_04_05, bda));
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.Amount, amountSchedule);
            assertEquals(test.Currency, GBP);
            assertEquals(test.allCurrencies(), ImmutableSet.of(GBP));
        }
 static BondDataSets()
 {
     for (int i = 0; i < NB_BOND_USD; ++i)
     {
         LocalDate        endDate        = START_DATE_USD[i].plus(BOND_TENOR_USD[i]);
         PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE_USD[i], endDate, Frequency.P6M, BUSINESS_ADJUST_USD, StubConvention.SHORT_INITIAL, false);
         FixedCouponBond  product        = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID[i])).dayCount(DAY_COUNT_USD).fixedRate(RATE_USD[i]).legalEntityId(ISSUER_ID_USD).currency(USD).notional(NOTIONAL_USD).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS_USD).yieldConvention(YIELD_CONVENTION_USD).exCouponPeriod(EX_COUPON_USD).build();
         BOND_USD[i] = product;
     }
     for (int i = 0; i < NB_BOND_EUR; ++i)
     {
         LocalDate        endDate        = START_DATE_EUR[i].plus(BOND_TENOR_EUR[i]);
         PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE_EUR[i], endDate, Frequency.P12M, BUSINESS_ADJUST_EUR, StubConvention.SHORT_INITIAL, false);
         FixedCouponBond  product        = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID_EUR[i])).dayCount(DAY_COUNT_EUR).fixedRate(RATE_EUR[i]).legalEntityId(ISSUER_ID_EUR).currency(EUR).notional(NOTIONAL_EUR).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS_EUR).yieldConvention(YIELD_CONVENTION_EUR).exCouponPeriod(EX_COUPON_EUR).build();
         BOND_EUR[i] = product;
     }
 }
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            BusinessDayAdjustment  bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule       accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(bda).build();
            PaymentSchedule        paymentSchedule  = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            FixedRateCalculation   rateCalc         = FixedRateCalculation.builder().dayCount(DayCounts.ACT_365F).rate(ValueSchedule.of(0.025d)).build();
            NotionalSchedule       notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg test             = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_01_05, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_04_05, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, PAY);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);
        }
示例#12
0
        internal static Dsf sut2()
        {
            SwapLeg iborLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P1M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(USD).amount(ValueSchedule.of(1d)).finalExchange(true).initialExchange(true).build()).calculation(IborRateCalculation.builder().index(INDEX).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, SAT_SUN, BDA_P)).build()).build();
            Swap    swap2   = Swap.of(SWAP.getLeg(RECEIVE).get(), iborLeg);

            return(Dsf.builder().securityId(SECURITY_ID2).notional(20000L).deliveryDate(LocalDate.of(2014, 9, 5)).lastTradeDate(LocalDate.of(2014, 9, 2)).underlyingSwap(swap2).build());
        }
示例#13
0
        public virtual void test_builder_notUnitNotional()
        {
            SwapLeg fixedLeg10     = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, 10d)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build();
            SwapLeg knownAmountLeg = KnownAmountSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).amount(ValueSchedule.of(0.015)).currency(USD).build();
            SwapLeg iborLeg500     = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 9, 12)).frequency(P1M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(USD).amount(ValueSchedule.of(500d)).finalExchange(true).initialExchange(true).build()).calculation(IborRateCalculation.builder().index(INDEX).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, SAT_SUN, BDA_P)).build()).build();
            Swap    swap1          = Swap.of(fixedLeg10, SWAP.getLeg(PAY).get());
            Swap    swap2          = Swap.of(SWAP.getLeg(RECEIVE).get(), iborLeg500);
            Swap    swap3          = Swap.of(knownAmountLeg, SWAP.getLeg(PAY).get());

            assertThrowsIllegalArg(() => Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap1).build());
            assertThrowsIllegalArg(() => Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap2).build());
            // should succeed normally (no notional to validate on known amount leg)
            Dsf.builder().securityId(SECURITY_ID).notional(NOTIONAL).deliveryDate(DELIVERY_DATE).lastTradeDate(LAST_TRADE_DATE).underlyingSwap(swap3).build();
        }
        //-------------------------------------------------------------------------
        public virtual void test_toTrade()
        {
            LocalDate tradeDate          = LocalDate.of(2015, 12, 21); // 19, 20 weekend
            LocalDate startDate          = LocalDate.of(2015, 12, 20);
            LocalDate endDate            = LocalDate.of(2020, 12, 20);
            LocalDate settlementDate     = LocalDate.of(2015, 12, 24);
            TradeInfo info               = TradeInfo.builder().tradeDate(tradeDate).settlementDate(settlementDate).build();
            Tenor     tenor              = Tenor.TENOR_5Y;
            ImmutableCdsConvention @base = ImmutableCdsConvention.of(NAME, GBP, ACT_360, P3M, BUSI_ADJ_STD, SETTLE_DAY_ADJ_STD);
            Cds      product             = Cds.builder().legalEntityId(LEGAL_ENTITY).paymentSchedule(PeriodicSchedule.builder().startDate(startDate).endDate(endDate).frequency(P3M).businessDayAdjustment(BUSI_ADJ_STD).startDateBusinessDayAdjustment(BUSI_ADJ_STD).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).stubConvention(StubConvention.SMART_INITIAL).rollConvention(RollConventions.DAY_20).build()).buySell(BUY).currency(GBP).dayCount(ACT_360).notional(NOTIONAL).fixedRate(COUPON).paymentOnDefault(PaymentOnDefault.ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.BEGINNING).stepinDateOffset(STEPIN_DAY_ADJ).settlementDateOffset(SETTLE_DAY_ADJ_STD).build();
            CdsTrade expected            = CdsTrade.builder().info(info).product(product).build();
            CdsTrade test1               = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA);

            assertEquals(test1, expected);
            CdsTrade test2 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA);

            assertEquals(test2, expected);
            CdsTrade test3 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, REF_DATA);

            assertEquals(test3, expected);
            CdsTrade test4 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON);

            assertEquals(test4, expected);

            AdjustablePayment upfront        = AdjustablePayment.of(CurrencyAmount.of(GBP, 0.1 * NOTIONAL), settlementDate);
            CdsTrade          expectedWithUf = CdsTrade.builder().info(info).product(product).upfrontFee(upfront).build();
            CdsTrade          test5          = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA);

            assertEquals(test5, expectedWithUf);
            CdsTrade test6 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA);

            assertEquals(test6, expectedWithUf);
            CdsTrade test7 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, upfront, REF_DATA);

            assertEquals(test7, expectedWithUf);
            CdsTrade test8 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON, upfront);

            assertEquals(test8, expectedWithUf);
        }
        //-------------------------------------------------------------------------
        public virtual void test_collectIndices()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of());
            assertEquals(test.allIndices(), ImmutableSet.of());
        }
        public virtual void test_resolve_twoAccrualsPerPayment_iborRate_varyingNotional_notionalExchange()
        {
            // test case
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_06_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(PLUS_TWO_DAYS).compoundingMethod(STRAIGHT).build()).notionalSchedule(NotionalSchedule.builder().currency(GBP).amount(ValueSchedule.of(1000d, ValueStep.of(1, ValueAdjustment.ofReplace(1500d)))).initialExchange(true).intermediateExchange(true).finalExchange(true).build()).calculation(IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)).build()).build();
            // expected
            RatePaymentPeriod rpp1 = RatePaymentPeriod.builder().paymentDate(DATE_03_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_01_06).endDate(DATE_02_05).unadjustedStartDate(DATE_01_05).yearFraction(ACT_365F.yearFraction(DATE_01_06, DATE_02_05)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_01_02, REF_DATA)).build(), RateAccrualPeriod.builder().startDate(DATE_02_05).endDate(DATE_03_05).yearFraction(ACT_365F.yearFraction(DATE_02_05, DATE_03_05)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_02_03, REF_DATA)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).compoundingMethod(STRAIGHT).build();
            RatePaymentPeriod rpp2 = RatePaymentPeriod.builder().paymentDate(DATE_05_08).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_03_05).endDate(DATE_04_07).unadjustedEndDate(DATE_04_05).yearFraction(ACT_365F.yearFraction(DATE_03_05, DATE_04_07)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_03_03, REF_DATA)).build(), RateAccrualPeriod.builder().startDate(DATE_04_07).endDate(DATE_05_06).unadjustedStartDate(DATE_04_05).unadjustedEndDate(DATE_05_05).yearFraction(ACT_365F.yearFraction(DATE_04_07, DATE_05_06)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_04_03, REF_DATA)).build()).dayCount(ACT_365F).currency(GBP).notional(-1500d).compoundingMethod(STRAIGHT).build();
            RatePaymentPeriod rpp3 = RatePaymentPeriod.builder().paymentDate(DATE_06_09).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_05_06).endDate(DATE_06_05).unadjustedStartDate(DATE_05_05).yearFraction(ACT_365F.yearFraction(DATE_05_06, DATE_06_05)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_05_01, REF_DATA)).build()).dayCount(ACT_365F).currency(GBP).notional(-1500d).compoundingMethod(STRAIGHT).build();
            // events (only one intermediate exchange)
            NotionalExchange nexInitial      = NotionalExchange.of(CurrencyAmount.of(GBP, 1000d), DATE_01_06);
            NotionalExchange nexIntermediate = NotionalExchange.of(CurrencyAmount.of(GBP, 500d), DATE_03_07);
            NotionalExchange nexFinal        = NotionalExchange.of(CurrencyAmount.of(GBP, -1500d), DATE_06_09);

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(IBOR).payReceive(PAY).paymentPeriods(rpp1, rpp2, rpp3).paymentEvents(nexInitial, nexIntermediate, nexFinal).build());
        }
        public virtual void test_serialization()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            assertSerialization(test);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.of(GBP, 1000d)).calculation(FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build()).build();

            coverImmutableBean(test);
            RateCalculationSwapLeg test2 = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_02_05).endDate(DATE_03_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_THREE_DAYS).build()).notionalSchedule(NotionalSchedule.of(GBP, 2000d)).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.025d)).build()).build();

            coverBeanEquals(test, test2);
        }
        public virtual void test_collectIndices_fxReset()
        {
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.builder().currency(GBP).amount(ValueSchedule.of(1000d)).finalExchange(true).fxReset(FxResetCalculation.builder().referenceCurrency(EUR).index(EUR_GBP_ECB).fixingDateOffset(MINUS_TWO_DAYS).build()).build()).calculation(IborRateCalculation.builder().dayCount(DayCounts.ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).build()).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M, EUR_GBP_ECB));
            assertEquals(test.allIndices(), ImmutableSet.of(GBP_LIBOR_3M, EUR_GBP_ECB));
            assertEquals(test.allCurrencies(), ImmutableSet.of(GBP, EUR));
        }
        //-------------------------------------------------------------------------
        public virtual void test_resolve_oneAccrualPerPayment_fxReset()
        {
            // test case
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.builder().currency(GBP).amount(ValueSchedule.of(1000d)).fxReset(FxResetCalculation.builder().referenceCurrency(EUR).index(EUR_GBP_ECB).fixingDateOffset(MINUS_TWO_DAYS).build()).initialExchange(true).intermediateExchange(true).finalExchange(true).build()).calculation(FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build()).build();
            // expected
            RatePaymentPeriod       rpp1 = RatePaymentPeriod.builder().paymentDate(DATE_02_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_01_06).endDate(DATE_02_05).unadjustedStartDate(DATE_01_05).yearFraction(ACT_365F.yearFraction(DATE_01_06, DATE_02_05)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).fxReset(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_01_02, REF_DATA), EUR)).build();
            RatePaymentPeriod       rpp2 = RatePaymentPeriod.builder().paymentDate(DATE_03_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_02_05).endDate(DATE_03_05).yearFraction(ACT_365F.yearFraction(DATE_02_05, DATE_03_05)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).fxReset(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_02_03, REF_DATA), EUR)).build();
            RatePaymentPeriod       rpp3 = RatePaymentPeriod.builder().paymentDate(DATE_04_09).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_03_05).endDate(DATE_04_07).unadjustedEndDate(DATE_04_05).yearFraction(ACT_365F.yearFraction(DATE_03_05, DATE_04_07)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).fxReset(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_03_03, REF_DATA), EUR)).build();
            FxResetNotionalExchange ne1a = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, 1000d), DATE_01_06, FxIndexObservation.of(EUR_GBP_ECB, DATE_01_02, REF_DATA));
            FxResetNotionalExchange ne1b = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, -1000d), DATE_02_07, FxIndexObservation.of(EUR_GBP_ECB, DATE_01_02, REF_DATA));
            FxResetNotionalExchange ne2a = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, 1000d), DATE_02_07, FxIndexObservation.of(EUR_GBP_ECB, DATE_02_03, REF_DATA));
            FxResetNotionalExchange ne2b = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, -1000d), DATE_03_07, FxIndexObservation.of(EUR_GBP_ECB, DATE_02_03, REF_DATA));
            FxResetNotionalExchange ne3a = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, 1000d), DATE_03_07, FxIndexObservation.of(EUR_GBP_ECB, DATE_03_03, REF_DATA));
            FxResetNotionalExchange ne3b = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, -1000d), DATE_04_09, FxIndexObservation.of(EUR_GBP_ECB, DATE_03_03, REF_DATA));

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(rpp1, rpp2, rpp3).paymentEvents(ne1a, ne1b, ne2a, ne2b, ne3a, ne3b).build());
        }
        public virtual void test_resolve_threeAccrualsPerPayment()
        {
            // test case
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(PLUS_TWO_DAYS).compoundingMethod(STRAIGHT).build()).notionalSchedule(NotionalSchedule.of(GBP, 1000d)).calculation(FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build()).build();
            // expected
            RatePaymentPeriod rpp1 = RatePaymentPeriod.builder().paymentDate(DATE_04_09).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_01_06).endDate(DATE_02_05).unadjustedStartDate(DATE_01_05).yearFraction(ACT_365F.yearFraction(DATE_01_06, DATE_02_05)).rateComputation(FixedRateComputation.of(0.025d)).build(), RateAccrualPeriod.builder().startDate(DATE_02_05).endDate(DATE_03_05).yearFraction(ACT_365F.yearFraction(DATE_02_05, DATE_03_05)).rateComputation(FixedRateComputation.of(0.025d)).build(), RateAccrualPeriod.builder().startDate(DATE_03_05).endDate(DATE_04_07).unadjustedEndDate(DATE_04_05).yearFraction(ACT_365F.yearFraction(DATE_03_05, DATE_04_07)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).compoundingMethod(STRAIGHT).build();

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(rpp1).build());
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            coverImmutableBean(test);
            KnownAmountSwapLeg test2 = KnownAmountSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_02_05).endDate(DATE_03_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_THREE_DAYS).build()).amount(ValueSchedule.of(2000d)).currency(EUR).build();

            coverBeanEquals(test, test2);
        }
示例#23
0
        //-------------------------------------------------------------------------
        public virtual void test_toLeg()
        {
            FixedRateSwapLegConvention @base = FixedRateSwapLegConvention.of(GBP, ACT_365F, P3M, BDA_MOD_FOLLOW);
            LocalDate startDate             = LocalDate.of(2015, 5, 5);
            LocalDate endDate               = LocalDate.of(2020, 5, 5);
            RateCalculationSwapLeg test     = @base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d);
            RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(P3M).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).stubConvention(StubConvention.SMART_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(FixedRateCalculation.of(0.25d, ACT_365F)).build();

            assertEquals(test, expected);
        }
 // fixed rate leg
 private static SwapLeg fixedLeg(LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention)
 {
     return(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(PeriodicSchedule.builder().startDate(start).endDate(end).frequency(frequency).businessDayAdjustment(BDA_MF).stubConvention(stubConvention).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(frequency).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(fixedRate)).build()).build());
 }
        public virtual void test_toLeg_withSpread()
        {
            IborRateSwapLegConvention @base = IborRateSwapLegConvention.builder().index(GBP_LIBOR_3M).build();
            LocalDate startDate             = LocalDate.of(2015, 5, 5);
            LocalDate endDate               = LocalDate.of(2020, 5, 5);
            RateCalculationSwapLeg test     = @base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d);
            RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(P3M).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(IborRateCalculation.builder().index(GBP_LIBOR_3M).spread(ValueSchedule.of(0.25d)).build()).build();

            assertEquals(test, expected);
        }
        // fixed rate leg
        private static SwapLeg iborLeg(LocalDate start, LocalDate end, IborIndex index, PayReceive payReceive, NotionalSchedule notional, StubConvention stubConvention)
        {
            Frequency freq = Frequency.of(index.Tenor.Period);

            return(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(PeriodicSchedule.builder().startDate(start).endDate(end).frequency(freq).businessDayAdjustment(BDA_MF).stubConvention(stubConvention).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(freq).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(index).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, index.FixingCalendar, BDA_P)).build()).build());
        }
        public virtual void test_serialization()
        {
            RateCalculationSwapLeg test = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.of(GBP, 1000d)).calculation(FixedRateCalculation.builder().dayCount(DayCounts.ACT_365F).rate(ValueSchedule.of(0.025d)).build()).build();

            assertSerialization(test);
        }
        public virtual void test_resolve_knownAmountStub()
        {
            // test case
            CurrencyAmount         knownAmount = CurrencyAmount.of(GBP, 150d);
            RateCalculationSwapLeg test        = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_02_03).endDate(DATE_04_03).firstRegularStartDate(DATE_02_05).lastRegularEndDate(DATE_03_05).frequency(P1M).stubConvention(StubConvention.BOTH).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.of(GBP, 1000d)).calculation(FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).initialStub(FixedRateStubCalculation.ofKnownAmount(knownAmount)).finalStub(FixedRateStubCalculation.ofFixedRate(0.1d)).build()).build();
            // expected
            KnownAmountNotionalSwapPaymentPeriod pp1 = KnownAmountNotionalSwapPaymentPeriod.builder().payment(Payment.of(knownAmount, DATE_02_07)).startDate(DATE_02_03).endDate(DATE_02_05).unadjustedStartDate(DATE_02_03).notionalAmount(CurrencyAmount.of(GBP, -1000d)).build();
            RatePaymentPeriod rpp2 = RatePaymentPeriod.builder().paymentDate(DATE_03_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_02_05).endDate(DATE_03_05).yearFraction(ACT_365F.yearFraction(DATE_02_05, DATE_03_05)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).build();
            RatePaymentPeriod rpp3 = RatePaymentPeriod.builder().paymentDate(DATE_04_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_03_05).endDate(DATE_04_03).unadjustedEndDate(DATE_04_03).yearFraction(ACT_365F.yearFraction(DATE_03_05, DATE_04_03)).rateComputation(FixedRateComputation.of(0.1d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).build();

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(pp1, rpp2, rpp3).build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_toLeg()
        {
            InflationRateSwapLegConvention @base = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
            LocalDate startDate         = LocalDate.of(2015, 5, 5);
            LocalDate endDate           = LocalDate.of(2020, 5, 5);
            RateCalculationSwapLeg test = @base.toLeg(startDate, endDate, PAY, NOTIONAL_2M);

            RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(Frequency.TERM).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(InflationRateCalculation.of(GB_HICP, 3, MONTHLY)).build();

            assertEquals(test, expected);
        }
        public virtual void test_createCap()
        {
            SabrIborCapletFloorletVolatilityBootstrapDefinition @base = SabrIborCapletFloorletVolatilityBootstrapDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, 0.5, STEP_UPPER, FLAT, FLAT, SabrVolatilityFormula.hagan());
            LocalDate       startDate = LocalDate.of(2012, 4, 20);
            LocalDate       endDate   = LocalDate.of(2017, 4, 20);
            double          strike    = 0.01;
            IborCapFloorLeg expected  = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(USD_LIBOR_3M)).capSchedule(ValueSchedule.of(strike)).currency(USD_LIBOR_3M.Currency).notional(ValueSchedule.ALWAYS_1).paymentDateOffset(DaysAdjustment.NONE).paymentSchedule(PeriodicSchedule.of(startDate, endDate, Frequency.of(USD_LIBOR_3M.Tenor.Period), BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.FixingCalendar), StubConvention.NONE, RollConventions.NONE)).payReceive(PayReceive.RECEIVE).build();
            IborCapFloorLeg computed  = @base.createCap(startDate, endDate, strike);

            assertEquals(computed, expected);
        }