//-------------------------------------------------------------------------
        // ibor rate calculation
        private static RateCalculation parseIborRateCalculation(CsvRow row, string leg, IborIndex iborIndex, BusinessDayAdjustment bda, Currency currency)
        {
            IborRateCalculation.Builder builder = IborRateCalculation.builder();
            // basics
            builder.index(iborIndex);
            // reset
            Optional <Frequency>  resetFrequencyOpt = findValue(row, leg, RESET_FREQUENCY_FIELD).map(v => Frequency.parse(v));
            IborRateResetMethod   resetMethod       = findValue(row, leg, RESET_METHOD_FIELD).map(v => IborRateResetMethod.of(v)).orElse(IborRateResetMethod.WEIGHTED);
            BusinessDayAdjustment resetDateAdj      = parseBusinessDayAdjustment(row, leg, RESET_DATE_CNV_FIELD, RESET_DATE_CAL_FIELD).orElse(bda);

            resetFrequencyOpt.ifPresent(freq => builder.resetPeriods(ResetSchedule.builder().resetFrequency(freq).resetMethod(resetMethod).businessDayAdjustment(resetDateAdj).build()));
            // optionals, no ability to set firstFixingDateOffset
            findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).ifPresent(v => builder.dayCount(v));
            findValue(row, leg, FIXING_RELATIVE_TO_FIELD).map(s => FixingRelativeTo.of(s)).ifPresent(v => builder.fixingRelativeTo(v));
            Optional <DaysAdjustment> fixingAdjOpt = parseDaysAdjustment(row, leg, FIXING_OFFSET_DAYS_FIELD, FIXING_OFFSET_CAL_FIELD, FIXING_OFFSET_ADJ_CNV_FIELD, FIXING_OFFSET_ADJ_CAL_FIELD);

            fixingAdjOpt.ifPresent(v => builder.fixingDateOffset(v));
            findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s => NegativeRateMethod.of(s)).ifPresent(v => builder.negativeRateMethod(v));
            findValue(row, leg, FIRST_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)).ifPresent(v => builder.firstRate(v));
            findValue(row, leg, GEARING_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.gearing(ValueSchedule.of(v)));
            findValue(row, leg, SPREAD_FIELD).map(s => LoaderUtils.parseDoublePercent(s)).ifPresent(v => builder.spread(ValueSchedule.of(v)));
            // initial stub
            Optional <IborRateStubCalculation> initialStub = parseIborStub(row, leg, currency, builder, INITIAL_STUB_RATE_FIELD, INITIAL_STUB_AMOUNT_FIELD, INITIAL_STUB_INDEX_FIELD, INITIAL_STUB_INTERPOLATED_INDEX_FIELD);

            initialStub.ifPresent(stub => builder.initialStub(stub));
            // final stub
            Optional <IborRateStubCalculation> finalStub = parseIborStub(row, leg, currency, builder, FINAL_STUB_RATE_FIELD, FINAL_STUB_AMOUNT_FIELD, FINAL_STUB_INDEX_FIELD, FINAL_STUB_INTERPOLATED_INDEX_FIELD);

            finalStub.ifPresent(stub => builder.finalStub(stub));
            return(builder.build());
        }
