public void test_collectIndices_simple() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M)); }
public void test_collectIndices_fxReset() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .fxReset(FX_RESET_USD) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M, GBP_USD_WM)); }
public void test_builder_twoAccrualPeriods() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP1, RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getCompoundingMethod(), CompoundingMethod.STRAIGHT); assertEquals(test.isCompoundingApplicable(), true); }
public void test_builder_oneAccrualPeriod() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.getStartDate(), DATE_2014_06_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getNotionalAmount(), CurrencyAmount.of(GBP, 1000d)); assertEquals(test.getCompoundingMethod(), CompoundingMethod.STRAIGHT); assertEquals(test.isCompoundingApplicable(), false); }
public void test_builder_twoAccrualPeriods_compoundingDefaultedToNone_fxReset() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .fxReset(FX_RESET_USD) .notional(1000d) .compoundingMethod(CompoundingMethod.NONE) .build(); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP1, RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.of(FX_RESET_USD)); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getNotionalAmount(), CurrencyAmount.of(USD, 1000d)); assertEquals(test.isCompoundingApplicable(), false); }
public void test_serialization() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertSerialization(test); }
public void test_adjustPaymentDate() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); RatePaymentPeriod expected = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01.plusDays(2)) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(0))), test); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(2))), expected); }
public void coverage() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .fxReset(FX_RESET_USD) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); coverImmutableBean(test); RatePaymentPeriod test2 = RatePaymentPeriod.builder() .paymentDate(DATE_2014_09_30) .accrualPeriods(RAP1) .dayCount(ACT_360) .currency(USD) .notional(2000d) .compoundingMethod(CompoundingMethod.NONE) .build(); coverBeanEquals(test, test2); }
public void test_builder_badFxReset() { assertThrowsIllegalArg(() -> RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(USD) .fxReset(FX_RESET_USD) .notional(1000d) .compoundingMethod(CompoundingMethod.NONE) .build()); assertThrowsIllegalArg(() -> RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(EUR) .fxReset(FX_RESET_USD) .notional(1000d) .compoundingMethod(CompoundingMethod.NONE) .build()); }
public 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).getAmount(), 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).getAmount(), ceUsdExpected, TOLERANCE); assertEquals(ceComputed2.getAmount(GBP).getAmount(), 0.0, TOLERANCE); }
public void currency_exposure_GBP() { 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), GBP)) .notional(notional) .paymentDate(endDate) .dayCount(DayCounts.ONE_ONE) .currency(USD).build(); // 1_000_000 GBP paid in USD at maturity PointSensitivityBuilder pts = PERIOD_PRICER.presentValueSensitivity(fixedFx, PROVIDER); MultiCurrencyAmount ceComputed = PERIOD_PRICER.currencyExposure(fixedFx, PROVIDER); double dfGbp = PROVIDER.discountFactor(GBP, endDate); double ceGbpExpected = notional * yearFraction * rate * dfGbp; assertEquals(ceComputed.getAmount(GBP).getAmount(), ceGbpExpected, 1.0E-6); MultiCurrencyAmount ceWithoutPvComputed = PROVIDER.currencyExposure(pts.build().convertedTo(GBP, PROVIDER)); CurrencyAmount pvComputed = CurrencyAmount.of(USD, PERIOD_PRICER.presentValue(fixedFx, PROVIDER)); MultiCurrencyAmount ceComputed2 = ceWithoutPvComputed.plus(pvComputed); assertEquals(ceComputed2.getAmount(GBP).getAmount(), ceGbpExpected, TOLERANCE); assertEquals(ceComputed2.getAmount(USD).getAmount(), 0.0, TOLERANCE); }
public void test_cashFlowEquivalentAndSensitivity_compounding() { RatePaymentPeriod iborCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(IBOR1, IBOR2) .dayCount(ACT_365F) .currency(GBP) .notional(-NOTIONAL) .build(); ResolvedSwapLeg iborLegCmp = ResolvedSwapLeg.builder() .type(IBOR) .payReceive(PAY) .paymentPeriods(iborCmp) .build(); ResolvedSwap swap1 = ResolvedSwap.of(iborLegCmp, FIXED_LEG); assertThrowsIllegalArg(() -> CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap1, PROVIDER)); RatePaymentPeriod fixedCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(FIXED1, FIXED2) .dayCount(ACT_365F) .currency(GBP) .notional(NOTIONAL) .build(); ResolvedSwapLeg fixedLegCmp = ResolvedSwapLeg.builder() .type(FIXED) .payReceive(RECEIVE) .paymentPeriods(fixedCmp) .build(); ResolvedSwap swap2 = ResolvedSwap.of(IBOR_LEG, fixedLegCmp); assertThrowsIllegalArg(() -> CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap2, PROVIDER)); }
public void test_cashFlowEquivalent_compounding() { RatePaymentPeriod iborCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(IBOR1, IBOR2) .dayCount(ACT_365F) .currency(GBP) .notional(-NOTIONAL) .build(); ResolvedSwapLeg iborLegCmp = ResolvedSwapLeg.builder() .type(IBOR) .payReceive(PAY) .paymentPeriods(iborCmp) .build(); ResolvedSwap swap1 = ResolvedSwap.of(iborLegCmp, FIXED_LEG); assertThrowsIllegalArg(() -> CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap1, PROVIDER)); RatePaymentPeriod fixedCmp = RatePaymentPeriod.builder() .paymentDate(PAYMENT2) .accrualPeriods(FIXED1, FIXED2) .dayCount(ACT_365F) .currency(GBP) .notional(NOTIONAL) .build(); ResolvedSwapLeg fixedLegCmp = ResolvedSwapLeg.builder() .type(FIXED) .payReceive(RECEIVE) .paymentPeriods(fixedCmp) .build(); ResolvedSwap swap2 = ResolvedSwap.of(IBOR_LEG, fixedLegCmp); assertThrowsIllegalArg(() -> CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap2, PROVIDER)); }
assertEquals(test.getCalculation(), rateCalc); RatePaymentPeriod rpp = RatePaymentPeriod.builder() .paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)) .accrualPeriods(RateAccrualPeriod.builder()
RatePaymentPeriod rpp0 = RatePaymentPeriod.builder() .paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)) .accrualPeriods(RateAccrualPeriod.builder()
.build(); RatePaymentPeriod rpp1 = RatePaymentPeriod.builder() .paymentDate(DATE_02_07) .accrualPeriods(RateAccrualPeriod.builder() .notional(-1000d) .build(); RatePaymentPeriod rpp2 = RatePaymentPeriod.builder() .paymentDate(DATE_03_07) .accrualPeriods(RateAccrualPeriod.builder() .notional(-1000d) .build(); RatePaymentPeriod rpp3 = RatePaymentPeriod.builder() .paymentDate(DATE_04_09) .accrualPeriods(RateAccrualPeriod.builder()
.notionalAmount(CurrencyAmount.of(GBP, -1000d)) .build(); RatePaymentPeriod rpp2 = RatePaymentPeriod.builder() .paymentDate(DATE_03_07) .accrualPeriods(RateAccrualPeriod.builder() .notional(-1000d) .build(); RatePaymentPeriod rpp3 = RatePaymentPeriod.builder() .paymentDate(DATE_04_07) .accrualPeriods(RateAccrualPeriod.builder()
.build()) .build(); RatePaymentPeriod pp1 = RatePaymentPeriod.builder() .paymentDate(date(2016, 2, 5)) // 3rd plus two days .accrualPeriods(RateAccrualPeriod.builder() .notional(NOTIONAL) .build(); RatePaymentPeriod pp2 = RatePaymentPeriod.builder() .paymentDate(date(2016, 3, 7)) // 3rd plus two days is Saturday, Monday is 7th .accrualPeriods(RateAccrualPeriod.builder() .notional(NOTIONAL) .build(); RatePaymentPeriod pp3 = RatePaymentPeriod.builder() .paymentDate(date(2016, 4, 6)) // 3rd is Sunday, bumped to Monday by schedule, then plus two days .accrualPeriods(RateAccrualPeriod.builder() .notional(NOTIONAL) .build(); RatePaymentPeriod pp4 = RatePaymentPeriod.builder() .paymentDate(date(2016, 5, 5)) // 3rd plus two days .accrualPeriods(RateAccrualPeriod.builder()
.build(); RatePaymentPeriod rpp1 = RatePaymentPeriod.builder() .paymentDate(DATE_02_07) .accrualPeriods(RateAccrualPeriod.builder() .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() .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()
.build(); RatePaymentPeriod rpp1 = RatePaymentPeriod.builder() .paymentDate(DATE_04_09) .accrualPeriods(