/** * Parses a string, handling different types of index. * <p> * This tries a number of ways to parse the input: * <ul> * <li>{@link IborIndex#of(String)} * <li>{@link OvernightIndex#of(String)} * <li>{@link PriceIndex#of(String)} * <li>{@link FloatingRateName#of(String)} * </ul> * If {@code FloatingRateName} is used to match an Ibor index, then a tenor is needed * to return an index. The tenor from {@link FloatingRateName#getDefaultTenor()} will be used. * * @param indexStr the index string to parse * @return the floating rate * @throws IllegalArgumentException if the name is not known */ public static FloatingRateIndex parse(String indexStr) { return parse(indexStr, null); }
public void test_parse_noTenor() { assertEquals(FloatingRateIndex.parse("GBP-LIBOR"), IborIndices.GBP_LIBOR_3M); assertEquals(FloatingRateIndex.parse("GBP-LIBOR-1M"), IborIndices.GBP_LIBOR_1M); assertEquals(FloatingRateIndex.parse("GBP-LIBOR-3M"), IborIndices.GBP_LIBOR_3M); assertEquals(FloatingRateIndex.parse("GBP-SONIA"), OvernightIndices.GBP_SONIA); assertEquals(FloatingRateIndex.parse("GB-RPI"), PriceIndices.GB_RPI); assertThrowsIllegalArg(() -> FloatingRateIndex.parse(null)); assertThrowsIllegalArg(() -> FloatingRateIndex.parse("NotAnIndex")); }
public void test_parse_withTenor() { assertEquals(FloatingRateIndex.parse("GBP-LIBOR", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_6M); assertEquals(FloatingRateIndex.parse("GBP-LIBOR-1M", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_1M); assertEquals(FloatingRateIndex.parse("GBP-LIBOR-3M", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_3M); assertEquals(FloatingRateIndex.parse("GBP-SONIA", Tenor.TENOR_6M), OvernightIndices.GBP_SONIA); assertEquals(FloatingRateIndex.parse("GB-RPI", Tenor.TENOR_6M), PriceIndices.GB_RPI); assertThrowsIllegalArg(() -> FloatingRateIndex.parse(null, Tenor.TENOR_6M)); assertThrowsIllegalArg(() -> FloatingRateIndex.parse("NotAnIndex", Tenor.TENOR_6M)); }
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(); }