// Converts an FpML 'InflationRateCalculation' to a {@code RateCalculation}. private RateCalculation parseInflation(XmlElement legEl, XmlElement calcEl, XmlElement inflationEl, PeriodicSchedule accrualSchedule, FpmlDocument document) { // supported elements: // 'calculationPeriodAmount/calculation/inflationRateCalculation' // 'calculationPeriodAmount/calculation/inflationRateCalculation/floatingRateIndex' // 'calculationPeriodAmount/calculation/inflationRateCalculation/indexTenor?' // 'calculationPeriodAmount/calculation/inflationRateCalculation/floatingRateMultiplierSchedule?' // 'calculationPeriodAmount/calculation/inflationRateCalculation/inflationLag' // 'calculationPeriodAmount/calculation/inflationRateCalculation/interpolationMethod' // 'calculationPeriodAmount/calculation/inflationRateCalculation/initialIndexLevel?' // 'calculationPeriodAmount/calculation/dayCountFraction' // ignored elements: // 'calculationPeriodAmount/calculation/inflationRateCalculation/indexSource' // 'calculationPeriodAmount/calculation/inflationRateCalculation/mainPublication' // 'calculationPeriodAmount/calculation/inflationRateCalculation/fallbackBondApplicable' // 'calculationPeriodAmount/calculation/floatingRateCalculation/initialRate?' // 'calculationPeriodAmount/calculation/floatingRateCalculation/finalRateRounding?' // 'calculationPeriodAmount/calculation/floatingRateCalculation/averagingMethod?' // 'calculationPeriodAmount/calculation/floatingRateCalculation/negativeInterestRateTreatment?' // 'resetDates' // rejected elements: // 'calculationPeriodAmount/calculation/floatingRateCalculation/spreadSchedule*' // 'calculationPeriodAmount/calculation/floatingRateCalculation/rateTreatment?' // 'calculationPeriodAmount/calculation/floatingRateCalculation/capRateSchedule?' // 'calculationPeriodAmount/calculation/floatingRateCalculation/floorRateSchedule?' // 'stubCalculationPeriodAmount' document.validateNotPresent(inflationEl, "spreadSchedule"); document.validateNotPresent(inflationEl, "rateTreatment"); document.validateNotPresent(inflationEl, "capRateSchedule"); document.validateNotPresent(inflationEl, "floorRateSchedule"); document.validateNotPresent(legEl, "stubCalculationPeriodAmount"); // TODO: parse fixed stub rate InflationRateCalculation.Builder builder = InflationRateCalculation.builder(); // index builder.index(document.parsePriceIndex(inflationEl)); // lag builder.lag(document.parsePeriod(inflationEl.getChild("inflationLag"))); // interpolation string interpStr = inflationEl.getChild("interpolationMethod").Content; builder.indexCalculationMethod(interpStr.ToLower(Locale.ENGLISH).Contains("linear") ? PriceIndexCalculationMethod.INTERPOLATED : PriceIndexCalculationMethod.MONTHLY); // initial index inflationEl.findChild("initialIndexLevel").ifPresent(el => { builder.firstIndexValue(document.parseDecimal(el)); }); // gearing inflationEl.findChild("floatingRateMultiplierSchedule").ifPresent(el => { builder.gearing(parseSchedule(el, document)); }); return(builder.build()); }
//------------------------------------------------------------------------- // inflation rate calculation private static RateCalculation parseInflationRateCalculation(CsvRow row, string leg, PriceIndex priceIndex, Currency currency) { InflationRateCalculation.Builder builder = InflationRateCalculation.builder(); // basics builder.index(priceIndex); builder.lag(parseInflationLag(findValue(row, leg, INFLATION_LAG_FIELD), currency)); builder.indexCalculationMethod(parseInflationMethod(findValue(row, leg, INFLATION_METHOD_FIELD), currency)); // optionals findValue(row, leg, INFLATION_FIRST_INDEX_VALUE_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.firstIndexValue(v)); findValue(row, leg, GEARING_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.gearing(ValueSchedule.of(v))); return(builder.build()); }