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_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)); }
.paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)) .accrualPeriods(rap0, rap1, rap2, rap3, rap4) .compoundingMethod(STRAIGHT) .dayCount(ONE_ONE) .currency(GBP)
.currency(GBP) .notional(-1000d) .compoundingMethod(STRAIGHT) .build(); RatePaymentPeriod rpp2 = RatePaymentPeriod.builder() .currency(GBP) .notional(-1500d) .compoundingMethod(STRAIGHT) .build(); RatePaymentPeriod rpp3 = RatePaymentPeriod.builder() .currency(GBP) .notional(-1500d) .compoundingMethod(STRAIGHT) .build();
.currency(GBP) .notional(-1000d) .compoundingMethod(STRAIGHT) .build();
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 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_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 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_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_forecastValue_compoundFlat_notional() { SimpleRatesProvider prov = createProvider(VAL_DATE); RatePaymentPeriod periodNot = PAYMENT_PERIOD_FULL_GS.toBuilder() .compoundingMethod(CompoundingMethod.FLAT).build(); RatePaymentPeriod period1 = PAYMENT_PERIOD_FULL_GS.toBuilder() .compoundingMethod(CompoundingMethod.FLAT).notional(1.0d).build(); double fvComputedNot = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(periodNot, prov); double fvComputed1 = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(period1, prov); assertEquals(fvComputedNot, fvComputed1 * NOTIONAL_100, TOLERANCE_PV); }
@ImmutableDefaults private static void applyDefaults(Builder builder) { builder.compoundingMethod(CompoundingMethod.NONE); }
public void test_forecastValue_compoundFlat() { SimpleRatesProvider prov = createProvider(VAL_DATE); RatePaymentPeriod period = PAYMENT_PERIOD_FULL_GS.toBuilder() .compoundingMethod(CompoundingMethod.FLAT).build(); double cpa1 = NOTIONAL_100 * ACCRUAL_FACTOR_1 * (RATE_1 * GEARING + SPREAD); double cpa2 = NOTIONAL_100 * ACCRUAL_FACTOR_2 * (RATE_2 * GEARING + SPREAD) + cpa1 * ACCRUAL_FACTOR_2 * (RATE_2 * GEARING); double cpa3 = NOTIONAL_100 * ACCRUAL_FACTOR_3 * (RATE_3 * GEARING + SPREAD) + (cpa1 + cpa2) * ACCRUAL_FACTOR_3 * (RATE_3 * GEARING); double fvExpected = cpa1 + cpa2 + cpa3; double fvComputed = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(period, prov); assertEquals(fvComputed, fvExpected, TOLERANCE_PV); }
public void test_forecastValue_compoundSpreadExclusive() { SimpleRatesProvider prov = createProvider(VAL_DATE); RatePaymentPeriod period = PAYMENT_PERIOD_FULL_GS.toBuilder() .compoundingMethod(CompoundingMethod.SPREAD_EXCLUSIVE).build(); double invFactor1 = 1.0d + ACCRUAL_FACTOR_1 * (RATE_1 * GEARING); double invFactor2 = 1.0d + ACCRUAL_FACTOR_2 * (RATE_2 * GEARING); double invFactor3 = 1.0d + ACCRUAL_FACTOR_3 * (RATE_3 * GEARING); double fvExpected = NOTIONAL_100 * (invFactor1 * invFactor2 * invFactor3 - 1.0d + (ACCRUAL_FACTOR_1 + ACCRUAL_FACTOR_2 + ACCRUAL_FACTOR_3) * SPREAD); double fvComputed = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(period, prov); assertEquals(fvComputed, fvExpected, TOLERANCE_PV); }
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_forecastValue_compoundSpreadExclusive_fx() { SimpleRatesProvider prov = createProvider(VAL_DATE); RatePaymentPeriod period = PAYMENT_PERIOD_FULL_GS_FX_USD.toBuilder() .compoundingMethod(CompoundingMethod.SPREAD_EXCLUSIVE).build(); double invFactor1 = 1.0d + ACCRUAL_FACTOR_1 * (RATE_1 * GEARING); double invFactor2 = 1.0d + ACCRUAL_FACTOR_2 * (RATE_2 * GEARING); double invFactor3 = 1.0d + ACCRUAL_FACTOR_3 * (RATE_3 * GEARING); double fvExpected = NOTIONAL_100 * RATE_FX * (invFactor1 * invFactor2 * invFactor3 - 1.0d + (ACCRUAL_FACTOR_1 + ACCRUAL_FACTOR_2 + ACCRUAL_FACTOR_3) * SPREAD); double fvComputed = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(period, prov); assertEquals(fvComputed, fvExpected, TOLERANCE_PV); }
public void test_forecastValue_compoundStraight() { SimpleRatesProvider prov = createProvider(VAL_DATE); RatePaymentPeriod period = PAYMENT_PERIOD_FULL_GS.toBuilder() .compoundingMethod(CompoundingMethod.STRAIGHT).build(); double invFactor1 = 1.0d + ACCRUAL_FACTOR_1 * (RATE_1 * GEARING + SPREAD); double invFactor2 = 1.0d + ACCRUAL_FACTOR_2 * (RATE_2 * GEARING + SPREAD); double invFactor3 = 1.0d + ACCRUAL_FACTOR_3 * (RATE_3 * GEARING + SPREAD); double fvExpected = NOTIONAL_100 * (invFactor1 * invFactor2 * invFactor3 - 1.0d); double fvComputed = DiscountingRatePaymentPeriodPricer.DEFAULT.forecastValue(period, prov); assertEquals(fvComputed, fvExpected, TOLERANCE_PV); }