public void test_normalized() { assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").normalized(), FloatingRateName.of("GBP-LIBOR")); assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").normalized(), FloatingRateName.of("GBP-SONIA")); for (FloatingRateName name : FloatingRateName.extendedEnum().lookupAll().values()) { assertNotNull(name.normalized()); } }
public void test_tiee() { assertEquals(FloatingRateName.of("MXN-TIIE").getDefaultTenor(), Tenor.TENOR_13W); assertEquals(FloatingRateName.of("MXN-TIIE").toFloatingRateIndex(), IborIndices.MXN_TIIE_13W); assertEquals(FloatingRateName.of("MXN-TIIE").toFloatingRateIndex(Tenor.TENOR_4W), IborIndices.MXN_TIIE_4W); assertEquals(FloatingRateName.of("MXN-TIIE").toIborIndex(Tenor.TENOR_4W), IborIndices.MXN_TIIE_4W); assertEquals(FloatingRateName.of("MXN-TIIE").toIborIndexFixingOffset(), DaysAdjustment.ofBusinessDays(-1, MXMC)); }
/** * 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()); } }
/** * Checks and returns the fixing offset associated with the Ibor index. * <p> * If this name represents an Ibor index, then this method returns the associated fixing offset. * If not, an exception is thrown. * <p> * This method exists primarily to handle DKK CIBOR, where there are two floating rate names but * only one underlying index. The CIBOR index itself has a convention where the fixing date is 2 days * before the reset date and the effective date is 2 days after the fixing date, matching the name "DKK-CIBOR2-DKNA13". * The alternative name, "DKK-CIBOR-DKNA13", has the fixing date equal to the reset date, but with * the effective date two days later. * * @return the fixing offset applicable to the index * @throws IllegalStateException if the type is not an Ibor index type */ public default DaysAdjustment toIborIndexFixingOffset() { return toIborIndex(Iterables.getFirst(getTenors(), Tenor.TENOR_3M)).getFixingDateOffset(); }
public void test_priceIndex() { assertEquals(FloatingRateName.of("UK-HICP").getDefaultTenor(), Tenor.TENOR_1Y); assertEquals(FloatingRateName.of("UK-HICP").toFloatingRateIndex(), PriceIndices.GB_HICP); assertEquals(FloatingRateName.of("UK-HICP").toFloatingRateIndex(Tenor.TENOR_1M), PriceIndices.GB_HICP); assertEquals(FloatingRateName.of("UK-HICP").toPriceIndex(), PriceIndices.GB_HICP); assertThrows(() -> FloatingRateName.of("GBP-LIBOR-BBA").toPriceIndex(), IllegalStateException.class); assertEquals(FloatingRateName.of("UK-HICP").getTenors(), ImmutableSet.of()); assertThrows(() -> FloatingRateName.of("UK-HICP").toIborIndexFixingOffset(), IllegalStateException.class); }
public void test_overnightIndex() { assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").getDefaultTenor(), Tenor.TENOR_1D); assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").toFloatingRateIndex(), OvernightIndices.GBP_SONIA); assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").toFloatingRateIndex(Tenor.TENOR_1M), OvernightIndices.GBP_SONIA); assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").toOvernightIndex(), OvernightIndices.GBP_SONIA); assertEquals(FloatingRateNames.USD_FED_FUND.toOvernightIndex(), OvernightIndices.USD_FED_FUND); assertEquals(FloatingRateNames.USD_FED_FUND_AVG.toOvernightIndex(), OvernightIndices.USD_FED_FUND); assertThrows(() -> FloatingRateName.of("GBP-LIBOR-BBA").toOvernightIndex(), IllegalStateException.class); assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").getTenors(), ImmutableSet.of()); assertThrows(() -> FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").toIborIndexFixingOffset(), IllegalStateException.class); }
@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()); }
@Override public FloatingRateName getFloatingRateName() { return FloatingRateName.of(name); }
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(); }
/** * Converts an FpML 'FloatingRateIndex' with multiple tenors to an {@code Index}. * * @param baseEl the FpML floating rate index element to parse * @return the index * @throws RuntimeException if unable to parse */ public List<Index> parseIndexes(XmlElement baseEl) { XmlElement indexEl = baseEl.getChild("floatingRateIndex"); validateScheme(indexEl, "floatingRateIndexScheme", "http://www.fpml.org/coding-scheme/floating-rate-index"); FloatingRateName floatingName = FloatingRateName.of(indexEl.getContent()); List<XmlElement> tenorEls = baseEl.getChildren("indexTenor"); if (tenorEls.isEmpty()) { return ImmutableList.of(floatingName.toOvernightIndex()); } else { return tenorEls.stream() .map(el -> floatingName.toIborIndex(parseIndexTenor(el))) .collect(toImmutableList()); } }
return (Optional) priceOpt; Optional<FloatingRateName> frnOpt = FloatingRateName.extendedEnum().find(indexStr); if (frnOpt.isPresent()) { return frnOpt .map(frn -> frn.toFloatingRateIndex(defaultIborTenor != null ? defaultIborTenor : frn.getDefaultTenor()));
/** * Converts an FpML 'FloatingRateIndex.model' to a {@code PriceIndex}. * * @param baseEl the FpML floating rate model element to parse * @return the index * @throws RuntimeException if unable to parse */ public PriceIndex parsePriceIndex(XmlElement baseEl) { XmlElement indexEl = baseEl.getChild("floatingRateIndex"); validateScheme(indexEl, "floatingRateIndexScheme", "http://www.fpml.org/coding-scheme/inflation-index-description"); FloatingRateName floatingName = FloatingRateName.of(indexEl.getContent()); return floatingName.toPriceIndex(); }
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); } }
public void test_nzd() { assertEquals(FloatingRateName.of("NZD-BKBM").getCurrency(), Currency.NZD); assertEquals(FloatingRateName.of("NZD-NZIONA").getCurrency(), Currency.NZD); }
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"); }
public void test_defaultOvernightIndex() { assertEquals(FloatingRateName.defaultOvernightIndex(Currency.GBP), FloatingRateName.of("GBP-SONIA")); assertEquals(FloatingRateName.defaultOvernightIndex(Currency.EUR), FloatingRateName.of("EUR-EONIA")); assertEquals(FloatingRateName.defaultOvernightIndex(Currency.USD), FloatingRateName.of("USD-FED-FUND")); }
/** * 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); }
/** * 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(); }