/** * 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()); } }
/** * 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()); } }
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); }