public virtual void test_resolve_beforeStart_threeDays()
        {
            FxResetCalculation @base = FxResetCalculation.builder().index(EUR_GBP_ECB).referenceCurrency(GBP).fixingDateOffset(MINUS_THREE_DAYS).build();
            Optional <FxReset> test  = @base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30));

            assertEquals(test, FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, date(2014, 3, 26), REF_DATA), GBP));
        }
        public virtual void test_resolve_beforeEnd_weekend()
        {
            FxResetCalculation @base = FxResetCalculation.builder().index(EUR_GBP_ECB).referenceCurrency(GBP).fixingDateOffset(MINUS_TWO_DAYS).fixingRelativeTo(FxResetFixingRelativeTo.PERIOD_END).build();
            Optional <FxReset> test  = @base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30));

            assertEquals(test, FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, date(2014, 6, 26), REF_DATA), GBP));
        }
Exemple #3
0
        public virtual void test_createSchedule_finalStubFullMerge()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_FINAL_STUB, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_03_05, DATE_01_05, DATE_03_05), ACCRUAL3STUB).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Exemple #4
0
        public virtual void test_createSchedule_firstDate_validInitialStub()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).firstRegularStartDate(DATE_02_05).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_02_05, DATE_01_05, DATE_02_05), SchedulePeriod.of(DATE_02_05, DATE_04_07, DATE_02_05, DATE_04_05)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Exemple #5
0
        public virtual void test_createSchedule_lastDate_finalAccrualStub()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).lastRegularEndDate(DATE_03_05).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_FINAL_STUB_4PERIODS, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_03_05, DATE_01_05, DATE_03_05), SchedulePeriod.of(DATE_03_05, DATE_04_30, DATE_03_05, DATE_04_30)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Exemple #6
0
        public virtual void test_createSchedule_initialStubPartMergeBackwards()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_INITIAL_STUB, REF_DATA);
            Schedule        expected = Schedule.builder().periods(ACCRUAL1STUB, SchedulePeriod.of(DATE_02_05, DATE_03_05, DATE_02_05, DATE_03_05), SchedulePeriod.of(DATE_03_05, DATE_05_06, DATE_03_05, DATE_05_05)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void selectDate()
        {
            LocalDate      date1  = date(2014, 3, 27);
            LocalDate      date2  = date(2014, 6, 27);
            SchedulePeriod period = SchedulePeriod.of(date1, date2);

            assertEquals(FixingRelativeTo.PERIOD_START.selectBaseDate(period), date1);
            assertEquals(FixingRelativeTo.PERIOD_END.selectBaseDate(period), date2);
        }
Exemple #8
0
        public virtual void test_collectIndices_fxReset()
        {
            SchedulePeriod sched = SchedulePeriod.of(DATE_2014_03_30, DATE_2014_09_30);
            KnownAmountNotionalSwapPaymentPeriod test = KnownAmountNotionalSwapPaymentPeriod.of(PAYMENT_2014_10_03, sched, USD_P50000, FX_RESET);

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of(FX_RESET.Index));
        }
        //-------------------------------------------------------------------------
        public virtual void test_resolve()
        {
            ResetSchedule  test          = ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build();
            SchedulePeriod accrualPeriod = SchedulePeriod.of(DATE_01_06, DATE_04_07, DATE_01_05, DATE_04_05);
            Schedule       schedule      = test.createSchedule(DAY_5, REF_DATA).apply(accrualPeriod);
            Schedule       expected      = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_02_05, DATE_01_05, DATE_02_05), SchedulePeriod.of(DATE_02_05, DATE_03_05, DATE_02_05, DATE_03_05), SchedulePeriod.of(DATE_03_05, DATE_04_07, DATE_03_05, DATE_04_05)).frequency(P1M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
        public virtual void test_resolve_initial_notional_override()
        {
            FxResetCalculation @base = FxResetCalculation.builder().index(EUR_GBP_ECB).referenceCurrency(GBP).fixingDateOffset(MINUS_TWO_DAYS).initialNotionalValue(100000d).build();
            Optional <FxReset> fxResetFirstPeriod = @base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30));

            assertFalse(fxResetFirstPeriod.Present);

            Optional <FxReset> fxResetSecondPeriod = @base.resolve(REF_DATA).apply(1, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30));

            assertTrue(fxResetSecondPeriod.Present);
        }
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            SchedulePeriod sched = SchedulePeriod.of(DATE_2014_03_30, DATE_2014_09_30);
            KnownAmountSwapPaymentPeriod test = KnownAmountSwapPaymentPeriod.of(PAYMENT_2014_10_03, sched);

            assertEquals(test.Payment, PAYMENT_2014_10_03);
            assertEquals(test.StartDate, DATE_2014_03_30);
            assertEquals(test.UnadjustedStartDate, DATE_2014_03_30);
            assertEquals(test.EndDate, DATE_2014_09_30);
            assertEquals(test.UnadjustedEndDate, DATE_2014_09_30);
            assertEquals(test.PaymentDate, DATE_2014_10_03);
            assertEquals(test.Currency, GBP);
        }
        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_schedulePeriod()
        {
            SchedulePeriod    schedulePeriod = SchedulePeriod.of(DATE_2014_03_31, DATE_2014_07_01, DATE_2014_03_30, DATE_2014_06_30);
            RateAccrualPeriod test           = RateAccrualPeriod.builder(schedulePeriod).yearFraction(0.25d).rateComputation(GBP_LIBOR_3M_2014_03_28).build();

            assertEquals(test.StartDate, DATE_2014_03_31);
            assertEquals(test.EndDate, DATE_2014_07_01);
            assertEquals(test.UnadjustedStartDate, DATE_2014_03_30);
            assertEquals(test.UnadjustedEndDate, DATE_2014_06_30);
            assertEquals(test.YearFraction, 0.25d, 0d);
            assertEquals(test.RateComputation, GBP_LIBOR_3M_2014_03_28);
            assertEquals(test.Gearing, 1d, 0d);
            assertEquals(test.Spread, 0d, 0d);
            assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE);
        }
