Ejemplo n.º 1
0
        //-------------------------------------------------------------------------
        // 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");
        }
Ejemplo n.º 2
0
        // 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);
        }
        //-------------------------------------------------------------------------
        public Trade parseTrade(FpmlDocument document, XmlElement tradeEl)
        {
            // supported elements:
            //  'buyerPartyReference'
            //  'sellerPartyReference'
            //  'adjustedTerminationDate'
            //  'paymentDate'
            //  'fixingDateOffset'
            //  'dayCountFraction'
            //  'notional'
            //  'fixedRate'
            //  'floatingRateIndex'
            //  'indexTenor+'
            //  'fraDiscounting'
            // ignored elements:
            //  'Product.model?'
            //  'buyerAccountReference?'
            //  'sellerAccountReference?'
            //  'calculationPeriodNumberOfDays'
            //  'additionalPayment*'
            TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl);
            XmlElement       fraEl            = tradeEl.getChild("fra");

            Fra.Builder fraBuilder = Fra.builder();
            // buy/sell and counterparty
            fraBuilder.buySell(document.parseBuyerSeller(fraEl, tradeInfoBuilder));
            // start date
            fraBuilder.startDate(document.parseDate(fraEl.getChild("adjustedEffectiveDate")));
            // end date
            fraBuilder.endDate(document.parseDate(fraEl.getChild("adjustedTerminationDate")));
            // payment date
            fraBuilder.paymentDate(document.parseAdjustableDate(fraEl.getChild("paymentDate")));
            // fixing offset
            fraBuilder.fixingDateOffset(document.parseRelativeDateOffsetDays(fraEl.getChild("fixingDateOffset")));
            // dateRelativeTo required to refer to adjustedEffectiveDate, so ignored here
            // day count
            fraBuilder.dayCount(document.parseDayCountFraction(fraEl.getChild("dayCountFraction")));
            // notional
            CurrencyAmount notional = document.parseCurrencyAmount(fraEl.getChild("notional"));

            fraBuilder.currency(notional.Currency);
            fraBuilder.notional(notional.Amount);
            // fixed rate
            fraBuilder.fixedRate(document.parseDecimal(fraEl.getChild("fixedRate")));
            // index
            IList <Index> indexes = document.parseIndexes(fraEl);

            switch (indexes.Count)
            {
            case 1:
                fraBuilder.index((IborIndex)indexes[0]);
                break;

            case 2:
                fraBuilder.index((IborIndex)indexes[0]);
                fraBuilder.indexInterpolated((IborIndex)indexes[1]);
                break;

            default:
                throw new FpmlParseException("Expected one or two indexes, but found " + indexes.Count);
            }
            // discounting
            fraBuilder.discounting(FraDiscountingMethod.of(fraEl.getChild("fraDiscounting").Content));

            return(FraTrade.builder().info(tradeInfoBuilder.build()).product(fraBuilder.build()).build());
        }