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_collectIndices()
        {
            FixedRateCalculation test = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of());
        }
        public virtual void test_builder()
        {
            FixedRateCalculation test = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).initialStub(FixedRateStubCalculation.ofFixedRate(0.1d)).finalStub(FixedRateStubCalculation.ofFixedRate(0.2d)).build();

            assertEquals(test.Rate, ValueSchedule.of(0.025d));
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.InitialStub, FixedRateStubCalculation.ofFixedRate(0.1d));
            assertEquals(test.FinalStub, FixedRateStubCalculation.ofFixedRate(0.2d));
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FixedRateCalculation test = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build();

            coverImmutableBean(test);
            FixedRateCalculation test2 = FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.030d)).build();

            coverBeanEquals(test, test2);
        }
        public virtual void test_expand_distinctValues()
        {
            FixedRateCalculation test                 = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d, ValueStep.of(1, ValueAdjustment.ofReplace(0.020d)), ValueStep.of(2, ValueAdjustment.ofReplace(0.015d)))).build();
            SchedulePeriod       period1              = SchedulePeriod.of(date(2014, 1, 6), date(2014, 2, 5), date(2014, 1, 5), date(2014, 2, 5));
            SchedulePeriod       period2              = SchedulePeriod.of(date(2014, 1, 5), date(2014, 2, 5), date(2014, 2, 5), date(2014, 3, 5));
            SchedulePeriod       period3              = SchedulePeriod.of(date(2014, 3, 5), date(2014, 4, 7), date(2014, 3, 5), date(2014, 4, 5));
            Schedule             schedule             = Schedule.builder().periods(period1, period2, period3).frequency(Frequency.P1M).rollConvention(RollConventions.DAY_5).build();
            RateAccrualPeriod    rap1                 = RateAccrualPeriod.builder(period1).yearFraction(period1.yearFraction(ACT_365F, schedule)).rateComputation(FixedRateComputation.of(0.025d)).build();
            RateAccrualPeriod    rap2                 = RateAccrualPeriod.builder(period2).yearFraction(period2.yearFraction(ACT_365F, schedule)).rateComputation(FixedRateComputation.of(0.020d)).build();
            RateAccrualPeriod    rap3                 = RateAccrualPeriod.builder(period3).yearFraction(period3.yearFraction(ACT_365F, schedule)).rateComputation(FixedRateComputation.of(0.015d)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
        //-------------------------------------------------------------------------
        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);
        }
Ejemplo n.º 7
0
        public virtual void test_summarize_irs_weird()
        {
            PeriodicSchedule       accrual  = PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false);
            PaymentSchedule        payment  = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build();
            NotionalSchedule       notional = NotionalSchedule.of(GBP, ValueSchedule.builder().initialValue(1_000_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-50_000))).build());
            RateCalculationSwapLeg payLeg   = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.builder().initialValue(0.0012).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(0.0001))).build()).build()).build();
            RateCalculationSwapLeg recLeg   = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.GBP_LIBOR_3M).gearing(ValueSchedule.of(1.1)).spread(ValueSchedule.of(0.002)).build()).build();
            Swap test = Swap.of(payLeg, recLeg);

            assertEquals(test.summaryDescription(), "2Y GBP 1mm variable Rec GBP-LIBOR-3M * 1.1 + 0.2% / Pay 0.12% variable : 12Feb18-12Feb20");
        }
        public virtual void test_serialization()
        {
            FixedRateCalculation test = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).build();

            assertSerialization(test);
        }
Ejemplo n.º 9
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains a rate calculation for the specified day count and rate.
 /// <para>
 /// The rate specified here does not vary during the life of the swap.
 /// If this method provides insufficient control, use the <seealso cref="#builder() builder"/>.
 ///
 /// </para>
 /// </summary>
 /// <param name="rate">  the rate </param>
 /// <param name="dayCount">  the day count </param>
 /// <returns> the calculation </returns>
 public static FixedRateCalculation of(double rate, DayCount dayCount)
 {
     return(FixedRateCalculation.builder().dayCount(dayCount).rate(ValueSchedule.of(rate)).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 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_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 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());
        }