/** * Creates curve metadata for a curve providing monthly prices, typically used in inflation. * <p> * The x-values represent months relative to an unspecified base month. * * @param name the curve name * @return the curve metadata */ public static CurveMetadata prices(String name) { return prices(CurveName.of(name)); }
public void prices_curveName() { CurveMetadata test = Curves.prices(CURVE_NAME); CurveMetadata expected = DefaultCurveMetadata.builder() .curveName(CURVE_NAME) .xValueType(ValueType.MONTHS) .yValueType(ValueType.PRICE_INDEX) .build(); assertEquals(test, expected); }
public void prices_string() { CurveMetadata test = Curves.prices(NAME); CurveMetadata expected = DefaultCurveMetadata.builder() .curveName(CURVE_NAME) .xValueType(ValueType.MONTHS) .yValueType(ValueType.PRICE_INDEX) .build(); assertEquals(test, expected); }
public void prices_curveNameParams() { CurveMetadata test = Curves.prices(CURVE_NAME, PARAMS); CurveMetadata expected = DefaultCurveMetadata.builder() .curveName(CURVE_NAME) .xValueType(ValueType.MONTHS) .yValueType(ValueType.PRICE_INDEX) .parameterMetadata(PARAMS) .build(); assertEquals(test, expected); }
private ImmutableRatesProvider createProvider( double rateStart, double rateEnd) { LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE.with(lastDayOfMonth()), 300); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of( Curves.prices("GB-RPIX"), DoubleArray.of(4, 16), DoubleArray.of(rateStart, rateEnd), INTERPOLATOR); return ImmutableRatesProvider.builder(VAL_DATE) .priceIndexCurve(GB_RPIX, curve) .timeSeries(GB_RPIX, timeSeries) .build(); }
private ImmutableRatesProvider createProvider(double rateEnd) { LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE.with(lastDayOfMonth()), 300); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of( Curves.prices("GB-RPIX"), DoubleArray.of(4, 16), DoubleArray.of(RATE_START, rateEnd), INTERPOLATOR); return ImmutableRatesProvider.builder(VAL_DATE) .priceIndexCurve(GB_RPIX, curve) .timeSeries(GB_RPIX, timeSeries) .build(); }
private ImmutableRatesProvider createProvider( double rateEnd, double rateEndInterp) { LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE.with(lastDayOfMonth()), 300); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of( Curves.prices("GB-RPIX"), DoubleArray.of(4, 5, 16, 17), DoubleArray.of(RATE_START, RATE_START_INTERP, rateEnd, rateEndInterp), INTERPOLATOR); return ImmutableRatesProvider.builder(VAL_DATE) .priceIndexCurve(GB_RPIX, curve) .timeSeries(GB_RPIX, timeSeries) .build(); }
private ImmutableRatesProvider createProvider( double rateStart, double rateStartInterp, double rateEnd, double rateEndInterp) { LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE.with(lastDayOfMonth()), 300); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of( Curves.prices("GB-RPIX"), DoubleArray.of(4, 5, 16, 17), DoubleArray.of(rateStart, rateStartInterp, rateEnd, rateEndInterp), INTERPOLATOR); return ImmutableRatesProvider.builder(VAL_DATE) .priceIndexCurve(GB_RPIX, curve) .timeSeries(GB_RPIX, timeSeries) .build(); }
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_of_badCurve() { InterpolatedNodalCurve notYearFraction = InterpolatedNodalCurve.of( Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); InterpolatedNodalCurve notZeroRate = InterpolatedNodalCurve.of( Curves.discountFactors(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata noDayCountMetadata = DefaultCurveMetadata.builder() .curveName(NAME) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.ZERO_RATE) .build(); InterpolatedNodalCurve notDayCount = InterpolatedNodalCurve.of( noDayCountMetadata, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); assertThrowsIllegalArg(() -> ZeroRateDiscountFactors.of(GBP, DATE_VAL, notYearFraction)); assertThrowsIllegalArg(() -> ZeroRateDiscountFactors.of(GBP, DATE_VAL, notZeroRate)); assertThrowsIllegalArg(() -> ZeroRateDiscountFactors.of(GBP, DATE_VAL, notDayCount)); }
public void test_of_badCurve() { InterpolatedNodalCurve notYearFraction = InterpolatedNodalCurve.of( Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); InterpolatedNodalCurve notDiscountFactor = InterpolatedNodalCurve.of( Curves.zeroRates(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); CurveMetadata noDayCountMetadata = DefaultCurveMetadata.builder() .curveName(NAME) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.DISCOUNT_FACTOR) .build(); InterpolatedNodalCurve notDayCount = InterpolatedNodalCurve.of( noDayCountMetadata, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); assertThrowsIllegalArg(() -> SimpleDiscountFactors.of(GBP, DATE_VAL, notYearFraction)); assertThrowsIllegalArg(() -> SimpleDiscountFactors.of(GBP, DATE_VAL, notDiscountFactor)); assertThrowsIllegalArg(() -> SimpleDiscountFactors.of(GBP, DATE_VAL, notDayCount)); }
public void test_of_badCurve() { InterpolatedNodalCurve notYearFraction = InterpolatedNodalCurve.of( Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR); InterpolatedNodalCurve notZeroRate = InterpolatedNodalCurve.of( Curves.discountFactors(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR);