Class FpmlDocument


  • public final class FpmlDocument
    extends java.lang.Object
    Provides data about the whole FpML document and parse helper methods.

    This is primarily used to support implementations of FpmlParserPlugin. See FpmlDocumentParser for the main entry point for FpML parsing.

    • Constructor Detail

      • FpmlDocument

        public FpmlDocument​(XmlElement fpmlRootEl,
                            java.util.Map<java.lang.String,​XmlElement> references,
                            FpmlPartySelector ourPartySelector,
                            FpmlTradeInfoParserPlugin tradeInfoParser,
                            ReferenceData refData)
        Creates an instance, based on the specified element.

        The map of references is used to link one part of the XML to another. For example, if one part of the XML has <foo id="fooId">, the references map will contain an entry mapping "fooId" to the parsed element <foo>.

        Parameters:
        fpmlRootEl - the source of the FpML XML document
        references - the map of id/href to referenced element
        ourPartySelector - the selector used to find "our" party within the set of parties in the FpML document
        tradeInfoParser - the trade info parser
        refData - the reference data to use
    • Method Detail

      • getFpmlRoot

        public XmlElement getFpmlRoot()
        Gets the FpML root element.

        This is not necessarily the root of the whole document.

        Returns:
        the FpML root element
      • getReferences

        public com.google.common.collect.ImmutableMap<java.lang.String,​XmlElement> getReferences()
        Gets the map of href/id references.
        Returns:
        the reference map
      • getParties

        public com.google.common.collect.ImmutableListMultimap<java.lang.String,​java.lang.String> getParties()
        Gets the map of party identifiers keyed by href/id reference.
        Returns:
        the party map
      • getOurPartyHrefIds

        public java.util.List<java.lang.String> getOurPartyHrefIds()
        Gets the party href/id references representing "our" party.

        In a typical trade there are two parties, where one pays and the other receives. In FpML these parties are represented by the party structure, which lists each party and assigns them identifiers. These identifiers are then used throughout the rest of the FpML document to specify who pays/receives each item. By contrast, the Strata trade model is directional. Each item in the Strata trade specifies whether it is pay or receive with respect to the company running the library.

        To convert between these two models, the FpmlPartySelector is used to find "our" party identifiers, in other words those party identifiers that belong to the company running the library. Note that the matching occurs against the content of <partyId> but the result of this method is the content of the attribute <party id="">.

        Most FpML documents have one party identifier for each party, however it is possible for a document to contain multiple identifiers for the same party. The list allows all these parties to be stored. The list will be empty if "our" party could not be identified.

        Returns:
        our party, empty if not known
      • getReferenceData

        public ReferenceData getReferenceData()
        Gets the reference data.

        Use of reference data is not necessary to parse most FpML documents. It is only needed to handle some edge cases, notably around relative dates.

        Returns:
        the reference data
      • parseTradeInfo

        public TradeInfoBuilder parseTradeInfo​(XmlElement tradeEl)
        Parses the trade header element.

        This parses the trade date and identifier.

        Parameters:
        tradeEl - the trade element
        Returns:
        the trade info builder
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseBuyerSeller

        public BuySell parseBuyerSeller​(XmlElement baseEl,
                                        TradeInfoBuilder tradeInfoBuilder)
        Converts an FpML 'BuyerSeller.model' to a BuySell.

        The TradeInfo builder is updated with the counterparty.

        Parameters:
        baseEl - the FpML payer receiver model element
        tradeInfoBuilder - the builder of the trade info
        Returns:
        the pay/receive flag
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parsePayerReceiver

        public PayReceive parsePayerReceiver​(XmlElement baseEl,
                                             TradeInfoBuilder tradeInfoBuilder)
        Converts an FpML 'PayerReceiver.model' to a PayReceive.

        The TradeInfo builder is updated with the counterparty.

        Parameters:
        baseEl - the FpML payer receiver model element
        tradeInfoBuilder - the builder of the trade info
        Returns:
        the pay/receive flag
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseAdjustedRelativeDateOffset

        public AdjustableDate parseAdjustedRelativeDateOffset​(XmlElement baseEl)
        Converts an FpML 'AdjustedRelativeDateOffset' to a resolved LocalDate.
        Parameters:
        baseEl - the FpML adjustable date element
        Returns:
        the resolved date
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseRelativeDateOffsetDays

        public DaysAdjustment parseRelativeDateOffsetDays​(XmlElement baseEl)
        Converts an FpML 'RelativeDateOffset' to a DaysAdjustment.
        Parameters:
        baseEl - the FpML adjustable date element
        Returns:
        the days adjustment
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseAdjustableDate

        public AdjustableDate parseAdjustableDate​(XmlElement baseEl)
        Converts an FpML 'AdjustableDate' or 'AdjustableDate2' to an AdjustableDate.
        Parameters:
        baseEl - the FpML adjustable date element
        Returns:
        the adjustable date
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseBusinessDayAdjustments

        public BusinessDayAdjustment parseBusinessDayAdjustments​(XmlElement baseEl)
        Converts an FpML 'BusinessDayAdjustments' to a BusinessDayAdjustment.
        Parameters:
        baseEl - the FpML business centers or reference element to parse
        Returns:
        the business day adjustment
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseBusinessCenters

        public HolidayCalendarId parseBusinessCenters​(XmlElement baseEl)
        Converts an FpML 'BusinessCentersOrReference.model' to a HolidayCalendar.
        Parameters:
        baseEl - the FpML business centers or reference element to parse
        Returns:
        the holiday calendar
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseBusinessCenter

        public HolidayCalendarId parseBusinessCenter​(XmlElement baseEl)
        Converts an FpML 'BusinessCenter' to a HolidayCalendar.
        Parameters:
        baseEl - the FpML calendar element to parse
        Returns:
        the calendar
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parsePriceIndex

        public PriceIndex parsePriceIndex​(XmlElement baseEl)
        Converts an FpML 'FloatingRateIndex.model' to a PriceIndex.
        Parameters:
        baseEl - the FpML floating rate model element to parse
        Returns:
        the index
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseIndex

        public Index parseIndex​(XmlElement baseEl)
        Converts an FpML 'FloatingRateIndex.model' to an Index.
        Parameters:
        baseEl - the FpML floating rate model element to parse
        Returns:
        the index
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseIndexes

        public java.util.List<Index> parseIndexes​(XmlElement baseEl)
        Converts an FpML 'FloatingRateIndex' with multiple tenors to an Index.
        Parameters:
        baseEl - the FpML floating rate index element to parse
        Returns:
        the index
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseIndexTenor

        public Tenor parseIndexTenor​(XmlElement baseEl)
        Converts an FpML 'FloatingRateIndex' tenor to a Tenor.
        Parameters:
        baseEl - the FpML floating rate index element to parse
        Returns:
        the period
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parsePeriod

        public java.time.Period parsePeriod​(XmlElement baseEl)
        Converts an FpML 'Period' to a Period.
        Parameters:
        baseEl - the FpML element to parse
        Returns:
        the period
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseFrequency

        public Frequency parseFrequency​(XmlElement baseEl)
        Converts an FpML frequency to a Frequency.
        Parameters:
        baseEl - the FpML element to parse
        Returns:
        the frequency
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseCurrencyAmount

        public CurrencyAmount parseCurrencyAmount​(XmlElement baseEl)
        Converts an FpML 'Money' to a CurrencyAmount.
        Parameters:
        baseEl - the FpML money element to parse
        Returns:
        the currency amount
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseCurrency

        public Currency parseCurrency​(XmlElement baseEl)
        Converts an FpML 'Currency' to a Currency.
        Parameters:
        baseEl - the FpML currency element to parse
        Returns:
        the currency
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseDayCountFraction

        public DayCount parseDayCountFraction​(XmlElement baseEl)
        Converts an FpML 'DayCountFraction' to a DayCount.
        Parameters:
        baseEl - the FpML day count element to parse
        Returns:
        the day count
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseDecimal

        public double parseDecimal​(XmlElement baseEl)
        Converts an FpML 'decimal' to a double.
        Parameters:
        baseEl - the FpML element to parse
        Returns:
        the double
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseDate

        public java.time.LocalDate parseDate​(XmlElement baseEl)
        Converts an FpML 'date' to a LocalDate.
        Parameters:
        baseEl - the FpML element to parse
        Returns:
        the date
        Throws:
        java.lang.RuntimeException - if unable to parse
      • parseTime

        public java.time.LocalTime parseTime​(XmlElement baseEl)
        Converts an FpML 'hourMinuteTime' to a LocalTime.
        Parameters:
        baseEl - the FpML element to parse
        Returns:
        the time
        Throws:
        java.lang.RuntimeException - if unable to parse
      • convertDayCount

        public DayCount convertDayCount​(java.lang.String fpmlDayCountName)
        Converts an FpML day count string to a DayCount.
        Parameters:
        fpmlDayCountName - the day count name used by FpML
        Returns:
        the day count
        Throws:
        java.lang.IllegalArgumentException - if the day count is not known
      • convertBusinessDayConvention

        public BusinessDayConvention convertBusinessDayConvention​(java.lang.String fmplBusinessDayConventionName)
        Converts an FpML business day convention string to a BusinessDayConvention.
        Parameters:
        fmplBusinessDayConventionName - the business day convention name used by FpML
        Returns:
        the business day convention
        Throws:
        java.lang.IllegalArgumentException - if the business day convention is not known
      • convertRollConvention

        public RollConvention convertRollConvention​(java.lang.String fmplRollConventionName)
        Converts an FpML roll convention string to a RollConvention.
        Parameters:
        fmplRollConventionName - the roll convention name used by FpML
        Returns:
        the roll convention
        Throws:
        java.lang.IllegalArgumentException - if the roll convention is not known
      • convertHolidayCalendar

        public HolidayCalendarId convertHolidayCalendar​(java.lang.String fpmlBusinessCenter)
        Converts an FpML business center string to a HolidayCalendar.
        Parameters:
        fpmlBusinessCenter - the business center name used by FpML
        Returns:
        the holiday calendar
        Throws:
        java.lang.IllegalArgumentException - if the holiday calendar is not known
      • convertFrequency

        public Frequency convertFrequency​(java.lang.String multiplier,
                                          java.lang.String unit)
        Converts an FpML frequency string to a Frequency.
        Parameters:
        multiplier - the multiplier
        unit - the unit
        Returns:
        the frequency
        Throws:
        java.lang.IllegalArgumentException - if the frequency is not known
      • convertIndexTenor

        public Tenor convertIndexTenor​(java.lang.String multiplier,
                                       java.lang.String unit)
        Converts an FpML tenor string to a Tenor.
        Parameters:
        multiplier - the multiplier
        unit - the unit
        Returns:
        the tenor
        Throws:
        java.lang.IllegalArgumentException - if the tenor is not known
      • convertDate

        public java.time.LocalDate convertDate​(java.lang.String dateStr)
        Converts an FpML date to a LocalDate.
        Parameters:
        dateStr - the business center name used by FpML
        Returns:
        the holiday calendar
        Throws:
        java.time.format.DateTimeParseException - if the date cannot be parsed
      • getZoneId

        public java.util.Optional<java.time.ZoneId> getZoneId​(java.lang.String holidayCalendarId)
        Returns the ZoneId matching this string representation of a holiday calendar id.
        Parameters:
        holidayCalendarId - the holiday calendar id string.
        Returns:
        an optional zone id, an empty optional is returned if no zone id can be found for the holiday calendar id.
      • validateNotPresent

        public void validateNotPresent​(XmlElement baseEl,
                                       java.lang.String elementName)
        Validates that a specific element is not present.
        Parameters:
        baseEl - the FpML element to parse
        elementName - the element name
        Throws:
        FpmlParseException - if the element is found
      • validateScheme

        public void validateScheme​(XmlElement baseEl,
                                   java.lang.String schemeAttr,
                                   java.lang.String... schemeValues)
        Validates that the scheme attribute is known.
        Parameters:
        baseEl - the FpML element to parse
        schemeAttr - the scheme attribute name
        schemeValues - the scheme attribute values that are accepted
        Throws:
        FpmlParseException - if the scheme does not match
      • lookupReference

        public XmlElement lookupReference​(XmlElement hrefEl)
        Looks up an element by href/id reference.
        Parameters:
        hrefEl - the element containing the href/id
        Returns:
        the matched element
        Throws:
        FpmlParseException - if the reference is not found