@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1770633379: // underlying return ((InflationNodalCurve) bean).getUnderlying(); case -857898080: // seasonality return ((InflationNodalCurve) bean).getSeasonality(); case -1002343865: // adjustmentType return ((InflationNodalCurve) bean).getAdjustmentType(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public NodalCurve curve(LocalDate valuationDate, CurveMetadata metadata, DoubleArray parameters) { NodalCurve curveWithoutFixing = curveWithoutFixingDefinition.curve(valuationDate, metadata, parameters); return InflationNodalCurve.of( curveWithoutFixing, valuationDate, lastFixingMonth, lastFixingValue, seasonalityDefinition); }
@Override public InflationNodalCurve build() { return new InflationNodalCurve( underlying, seasonality, adjustmentType); }
public void of_construction_multiplicative_2() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); assertEquals(curveComputed.getUnderlying().getXValues().get(0), NB_MONTHS_2, TOLERANCE_TIME); assertEquals(curveComputed.getUnderlying().getYValues().get(0), LAST_FIX_VALUE, TOLERANCE_TIME); assertEquals(curveComputed.yValue(NB_MONTHS_2), LAST_FIX_VALUE, TOLERANCE_TIME); }
public void parameter_sensitivity_additive() { InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF); double shift = 1.0E-2; for (int i = 1; i < TEST_MONTHS.length; i++) { double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS); UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths); for (int j = 0; j < TIMES.size(); j++) { double[] valuePM = new double[2]; for (int pm = 0; pm < 2; pm++) { DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift); InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR); InflationNodalCurve seaCurveShifted = InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF); valuePM[pm] = seaCurveShifted.yValue(nbMonths); } assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA); } } }
public void value_multiplicative() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); for (int i = 1; i < TEST_MONTHS.length; i++) { double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS); double valueComputed = curveComputed.yValue(nbMonths); int x = (int) ((nbMonths + 12) % 12); double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths); double adj = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x); double valueExpected = valueNoAdj * adj; assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE); } }
public void test_value_parameter_sensitivity() { for (int i = 0; i < TEST_MONTHS.length; i++) { YearMonth fixingMonth = TEST_OBS[i].getFixingMonth(); if (!USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d); CurrencyParameterSensitivities psComputed = INSTANCE.parameterSensitivity(ptsExpected); double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS); UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL.yValueParameterSensitivity(x)); CurrencyParameterSensitivities psExpected = sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity()); assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i); } } }
public void test_value() { for (int i = 0; i < TEST_MONTHS.length; i++) { double valueComputed = INSTANCE.value(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].getFixingMonth(); double valueExpected; if (USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble(); } else { double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS); valueExpected = CURVE_INFL.yValue(x); } assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i); } }
@Override public double yValue(double x) { int i = seasonalityIndex(x); double adjustment = seasonality.get(i); return adjustmentType.applyShift(underlying.yValue(x), adjustment); }
public void of_construction_multiplicative_1() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_1, LAST_FIX_MONTH_1, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); assertEquals(curveComputed.getUnderlying().getXValues().get(0), NB_MONTHS_1, TOLERANCE_TIME); assertEquals(curveComputed.getUnderlying().getYValues().get(0), LAST_FIX_VALUE, TOLERANCE_TIME); assertEquals(curveComputed.yValue(NB_MONTHS_1), LAST_FIX_VALUE, TOLERANCE_TIME); }
public void parameter_sensitivity_multiplicative() { InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); double shift = 1.0E-2; for (int i = 1; i < TEST_MONTHS.length; i++) { double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS); UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths); for (int j = 0; j < TIMES.size(); j++) { double[] valuePM = new double[2]; for (int pm = 0; pm < 2; pm++) { DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift); InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR); InflationNodalCurve seaCurveShifted = InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); valuePM[pm] = seaCurveShifted.yValue(nbMonths); } assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA); } } }
public void value_additive() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF); for (int i = 1; i < TEST_MONTHS.length; i++) { double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS); double valueComputed = curveComputed.yValue(nbMonths); int x = (int) ((nbMonths + 12) % 12); double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths); DoubleArray seasonalityAdditiveCompounded = seasonalityCompounded(VAL_DATE_2, LAST_FIX_MONTH_2, SEASONALITY_ADDITIVE, (v, a) -> v + a); double adj = seasonalityAdditiveCompounded.get(x); double valueExpected = valueNoAdj + adj; assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE); } }
public void test_value_parameter_sensitivity_futfixing() { for (int i = 0; i < TEST_MONTHS.length; i++) { YearMonth fixingMonth = TEST_OBS[i].getFixingMonth(); if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d); CurrencyParameterSensitivities psComputed = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected); double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS); UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x)); CurrencyParameterSensitivities psExpected = sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity()); assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i); } } }
public void test_value_futfixing() { for (int i = 0; i < TEST_MONTHS.length; i++) { double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].getFixingMonth(); double valueExpected; if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble(); } else { double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS); valueExpected = CURVE_INFL2.yValue(x); } assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i); } }
@Override public UnitParameterSensitivity yValueParameterSensitivity(double x) { int i = seasonalityIndex(x); double adjustment = seasonality.get(i); double derivativeFactor = 0d; if (adjustmentType.equals(ShiftType.ABSOLUTE)) { derivativeFactor = 1d; } else if (adjustmentType.equals(ShiftType.SCALED)) { derivativeFactor = adjustment; } else { throw new IllegalArgumentException("ShiftType " + adjustmentType + " is not supported for sensitivities"); } // remove the first point from the underlying sensitivity UnitParameterSensitivity u = underlying.yValueParameterSensitivity(x); UnitParameterSensitivity u2 = UnitParameterSensitivity.of( u.getMarketDataName(), u.getParameterMetadata().subList(1, u.getParameterMetadata().size()), u.getSensitivity().subArray(1)); return u2.multipliedBy(derivativeFactor); }
public void of_construction_additive_1() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_1, LAST_FIX_MONTH_1, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF); assertEquals(curveComputed.getUnderlying().getXValues().get(0), NB_MONTHS_1, TOLERANCE_TIME); assertEquals(curveComputed.getUnderlying().getYValues().get(0), LAST_FIX_VALUE, TOLERANCE_TIME); assertEquals(curveComputed.yValue(NB_MONTHS_1), LAST_FIX_VALUE, TOLERANCE_TIME); }
public void coverage() { InflationNodalCurve test = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_1, LAST_FIX_MONTH_1, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); coverImmutableBean(test); InflationNodalCurve test2 = InflationNodalCurve .of(CURVE2_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE + 1.0d, SEASONALITY_ADDITIVE_DEF); coverBeanEquals(test, test2); }
private Object readResolve() { return new InflationNodalCurve(underlying, seasonality, adjustmentType); }
@ImmutableConstructor private InflationNodalCurve( NodalCurve curve, DoubleArray seasonality, ShiftType adjustmentType) { this.underlying = curve; this.seasonality = seasonality; this.xFixing = curve.getXValues().get(0); this.yFixing = curve.getYValues().get(0); int i = seasonalityIndex(xFixing); ArgChecker.isTrue( adjustmentType.applyShift(yFixing, seasonality.get(i)) - yFixing < 1.0E-10, "Fixing value should be unadjusted"); this.adjustmentType = adjustmentType; }
public void test_serialization() { InflationNodalCurve test = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_1, LAST_FIX_MONTH_1, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); assertSerialization(test); }