private RateComputation createRateComputation(SchedulePeriod period, int scheduleIndex) { // handle where index value at start date is known LocalDate endDate = period.getEndDate(); if (firstIndexValue != null && scheduleIndex == 0) { return createRateComputation(endDate); } YearMonth referenceStartMonth = YearMonth.from(period.getStartDate().minus(lag)); YearMonth referenceEndMonth = YearMonth.from(endDate.minus(lag)); if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED)) { // interpolate between data from two different months double weight = 1d - (endDate.getDayOfMonth() - 1d) / endDate.lengthOfMonth(); return InflationInterpolatedRateComputation.of(index, referenceStartMonth, referenceEndMonth, weight); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { // no interpolation return InflationMonthlyRateComputation.of(index, referenceStartMonth, referenceEndMonth); } else { throw new IllegalArgumentException( "PriceIndexCalculationMethod " + indexCalculationMethod.toString() + " is not supported"); } }