}); overnightRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction"))); overnightRateBuilder.index((OvernightIndex) document.parseIndex(floatingEl)); overnightRateBuilder.accrualMethod(OvernightAccrualMethod.COMPOUNDED); overnightRateBuilder.gearing(parseSchedule(el, document)); }); overnightRateBuilder.spread(parseSchedule(el, document)); }); overnightRateBuilder.negativeRateMethod(parseNegativeInterestRateTreatment(el)); }); throw new FpmlParseException("Invalid 'rateCutOffDaysOffset' value, expected days-based period: " + cutOff); overnightRateBuilder.rateCutOffDays(-cutOff.getDays()); }); }); return overnightRateBuilder.build(); } else { throw new FpmlParseException("Invalid 'floatingRateIndex' type, not Ibor or Overnight");
.notionalSchedule(NOTIONAL) .calculation(OvernightRateCalculation.builder() .dayCount(ACT_360) .index(USD_FED_FUND) .accrualMethod(OvernightAccrualMethod.AVERAGED) .rateCutOffDays(0) // Should be 2, put to 0 for comparison .spread(ValueSchedule.of(0.0025)) .build()) .build();
.notionalSchedule(NotionalSchedule.of(getCurrency(), notional)) .calculation(OvernightRateCalculation.builder() .index(index) .dayCount(getDayCount()) .accrualMethod(getAccrualMethod()) .rateCutOffDays(getRateCutOffDays()) .spread(spread != 0 ? ValueSchedule.of(spread) : null) .build()) .build();
public void test_toLeg_withSpread() { OvernightRateSwapLegConvention base = OvernightRateSwapLegConvention.builder() .index(GBP_SONIA) .accrualMethod(AVERAGED) .build(); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .frequency(TERM) .startDate(startDate) .endDate(endDate) .businessDayAdjustment(BDA_MOD_FOLLOW) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(OvernightRateCalculation.builder() .index(GBP_SONIA) .accrualMethod(AVERAGED) .spread(ValueSchedule.of(0.25d)) .build()) .build(); assertEquals(test, expected); }
public void test_expand_gearingSpreadEverythingElse() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_SONIA) .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)))) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE))
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(); }
@SuppressWarnings("deprecation") public void test_expand_tomNext() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_360) .index(CHF_TOIS) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(ACCRUAL1.yearFraction(ACT_360, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_01_06, DATE_02_05, 0, REF_DATA)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2) .yearFraction(ACCRUAL2.yearFraction(ACT_360, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_02_05, DATE_03_05, 0, REF_DATA)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3) .yearFraction(ACCRUAL3.yearFraction(ACT_360, ACCRUAL_SCHEDULE)) .rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_03_05, DATE_04_07, 0, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
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)); }
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 test_expand_simple() { OvernightRateCalculation test = OvernightRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_SONIA) .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, 0, 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); }
/** * Obtains a rate calculation for the specified index with accrual by compounding. * <p> * The calculation will use the day count of the index. * All optional fields will be set to their default values. * Thus, there will be no spread, gearing or rate cut-off. * If this method provides insufficient control, use the {@linkplain #builder() builder}. * * @param index the index * @return the calculation */ public static OvernightRateCalculation of(OvernightIndex index) { return OvernightRateCalculation.builder().index(index).build(); }
public void test_builder_noIndex() { assertThrowsIllegalArg(() -> OvernightRateCalculation.builder().build()); }
@ImmutableDefaults private static void applyDefaults(Builder builder) { builder.accrualMethod(OvernightAccrualMethod.COMPOUNDED); builder.negativeRateMethod(NegativeRateMethod.ALLOW_NEGATIVE); }
public void test_builder_ensureDefaults() { OvernightRateCalculation test = OvernightRateCalculation.builder() .index(GBP_SONIA) .build(); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getIndex(), GBP_SONIA); assertEquals(test.getAccrualMethod(), COMPOUNDED); assertEquals(test.getNegativeRateMethod(), ALLOW_NEGATIVE); assertEquals(test.getRateCutOffDays(), 0); assertEquals(test.getGearing(), Optional.empty()); assertEquals(test.getSpread(), Optional.empty()); }