Exemplo n.º 1
0
        //-------------------------------------------------------------------------
        public Trade parseTrade(FpmlDocument document, XmlElement tradeEl)
        {
            // supported elements:
            //  'swapStream+'
            //  'swapStream/buyerPartyReference'
            //  'swapStream/sellerPartyReference'
            //  'swapStream/calculationPeriodDates'
            //  'swapStream/paymentDates'
            //  'swapStream/resetDates?'
            //  'swapStream/calculationPeriodAmount'
            //  'swapStream/stubCalculationPeriodAmount?'
            //  'swapStream/principalExchanges?'
            //  'swapStream/calculationPeriodAmount/knownAmountSchedule'
            // ignored elements:
            //  'Product.model?'
            //  'swapStream/cashflows?'
            //  'swapStream/settlementProvision?'
            //  'swapStream/formula?'
            //  'earlyTerminationProvision?'
            //  'cancelableProvision?'
            //  'extendibleProvision?'
            //  'additionalPayment*'
            //  'additionalTerms?'
            // rejected elements:
            //  'swapStream/calculationPeriodAmount/calculation/fxLinkedNotionalSchedule'
            //  'swapStream/calculationPeriodAmount/calculation/futureValueNotional'
            TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl);
            Swap             swap             = parseSwap(document, tradeEl, tradeInfoBuilder);

            return(SwapTrade.builder().info(tradeInfoBuilder.build()).product(swap).build());
        }
