public void test_builder_ensureDefaults() { IborRateCalculation test = IborRateCalculation.builder() .index(GBP_LIBOR_3M) .build(); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getResetPeriods(), Optional.empty()); assertEquals(test.getFixingRelativeTo(), PERIOD_START); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_3M.getFixingDateOffset()); assertEquals(test.getNegativeRateMethod(), ALLOW_NEGATIVE); assertEquals(test.getFirstRegularRate(), OptionalDouble.empty()); assertEquals(test.getInitialStub(), Optional.empty()); assertEquals(test.getFinalStub(), Optional.empty()); assertEquals(test.getGearing(), Optional.empty()); assertEquals(test.getSpread(), Optional.empty()); }
public void test_of() { IborRateCalculation test = IborRateCalculation.of(GBP_LIBOR_3M); assertEquals(test.getType(), SwapLegType.IBOR); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getResetPeriods(), Optional.empty()); assertEquals(test.getFixingRelativeTo(), PERIOD_START); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_3M.getFixingDateOffset()); assertEquals(test.getNegativeRateMethod(), ALLOW_NEGATIVE); assertEquals(test.getFirstRegularRate(), OptionalDouble.empty()); assertEquals(test.getInitialStub(), Optional.empty()); assertEquals(test.getFinalStub(), Optional.empty()); assertEquals(test.getGearing(), Optional.empty()); assertEquals(test.getSpread(), Optional.empty()); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(IborRateCalculation beanToCopy) { this.dayCount = beanToCopy.getDayCount(); this.index = beanToCopy.getIndex(); this.resetPeriods = beanToCopy.resetPeriods; this.fixingRelativeTo = beanToCopy.getFixingRelativeTo(); this.fixingDateOffset = beanToCopy.getFixingDateOffset(); this.negativeRateMethod = beanToCopy.getNegativeRateMethod(); this.firstRegularRate = beanToCopy.firstRegularRate; this.firstRate = beanToCopy.firstRate; this.firstFixingDateOffset = beanToCopy.firstFixingDateOffset; this.initialStub = beanToCopy.initialStub; this.finalStub = beanToCopy.finalStub; this.gearing = beanToCopy.gearing; this.spread = beanToCopy.spread; }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { builder.add(index); getInitialStub().ifPresent(stub -> stub.collectIndices(builder)); getFinalStub().ifPresent(stub -> stub.collectIndices(builder)); }
/** * Obtains a rate calculation for the specified index. * <p> * The calculation will use the day count and fixing offset of the index. * All optional fields will be set to their default values. * Thus, fixing will be in advance, with no spread, gearing or reset periods. * If this method provides insufficient control, use the {@linkplain #builder() builder}. * * @param index the index * @return the calculation */ public static IborRateCalculation of(IborIndex index) { return IborRateCalculation.builder().index(index).build(); }
public void test_expand_singlePeriod_stubCalcsInitialStub_interpolated() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_2M) .fixingDateOffset(MINUS_TWO_DAYS) .initialStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_1W, GBP_LIBOR_1M)) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB) .yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)) .rateComputation(IborInterpolatedRateComputation.of(GBP_LIBOR_1W, GBP_LIBOR_1M, DATE_01_06, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(SINGLE_ACCRUAL_SCHEDULE_STUB, SINGLE_ACCRUAL_SCHEDULE_STUB, REF_DATA); assertEquals(periods, ImmutableList.of(rap1)); }
public void test_collectIndices_simple() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_1M) .fixingDateOffset(MINUS_TWO_DAYS) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_1M)); }
/** * Creates a standard cap from start date, end date and strike. * * @param startDate the start date * @param endDate the end date * @param strike the strike * @return the cap */ public default IborCapFloorLeg createCap(LocalDate startDate, LocalDate endDate, double strike) { IborIndex index = getIndex(); return IborCapFloorLeg.builder() .calculation(IborRateCalculation.of(index)) .capSchedule(ValueSchedule.of(strike)) .currency(index.getCurrency()) .notional(ValueSchedule.ALWAYS_1) .paymentSchedule( PeriodicSchedule.of( startDate, endDate, Frequency.of(index.getTenor().getPeriod()), BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, index.getFixingCalendar()), StubConvention.NONE, RollConventions.NONE)) .payReceive(PayReceive.RECEIVE) .build(); }
public void test_resolve_cap() { IborRateCalculation rateCalc = IborRateCalculation.builder() .index(EUR_EURIBOR_3M) .fixingRelativeTo(FixingRelativeTo.PERIOD_END) .paymentDate(PAYMENT_OFFSET.adjust(end, REF_DATA)) .notional(NOTIONALS[i]) .iborRate(IborRateComputation.of(EUR_EURIBOR_3M, rateCalc.getFixingDateOffset().adjust(end, REF_DATA), REF_DATA)) .yearFraction(yearFraction) .build();
String gearing = calc.getGearing().map(g -> " * " + SummarizerUtils.value(g.getInitialValue())).orElse(""); String spread = calc.getSpread().map(s -> " + " + SummarizerUtils.percent(s.getInitialValue())).orElse(""); return calc.getIndex().getName() + gearing + spread;
/** * Gets the Ibor index. * <p> * The rate to be paid is based on this index * It will be a well known market index such as 'GBP-LIBOR-3M'. * * @return the Ibor index */ public IborIndex getIndex() { return calculation.getIndex(); }
LocalDate end = BUSS_ADJ.adjust(unadjustedDates[i + 1], REF_DATA); double yearFraction = EUR_EURIBOR_3M.getDayCount().relativeYearFraction(start, end); LocalDate fixingDate = RATE_CALCULATION.getFixingDateOffset().adjust(start, REF_DATA); periods[i] = IborCapletFloorletPeriod.builder() .floorlet(STRIKES[i])
public void test_builder_noIndex() { assertThrowsIllegalArg(() -> IborRateCalculation.builder().build()); }
public void test_expand_simple() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_1M) .fixingDateOffset(MINUS_TWO_DAYS) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_01_02, REF_DATA)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2) .yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_02_03, REF_DATA)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3) .yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)) .rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_03_03, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
switch (propertyName.hashCode()) { case 1905311443: // dayCount return ((IborRateCalculation) bean).getDayCount(); case 100346066: // index return ((IborRateCalculation) bean).getIndex(); case -1272973693: // resetPeriods return ((IborRateCalculation) bean).resetPeriods; case 232554996: // fixingRelativeTo return ((IborRateCalculation) bean).getFixingRelativeTo(); case 873743726: // fixingDateOffset return ((IborRateCalculation) bean).getFixingDateOffset(); case 1969081334: // negativeRateMethod return ((IborRateCalculation) bean).getNegativeRateMethod(); case 570227148: // firstRegularRate return ((IborRateCalculation) bean).firstRegularRate;
public void test_collectIndices_stubCalcsTwoStubs() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_1M) .fixingDateOffset(MINUS_TWO_DAYS) .initialStub(IborRateStubCalculation.ofIborRate(GBP_LIBOR_1W)) .finalStub(IborRateStubCalculation.ofIborRate(GBP_LIBOR_3M)) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_1M, GBP_LIBOR_1W, GBP_LIBOR_3M)); }
public void test_createCap() { SurfaceIborCapletFloorletVolatilityBootstrapDefinition base = SurfaceIborCapletFloorletVolatilityBootstrapDefinition.of( NAME, USD_LIBOR_3M, ACT_ACT_ISDA, TIME_SQUARE, DOUBLE_QUADRATIC); LocalDate startDate = LocalDate.of(2012, 4, 20); LocalDate endDate = LocalDate.of(2017, 4, 20); double strike = 0.01; IborCapFloorLeg expected = IborCapFloorLeg.builder() .calculation(IborRateCalculation.of(USD_LIBOR_3M)) .capSchedule(ValueSchedule.of(strike)) .currency(USD_LIBOR_3M.getCurrency()) .notional(ValueSchedule.ALWAYS_1) .paymentDateOffset(DaysAdjustment.NONE) .paymentSchedule( PeriodicSchedule.of( startDate, endDate, Frequency.of(USD_LIBOR_3M.getTenor().getPeriod()), BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.getFixingCalendar()), StubConvention.NONE, RollConventions.NONE)) .payReceive(PayReceive.RECEIVE) .build(); IborCapFloorLeg computed = base.createCap(startDate, endDate, strike); assertEquals(computed, expected); }
@Override public void collectCurrencies(ImmutableSet.Builder<Currency> builder) { builder.add(index.getCurrency()); getInitialStub().ifPresent(stub -> stub.collectCurrencies(builder)); getFinalStub().ifPresent(stub -> stub.collectCurrencies(builder)); }
/** * Returns the set of indices referred to by the cap/floor. * <p> * A cap/floor will typically refer to one index, such as 'GBP-LIBOR-3M'. * Calling this method will return the complete list of indices. * * @return the set of indices referred to by this cap/floor */ public ImmutableSet<Index> allIndices() { ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); builder.add(capFloorLeg.getCalculation().getIndex()); if (payLeg != null) { payLeg.collectIndices(builder); } return builder.build(); }
public void test_builder_ensureOptionalDouble() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_3M) .fixingDateOffset(MINUS_TWO_DAYS) .firstRegularRate(0.028d) .build(); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getResetPeriods(), Optional.empty()); assertEquals(test.getFixingRelativeTo(), PERIOD_START); assertEquals(test.getFixingDateOffset(), MINUS_TWO_DAYS); assertEquals(test.getNegativeRateMethod(), ALLOW_NEGATIVE); assertEquals(test.getFirstRegularRate(), OptionalDouble.of(0.028d)); assertEquals(test.getInitialStub(), Optional.empty()); assertEquals(test.getFinalStub(), Optional.empty()); assertEquals(test.getGearing(), Optional.empty()); assertEquals(test.getSpread(), Optional.empty()); }