Exemple #1
0
        private Trade parseNdf(FpmlDocument document, XmlElement fxEl, XmlElement ndfEl, CurrencyAmount curr1Amount, CurrencyAmount curr2Amount, LocalDate valueDate, TradeInfoBuilder tradeInfoBuilder)
        {
            // rate
            XmlElement rateEl = fxEl.getChild("exchangeRate");
            double     rate   = document.parseDecimal(rateEl.getChild("rate"));
            XmlElement pairEl = rateEl.getChild("quotedCurrencyPair");
            Currency   curr1  = document.parseCurrency(pairEl.getChild("currency1"));
            Currency   curr2  = document.parseCurrency(pairEl.getChild("currency2"));
            string     basis  = pairEl.getChild("quoteBasis").Content;
            FxRate     fxRate;

            if ("Currency2PerCurrency1".Equals(basis))
            {
                fxRate = FxRate.of(curr1, curr2, rate);
            }
            else if ("Currency1PerCurrency2".Equals(basis))
            {
                fxRate = FxRate.of(curr2, curr1, rate);
            }
            else
            {
                throw new FpmlParseException("Unknown quote basis: " + basis);
            }
            // settlement currency
            Currency       settleCurr       = document.parseCurrency(ndfEl.getChild("settlementCurrency"));
            CurrencyAmount settleCurrAmount = curr1Amount.Currency.Equals(settleCurr) ? curr1Amount : curr2Amount;
            // index
            XmlElement        fixingEl        = ndfEl.getChild("fixing"); // only support one of these in pricing model
            LocalDate         fixingDate      = document.parseDate(fixingEl.getChild("fixingDate"));
            DaysAdjustment    offset          = DaysAdjustment.ofCalendarDays(Math.toIntExact(valueDate.until(fixingDate, DAYS)));
            XmlElement        sourceEl        = fixingEl.getChild("fxSpotRateSource"); // required for our model
            XmlElement        primarySourceEl = sourceEl.getChild("primaryRateSource");
            string            primarySource   = primarySourceEl.getChild("rateSource").Content;
            string            primaryPage     = primarySourceEl.findChild("rateSourcePage").map(e => e.Content).orElse("");
            LocalTime         time            = document.parseTime(sourceEl.getChild("fixingTime").getChild("hourMinuteTime")); // required for our model
            HolidayCalendarId calendar        = document.parseBusinessCenter(sourceEl.getChild("fixingTime").getChild("businessCenter"));
            FxIndex           index           = ImmutableFxIndex.builder().name(primarySource + "/" + primaryPage + "/" + time).currencyPair(CurrencyPair.of(curr1, curr2)).fixingCalendar(calendar).maturityDateOffset(offset).build();

            return(FxNdfTrade.builder().info(tradeInfoBuilder.build()).product(FxNdf.builder().settlementCurrencyNotional(settleCurrAmount).agreedFxRate(fxRate).index(index).paymentDate(valueDate).build()).build());
        }