/** * Creates an instance from an index, reference start month and reference end month. * * @param index the index * @param referenceStartMonth the reference start month * @param referenceEndMonth the reference end month * @return the inflation rate computation */ public static InflationMonthlyRateComputation of( PriceIndex index, YearMonth referenceStartMonth, YearMonth referenceEndMonth) { return new InflationMonthlyRateComputation( PriceIndexObservation.of(index, referenceStartMonth), PriceIndexObservation.of(index, referenceEndMonth)); }
/** * Creates an instance from an index, start index value and reference end month. * * @param index the index * @param startIndexValue the start index value * @param referenceEndMonth the reference end month * @return the inflation rate computation */ public static InflationEndMonthRateComputation of( PriceIndex index, double startIndexValue, YearMonth referenceEndMonth) { return new InflationEndMonthRateComputation(startIndexValue, PriceIndexObservation.of(index, referenceEndMonth)); }
/** * Creates an instance from an index, reference start month and reference end month. * <p> * The second start/end observations will be one month later than the start/end month. * * @param index the index * @param referenceStartMonth the reference start month * @param referenceEndMonth the reference end month * @param weight the weight * @return the inflation rate computation */ public static InflationInterpolatedRateComputation of( PriceIndex index, YearMonth referenceStartMonth, YearMonth referenceEndMonth, double weight) { return new InflationInterpolatedRateComputation( PriceIndexObservation.of(index, referenceStartMonth), PriceIndexObservation.of(index, referenceStartMonth.plusMonths(1)), PriceIndexObservation.of(index, referenceEndMonth), PriceIndexObservation.of(index, referenceEndMonth.plusMonths(1)), weight); }
/** * Creates an instance from an index, start index value and reference end month. * <p> * The second end observations will be one month later than the end month. * * @param index the index * @param startIndexValue the start index value * @param referenceEndMonth the reference end month * @param weight the weight * @return the inflation rate computation */ public static InflationEndInterpolatedRateComputation of( PriceIndex index, double startIndexValue, YearMonth referenceEndMonth, double weight) { return new InflationEndInterpolatedRateComputation( startIndexValue, PriceIndexObservation.of(index, referenceEndMonth), PriceIndexObservation.of(index, referenceEndMonth.plusMonths(1)), weight); }
public void test_serialization() { PriceIndexObservation test = PriceIndexObservation.of(GB_HICP, FIXING_MONTH); assertSerialization(test); }
public void test_of() { PriceIndexObservation test = PriceIndexObservation.of(GB_HICP, FIXING_MONTH); assertEquals(test.getIndex(), GB_HICP); assertEquals(test.getFixingMonth(), FIXING_MONTH); assertEquals(test.getCurrency(), GB_HICP.getCurrency()); assertEquals(test.toString(), "PriceIndexObservation[GB-HICP on 2016-02]"); }
public 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()); }
public void test_valuePointSensitivity_fixing() { HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS); PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, VAL_MONTH.minusMonths(3)); assertEquals(test.value(obs), 234.722d, TOLERANCE_VALUE); assertEquals(test.valuePointSensitivity(obs), PointSensitivityBuilder.none()); }
public 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); }
public 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); }
public 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 void test_parameterSensitivity() { HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS); InflationRateSensitivity point = InflationRateSensitivity.of(PriceIndexObservation.of(US_CPI_U, VAL_MONTH.plusMonths(3)), 1d); assertThrows(MarketDataNotFoundException.class, () -> test.parameterSensitivity(point)); }
public void test_valuePointSensitivity_forward() { YearMonth month = VAL_MONTH.plusMonths(3); HistoricPriceIndexValues test = HistoricPriceIndexValues.of(US_CPI_U, VAL_DATE, USCPI_TS); PriceIndexObservation obs = PriceIndexObservation.of(US_CPI_U, month); assertThrows(MarketDataNotFoundException.class, () -> test.value(obs)); assertThrows(MarketDataNotFoundException.class, () -> test.valuePointSensitivity(obs)); }
public void pointAndParameterPriceIndex() { double eps = 1.0e-13; LocalDate valuationDate = LocalDate.of(2014, 1, 22); DoubleArray x = DoubleArray.of(0.5, 1.0, 2.0); DoubleArray y = DoubleArray.of(224.2, 262.6, 277.5); CurveInterpolator interp = CurveInterpolators.NATURAL_CUBIC_SPLINE; String curveName = "GB_RPI_CURVE"; InterpolatedNodalCurve interpCurve = InterpolatedNodalCurve.of(Curves.prices(curveName), x, y, interp); ImmutableRatesProvider provider = ImmutableRatesProvider.builder(VAL_DATE) .priceIndexCurve(GB_RPI, interpCurve) .timeSeries(GB_RPI, LocalDateDoubleTimeSeries.of(date(2013, 11, 30), 200)) .build(); double pointSensiValue = 2.5; YearMonth refMonth = YearMonth.from(valuationDate.plusMonths(9)); InflationRateSensitivity pointSensi = InflationRateSensitivity.of( PriceIndexObservation.of(GB_RPI, refMonth), pointSensiValue); CurrencyParameterSensitivities computed = provider.parameterSensitivity(pointSensi.build()); DoubleArray sensiComputed = computed.getSensitivities().get(0).getSensitivity(); InflationRateSensitivity pointSensi1 = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPI, refMonth), 1); DoubleArray sensiExpectedUnit = provider.priceIndexValues(GB_RPI).parameterSensitivity(pointSensi1).getSensitivities().get(0).getSensitivity(); assertTrue(sensiComputed.equalWithTolerance(sensiExpectedUnit.multipliedBy(pointSensiValue), eps)); }
public 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()); }
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)))
public 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 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)); }
public 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)); }