Exemplo n.º 1
0
        //-------------------------------------------------------------------------
        public virtual void test_rate()
        {
            ImmutableRatesProvider prov = createProvider(RATE_END, RATE_END_INTERP);
            InflationEndInterpolatedRateComputation          ro    = InflationEndInterpolatedRateComputation.of(GB_RPIX, START_INDEX_VALUE, REF_END_MONTH, WEIGHT);
            ForwardInflationEndInterpolatedRateComputationFn obsFn = ForwardInflationEndInterpolatedRateComputationFn.DEFAULT;
            // rate
            double rateExpected = (WEIGHT * RATE_END + (1.0 - WEIGHT) * RATE_END_INTERP) / 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(), 2);
            ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0);

            assertEquals(explain0.get(ExplainKey.FIXING_DATE), REF_END_MONTH.atEndOfMonth());
            assertEquals(explain0.get(ExplainKey.INDEX), GB_RPIX);
            assertEquals(explain0.get(ExplainKey.INDEX_VALUE), RATE_END);
            assertEquals(explain0.get(ExplainKey.WEIGHT), WEIGHT);
            ExplainMap explain1 = built.get(ExplainKey.OBSERVATIONS).get().get(1);

            assertEquals(explain1.get(ExplainKey.FIXING_DATE), REF_END_MONTH_INTERP.atEndOfMonth());
            assertEquals(explain1.get(ExplainKey.INDEX), GB_RPIX);
            assertEquals(explain1.get(ExplainKey.INDEX_VALUE), RATE_END_INTERP);
            assertEquals(explain1.get(ExplainKey.WEIGHT), (1d - WEIGHT));
            assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, EPS);
        }
Exemplo n.º 2
0
        public virtual void test_createRateComputation_Interpolated()
        {
            InflationRateCalculation test = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - 4.0 / 28.0;
            double weight2 = 1.0 - 6.0 / 31.0;
            double weight3 = 1.0 - 4.0 / 30.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
            assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
            assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
        }
Exemplo n.º 3
0
        public virtual void test_createRateComputation_InterpolatedJapan()
        {
            LocalDate date1 = LocalDate.of(2013, 3, 9);
            LocalDate date2 = LocalDate.of(2013, 3, 10);
            LocalDate date3 = LocalDate.of(2013, 3, 11);
            InflationRateCalculation test = InflationRateCalculation.builder().index(JP_CPI_EXF).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED_JAPAN).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - (9.0 + 28.0 - 10.0) / 28.0;
            double weight2 = 1.0;
            double weight3 = 1.0 - 1.0 / 31.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date1).minusMonths(4), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date2).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date3).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(date1), obs1);
            assertEquals(test.createRateComputation(date2), obs2);
            assertEquals(test.createRateComputation(date3), obs3);
        }
Exemplo n.º 4
0
        //-------------------------------------------------------------------------
        public virtual void test_rateSensitivity()
        {
            ImmutableRatesProvider prov         = createProvider(RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provEndUp    = createProvider(RATE_END + EPS_FD, RATE_END_INTERP);
            ImmutableRatesProvider provEndDw    = createProvider(RATE_END - EPS_FD, RATE_END_INTERP);
            ImmutableRatesProvider provEndIntUp = createProvider(RATE_END, RATE_END_INTERP + EPS_FD);
            ImmutableRatesProvider provEndIntDw = createProvider(RATE_END, RATE_END_INTERP - EPS_FD);

            InflationEndInterpolatedRateComputation          ro    = InflationEndInterpolatedRateComputation.of(GB_RPIX, START_INDEX_VALUE, REF_END_MONTH, WEIGHT);
            ForwardInflationEndInterpolatedRateComputationFn obsFn = ForwardInflationEndInterpolatedRateComputationFn.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);
            double rateEndIntUp = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndIntUp);
            double rateEndIntDw = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndIntDw);

            PointSensitivityBuilder sensEnd       = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REF_END_MONTH), 0.5 * (rateEndUp - rateEndDw) / EPS_FD);
            PointSensitivityBuilder sensEndInt    = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REF_END_MONTH_INTERP), 0.5 * (rateEndIntUp - rateEndIntDw) / EPS_FD);
            PointSensitivityBuilder sensiExpected = sensEnd.combinedWith(sensEndInt);

            PointSensitivityBuilder sensiComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov);

            assertTrue(sensiComputed.build().normalized().equalWithTolerance(sensiExpected.build().normalized(), EPS_FD));
        }