Esempio n. 1
0
        //-------------------------------------------------------------------------
        public Trade parseTrade(FpmlDocument document, XmlElement tradeEl)
        {
            // supported elements:
            // 'exchangedCurrency1/paymentAmount'
            // 'exchangedCurrency2/paymentAmount'
            // 'valueDate'
            // 'currency1ValueDate'
            // 'currency2ValueDate'
            // 'nonDeliverableSettlement?'
            // ignored elements:
            // 'dealtCurrency?'
            // 'exchangeRate'
            XmlElement fxEl = tradeEl.getChild("fxSingleLeg");
            // amounts
            TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl);
            XmlElement       curr1El          = fxEl.getChild("exchangedCurrency1");
            XmlElement       curr2El          = fxEl.getChild("exchangedCurrency2");
            // pay/receive and counterparty
            PayReceive curr1PayReceive = document.parsePayerReceiver(curr1El, tradeInfoBuilder);
            PayReceive curr2PayReceive = document.parsePayerReceiver(curr2El, tradeInfoBuilder);

            if (curr1PayReceive == curr2PayReceive)
            {
                throw new FpmlParseException("FX single leg currencies must not have same Pay/Receive direction");
            }
            // amount
            CurrencyAmount curr1Amount = document.parseCurrencyAmount(curr1El.getChild("paymentAmount"));
            CurrencyAmount curr2Amount = document.parseCurrencyAmount(curr2El.getChild("paymentAmount"));

            if (curr1PayReceive == PayReceive.PAY)
            {
                curr1Amount = curr1Amount.negative();
                curr2Amount = curr2Amount.positive();
            }
            else
            {
                curr1Amount = curr1Amount.positive();
                curr2Amount = curr2Amount.negative();
            }
            // payment date
            LocalDate currency1Date = document.parseDate(fxEl.findChild("currency1ValueDate").orElseGet(() => fxEl.getChild("valueDate")));
            LocalDate currency2Date = document.parseDate(fxEl.findChild("currency2ValueDate").orElseGet(() => fxEl.getChild("valueDate")));
            // FxSingle or NDF
            Optional <XmlElement> ndfEl = fxEl.findChild("nonDeliverableSettlement");

            if (!ndfEl.Present)
            {
                return(FxSingleTrade.builder().info(tradeInfoBuilder.build()).product(FxSingle.of(Payment.of(curr1Amount, currency1Date), Payment.of(curr2Amount, currency2Date))).build());
            }
            if (!currency1Date.Equals(currency2Date))
            {
                throw new FpmlParseException("FxNdf only supports a single payment date");
            }
            return(parseNdf(document, fxEl, ndfEl.get(), curr1Amount, curr2Amount, currency1Date, tradeInfoBuilder));
        }
        private FxSingle parseLeg(XmlElement legEl, FpmlDocument document, TradeInfoBuilder tradeInfoBuilder)
        {
            // supported elements:
            // 'exchangedCurrency1/paymentAmount'
            // 'exchangedCurrency2/paymentAmount'
            // 'valueDate'
            // ignored elements:
            // 'dealtCurrency?'
            // 'exchangeRate'
            // rejected elements:
            // 'nonDeliverableSettlement?'
            // 'currency1ValueDate'
            // 'currency2ValueDate'
            document.validateNotPresent(legEl, "currency1ValueDate");
            document.validateNotPresent(legEl, "currency2ValueDate");
            document.validateNotPresent(legEl, "nonDeliverableSettlement");
            XmlElement curr1El = legEl.getChild("exchangedCurrency1");
            XmlElement curr2El = legEl.getChild("exchangedCurrency2");
            // pay/receive and counterparty
            PayReceive curr1PayReceive = document.parsePayerReceiver(curr1El, tradeInfoBuilder);
            PayReceive curr2PayReceive = document.parsePayerReceiver(curr2El, tradeInfoBuilder);

            if (curr1PayReceive == curr2PayReceive)
            {
                throw new FpmlParseException("FX single leg currencies must not have same Pay/Receive direction");
            }
            // amount
            CurrencyAmount curr1Amount = document.parseCurrencyAmount(curr1El.getChild("paymentAmount"));
            CurrencyAmount curr2Amount = document.parseCurrencyAmount(curr2El.getChild("paymentAmount"));

            if (curr1PayReceive == PayReceive.PAY)
            {
                curr1Amount = curr1Amount.negative();
                curr2Amount = curr2Amount.positive();
            }
            else
            {
                curr1Amount = curr1Amount.positive();
                curr2Amount = curr2Amount.negative();
            }
            // payment date
            LocalDate valueDate = document.parseDate(legEl.getChild("valueDate"));

            // result
            return(FxSingle.of(curr1Amount, curr2Amount, valueDate));
        }