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);
        }
        //-------------------------------------------------------------------------
        public virtual void test_resolve()
        {
            RatePeriodSwapLeg test     = RatePeriodSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();
            ResolvedSwapLeg   expected = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();

            assertEquals(test.resolve(REF_DATA), expected);
        }
        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);
        }
        public virtual void test_resolve_createNotionalExchange_finalOnly()
        {
            RatePeriodSwapLeg test     = RatePeriodSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).initialExchange(false).intermediateExchange(false).finalExchange(true).build();
            ResolvedSwapLeg   expected = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NotionalExchange.of(CurrencyAmount.of(GBP, 5000d), DATE_2014_10_01)).build();

            assertEquals(test.resolve(REF_DATA), expected);
        }
Exemple #5
0
        public virtual void test_collectIndices()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M));
        }
Exemple #6
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();

            coverImmutableBean(test);
            ResolvedSwapLeg test2 = ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(RPP2).build();

            coverBeanEquals(test, test2);
        }
        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 test_resolve_FxResetOmitInitialNotionalExchange()
        {
            RatePeriodSwapLeg test = RatePeriodSwapLeg.builder().type(IBOR).payReceive(PAY).paymentPeriods(RPP1_FXRESET).initialExchange(false).intermediateExchange(true).finalExchange(true).build();

            FxResetNotionalExchange finalExchange = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 8000d), DATE_2014_10_01, FxIndexObservation.of(GBP_USD_WM, DATE_2014_06_28, REF_DATA));

            ResolvedSwapLeg expected = ResolvedSwapLeg.builder().type(IBOR).payReceive(PAY).paymentPeriods(RPP1_FXRESET).paymentEvents(finalExchange).build();

            assertEquals(test.resolve(REF_DATA), expected);
        }
Exemple #9
0
        public virtual void test_resolve_unadjustedAccrualAdjustedPayment()
        {
            Swap test                  = Swap.builder().legs(RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(date(2016, 1, 3)).endDate(date(2016, 5, 3)).frequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, SAT_SUN)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)).calculation(FixedRateCalculation.of(RATE, ACT_360)).build()).build();
            RatePaymentPeriod pp1      = RatePaymentPeriod.builder().paymentDate(date(2016, 2, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 1, 3)).unadjustedStartDate(date(2016, 1, 3)).endDate(date(2016, 2, 3)).unadjustedEndDate(date(2016, 2, 3)).yearFraction(ACT_360.yearFraction(date(2016, 1, 3), date(2016, 2, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp2      = RatePaymentPeriod.builder().paymentDate(date(2016, 3, 7)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 2, 3)).unadjustedStartDate(date(2016, 2, 3)).endDate(date(2016, 3, 3)).unadjustedEndDate(date(2016, 3, 3)).yearFraction(ACT_360.yearFraction(date(2016, 2, 3), date(2016, 3, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp3      = RatePaymentPeriod.builder().paymentDate(date(2016, 4, 6)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 3, 3)).unadjustedStartDate(date(2016, 3, 3)).endDate(date(2016, 4, 3)).unadjustedEndDate(date(2016, 4, 3)).yearFraction(ACT_360.yearFraction(date(2016, 3, 3), date(2016, 4, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp4      = RatePaymentPeriod.builder().paymentDate(date(2016, 5, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 4, 3)).unadjustedStartDate(date(2016, 4, 3)).endDate(date(2016, 5, 3)).unadjustedEndDate(date(2016, 5, 3)).yearFraction(ACT_360.yearFraction(date(2016, 4, 3), date(2016, 5, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            ResolvedSwap      expected = ResolvedSwap.builder().legs(ResolvedSwapLeg.builder().paymentPeriods(pp1, pp2, pp3, pp4).payReceive(RECEIVE).type(FIXED).build()).build();

            assertEqualsBean(test.resolve(REF_DATA), expected);
        }
        public virtual void test_resolve_fxResetNotionalExchange()
        {
            RatePeriodSwapLeg       test     = RatePeriodSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1_FXRESET, RPP2).initialExchange(true).intermediateExchange(true).finalExchange(true).build();
            FxResetNotionalExchange ne1a     = FxResetNotionalExchange.of(CurrencyAmount.of(USD, -8000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_06_28, REF_DATA));
            FxResetNotionalExchange ne1b     = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 8000d), DATE_2014_10_01, FxIndexObservation.of(GBP_USD_WM, DATE_2014_06_28, REF_DATA));
            NotionalExchange        ne2a     = NotionalExchange.of(CurrencyAmount.of(GBP, -6000d), DATE_2014_10_01);
            NotionalExchange        ne2b     = NotionalExchange.of(CurrencyAmount.of(GBP, 6000d), DATE_2014_01_02);
            ResolvedSwapLeg         expected = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1_FXRESET, RPP2).paymentEvents(ne1a, ne1b, ne2a, ne2b).build();

            assertEquals(test.resolve(REF_DATA), expected);
        }
Exemple #11
0
        //-------------------------------------------------------------------------
        public virtual void test_findPaymentPeriod()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1, RPP2).build();

            assertEquals(test.findPaymentPeriod(RPP1.StartDate), null);
            assertEquals(test.findPaymentPeriod(RPP1.StartDate.plusDays(1)), RPP1);
            assertEquals(test.findPaymentPeriod(RPP1.EndDate), RPP1);
            assertEquals(test.findPaymentPeriod(RPP2.StartDate), RPP1);
            assertEquals(test.findPaymentPeriod(RPP2.StartDate.plusDays(1)), RPP2);
            assertEquals(test.findPaymentPeriod(RPP2.EndDate), RPP2);
            assertEquals(test.findPaymentPeriod(RPP2.EndDate.plusDays(1)), null);
        }
Exemple #12
0
        public virtual void test_builder()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();

            assertEquals(test.Type, IBOR);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.StartDate, DATE_2014_06_30);
            assertEquals(test.EndDate, DATE_2014_09_30);
            assertEquals(test.Currency, GBP);
            assertEquals(test.PaymentPeriods, ImmutableList.of(RPP1));
            assertEquals(test.PaymentEvents, ImmutableList.of(NOTIONAL_EXCHANGE));
        }
        //-------------------------------------------------------------------------
        public virtual void test_resolve()
        {
            // test case
            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.builder().initialValue(123d).steps(ValueStep.of(1, ValueAdjustment.ofReplace(234d))).build()).currency(GBP).build();
            // expected
            KnownAmountSwapPaymentPeriod rpp1 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 123d), DATE_02_07)).startDate(DATE_01_06).endDate(DATE_02_05).unadjustedStartDate(DATE_01_05).build();
            KnownAmountSwapPaymentPeriod rpp2 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 234d), DATE_03_07)).startDate(DATE_02_05).endDate(DATE_03_05).build();
            KnownAmountSwapPaymentPeriod rpp3 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 234d), DATE_04_09)).startDate(DATE_03_05).endDate(DATE_04_07).unadjustedEndDate(DATE_04_05).build();

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(rpp1, rpp2, rpp3).build());
        }
        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 ResolvedSwap resolve(ReferenceData refData)
 {
     // avoid streams as profiling showed a hotspot
     // most efficient to loop around legs once
     ImmutableList.Builder <ResolvedSwapLeg> resolvedLegs = ImmutableList.builder();
     ImmutableSet.Builder <Currency>         currencies   = ImmutableSet.builder();
     ImmutableSet.Builder <Index>            indices      = ImmutableSet.builder();
     foreach (SwapLeg leg in legs)
     {
         ResolvedSwapLeg resolvedLeg = leg.resolve(refData);
         resolvedLegs.add(resolvedLeg);
         currencies.add(resolvedLeg.Currency);
         leg.collectIndices(indices);
     }
     return(new ResolvedSwap(resolvedLegs.build(), currencies.build(), indices.build()));
 }
        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());
        }
