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());
        }
        //-------------------------------------------------------------------------
        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());
        }