private UnitParameterSensitivities unitParameterSensitivity(YearMonth month) { // If fixing in the past, check time series and returns the historic month price index if present if (month.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(month.atEndOfMonth()).HasValue) { return(UnitParameterSensitivities.empty()); } } double nbMonth = numberOfMonths(month); return(UnitParameterSensitivities.of(curve.yValueParameterSensitivity(nbMonth))); }
//------------------------------------------------------------------------- public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) { YearMonth fixingMonth = observation.FixingMonth; // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(fixingMonth.atEndOfMonth()).HasValue) { return(PointSensitivityBuilder.none()); } } return(InflationRateSensitivity.of(observation, 1d)); }
public virtual void test_value_parameter_sensitivity_futfixing() { for (int i = 0; i < TEST_MONTHS.Length; i++) { YearMonth fixingMonth = TEST_OBS[i].FixingMonth; 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.Currency, ptsExpected.Sensitivity); assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i); } } }
public virtual void test_value_pts_sensitivity_futfixing() { for (int i = 0; i < TEST_MONTHS.Length; i++) { PointSensitivityBuilder ptsComputed = INSTANCE_WITH_FUTFIXING.valuePointSensitivity(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].FixingMonth; PointSensitivityBuilder ptsExpected; if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { ptsExpected = PointSensitivityBuilder.none(); } else { ptsExpected = InflationRateSensitivity.of(TEST_OBS[i], 1d); } assertTrue(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE), "test " + i); } }
//------------------------------------------------------------------------- public double value(PriceIndexObservation observation) { YearMonth fixingMonth = observation.FixingMonth; // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { double?fixing = fixings.get(fixingMonth.atEndOfMonth()); if (fixing.HasValue) { return(fixing.Value); } } // otherwise, return the estimate from the curve. double nbMonth = numberOfMonths(fixingMonth); return(curve.yValue(nbMonth)); }
/* Test values when a fixing in the futures in present in the TS. */ public virtual 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].FixingMonth; double valueExpected; if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).Value; } else { double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS); valueExpected = CURVE_INFL2.yValue(x); } assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i); } }
/// <summary> /// Obtains an instance from a curve without initial fixing point and month-on-month seasonal adjustment. /// <para> /// The total adjustment is computed by accumulation of the monthly adjustment, starting with no adjustment for the /// last fixing month. /// /// </para> /// </summary> /// <param name="curveWithoutFixing"> the curve without the fixing </param> /// <param name="valuationDate"> the valuation date of the curve </param> /// <param name="lastMonth"> the last month for which the fixing is known </param> /// <param name="lastFixingValue"> the value of the last fixing </param> /// <param name="seasonalityDefinition"> the seasonality definition, which is made of month-on-month adjustment /// and the adjustment type </param> /// <returns> the seasonal curve instance </returns> public static InflationNodalCurve of(NodalCurve curveWithoutFixing, LocalDate valuationDate, YearMonth lastMonth, double lastFixingValue, SeasonalityDefinition seasonalityDefinition) { YearMonth valuationMonth = YearMonth.from(valuationDate); ArgChecker.isTrue(lastMonth.isBefore(valuationMonth), "Last fixing month must be before valuation date"); double nbMonth = valuationMonth.until(lastMonth, MONTHS); DoubleArray x = curveWithoutFixing.XValues; ArgChecker.isTrue(nbMonth < x.get(0), "The first estimation month should be after the last known index fixing"); NodalCurve extendedCurve = curveWithoutFixing.withNode(nbMonth, lastFixingValue, ParameterMetadata.empty()); double[] seasonalityCompoundedArray = new double[12]; int lastMonthIndex = lastMonth.Month.Value - 1; seasonalityCompoundedArray[(int)((nbMonth + 12 + 1) % 12)] = seasonalityDefinition.SeasonalityMonthOnMonth.get(lastMonthIndex % 12); for (int i = 1; i < 12; i++) { int j = (int)((nbMonth + 12 + 1 + i) % 12); seasonalityCompoundedArray[j] = seasonalityDefinition.AdjustmentType.applyShift(seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonalityDefinition.SeasonalityMonthOnMonth.get((lastMonthIndex + i) % 12)); } return(new InflationNodalCurve(extendedCurve, DoubleArray.ofUnsafe(seasonalityCompoundedArray), seasonalityDefinition.AdjustmentType)); }