Esempio n. 1
0
        //-------------------------------------------------------------------------
        // proper end-to-end tests are elsewhere
        public virtual void test_parameterSensitivity()
        {
            SimplePriceIndexValues   test  = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            InflationRateSensitivity point = InflationRateSensitivity.of(PriceIndexObservation.of(US_CPI_U, VAL_MONTH.plusMonths(3)), 1d);

            assertEquals(test.parameterSensitivity(point).size(), 1);
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------
        public virtual void test_valuePointSensitivity_fixing()
        {
            SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            PriceIndexObservation  obs  = PriceIndexObservation.of(US_CPI_U, VAL_MONTH.minusMonths(3));

            assertEquals(test.valuePointSensitivity(obs), PointSensitivityBuilder.none());
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------
        public virtual void test_rateSensitivity()
        {
            ImmutableRatesProvider prov         = createProvider(RATE_START, RATE_START_INTERP, RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provSrtUp    = createProvider(RATE_START + EPS_FD, RATE_START_INTERP, RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provSrtDw    = createProvider(RATE_START - EPS_FD, RATE_START_INTERP, RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provSrtIntUp = createProvider(RATE_START, RATE_START_INTERP + EPS_FD, RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provSrtIntDw = createProvider(RATE_START, RATE_START_INTERP - EPS_FD, RATE_END, RATE_END_INTERP);
            ImmutableRatesProvider provEndUp    = createProvider(RATE_START, RATE_START_INTERP, RATE_END + EPS_FD, RATE_END_INTERP);
            ImmutableRatesProvider provEndDw    = createProvider(RATE_START, RATE_START_INTERP, RATE_END - EPS_FD, RATE_END_INTERP);
            ImmutableRatesProvider provEndIntUp = createProvider(RATE_START, RATE_START_INTERP, RATE_END, RATE_END_INTERP + EPS_FD);
            ImmutableRatesProvider provEndIntDw = createProvider(RATE_START, RATE_START_INTERP, RATE_END, RATE_END_INTERP - EPS_FD);

            InflationInterpolatedRateComputation          ro    = InflationInterpolatedRateComputation.of(GB_RPIX, REF_START_MONTH, REF_END_MONTH, WEIGHT);
            ForwardInflationInterpolatedRateComputationFn obsFn = ForwardInflationInterpolatedRateComputationFn.DEFAULT;

            double rateSrtUp    = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provSrtUp);
            double rateSrtDw    = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provSrtDw);
            double rateSrtIntUp = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provSrtIntUp);
            double rateSrtIntDw = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provSrtIntDw);
            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 sensSrt       = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REF_START_MONTH), 0.5 * (rateSrtUp - rateSrtDw) / EPS_FD);
            PointSensitivityBuilder sensSrtInt    = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPIX, REF_START_MONTH_INTERP), 0.5 * (rateSrtIntUp - rateSrtIntDw) / EPS_FD);
            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 = sensSrt.combinedWith(sensSrtInt).combinedWith(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));
        }
Esempio n. 4
0
        public virtual void test_valuePointSensitivity_forward()
        {
            YearMonth month = VAL_MONTH.plusMonths(3);
            SimplePriceIndexValues   test     = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            PriceIndexObservation    obs      = PriceIndexObservation.of(US_CPI_U, month);
            InflationRateSensitivity expected = InflationRateSensitivity.of(obs, 1d);

            assertEquals(test.valuePointSensitivity(obs), expected);
        }
Esempio n. 5
0
        static SimplePriceIndexValuesTest()
        {
            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < USCPI_VALUES.Length; i++)
            {
                builder.put(USCPI_START_DATE.plusMonths(i), USCPI_VALUES[i]);
            }
            USCPI_TS = builder.build();
            for (int i = 0; i < TEST_MONTHS.Length; i++)
            {
                TEST_OBS[i] = PriceIndexObservation.of(US_CPI_U, TEST_MONTHS[i]);
            }
        }
        //-------------------------------------------------------------------------
        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));
        }
Esempio n. 7
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            InflationRateSensitivity a1    = InflationRateSensitivity.of(GB_HICP_OBS, 32d);
            InflationRateSensitivity a2    = InflationRateSensitivity.of(GB_HICP_OBS, 32d);
            InflationRateSensitivity b     = InflationRateSensitivity.of(CH_CPI_OBS, 32d);
            InflationRateSensitivity c     = InflationRateSensitivity.of(GB_HICP_OBS, USD, 32d);
            InflationRateSensitivity d     = InflationRateSensitivity.of(PriceIndexObservation.of(GB_HICP, YearMonth.of(2015, 10)), 32d);
            ZeroRateSensitivity      other = ZeroRateSensitivity.of(GBP, 2d, 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) > 0, true);
            assertEquals(b.compareKey(a1) < 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(d) < 0, true);
            assertEquals(d.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) < 0, true);
            assertEquals(other.compareKey(a1) > 0, true);
        }
 public virtual void test_wrongMonthOrder()
 {
     assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.of(GB_HICP, END_MONTH_FIRST, START_MONTH_FIRST, WEIGHT));
     assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build());
     assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 2))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build());
     assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 9))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build());
 }
 public virtual void test_wrongMonthOrder()
 {
     assertThrowsIllegalArg(() => InflationEndInterpolatedRateComputation.meta().builder().set(InflationEndInterpolatedRateComputation.meta().startIndexValue(), START_INDEX).set(InflationEndInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationEndInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationEndInterpolatedRateComputation.meta().weight(), WEIGHT).build());
 }