Beispiel #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));
        }
        // convention-based
        // ideally we'd use the trade date plus "period to start" to get the spot/payment date
        // but we don't have all the data and it gets complicated in places like TRY, RUB and AED
        private static FxSingleTrade parseConvention(CsvRow row, TradeInfo info)
        {
            CurrencyPair pair        = CurrencyPair.parse(row.getValue(CONVENTION_FIELD));
            BuySell      buySell     = LoaderUtils.parseBuySell(row.getValue(BUY_SELL_FIELD));
            Currency     currency    = Currency.parse(row.getValue(CURRENCY_FIELD));
            double       notional    = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD));
            double       fxRate      = LoaderUtils.parseDouble(row.getValue(FX_RATE_FIELD));
            LocalDate    paymentDate = LoaderUtils.parseDate(row.getValue(PAYMENT_DATE_FIELD));
            Optional <BusinessDayAdjustment> paymentAdj = parsePaymentDateAdjustment(row);

            CurrencyAmount amount = CurrencyAmount.of(currency, buySell.normalize(notional));
            FxSingle       fx     = paymentAdj.map(adj => FxSingle.of(amount, FxRate.of(pair, fxRate), paymentDate, adj)).orElseGet(() => FxSingle.of(amount, FxRate.of(pair, fxRate), paymentDate));

            return(FxSingleTrade.of(info, fx));
        }
        /// <summary>
        /// Parses the data from a CSV row.
        /// </summary>
        /// <param name="row">  the CSV row object </param>
        /// <param name="info">  the trade info object </param>
        /// <param name="resolver">  the resolver used to parse additional information. This is not currently used in this method. </param>
        /// <returns> the parsed trade, as an instance of <seealso cref="FxSingleTrade"/> </returns>
        internal static FxSingleTrade parse(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver)
        {
            FxSingleTrade trade = parseRow(row, info);

            return(resolver.completeTrade(row, trade));
        }
        // parse full definition
        private static FxSingleTrade parseFull(CsvRow row, TradeInfo info)
        {
            FxSingle fx = parseFxSingle(row, "");

            return(FxSingleTrade.of(info, fx));
        }