Exemple #14
0
        public virtual void test_of_fxReset()
        {
            SchedulePeriod sched = SchedulePeriod.of(DATE_2014_03_30, DATE_2014_09_30);
            KnownAmountNotionalSwapPaymentPeriod test = KnownAmountNotionalSwapPaymentPeriod.of(PAYMENT_2014_10_03, sched, USD_P50000, FX_RESET);

            assertEquals(test.Payment, PAYMENT_2014_10_03);
            assertEquals(test.StartDate, DATE_2014_03_30);
            assertEquals(test.UnadjustedStartDate, DATE_2014_03_30);
            assertEquals(test.EndDate, DATE_2014_09_30);
            assertEquals(test.UnadjustedEndDate, DATE_2014_09_30);
            assertEquals(test.PaymentDate, DATE_2014_10_03);
            assertEquals(test.Currency, GBP);
            assertEquals(test.NotionalAmount, USD_P50000);
            assertEquals(test.FxResetObservation, FX_RESET);
        }
        public virtual void test_expand_initialStubAndResetPeriods_weighted_firstFixed()
        {
            IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_360).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstRegularRate(0.028d).initialStub(IborRateStubCalculation.ofFixedRate(0.030d)).build();

            SchedulePeriod accrual1 = SchedulePeriod.of(DATE_02_05, DATE_04_07, DATE_02_05, DATE_04_05);
            SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05);
            Schedule       schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build();

            RateAccrualPeriod    rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_360, schedule)).rateComputation(FixedRateComputation.of(0.030d)).build();
            IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA);
            IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA);
            IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06, 0.028d), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07));
            RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_360, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2));
        }
Exemple #16
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);
        }
        public virtual void test_expand_resetPeriods_weighted_firstFixingDateOffset()
        {
            // only the fixing date of the first reset period is changed, everything else stays the same
            IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstFixingDateOffset(MINUS_ONE_DAY).build();

            SchedulePeriod accrual1 = SchedulePeriod.of(DATE_01_06, DATE_04_07, DATE_01_05, DATE_04_05);
            SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05);
            Schedule       schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build();

            IborIndexObservation obs1 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_01_03, REF_DATA);
            IborIndexObservation obs2 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_02_03, REF_DATA);
            IborIndexObservation obs3 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_03_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings1 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs1, DATE_01_06, DATE_02_05), IborAveragedFixing.ofDaysInResetPeriod(obs2, DATE_02_05, DATE_03_05), IborAveragedFixing.ofDaysInResetPeriod(obs3, DATE_03_05, DATE_04_07));
            RateAccrualPeriod rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings1)).build();

            IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA);
            IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA);
            IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07));
            RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2));
        }