/// <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)); }