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