Пример #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());
        }
Пример #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 '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());
        }