Пример #1
0
        // create notional exchange events when no FxReset
        private static ImmutableList <SwapPaymentEvent> createStandardEvents(IList <NotionalPaymentPeriod> payPeriods, LocalDate initialExchangePaymentDate, bool initialExchange, bool intermediateExchange, bool finalExchange)
        {
            NotionalPaymentPeriod firstPeriod = payPeriods[0];

            ImmutableList.Builder <SwapPaymentEvent> events = ImmutableList.builder();
            if (initialExchange)
            {
                events.add(NotionalExchange.of(firstPeriod.NotionalAmount.negated(), initialExchangePaymentDate));
            }
            if (intermediateExchange)
            {
                for (int i = 0; i < payPeriods.Count - 1; i++)
                {
                    NotionalPaymentPeriod period1 = payPeriods[i];
                    NotionalPaymentPeriod period2 = payPeriods[i + 1];
                    if (period1.NotionalAmount.Amount != period2.NotionalAmount.Amount)
                    {
                        events.add(NotionalExchange.of(period1.NotionalAmount.minus(period2.NotionalAmount), period1.PaymentDate));
                    }
                }
            }
            if (finalExchange)
            {
                NotionalPaymentPeriod lastPeriod = payPeriods[payPeriods.Count - 1];
                events.add(NotionalExchange.of(lastPeriod.NotionalAmount, lastPeriod.PaymentDate));
            }
            return(events.build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            NotionalExchange test     = NotionalExchange.of(GBP_1000, DATE_2014_06_30);
            NotionalExchange expected = NotionalExchange.of(GBP_1000, DATE_2014_06_30.plusDays(2));

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            NotionalExchange test = NotionalExchange.of(GBP_1000, DATE_2014_06_30);

            coverImmutableBean(test);
            NotionalExchange test2 = NotionalExchange.of(CurrencyAmount.of(GBP, 200d), date(2014, 1, 15));

            coverBeanEquals(test, test2);
        }
        public virtual void test_of_Payment()
        {
            NotionalExchange test = NotionalExchange.of(Payment.of(GBP_1000, DATE_2014_06_30));

            assertEquals(test.Payment, Payment.of(GBP_1000, DATE_2014_06_30));
            assertEquals(test.PaymentDate, DATE_2014_06_30);
            assertEquals(test.PaymentAmount, GBP_1000);
            assertEquals(test.Currency, GBP);
        }
        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);
        }
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         NotionalExchange other = (NotionalExchange)obj;
         return(JodaBeanUtils.equal(payment, other.payment));
     }
     return(false);
 }
        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());
        }
Пример #8
0
        // create notional exchange events when FxReset specified
        private static ImmutableList <SwapPaymentEvent> createFxResetEvents(IList <NotionalPaymentPeriod> payPeriods, LocalDate initialExchangeDate, bool initialExchange, bool intermediateExchange, bool finalExchange)
        {
            ImmutableList.Builder <SwapPaymentEvent> events = ImmutableList.builder();
            for (int i = 0; i < payPeriods.Count; i++)
            {
                NotionalPaymentPeriod period           = payPeriods[i];
                LocalDate             startPaymentDate = (i == 0 ? initialExchangeDate : payPeriods[i - 1].PaymentDate);

                bool includeStartPayment = i == 0 ? initialExchange : intermediateExchange;
                bool includeEndPayment   = i == payPeriods.Count - 1 ? finalExchange : intermediateExchange;

                if (period.FxResetObservation.Present)
                {
                    FxIndexObservation observation = period.FxResetObservation.get();

                    // notional out at start of period
                    if (includeStartPayment)
                    {
                        events.add(FxResetNotionalExchange.of(period.NotionalAmount.negated(), startPaymentDate, observation));
                    }

                    // notional in at end of period
                    if (includeEndPayment)
                    {
                        events.add(FxResetNotionalExchange.of(period.NotionalAmount, period.PaymentDate, observation));
                    }
                }
                else
                {
                    // handle weird swap where only some periods have FX reset

                    // notional out at start of period
                    if (includeStartPayment)
                    {
                        events.add(NotionalExchange.of(CurrencyAmount.of(period.Currency, -period.NotionalAmount.Amount), startPaymentDate));
                    }
                    // notional in at end of period
                    if (includeEndPayment)
                    {
                        events.add(NotionalExchange.of(CurrencyAmount.of(period.Currency, period.NotionalAmount.Amount), period.PaymentDate));
                    }
                }
            }
            return(events.build());
        }
        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);
        }
        public virtual void test_serialization()
        {
            NotionalExchange test = NotionalExchange.of(GBP_1000, DATE_2014_06_30);

            assertSerialization(test);
        }
 public virtual void test_of_null()
 {
     assertThrowsIllegalArg(() => NotionalExchange.of(GBP_1000, null));
     assertThrowsIllegalArg(() => NotionalExchange.of(null, DATE_2014_06_30));
     assertThrowsIllegalArg(() => NotionalExchange.of(null, null));
 }