//------------------------------------------------------------------------- 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); }