Esempio n. 1
0
        // Converts an FpML 'NonNegativeAmountSchedule' to a {@code ValueStepSequence}.
        private ValueStepSequence parseAmountSchedule(XmlElement scheduleEl, double initialValue, FpmlDocument document)
        {
            Frequency             freq        = document.parseFrequency(scheduleEl.getChild("stepFrequency"));
            LocalDate             start       = document.parseDate(scheduleEl.getChild("firstNotionalStepDate"));
            LocalDate             end         = document.parseDate(scheduleEl.getChild("lastNotionalStepDate"));
            Optional <XmlElement> amountElOpt = scheduleEl.findChild("notionalStepAmount");

            if (amountElOpt.Present)
            {
                double amount = document.parseDecimal(amountElOpt.get());
                return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)));
            }
            double rate       = document.parseDecimal(scheduleEl.getChild("notionalStepRate"));
            string relativeTo = scheduleEl.findChild("stepRelativeTo").map(el => el.Content).orElse("Previous");

            if (relativeTo.Equals("Previous"))
            {
                return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaMultiplier(rate)));
            }
            else if (relativeTo.Equals("Initial"))
            {
                // data model does not support 'relative to initial' but can calculate amount here
                double amount = initialValue * rate;
                return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)));
            }
            else
            {
                throw new FpmlParseException(Messages.format("Unknown 'stepRelativeTo' value '{}', expected 'Initial' or 'Previous'", relativeTo));
            }
        }
Esempio n. 2
0
        // parses the notional schedule
        private NotionalSchedule parseSwapNotionalSchedule(XmlElement legEl, XmlElement calcEl, FpmlDocument document)
        {
            // supported elements:
            //  'principalExchanges/initialExchange'
            //  'principalExchanges/finalExchange'
            //  'principalExchanges/intermediateExchange'
            //  'calculationPeriodAmount/calculation/notionalSchedule/notionalStepSchedule'
            //  'calculationPeriodAmount/calculation/notionalSchedule/notionalStepParameters'
            NotionalSchedule.Builder notionalScheduleBuilder = NotionalSchedule.builder();
            // exchanges
            legEl.findChild("principalExchanges").ifPresent(el =>
            {
                notionalScheduleBuilder.initialExchange(bool.Parse(el.getChild("initialExchange").Content));
                notionalScheduleBuilder.intermediateExchange(bool.Parse(el.getChild("intermediateExchange").Content));
                notionalScheduleBuilder.finalExchange(bool.Parse(el.getChild("finalExchange").Content));
            });
            // notional schedule
            XmlElement            notionalEl         = calcEl.getChild("notionalSchedule");
            XmlElement            stepScheduleEl     = notionalEl.getChild("notionalStepSchedule");
            Optional <XmlElement> paramScheduleElOpt = notionalEl.findChild("notionalStepParameters");
            double            initialValue           = document.parseDecimal(stepScheduleEl.getChild("initialValue"));
            ValueStepSequence seq = paramScheduleElOpt.map(el => parseAmountSchedule(el, initialValue, document)).orElse(null);

            notionalScheduleBuilder.amount(parseSchedule(stepScheduleEl, initialValue, seq, document));
            notionalScheduleBuilder.currency(document.parseCurrency(stepScheduleEl.getChild("currency")));
            return(notionalScheduleBuilder.build());
        }
Esempio n. 3
0
        public virtual void test_summarize_knownAmountVarying()
        {
            Swap test = Swap.of(KnownAmountSwapLeg.builder().accrualSchedule(PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false)).amount(ValueSchedule.builder().initialValue(145_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-20_000))).build()).currency(GBP).payReceive(PAY).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).build());

            assertEquals(test.summaryDescription(), "2Y Pay GBP 145k variable : 12Feb18-12Feb20");
        }
Esempio n. 4
0
        public virtual void test_summarize_irs_weird()
        {
            PeriodicSchedule       accrual  = PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false);
            PaymentSchedule        payment  = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build();
            NotionalSchedule       notional = NotionalSchedule.of(GBP, ValueSchedule.builder().initialValue(1_000_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-50_000))).build());
            RateCalculationSwapLeg payLeg   = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.builder().initialValue(0.0012).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(0.0001))).build()).build()).build();
            RateCalculationSwapLeg recLeg   = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.GBP_LIBOR_3M).gearing(ValueSchedule.of(1.1)).spread(ValueSchedule.of(0.002)).build()).build();
            Swap test = Swap.of(payLeg, recLeg);

            assertEquals(test.summaryDescription(), "2Y GBP 1mm variable Rec GBP-LIBOR-3M * 1.1 + 0.2% / Pay 0.12% variable : 12Feb18-12Feb20");
        }
Esempio n. 5
0
        // Converts an FpML 'Schedule' to a {@code ValueSchedule}.
        private ValueSchedule parseSchedule(XmlElement scheduleEl, double initialValue, ValueStepSequence seq, FpmlDocument document)
        {
            IList <XmlElement> stepEls = scheduleEl.getChildren("step");

            ImmutableList.Builder <ValueStep> stepBuilder = ImmutableList.builder();
            foreach (XmlElement stepEl in stepEls)
            {
                LocalDate stepDate  = document.parseDate(stepEl.getChild("stepDate"));
                double    stepValue = document.parseDecimal(stepEl.getChild("stepValue"));
                stepBuilder.add(ValueStep.of(stepDate, ValueAdjustment.ofReplace(stepValue)));
            }
            return(ValueSchedule.builder().initialValue(initialValue).steps(stepBuilder.build()).stepSequence(seq).build());
        }