//------------------------------------------------------------------------- public virtual void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_START, RATE_END); InflationMonthlyRateComputation ro = InflationMonthlyRateComputation.of(GB_RPIX, REFERENCE_START_MONTH, REFERENCE_END_MONTH); ForwardInflationMonthlyRateComputationFn obsFn = ForwardInflationMonthlyRateComputationFn.DEFAULT; double rateExpected = RATE_END / RATE_START - 1.0; 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(), 2); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), REFERENCE_START_MONTH.atEndOfMonth()); assertEquals(explain0.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), RATE_START); ExplainMap explain1 = built.get(ExplainKey.OBSERVATIONS).get().get(1); assertEquals(explain1.get(ExplainKey.FIXING_DATE), REFERENCE_END_MONTH.atEndOfMonth()); assertEquals(explain1.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain1.get(ExplainKey.INDEX_VALUE), RATE_END); assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, EPS); }
//------------------------------------------------------------------------- public virtual void test_rateSensitivity() { ImmutableRatesProvider prov = createProvider(RATE_START, RATE_END); ImmutableRatesProvider provStartUp = createProvider(RATE_START + EPS_FD, RATE_END); ImmutableRatesProvider provStartDw = createProvider(RATE_START - EPS_FD, RATE_END); ImmutableRatesProvider provEndUp = createProvider(RATE_START, RATE_END + EPS_FD); ImmutableRatesProvider provEndDw = createProvider(RATE_START, RATE_END - EPS_FD); InflationMonthlyRateComputation ro = InflationMonthlyRateComputation.of(GB_RPIX, REFERENCE_START_MONTH, REFERENCE_END_MONTH); ForwardInflationMonthlyRateComputationFn obsFn = ForwardInflationMonthlyRateComputationFn.DEFAULT; double rateSrtUp = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provStartUp); double rateSrtDw = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provStartDw); 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 sensiStr = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REFERENCE_START_MONTH), 0.5 * (rateSrtUp - rateSrtDw) / EPS_FD); PointSensitivityBuilder sensiEnd = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REFERENCE_END_MONTH), 0.5 * (rateEndUp - rateEndDw) / EPS_FD); PointSensitivityBuilder sensiExpected = sensiStr.combinedWith(sensiEnd); PointSensitivityBuilder sensiComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov); assertTrue(sensiComputed.build().normalized().equalWithTolerance(sensiExpected.build().normalized(), EPS_FD)); }