switch (getType()) { case IBOR: { Set<Tenor> tenors = getTenors();
/** * Returns a floating rate index. * <p> * Returns a {@link FloatingRateIndex} for this rate name. * Only Ibor, Overnight and Price indices are handled. * If the rate name is an Ibor rate, the specified tenor is used. * * @param iborTenor the tenor to use if this rate is Ibor * @return the index * @throws IllegalArgumentException if unable to return an index, which should * only happen if the system is not configured correctly */ public default FloatingRateIndex toFloatingRateIndex(Tenor iborTenor) { switch (getType()) { case IBOR: return toIborIndex(iborTenor); case OVERNIGHT_COMPOUNDED: case OVERNIGHT_AVERAGED: return toOvernightIndex(); case PRICE: return toPriceIndex(); default: throw new IllegalArgumentException("Floating rate index type not known: " + getType()); } }
/** * Returns a floating rate index. * <p> * Returns a {@link FloatingRateIndex} for this rate name. * Only Ibor, Overnight and Price indices are handled. * If the rate name is an Ibor rate, the {@linkplain #getDefaultTenor() default tenor} is used. * * @return the index * @throws IllegalArgumentException if unable to return an index, which should * only happen if the system is not configured correctly */ public default FloatingRateIndex toFloatingRateIndex() { // code copied to avoid calling getDefaultTenor() unless necessary switch (getType()) { case IBOR: return toIborIndex(getDefaultTenor()); case OVERNIGHT_COMPOUNDED: case OVERNIGHT_AVERAGED: return toOvernightIndex(); case PRICE: return toPriceIndex(); default: throw new IllegalArgumentException("Floating rate index type not known: " + getType()); } }
private static FloatingRateIndex parseIndex(CsvRow row, String leg) { Optional<String> fixedRateOpt = findValue(row, leg, FIXED_RATE_FIELD); Optional<String> indexOpt = findValue(row, leg, INDEX_FIELD); if (fixedRateOpt.isPresent()) { if (indexOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must not define both '" + leg + FIXED_RATE_FIELD + "' and '" + leg + INDEX_FIELD + "'"); } return null; } if (!indexOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must define either '" + leg + FIXED_RATE_FIELD + "' or '" + leg + INDEX_FIELD + "'"); } // use FloatingRateName to identify Ibor vs other String indexStr = indexOpt.get(); FloatingRateName frn = FloatingRateName.parse(indexStr); if (frn.getType() == FloatingRateType.IBOR) { // re-parse Ibor using tenor, which ensures tenor picked up from indexStr if present Frequency freq = Frequency.parse(getValue(row, leg, FREQUENCY_FIELD)); Tenor iborTenor = freq.isTerm() ? frn.getDefaultTenor() : Tenor.of(freq.getPeriod()); return FloatingRateIndex.parse(indexStr, iborTenor); } return frn.toFloatingRateIndex(); }
@Test(dataProvider = "nameType") public void test_name(String name, String indexName, FloatingRateType type) { FloatingRateName test = FloatingRateName.of(name); assertEquals(test.getName(), name); assertEquals(test.getType(), type); assertEquals(test.getCurrency(), test.toFloatingRateIndex().getCurrency()); }
private static RateCalculation parseRateCalculation( CsvRow row, String leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount, BusinessDayAdjustment bda, Currency currency) { if (index instanceof IborIndex) { return parseIborRateCalculation(row, leg, (IborIndex) index, bda, currency); } else if (index instanceof OvernightIndex) { Optional<FloatingRateName> frnOpt = FloatingRateName.extendedEnum().find(getValue(row, leg, INDEX_FIELD)); if (frnOpt.isPresent()) { FloatingRateName frn = frnOpt.get(); if (frn.getType() == FloatingRateType.OVERNIGHT_AVERAGED) { return parseOvernightRateCalculation(row, leg, (OvernightIndex) index, OvernightAccrualMethod.AVERAGED); } } return parseOvernightRateCalculation(row, leg, (OvernightIndex) index, OvernightAccrualMethod.COMPOUNDED); } else if (index instanceof PriceIndex) { return parseInflationRateCalculation(row, leg, (PriceIndex) index, currency); } else { return parseFixedRateCalculation(row, leg, currency, defaultFixedLegDayCount); } }
if (idx.getType() == FloatingRateType.OVERNIGHT_COMPOUNDED) { overnightRateBuilder.accrualMethod(OvernightAccrualMethod.COMPOUNDED);