//------------------------------------------------------------------------- // fixed rate calculation private static RateCalculation parseFixedRateCalculation(CsvRow row, string leg, Currency currency, DayCount defaultFixedLegDayCount) { FixedRateCalculation.Builder builder = FixedRateCalculation.builder(); // basics double fixedRate = LoaderUtils.parseDoublePercent(getValue(row, leg, FIXED_RATE_FIELD)); DayCount dayCount = findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).orElse(defaultFixedLegDayCount); if (dayCount == null) { throw new System.ArgumentException("Swap leg must define day count using '" + leg + DAY_COUNT_FIELD + "'"); } builder.dayCount(dayCount); builder.rate(ValueSchedule.of(fixedRate)); // initial stub double?initialStubRateOpt = findValue(row, leg, INITIAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)); double?initialStubAmountOpt = findValue(row, leg, INITIAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s)); if (initialStubRateOpt.HasValue && initialStubAmountOpt.HasValue) { throw new System.ArgumentException("Swap leg must not define both '" + leg + INITIAL_STUB_RATE_FIELD + "' and '" + leg + INITIAL_STUB_AMOUNT_FIELD + "'"); } initialStubRateOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofFixedRate(v))); initialStubAmountOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); // final stub double?finalStubRateOpt = findValue(row, leg, FINAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)); double?finalStubAmountOpt = findValue(row, leg, FINAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s)); if (finalStubRateOpt.HasValue && finalStubAmountOpt.HasValue) { throw new System.ArgumentException("Swap leg must not define both '" + leg + FINAL_STUB_RATE_FIELD + "' and '" + leg + FINAL_STUB_AMOUNT_FIELD + "'"); } finalStubRateOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofFixedRate(v))); finalStubAmountOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); return(builder.build()); }
//------------------------------------------------------------------------- // Converts an FpML 'StubValue' to a {@code FixedRateStubCalculation}. private FixedRateStubCalculation parseStubCalculationForFixed(XmlElement baseEl, FpmlDocument document) { Optional <XmlElement> rateOptEl = baseEl.findChild("stubRate"); if (rateOptEl.Present) { return(FixedRateStubCalculation.ofFixedRate(document.parseDecimal(rateOptEl.get()))); } Optional <XmlElement> amountOptEl = baseEl.findChild("stubAmount"); if (amountOptEl.Present) { return(FixedRateStubCalculation.ofKnownAmount(document.parseCurrencyAmount(amountOptEl.get()))); } throw new FpmlParseException("Invalid stub, fixed rate leg cannot have a floating rate stub"); }