예제 #2
0
        // Converts an FpML 'FloatingRateCalculation' to a {@code RateCalculation}.
        private RateCalculation parseFloat(XmlElement legEl, XmlElement calcEl, XmlElement floatingEl, PeriodicSchedule accrualSchedule, FpmlDocument document)
        {
            // supported elements:
            //  'calculationPeriodAmount/calculation/floatingRateCalculation'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/floatingRateIndex'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/indexTenor?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/floatingRateMultiplierSchedule?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/spreadSchedule*'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/initialRate?' (Ibor only)
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/averagingMethod?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/negativeInterestRateTreatment?'
            //  'calculationPeriodAmount/calculation/dayCountFraction'
            //  'resetDates/resetRelativeTo'
            //  'resetDates/fixingDates'
            //  'resetDates/rateCutOffDaysOffset' (OIS only)
            //  'resetDates/resetFrequency'
            //  'resetDates/resetDatesAdjustments'
            //  'stubCalculationPeriodAmount/initalStub' (Ibor only, Overnight must match index)
            //  'stubCalculationPeriodAmount/finalStub' (Ibor only, Overnight must match index)
            // ignored elements:
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/finalRateRounding?'
            //  'calculationPeriodAmount/calculation/discounting?'
            //  'resetDates/calculationPeriodDatesReference'
            // rejected elements:
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/spreadSchedule/type?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/rateTreatment?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/capRateSchedule?'
            //  'calculationPeriodAmount/calculation/floatingRateCalculation/floorRateSchedule?'
            //  'resetDates/initialFixingDate'
            document.validateNotPresent(floatingEl, "rateTreatment");
            document.validateNotPresent(floatingEl, "capRateSchedule");
            document.validateNotPresent(floatingEl, "floorRateSchedule");
            Index index = document.parseIndex(floatingEl);

            if (index is IborIndex)
            {
                IborRateCalculation.Builder iborRateBuilder = IborRateCalculation.builder();
                // day count
                iborRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction")));
                // index
                iborRateBuilder.index((IborIndex)document.parseIndex(floatingEl));
                // gearing
                floatingEl.findChild("floatingRateMultiplierSchedule").ifPresent(el =>
                {
                    iborRateBuilder.gearing(parseSchedule(el, document));
                });
                // spread
                if (floatingEl.getChildren("spreadSchedule").size() > 1)
                {
                    throw new FpmlParseException("Only one 'spreadSchedule' is supported");
                }
                floatingEl.findChild("spreadSchedule").ifPresent(el =>
                {
                    document.validateNotPresent(el, "type");
                    iborRateBuilder.spread(parseSchedule(el, document));
                });
                // initial fixed rate
                floatingEl.findChild("initialRate").ifPresent(el =>
                {
                    iborRateBuilder.firstRegularRate(document.parseDecimal(el));
                });
                // negative rates
                floatingEl.findChild("negativeInterestRateTreatment").ifPresent(el =>
                {
                    iborRateBuilder.negativeRateMethod(parseNegativeInterestRateTreatment(el));
                });
                // resets
                legEl.findChild("resetDates").ifPresent(resetDatesEl =>
                {
                    document.validateNotPresent(resetDatesEl, "initialFixingDate");
                    document.validateNotPresent(resetDatesEl, "rateCutOffDaysOffset");
                    resetDatesEl.findChild("resetRelativeTo").ifPresent(el =>
                    {
                        iborRateBuilder.fixingRelativeTo(parseResetRelativeTo(el));
                    });
                    iborRateBuilder.fixingDateOffset(document.parseRelativeDateOffsetDays(resetDatesEl.getChild("fixingDates")));
                    Frequency resetFreq = document.parseFrequency(resetDatesEl.getChild("resetFrequency"));
                    if (!accrualSchedule.Frequency.Equals(resetFreq))
                    {
                        ResetSchedule.Builder resetScheduleBuilder = ResetSchedule.builder();
                        resetScheduleBuilder.resetFrequency(resetFreq);
                        floatingEl.findChild("averagingMethod").ifPresent(el =>
                        {
                            resetScheduleBuilder.resetMethod(parseAveragingMethod(el));
                        });
                        resetScheduleBuilder.businessDayAdjustment(document.parseBusinessDayAdjustments(resetDatesEl.getChild("resetDatesAdjustments")));
                        iborRateBuilder.resetPeriods(resetScheduleBuilder.build());
                    }
                });

                // stubs
                legEl.findChild("stubCalculationPeriodAmount").ifPresent(stubsEl =>
                {
                    stubsEl.findChild("initialStub").ifPresent(el =>
                    {
                        iborRateBuilder.initialStub(parseStubCalculation(el, document));
                    });
                    stubsEl.findChild("finalStub").ifPresent(el =>
                    {
                        iborRateBuilder.finalStub(parseStubCalculation(el, document));
                    });
                });
                return(iborRateBuilder.build());
            }
            else if (index is OvernightIndex)
            {
                OvernightRateCalculation.Builder overnightRateBuilder = OvernightRateCalculation.builder();
                document.validateNotPresent(floatingEl, "initialRate");   // TODO: should support this in the model
                // stubs
                legEl.findChild("stubCalculationPeriodAmount").ifPresent(stubsEl =>
                {
                    stubsEl.findChild("initialStub").ifPresent(el =>
                    {
                        checkStubForOvernightIndex(el, document, (OvernightIndex)index);
                    });
                    stubsEl.findChild("finalStub").ifPresent(el =>
                    {
                        checkStubForOvernightIndex(el, document, (OvernightIndex)index);
                    });
                });
                // day count
                overnightRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction")));
                // index
                overnightRateBuilder.index((OvernightIndex)document.parseIndex(floatingEl));
                // accrual method
                FloatingRateName idx = FloatingRateName.of(floatingEl.getChild("floatingRateIndex").Content);
                if (idx.Type == FloatingRateType.OVERNIGHT_COMPOUNDED)
                {
                    overnightRateBuilder.accrualMethod(OvernightAccrualMethod.COMPOUNDED);
                }
                // gearing
                floatingEl.findChild("floatingRateMultiplierSchedule").ifPresent(el =>
                {
                    overnightRateBuilder.gearing(parseSchedule(el, document));
                });
                // spread
                if (floatingEl.getChildren("spreadSchedule").size() > 1)
                {
                    throw new FpmlParseException("Only one 'spreadSchedule' is supported");
                }
                floatingEl.findChild("spreadSchedule").ifPresent(el =>
                {
                    document.validateNotPresent(el, "type");
                    overnightRateBuilder.spread(parseSchedule(el, document));
                });
                // negative rates
                floatingEl.findChild("negativeInterestRateTreatment").ifPresent(el =>
                {
                    overnightRateBuilder.negativeRateMethod(parseNegativeInterestRateTreatment(el));
                });
                // rate cut off
                legEl.findChild("resetDates").ifPresent(resetDatesEl =>
                {
                    document.validateNotPresent(resetDatesEl, "initialFixingDate");
                    resetDatesEl.findChild("rateCutOffDaysOffset").ifPresent(el =>
                    {
                        Period cutOff = document.parsePeriod(el);
                        if (cutOff.toTotalMonths() != 0)
                        {
                            throw new FpmlParseException("Invalid 'rateCutOffDaysOffset' value, expected days-based period: " + cutOff);
                        }
                        overnightRateBuilder.rateCutOffDays(-cutOff.Days);
                    });
                });
                return(overnightRateBuilder.build());
            }
            else
            {
                throw new FpmlParseException("Invalid 'floatingRateIndex' type, not Ibor or Overnight");
            }
        }