@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.index != null) { if (builder.dayCount == null) { builder.dayCount = builder.index.getDayCount(); } if (builder.fixingDateOffset == null) { builder.fixingDateOffset = builder.index.getFixingDateOffset(); } if (builder.currency == null) { builder.currency = builder.index.getCurrency(); } } }
/** * Gets the business day adjustment to apply to accrual schedule dates, * providing a default result if no override specified. * <p> * Each date in the calculated schedule is determined without taking into account weekends and holidays. * The adjustment specified here is used to convert those dates to valid business days. * The start date and end date have their own business day adjustment rules. * <p> * This will default to 'ModifiedFollowing' using the index fixing calendar if not specified. * * @return the business day adjustment, not null */ public BusinessDayAdjustment getAccrualBusinessDayAdjustment() { return accrualBusinessDayAdjustment != null ? accrualBusinessDayAdjustment : BusinessDayAdjustment.of(MODIFIED_FOLLOWING, index.getFixingCalendar()); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.index != null) { if (builder.dayCount == null) { builder.dayCount = builder.index.getDayCount(); } if (builder.fixingDateOffset == null) { builder.fixingDateOffset = builder.index.getFixingDateOffset(); } } }
@Override public Set<Tenor> getTenors() { if (!type.isIbor()) { return ImmutableSet.of(); } return IborIndex.extendedEnum().lookupAll().values().stream() .filter(index -> index.getName().startsWith(indexName)) .filter(index -> index.isActive()) .map(index -> index.getTenor()) .sorted() .collect(toImmutableSet()); }
public void test_dkk_cibor() { IborIndex test = IborIndex.of("DKK-CIBOR-3M"); assertEquals(test.getCurrency(), DKK); assertEquals(test.getName(), "DKK-CIBOR-3M"); assertEquals(test.getTenor(), TENOR_3M); assertEquals(test.getFixingCalendar(), DKCO); assertEquals(test.getFixingDateOffset(), DaysAdjustment.ofBusinessDays(-2, DKCO)); assertEquals(test.getEffectiveDateOffset(), DaysAdjustment.ofBusinessDays(2, DKCO)); assertEquals(test.getMaturityDateOffset(), TenorAdjustment.of(TENOR_3M, PeriodAdditionConventions.NONE, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, DKCO))); assertEquals(test.getDayCount(), ACT_360); assertEquals(test.getDefaultFixedLegDayCount(), THIRTY_U_360); assertEquals(test.toString(), "DKK-CIBOR-3M"); }
public void test_tibor_euroyen3m_dates() { IborIndex test = IborIndex.of("JPY-TIBOR-EUROYEN-3M"); assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 27), REF_DATA), date(2014, 10, 29)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 27), REF_DATA), date(2015, 1, 29)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 29), REF_DATA), date(2014, 10, 27)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 29), REF_DATA), date(2015, 1, 29)); // weekend assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 10), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 10), REF_DATA), date(2015, 1, 15)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 15), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 15), REF_DATA), date(2015, 1, 15)); // input date is Sunday assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 12), REF_DATA), date(2014, 10, 16)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 12), REF_DATA), date(2015, 1, 16)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 12), REF_DATA), date(2014, 10, 9)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 12), REF_DATA), date(2015, 1, 14)); // fixing time and zone assertEquals(test.calculateFixingDateTime(date(2014, 10, 13)), date(2014, 10, 13).atTime(LocalTime.of(11, 50)).atZone(ZoneId.of("Asia/Tokyo"))); }
public void test_of_indexOnly() { ImmutableIborFixingDepositConvention test = ImmutableIborFixingDepositConvention.of(GBP_LIBOR_6M); assertEquals(test.getBusinessDayAdjustment(), BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBP_LIBOR_6M.getFixingCalendar())); assertEquals(test.getCurrency(), GBP_LIBOR_6M.getCurrency()); assertEquals(test.getDayCount(), GBP_LIBOR_6M.getDayCount()); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_6M.getFixingDateOffset()); assertEquals(test.getIndex(), GBP_LIBOR_6M); assertEquals(test.getSpotDateOffset(), GBP_LIBOR_6M.getEffectiveDateOffset()); }
/** * 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(); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.index != null) { if (builder.accrualFactor == 0d && builder.index.getTenor().isMonthBased()) { builder.accrualFactor(builder.index.getTenor().getPeriod().toTotalMonths() / 12d); } if (builder.currency == null) { builder.currency = builder.index.getCurrency(); } } }
public void test_builder_minSpecified() { ImmutableFraConvention test = ImmutableFraConvention.builder() .index(GBP_LIBOR_3M) .build(); assertEquals(test.getName(), GBP_LIBOR_3M.getName()); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getCurrency(), GBP); assertEquals(test.getSpotDateOffset(), GBP_LIBOR_3M.getEffectiveDateOffset()); assertEquals(test.getBusinessDayAdjustment(), BDA_MOD_FOLLOW); assertEquals(test.getPaymentDateOffset(), DaysAdjustment.NONE); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_3M.getFixingDateOffset()); assertEquals(test.getDayCount(), GBP_LIBOR_3M.getDayCount()); assertEquals(test.getDiscounting(), ISDA); }
/** * Gets the currency of the Ibor index. * * @return the currency of the index */ public Currency getCurrency() { return index.getCurrency(); }
private static SwapLeg iborLeg( LocalDate start, LocalDate end, IborIndex index, PayReceive payReceive, NotionalSchedule notional, StubConvention stubConvention) { Frequency freq = Frequency.of(index.getTenor().getPeriod()); return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(freq) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(freq) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(IborRateCalculation.builder() .index(index) .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, index.getFixingCalendar(), BDA_P)) .build()) .build(); }
/** * Creates an instance from an index and fixing date. * <p> * The reference data is used to find the maturity date from the fixing date. * * @param index the index * @param fixingDate the fixing date * @param refData the reference data to use when resolving holiday calendars * @return the rate observation */ public static IborIndexObservation of( IborIndex index, LocalDate fixingDate, ReferenceData refData) { LocalDate effectiveDate = index.calculateEffectiveFromFixing(fixingDate, refData); LocalDate maturityDate = index.calculateMaturityFromEffective(effectiveDate, refData); double yearFraction = index.getDayCount().yearFraction(effectiveDate, maturityDate); return new IborIndexObservation(index, fixingDate, effectiveDate, maturityDate, yearFraction); }
public void test_of_index() { ImmutableFraConvention test = ImmutableFraConvention.of(GBP_LIBOR_3M); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getName(), GBP_LIBOR_3M.getName()); assertEquals(test.getCurrency(), GBP); assertEquals(test.getSpotDateOffset(), GBP_LIBOR_3M.getEffectiveDateOffset()); assertEquals(test.getBusinessDayAdjustment(), BDA_MOD_FOLLOW); assertEquals(test.getPaymentDateOffset(), DaysAdjustment.NONE); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_3M.getFixingDateOffset()); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getDiscounting(), ISDA); // ensure other factories match assertEquals(FraConvention.of(GBP_LIBOR_3M), test); assertEquals(FraConventions.of(GBP_LIBOR_3M), test); }
private static Currency parseCurrency(CsvRow row, CurveName reference) { Optional<String> currencyStr = row.findValue(CURRENCY_HEADER); if (currencyStr.isPresent()) { return LoaderUtils.parseCurrency(currencyStr.get()); } String referenceStr = reference.getName().toUpperCase(Locale.ENGLISH); try { Optional<IborIndex> ibor = IborIndex.extendedEnum().find(referenceStr); if (ibor.isPresent()) { return ibor.get().getCurrency(); } else { Optional<FloatingRateName> frName = FloatingRateName.extendedEnum().find(referenceStr); if (frName.isPresent()) { return frName.get().getCurrency(); } else if (referenceStr.length() == 3) { return Currency.of(referenceStr); } else if (referenceStr.length() > 3 && referenceStr.charAt(3) == '-' || referenceStr.charAt(3) == '_') { return LoaderUtils.parseCurrency(referenceStr.substring(0, 3)); } else { // drop out to exception } } } catch (RuntimeException ex) { // drop out to exception } throw new IllegalArgumentException("Unable to parse currency from reference, consider adding a 'Currency' column"); }
/** * Gets the offset of the spot value date from the trade date, * providing a default result if no override specified. * <p> * The offset is applied to the trade date and is typically plus 2 business days. * The start and end date of the FRA term are relative to the spot date. * <p> * This will default to the effective date offset of the index if not specified. * * @return the spot date offset, not null */ @Override public DaysAdjustment getSpotDateOffset() { return spotDateOffset != null ? spotDateOffset : index.getEffectiveDateOffset(); }
public void test_getFloatingRateName() { for (IborIndex index : IborIndex.extendedEnum().lookupAll().values()) { String name = index.getName().substring(0, index.getName().lastIndexOf('-')); assertEquals(index.getFloatingRateName(), FloatingRateName.of(name)); } }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.index != null) { if (builder.name == null && builder.dateSequence != null) { builder.name = builder.index.getName() + "-" + builder.dateSequence.getName(); } if (builder.businessDayAdjustment == null) { builder.businessDayAdjustment = BusinessDayAdjustment.of( FOLLOWING, builder.index.getEffectiveDateOffset().getCalendar()); } } }
/** * Gets the day count convention applicable, * providing a default result if no override specified. * <p> * This is used to convert dates to a numerical value. * The data model permits the day count to differ from that of the index, * however the two are typically the same. * <p> * This will default to the day count of the index if not specified. * * @return the day count, not null */ public DayCount getDayCount() { return dayCount != null ? dayCount : index.getDayCount(); }