// an Ibor stub private static Optional <IborRateStubCalculation> parseIborStub(CsvRow row, string leg, Currency currency, IborRateCalculation.Builder builder, string rateField, string amountField, string indexField, string interpolatedField) { double?stubRateOpt = findValue(row, leg, rateField).map(s => LoaderUtils.parseDoublePercent(s)); double?stubAmountOpt = findValue(row, leg, amountField).map(s => LoaderUtils.parseDouble(s)); Optional <IborIndex> stubIndexOpt = findValue(row, leg, indexField).map(s => IborIndex.of(s)); Optional <IborIndex> stubIndex2Opt = findValue(row, leg, interpolatedField).map(s => IborIndex.of(s)); if (stubRateOpt.HasValue && !stubAmountOpt.HasValue && !stubIndexOpt.Present && !stubIndex2Opt.Present) { return(IborRateStubCalculation.ofFixedRate(stubRateOpt.Value)); } else if (!stubRateOpt.HasValue && stubAmountOpt.HasValue && !stubIndexOpt.Present && !stubIndex2Opt.Present) { return(IborRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, stubAmountOpt.Value))); } else if (!stubRateOpt.HasValue && !stubAmountOpt.HasValue && stubIndexOpt.Present) { if (stubIndex2Opt.Present) { return(IborRateStubCalculation.ofIborInterpolatedRate(stubIndexOpt.get(), stubIndex2Opt.get())); } else { return(IborRateStubCalculation.ofIborRate(stubIndexOpt.get())); } } else if (stubRateOpt.HasValue || stubAmountOpt.HasValue || stubIndexOpt.Present || stubIndex2Opt.Present) { throw new System.ArgumentException("Swap leg must define only one of the following fields " + ImmutableList.of(leg + rateField, leg + amountField, leg + indexField) + ", and '" + leg + interpolatedField + "' is only allowed with '" + leg + indexField + "'"); } return(null); }
// Converts an FpML 'StubValue' to a {@code IborRateStubCalculation}. private IborRateStubCalculation parseStubCalculation(XmlElement baseEl, FpmlDocument document) { Optional <XmlElement> rateOptEl = baseEl.findChild("stubRate"); if (rateOptEl.Present) { return(IborRateStubCalculation.ofFixedRate(document.parseDecimal(rateOptEl.get()))); } Optional <XmlElement> amountOptEl = baseEl.findChild("stubAmount"); if (amountOptEl.Present) { return(IborRateStubCalculation.ofKnownAmount(document.parseCurrencyAmount(amountOptEl.get()))); } IList <XmlElement> indicesEls = baseEl.getChildren("floatingRate"); if (indicesEls.Count == 1) { XmlElement indexEl = indicesEls[0]; document.validateNotPresent(indexEl, "floatingRateMultiplierSchedule"); document.validateNotPresent(indexEl, "spreadSchedule"); document.validateNotPresent(indexEl, "rateTreatment"); document.validateNotPresent(indexEl, "capRateSchedule"); document.validateNotPresent(indexEl, "floorRateSchedule"); return(IborRateStubCalculation.ofIborRate((IborIndex)document.parseIndex(indexEl))); } else if (indicesEls.Count == 2) { XmlElement index1El = indicesEls[0]; document.validateNotPresent(index1El, "floatingRateMultiplierSchedule"); document.validateNotPresent(index1El, "spreadSchedule"); document.validateNotPresent(index1El, "rateTreatment"); document.validateNotPresent(index1El, "capRateSchedule"); document.validateNotPresent(index1El, "floorRateSchedule"); XmlElement index2El = indicesEls[1]; document.validateNotPresent(index2El, "floatingRateMultiplierSchedule"); document.validateNotPresent(index2El, "spreadSchedule"); document.validateNotPresent(index2El, "rateTreatment"); document.validateNotPresent(index2El, "capRateSchedule"); document.validateNotPresent(index2El, "floorRateSchedule"); return(IborRateStubCalculation.ofIborInterpolatedRate((IborIndex)document.parseIndex(index1El), (IborIndex)document.parseIndex(index2El))); } throw new FpmlParseException("Unknown stub structure: " + baseEl); }