//------------------------------------------------------------------------- public virtual void test_createRateComputation_Monthly() { InflationRateCalculation test = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(START_INDEX).build(); InflationEndMonthRateComputation obs1 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3)); InflationEndMonthRateComputation obs2 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3)); InflationEndMonthRateComputation obs3 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3)); assertEquals(test.createRateComputation(DATE_2015_02_05), obs1); assertEquals(test.createRateComputation(DATE_2015_03_07), obs2); assertEquals(test.createRateComputation(DATE_2015_04_05), obs3); }
//------------------------------------------------------------------------- public virtual void test_rateSensitivity() { ImmutableRatesProvider prov = createProvider(RATE_END); ImmutableRatesProvider provEndUp = createProvider(RATE_END + EPS_FD); ImmutableRatesProvider provEndDw = createProvider(RATE_END - EPS_FD); InflationEndMonthRateComputation ro = InflationEndMonthRateComputation.of(GB_RPIX, START_INDEX_VALUE, REFERENCE_END_MONTH); ForwardInflationEndMonthRateComputationFn obsFn = ForwardInflationEndMonthRateComputationFn.DEFAULT; double rateEndUp = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndUp); double rateEndDw = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndDw); PointSensitivityBuilder sensiExpected = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REFERENCE_END_MONTH), 0.5 * (rateEndUp - rateEndDw) / EPS_FD); PointSensitivityBuilder sensiComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov); assertTrue(sensiComputed.build().normalized().equalWithTolerance(sensiExpected.build().normalized(), EPS_FD)); }
//------------------------------------------------------------------------- public virtual void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_END); InflationEndMonthRateComputation ro = InflationEndMonthRateComputation.of(GB_RPIX, START_INDEX_VALUE, REFERENCE_END_MONTH); ForwardInflationEndMonthRateComputationFn obsFn = ForwardInflationEndMonthRateComputationFn.DEFAULT; double rateExpected = RATE_END / START_INDEX_VALUE - 1; assertEquals(obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov), rateExpected, EPS); // explain ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(obsFn.explainRate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov, builder), rateExpected, EPS); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true); assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 1); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), REFERENCE_END_MONTH.atEndOfMonth()); assertEquals(explain0.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), RATE_END); assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, EPS); }
//------------------------------------------------------------------------- public virtual void coverage() { CapitalIndexedBondPaymentPeriod test1 = CapitalIndexedBondPaymentPeriod.builder().currency(USD).notional(NOTIONAL).detachmentDate(DETACHMENT).startDate(START).endDate(END).unadjustedStartDate(START_UNADJ).unadjustedEndDate(END_UNADJ).rateComputation(COMPUTE_INTERP).realCoupon(REAL_COUPON).build(); coverImmutableBean(test1); CapitalIndexedBondPaymentPeriod test2 = CapitalIndexedBondPaymentPeriod.builder().currency(GBP).notional(5.0e6).startDate(LocalDate.of(2008, 1, 15)).endDate(LocalDate.of(2008, 7, 15)).rateComputation(InflationEndMonthRateComputation.of(GB_RPI, 155.32, REF_END)).realCoupon(1d).build(); coverBeanEquals(test1, test2); }
public virtual void test_createAccrualPeriods_Monthly_firstKnown() { InflationRateCalculation test = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(123d).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(1.0).rateComputation(InflationEndMonthRateComputation.of(GB_HICP, 123d, YearMonth.from(DATE_2015_02_05).minusMonths(3))).build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_02_05).minusMonths(3), YearMonth.from(DATE_2015_03_07).minusMonths(3))).build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_03_07).minusMonths(3), YearMonth.from(DATE_2015_04_05).minusMonths(3))).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }