Ejemplo n.º 1
0
        public virtual void test_of()
        {
            FxReset test = FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_2014_06_30, REF_DATA), GBP);

            assertEquals(test.Index, EUR_GBP_ECB);
            assertEquals(test.ReferenceCurrency, 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));
        }
        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));
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FxReset test = FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_2014_06_30, REF_DATA), GBP);

            coverImmutableBean(test);
            FxReset test2 = FxReset.of(FxIndexObservation.of(EUR_USD_ECB, date(2014, 1, 15), REF_DATA), USD);

            coverBeanEquals(test, test2);
            FxReset test3 = FxReset.of(FxIndexObservation.of(EUR_USD_ECB, date(2014, 1, 15), REF_DATA), EUR);

            coverBeanEquals(test2, test3);
        }
 //-------------------------------------------------------------------------
 internal static ResolvedFxNdf sut()
 {
     return(ResolvedFxNdf.builder().agreedFxRate(FX_RATE).observation(FxIndexObservation.of(GBP_USD_WM, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).settlementCurrencyNotional(CURRENCY_NOTIONAL).build());
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public virtual void test_invalidCurrency()
 {
     assertThrowsIllegalArg(() => FxResetNotionalExchange.meta().builder().set(FxResetNotionalExchange.meta().paymentDate(), DATE_2014_06_30).set(FxResetNotionalExchange.meta().notionalAmount(), CurrencyAmount.of(GBP, 1000d)).set(FxResetNotionalExchange.meta().observation(), FxIndexObservation.of(EUR_USD_ECB, DATE_2014_03_28, REF_DATA)).build());
 }
Ejemplo n.º 10
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_builder_wrongCurrency()
        {
            CurrencyAmount currencyNotional = CurrencyAmount.of(EUR, NOTIONAL);

            assertThrowsIllegalArg(() => ResolvedFxNdf.builder().agreedFxRate(FX_RATE).observation(FxIndexObservation.of(GBP_USD_WM, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).settlementCurrencyNotional(currencyNotional).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);
        }
        public virtual void test_forwardValue()
        {
            FxRate         computed    = PRICER.forwardFxRate(NDF, PROVIDER);
            ResolvedFxNdf  ndfFwd      = ResolvedFxNdf.builder().settlementCurrencyNotional(CURRENCY_NOTIONAL).agreedFxRate(computed).observation(FxIndexObservation.of(INDEX, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).build();
            CurrencyAmount computedFwd = PRICER.presentValue(ndfFwd, PROVIDER);

            assertEquals(computedFwd.Amount, 0d, NOMINAL_USD * TOL);
        }
        //-------------------------------------------------------------------------
        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_presentValue_ended()
        {
            ResolvedFxNdf  ndf      = ResolvedFxNdf.builder().settlementCurrencyNotional(CURRENCY_NOTIONAL).agreedFxRate(FxRate.of(USD, KRW, FX_RATE)).observation(FxIndexObservation.of(INDEX, FIXING_DATE_PAST, REF_DATA)).paymentDate(PAYMENT_DATE_PAST).build();
            CurrencyAmount computed = PRICER.presentValue(ndf, PROVIDER);

            assertEquals(computed.Amount, 0d);
        }
        public virtual void test_currencyExposure_ended()
        {
            ResolvedFxNdf       ndf      = ResolvedFxNdf.builder().settlementCurrencyNotional(CURRENCY_NOTIONAL).agreedFxRate(FxRate.of(USD, KRW, FX_RATE)).observation(FxIndexObservation.of(INDEX, LocalDate.of(2011, 5, 2), REF_DATA)).paymentDate(LocalDate.of(2011, 5, 4)).build();
            MultiCurrencyAmount computed = PRICER.currencyExposure(ndf, PROVIDER);

            assertEquals(computed.size(), 0);
        }
Ejemplo n.º 17
0
        public virtual void test_serialization()
        {
            FxReset test = FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, DATE_2014_06_30, REF_DATA), GBP);

            assertSerialization(test);
        }
        internal static ResolvedFxNdf sut2()
        {
            FxRate fxRate = FxRate.of(GBP, EUR, 1.1d);

            return(ResolvedFxNdf.builder().agreedFxRate(fxRate).observation(FxIndexObservation.of(EUR_GBP_ECB, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).settlementCurrencyNotional(CURRENCY_NOTIONAL).build());
        }
        public virtual void currency_exposure_USD()
        {
            LocalDate               startDate     = LocalDate.of(2016, 8, 2);
            LocalDate               fixingDate    = LocalDate.of(2016, 11, 2);
            LocalDate               endDate       = LocalDate.of(2016, 11, 4);
            double                  yearFraction  = 0.25;
            double                  rate          = 0.10;
            RateAccrualPeriod       accrual       = RateAccrualPeriod.builder().startDate(startDate).endDate(endDate).yearFraction(yearFraction).rateComputation(FixedRateComputation.of(rate)).build();
            double                  notional      = 1000000;
            RatePaymentPeriod       fixedFx       = RatePaymentPeriod.builder().accrualPeriods(accrual).fxReset(FxReset.of(FxIndexObservation.of(FxIndices.GBP_USD_WM, fixingDate, REF_DATA), USD)).notional(notional).paymentDate(endDate).dayCount(DayCounts.ONE_ONE).currency(GBP).build(); // 1_000_000 USD paid in GBP at maturity
            PointSensitivityBuilder pts           = PERIOD_PRICER.presentValueSensitivity(fixedFx, PROVIDER);
            MultiCurrencyAmount     ceComputed    = PERIOD_PRICER.currencyExposure(fixedFx, PROVIDER);
            double                  dfUsd         = PROVIDER.discountFactor(USD, endDate);
            double                  ceUsdExpected = notional * yearFraction * rate * dfUsd;

            assertEquals(ceComputed.getAmount(USD).Amount, ceUsdExpected, 1.0E-6);
            MultiCurrencyAmount ceWithoutPvComputed = PROVIDER.currencyExposure(pts.build().convertedTo(USD, PROVIDER));
            CurrencyAmount      pvComputed          = CurrencyAmount.of(GBP, PERIOD_PRICER.presentValue(fixedFx, PROVIDER));
            MultiCurrencyAmount ceComputed2         = ceWithoutPvComputed.plus(pvComputed);

            assertEquals(ceComputed2.getAmount(USD).Amount, ceUsdExpected, TOLERANCE);
            assertEquals(ceComputed2.getAmount(GBP).Amount, 0.0, TOLERANCE);
        }
        public virtual void test_builder_inverse()
        {
            CurrencyAmount currencyNotional = CurrencyAmount.of(USD, NOTIONAL);
            ResolvedFxNdf  test             = ResolvedFxNdf.builder().agreedFxRate(FX_RATE).observation(FxIndexObservation.of(GBP_USD_WM, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).settlementCurrencyNotional(currencyNotional).build();

            assertEquals(test.AgreedFxRate, FX_RATE);
            assertEquals(test.Index, GBP_USD_WM);
            assertEquals(test.NonDeliverableCurrency, GBP);
            assertEquals(test.PaymentDate, PAYMENT_DATE);
            assertEquals(test.SettlementCurrency, USD);
            assertEquals(test.SettlementCurrencyNotional, currencyNotional);
            assertEquals(test.SettlementNotional, NOTIONAL);
        }
Ejemplo n.º 21
0
 public virtual void test_invalidCurrency()
 {
     assertThrowsIllegalArg(() => FxReset.meta().builder().set(FxReset.meta().observation(), FxIndexObservation.of(EUR_USD_ECB, DATE_2014_06_30, REF_DATA)).set(FxReset.meta().referenceCurrency(), GBP).build());
     assertThrowsIllegalArg(() => FxReset.of(FxIndexObservation.of(EUR_USD_ECB, DATE_2014_06_30, REF_DATA), GBP));
 }
        public virtual void test_builder_wrongRate()
        {
            FxRate fxRate = FxRate.of(GBP, EUR, 1.1d);

            assertThrowsIllegalArg(() => ResolvedFxNdf.builder().agreedFxRate(fxRate).observation(FxIndexObservation.of(GBP_USD_WM, FIXING_DATE, REF_DATA)).paymentDate(PAYMENT_DATE).settlementCurrencyNotional(CURRENCY_NOTIONAL).build());
        }
        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);
        }