Exemplo n.º 2
0
        // parse the trade info
        private TradeInfo parseTradeInfo(CsvRow row)
        {
            TradeInfoBuilder infoBuilder = TradeInfo.builder();
            string           scheme      = row.findField(ID_SCHEME_FIELD).orElse(DEFAULT_TRADE_SCHEME);

            row.findValue(ID_FIELD).ifPresent(id => infoBuilder.id(StandardId.of(scheme, id)));
            string schemeCpty = row.findValue(CPTY_SCHEME_FIELD).orElse(DEFAULT_CPTY_SCHEME);

            row.findValue(CPTY_FIELD).ifPresent(cpty => infoBuilder.counterparty(StandardId.of(schemeCpty, cpty)));
            row.findValue(TRADE_DATE_FIELD).ifPresent(dateStr => infoBuilder.tradeDate(LoaderUtils.parseDate(dateStr)));
            row.findValue(TRADE_TIME_FIELD).ifPresent(timeStr => infoBuilder.tradeTime(LoaderUtils.parseTime(timeStr)));
            row.findValue(TRADE_ZONE_FIELD).ifPresent(zoneStr => infoBuilder.zone(ZoneId.of(zoneStr)));
            row.findValue(SETTLEMENT_DATE_FIELD).ifPresent(dateStr => infoBuilder.settlementDate(LoaderUtils.parseDate(dateStr)));
            resolver.parseTradeInfo(row, infoBuilder);
            return(infoBuilder.build());
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Converts an FpML 'BuyerSeller.model' to a {@code BuySell}.
        /// <para>
        /// The <seealso cref="TradeInfo"/> builder is updated with the counterparty.
        ///
        /// </para>
        /// </summary>
        /// <param name="baseEl">  the FpML payer receiver model element </param>
        /// <param name="tradeInfoBuilder">  the builder of the trade info </param>
        /// <returns> the pay/receive flag </returns>
        /// <exception cref="RuntimeException"> if unable to parse </exception>
        public BuySell parseBuyerSeller(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
        {
            string buyerPartyReference  = baseEl.getChild("buyerPartyReference").getAttribute(FpmlDocument.HREF);
            string sellerPartyReference = baseEl.getChild("sellerPartyReference").getAttribute(FpmlDocument.HREF);

            if (ourPartyHrefIds.Empty || ourPartyHrefIds.contains(buyerPartyReference))
            {
                tradeInfoBuilder.counterparty(StandardId.of(FPML_PARTY_SCHEME, parties.get(sellerPartyReference).get(0)));
                return(BuySell.BUY);
            }
            else if (ourPartyHrefIds.contains(sellerPartyReference))
            {
                tradeInfoBuilder.counterparty(StandardId.of(FPML_PARTY_SCHEME, parties.get(buyerPartyReference).get(0)));
                return(BuySell.SELL);
            }
            else
            {
                throw new FpmlParseException(Messages.format("Neither buyerPartyReference nor sellerPartyReference contain our party ID: {}", ourPartyHrefIds));
            }
        }
Exemplo n.º 4
0
        // parses the swap
        internal Swap parseSwap(FpmlDocument document, XmlElement tradeEl, TradeInfoBuilder tradeInfoBuilder)
        {
            XmlElement swapEl = tradeEl.getChild("swap");
            ImmutableList <XmlElement> legEls = swapEl.getChildren("swapStream");

            ImmutableList.Builder <SwapLeg> legsBuilder = ImmutableList.builder();
            foreach (XmlElement legEl in legEls)
            {
                // calculation
                XmlElement       calcPeriodAmountEl = legEl.getChild("calculationPeriodAmount");
                XmlElement       calcEl             = calcPeriodAmountEl.findChild("calculation").orElse(XmlElement.ofChildren("calculation", ImmutableList.of()));
                PeriodicSchedule accrualSchedule    = parseSwapAccrualSchedule(legEl, document);
                PaymentSchedule  paymentSchedule    = parseSwapPaymentSchedule(legEl, calcEl, document);
                // known amount or rate calculation
                Optional <XmlElement> knownAmountOptEl = calcPeriodAmountEl.findChild("knownAmountSchedule");
                if (knownAmountOptEl.Present)
                {
                    XmlElement knownAmountEl = knownAmountOptEl.get();
                    document.validateNotPresent(legEl, "stubCalculationPeriodAmount");
                    document.validateNotPresent(legEl, "resetDates");
                    // pay/receive and counterparty
                    PayReceive    payReceive     = document.parsePayerReceiver(legEl, tradeInfoBuilder);
                    ValueSchedule amountSchedule = parseSchedule(knownAmountEl, document);
                    // build
                    legsBuilder.add(KnownAmountSwapLeg.builder().payReceive(payReceive).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).amount(amountSchedule).currency(document.parseCurrency(knownAmountEl.getChild("currency"))).build());
                }
                else
                {
                    document.validateNotPresent(calcEl, "fxLinkedNotionalSchedule");
                    document.validateNotPresent(calcEl, "futureValueNotional");
                    // pay/receive and counterparty
                    PayReceive       payReceive       = document.parsePayerReceiver(legEl, tradeInfoBuilder);
                    NotionalSchedule notionalSchedule = parseSwapNotionalSchedule(legEl, calcEl, document);
                    RateCalculation  calculation      = parseSwapCalculation(legEl, calcEl, accrualSchedule, document);
                    // build
                    legsBuilder.add(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(calculation).build());
                }
            }
            return(Swap.of(legsBuilder.build()));
        }
        /// <summary>
        /// Converts an FpML 'PayerReceiver.model' to a {@code PayReceive}.
        /// <para>
        /// The <seealso cref="TradeInfo"/> builder is updated with the counterparty.
        ///
        /// </para>
        /// </summary>
        /// <param name="baseEl">  the FpML payer receiver model element </param>
        /// <param name="tradeInfoBuilder">  the builder of the trade info </param>
        /// <returns> the pay/receive flag </returns>
        /// <exception cref="RuntimeException"> if unable to parse </exception>
        public PayReceive parsePayerReceiver(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
        {
            string payerPartyReference    = baseEl.getChild("payerPartyReference").getAttribute(HREF);
            string receiverPartyReference = baseEl.getChild("receiverPartyReference").getAttribute(HREF);
            object currentCounterparty    = tradeInfoBuilder.build().Counterparty.orElse(null);

            // determine direction and setup counterparty
            if ((ourPartyHrefIds.Empty && currentCounterparty == null) || ourPartyHrefIds.contains(payerPartyReference))
            {
                StandardId proposedCounterparty = StandardId.of(FPML_PARTY_SCHEME, parties.get(receiverPartyReference).get(0));
                if (currentCounterparty == null)
                {
                    tradeInfoBuilder.counterparty(proposedCounterparty);
                }
                else if (!currentCounterparty.Equals(proposedCounterparty))
                {
                    throw new FpmlParseException(Messages.format("Two different counterparties found: {} and {}", currentCounterparty, proposedCounterparty));
                }
                return(PayReceive.PAY);
            }
            else if (ourPartyHrefIds.Empty || ourPartyHrefIds.contains(receiverPartyReference))
            {
                StandardId proposedCounterparty = StandardId.of(FPML_PARTY_SCHEME, parties.get(payerPartyReference).get(0));
                if (currentCounterparty == null)
                {
                    tradeInfoBuilder.counterparty(proposedCounterparty);
                }
                else if (!currentCounterparty.Equals(proposedCounterparty))
                {
                    throw new FpmlParseException(Messages.format("Two different counterparties found: {} and {}", currentCounterparty, proposedCounterparty));
                }
                return(PayReceive.RECEIVE);
            }
            else
            {
                throw new FpmlParseException(Messages.format("Neither payerPartyReference nor receiverPartyReference contain our party ID: {}", ourPartyHrefIds));
            }
        }
        //-------------------------------------------------------------------------
        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());
        }