FloatingAnnuityDefinitionBuilder extends AbstractAnnuityDefinitionBuilder<FloatingAnnuityDefinitionBuilder> { public static Pair<Double, Double> getInterpolationWeights(ZonedDateTime accrualStartDate, ZonedDateTime accrualEndDate, ZonedDateTime firstInterpolatedDate, ZonedDateTime secondInterpolatedDate) { ArgumentChecker.isTrue(!accrualEndDate.isBefore(firstInterpolatedDate), "First interpolated date {} should be before or equal to the accrual end date {}", firstInterpolatedDate, accrualEndDate); ArgumentChecker.isTrue(!accrualEndDate.isAfter(secondInterpolatedDate), "Second interpolated date {} should be equal to or after the accrual end date {}", secondInterpolatedDate, accrualEndDate); ArgumentChecker.isTrue(firstInterpolatedDate.isBefore(secondInterpolatedDate), "First interpolated date {} should be strictly before the second interpolated date {}", firstInterpolatedDate, secondInterpolatedDate); double daysToPeriodEnd = accrualEndDate.toLocalDate().toEpochDay() - accrualStartDate.toLocalDate().toEpochDay(); double daysToFirstInterpolatedRateDate = firstInterpolatedDate.toLocalDate().toEpochDay() - accrualStartDate.toLocalDate().toEpochDay(); double daysToSecondInterpolatedRateDate = secondInterpolatedDate.toLocalDate().toEpochDay() - accrualStartDate.toLocalDate().toEpochDay(); double weightDenominator = daysToSecondInterpolatedRateDate - daysToFirstInterpolatedRateDate; double weightFirstIndex = (daysToSecondInterpolatedRateDate - daysToPeriodEnd) / weightDenominator; double weightSecondIndex = (daysToPeriodEnd - daysToFirstInterpolatedRateDate) / weightDenominator; return Pairs.of(weightFirstIndex, weightSecondIndex); }  FloatingAnnuityDefinitionBuilder initialRate(double initialRate); FloatingAnnuityDefinitionBuilder spread(double spread); FloatingAnnuityDefinitionBuilder gearing(double gearing); FloatingAnnuityDefinitionBuilder index(IndexDeposit index); FloatingAnnuityDefinitionBuilder resetDateAdjustmentParameters(AdjustedDateParameters resetDateAdjustmentParameters); FloatingAnnuityDefinitionBuilder resetRelativeTo(DateRelativeTo resetRelativeTo); FloatingAnnuityDefinitionBuilder fixingDateAdjustmentParameters(OffsetAdjustedDateParameters fixingDateAdjustmentParameters); @Override AnnuityDefinition<?> build(); static Pair<Double, Double> getInterpolationWeights(ZonedDateTime accrualStartDate, 
      ZonedDateTime accrualEndDate, ZonedDateTime firstInterpolatedDate, ZonedDateTime secondInterpolatedDate);  }
@Test public void stub_interpolation_weights(){ double toleranceWeight = 1.0E-8; ZonedDateTime accrualStartDate = DateUtils.getUTCDate(2015, 7, 4); ZonedDateTime accrualEndDate = DateUtils.getUTCDate(2015, 11, 27); ZonedDateTime firstInterpolatedDate = DateUtils.getUTCDate(2015, 10, 6); ZonedDateTime secondInterpolatedDate = DateUtils.getUTCDate(2016, 1, 6); Pair<Double, Double> weights = FloatingAnnuityDefinitionBuilder .getInterpolationWeights(accrualStartDate, accrualEndDate, firstInterpolatedDate, secondInterpolatedDate); double weight1Expected = ((double)(secondInterpolatedDate.toLocalDate().toEpochDay() - accrualEndDate.toLocalDate().toEpochDay())) / (secondInterpolatedDate.toLocalDate().toEpochDay() - firstInterpolatedDate.toLocalDate().toEpochDay()); double weight2Expected = ((double)(accrualEndDate.toLocalDate().toEpochDay() - firstInterpolatedDate.toLocalDate().toEpochDay())) / (secondInterpolatedDate.toLocalDate().toEpochDay() - firstInterpolatedDate.toLocalDate().toEpochDay()); assertEquals("Stub Interpolation Weights", weight1Expected, weights.getFirst(), toleranceWeight); assertEquals("Stub Interpolation Weights", weight2Expected, weights.getSecond(), toleranceWeight); }