//-------------------------------------------------------------------------
        // 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());
        }
Exemple #2
0
 // Converts an FpML 'fixedRateSchedule' to a {@code RateCalculation}.
 private RateCalculation parseFixed(XmlElement legEl, XmlElement calcEl, XmlElement fixedEl, FpmlDocument document)
 {
     // supported elements:
     //  'calculationPeriodAmount/calculation/fixedRateSchedule'
     //  'calculationPeriodAmount/calculation/dayCountFraction'
     //  'stubCalculationPeriodAmount'
     // rejected elements:
     //  'resetDates'
     //  'stubCalculationPeriodAmount/initialStub/floatingRate'
     //  'stubCalculationPeriodAmount/finalStub/floatingRate'
     document.validateNotPresent(legEl, "resetDates");
     FixedRateCalculation.Builder fixedRateBuilder = FixedRateCalculation.builder();
     fixedRateBuilder.rate(parseSchedule(fixedEl, document));
     fixedRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction")));
     // stub
     legEl.findChild("stubCalculationPeriodAmount").ifPresent(stubsEl =>
     {
         stubsEl.findChild("initialStub").ifPresent(el =>
         {
             fixedRateBuilder.initialStub(parseStubCalculationForFixed(el, document));
         });
         stubsEl.findChild("finalStub").ifPresent(el =>
         {
             fixedRateBuilder.finalStub(parseStubCalculationForFixed(el, document));
         });
     });
     return(fixedRateBuilder.build());
 }