Exemple #17
0
        public virtual void test_findNotional()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1, RPP2).build();

            // Date is before the start date
            assertEquals(test.findNotional(RPP1.StartDate.minusMonths(1)), RPP1.NotionalAmount);
            // Date is on the start date
            assertEquals(test.findNotional(RPP1.StartDate), RPP1.NotionalAmount);
            // Date is after the start date
            assertEquals(test.findNotional(RPP1.StartDate.plusDays(1)), RPP1.NotionalAmount);
            // Date is before the end date
            assertEquals(test.findNotional(RPP2.EndDate.minusDays(1)), RPP2.NotionalAmount);
            // Date is on the end date
            assertEquals(test.findNotional(RPP2.EndDate), RPP2.NotionalAmount);
            // Date is after the end date
            assertEquals(test.findNotional(RPP2.EndDate.plusMonths(1)), RPP2.NotionalAmount);
        }
        //-------------------------------------------------------------------------
        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());
        }
Exemple #19
0
        public virtual void test_findNotionalKnownAmount()
        {
            Payment        payment        = Payment.of(GBP, 1000, LocalDate.of(2011, 3, 8));
            SchedulePeriod schedulePeriod = SchedulePeriod.of(LocalDate.of(2010, 3, 8), LocalDate.of(2011, 3, 8));
            KnownAmountSwapPaymentPeriod paymentPeriod = KnownAmountSwapPaymentPeriod.of(payment, schedulePeriod);
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(paymentPeriod).build();

            // Date is before the start date
            assertEquals(test.findNotional(RPP1.StartDate.minusMonths(1)), null);
            // Date is on the start date
            assertEquals(test.findNotional(RPP1.StartDate), null);
            // Date is after the start date
            assertEquals(test.findNotional(RPP1.StartDate.plusDays(1)), null);
            // Date is before the end date
            assertEquals(test.findNotional(RPP2.EndDate.minusDays(1)), null);
            // Date is on the end date
            assertEquals(test.findNotional(RPP2.EndDate), null);
            // Date is after the end date
            assertEquals(test.findNotional(RPP2.EndDate.plusMonths(1)), null);
        }
Exemple #20
0
 public virtual void test_builder_invalidMixedCurrency()
 {
     assertThrowsIllegalArg(() => ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP3).paymentEvents(NOTIONAL_EXCHANGE).build());
 }
Exemple #21
0
        public virtual void test_serialization()
        {
            ResolvedSwapLeg test = ResolvedSwapLeg.builder().type(IBOR).payReceive(RECEIVE).paymentPeriods(RPP1).paymentEvents(NOTIONAL_EXCHANGE).build();

            assertSerialization(test);
        }