private static RateCalculation parseOvernightRateCalculation( CsvRow row, String leg, OvernightIndex overnightIndex, OvernightAccrualMethod accrualMethod) { OvernightRateCalculation.Builder builder = OvernightRateCalculation.builder(); // basics builder.index(overnightIndex); builder.accrualMethod(findValue(row, leg, ACCRUAL_METHOD_FIELD) .map(s -> OvernightAccrualMethod.of(s)) .orElse(accrualMethod)); // optionals findValue(row, leg, DAY_COUNT_FIELD) .map(s -> LoaderUtils.parseDayCount(s)) .ifPresent(v -> builder.dayCount(v)); findValue(row, leg, RATE_CUT_OFF_DAYS_FIELD) .map(s -> Integer.valueOf(s)) .ifPresent(v -> builder.rateCutOffDays(v)); findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s -> NegativeRateMethod.of(s)) .ifPresent(v -> builder.negativeRateMethod(v)); findValue(row, leg, GEARING_FIELD) .map(s -> LoaderUtils.parseDouble(s)) .ifPresent(v -> builder.gearing(ValueSchedule.of(v))); findValue(row, leg, SPREAD_FIELD) .map(s -> LoaderUtils.parseDoublePercent(s)) .ifPresent(v -> builder.spread(ValueSchedule.of(v))); return builder.build(); }
throw new FpmlParseException("Invalid 'rateCutOffDaysOffset' value, expected days-based period: " + cutOff); overnightRateBuilder.rateCutOffDays(-cutOff.getDays()); }); });
public void test_expand_rateCutOffDays_threeAccrualsInPaymentPeriod() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_SONIA) .rateCutOffDays(2) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_01_06, DATE_02_05, 0, REF_DATA)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2) .yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_02_05, DATE_03_05, 0, REF_DATA)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3) .yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_03_05, DATE_04_07, 2, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, PAYMENT_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
.index(USD_FED_FUND) .accrualMethod(OvernightAccrualMethod.AVERAGED) .rateCutOffDays(0) // Should be 2, put to 0 for comparison .spread(ValueSchedule.of(0.0025)) .build())
.dayCount(getDayCount()) .accrualMethod(getAccrualMethod()) .rateCutOffDays(getRateCutOffDays()) .spread(spread != 0 ? ValueSchedule.of(spread) : null) .build())
.accrualMethod(AVERAGED) .negativeRateMethod(NOT_NEGATIVE) .rateCutOffDays(2) .gearing(ValueSchedule.of(1d, ValueStep.of(2, ValueAdjustment.ofReplace(2d)))) .spread(ValueSchedule.of(0d, ValueStep.of(1, ValueAdjustment.ofReplace(-0.025d))))
public void test_expand_rateCutOffDays_accrualIsPaymentPeriod() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_SONIA) .rateCutOffDays(2) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_01_06, DATE_02_05, 2, REF_DATA)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2) .yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_02_05, DATE_03_05, 2, REF_DATA)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3) .yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_03_05, DATE_04_07, 2, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
public void coverage() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_SONIA) .build(); coverImmutableBean(test); OvernightRateCalculation test2 = OvernightRateCalculation.builder() .dayCount(ACT_360) .index(USD_FED_FUND) .accrualMethod(AVERAGED) .negativeRateMethod(NOT_NEGATIVE) .rateCutOffDays(2) .gearing(ValueSchedule.of(2d)) .spread(ValueSchedule.of(-0.025d)) .build(); coverBeanEquals(test, test2); }