/** * 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); }
/** * Gets the currency of the floating rate. * * @return the currency * @throws IllegalArgumentException if unable to return an index, which should * only happen if the system is not configured correctly */ public default Currency getCurrency() { return toFloatingRateIndex().getCurrency(); }
/** * 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 index, empty if not found */ public static Optional<FloatingRateIndex> tryParse(String indexStr) { return tryParse(indexStr, null); }
/** * Gets the default day count convention for the associated fixed leg. * <p> * A rate index is often paid against a fixed leg, such as in a vanilla Swap. * The day count convention of the fixed leg often differs from that of the index, * and the default is value is available here. * * @return the day count convention */ public default DayCount getDefaultFixedLegDayCount() { return getDayCount(); }
/** * Finds the forward curve names for the specified floating rate name. * <p> * If the curve name is not found, optional empty is returned. * * @param forwardName the floating rate name to find a forward curve name for * @return the set of curve names */ public ImmutableSet<CurveName> findForwardCurveNames(FloatingRateName forwardName) { ImmutableSet.Builder<CurveName> result = ImmutableSet.builder(); FloatingRateName normalized = forwardName.normalized(); for (RatesCurveGroupEntry entry : entries) { for (Index index : entry.getIndices()) { if (index instanceof FloatingRateIndex) { FloatingRateName frName = ((FloatingRateIndex) index).getFloatingRateName(); if (frName.equals(normalized)) { result.add(entry.getCurveName()); break; } } } } return result.build(); }
indices.add(index); if (index != null) { dayCounts.add(index.getDefaultFixedLegDayCount());
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")); }
/** * Parses a string, handling different types of index, optionally specifying a tenor for Ibor. * <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 can optionally be supplied. If needed and missing, * the result of {@link FloatingRateName#getDefaultTenor()} will be used. * * @param indexStr the index string to parse * @param defaultIborTenor the tenor to use for Ibor if matched as a {@code FloatingRateName}, may be null * @return the floating rate * @throws IllegalArgumentException if the name is not known */ public static FloatingRateIndex parse(String indexStr, Tenor defaultIborTenor) { ArgChecker.notNull(indexStr, "indexStr"); return tryParse(indexStr, defaultIborTenor) .orElseThrow(() -> new IllegalArgumentException("Floating rate index not known: " + indexStr)); }
@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()); }
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)); }
public void test_tryParse_noTenor() { assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR"), Optional.of(IborIndices.GBP_LIBOR_3M)); assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-1M"), Optional.of(IborIndices.GBP_LIBOR_1M)); assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-3M"), Optional.of(IborIndices.GBP_LIBOR_3M)); assertEquals(FloatingRateIndex.tryParse("GBP-SONIA"), Optional.of(OvernightIndices.GBP_SONIA)); assertEquals(FloatingRateIndex.tryParse("GB-RPI"), Optional.of(PriceIndices.GB_RPI)); assertEquals(FloatingRateIndex.tryParse(null), Optional.empty()); assertEquals(FloatingRateIndex.tryParse("NotAnIndex"), Optional.empty()); }
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(); }
public void test_tryParse_withTenor() { assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR", Tenor.TENOR_6M), Optional.of(IborIndices.GBP_LIBOR_6M)); assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-1M", Tenor.TENOR_6M), Optional.of(IborIndices.GBP_LIBOR_1M)); assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-3M", Tenor.TENOR_6M), Optional.of(IborIndices.GBP_LIBOR_3M)); assertEquals(FloatingRateIndex.tryParse("GBP-SONIA", Tenor.TENOR_6M), Optional.of(OvernightIndices.GBP_SONIA)); assertEquals(FloatingRateIndex.tryParse("GB-RPI", Tenor.TENOR_6M), Optional.of(PriceIndices.GB_RPI)); assertEquals(FloatingRateIndex.tryParse(null, Tenor.TENOR_6M), Optional.empty()); assertEquals(FloatingRateIndex.tryParse("NotAnIndex", Tenor.TENOR_6M), Optional.empty()); }
/** * Tries to parse a string, with extended handling of indices. * <p> * This tries a number of ways to parse the input: * <ul> * <li>{@link FloatingRateName#of(String)} * <li>{@link IborIndex#of(String)} * <li>{@link OvernightIndex#of(String)} * <li>{@link PriceIndex#of(String)} * </ul> * Note that if an {@link IborIndex} is parsed, the tenor will be lost. * * @param str the string to parse * @return the floating rate, empty if not found */ public static Optional<FloatingRateName> tryParse(String str) { Optional<FloatingRateName> frnOpt = FloatingRateName.extendedEnum().find(str); if (frnOpt.isPresent()) { return frnOpt; } return FloatingRateIndex.tryParse(str).map(FloatingRateIndex::getFloatingRateName); }