Exemplo n.º 1
0
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            FxResetNotionalExchange test     = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));
            FxResetNotionalExchange expected = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30.plusDays(2), FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_03_28, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));

            coverImmutableBean(test);
            FxResetNotionalExchange test2 = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, 2000d), DATE_2014_06_30, FxIndexObservation.of(EUR_USD_ECB, DATE_2014_06_30, REF_DATA));

            coverBeanEquals(test, test2);
        }
Exemplo n.º 3
0
        public virtual void test_of()
        {
            FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));

            assertEquals(test.PaymentDate, DATE_2014_06_30);
            assertEquals(test.ReferenceCurrency, USD);
            assertEquals(test.NotionalAmount, CurrencyAmount.of(USD, 1000d));
            assertEquals(test.Notional, 1000d, 0d);
        }
        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);
        }
        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);
        }
Exemplo n.º 6
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_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());
        }
Exemplo n.º 8
0
        public virtual void test_serialization()
        {
            FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));

            assertSerialization(test);
        }