Class FpmlDocument
- java.lang.Object
-
- com.opengamma.strata.loader.fpml.FpmlDocument
-
public final class FpmlDocument extends Object
Provides data about the whole FpML document and parse helper methods.This is primarily used to support implementations of
FpmlParserPlugin
. SeeFpmlDocumentParser
for the main entry point for FpML parsing.
-
-
Constructor Summary
Constructors Constructor Description FpmlDocument(XmlElement fpmlRootEl, Map<String,XmlElement> references, FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser, ReferenceData refData)
Creates an instance, based on the specified element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BusinessDayConvention
convertBusinessDayConvention(String fmplBusinessDayConventionName)
Converts an FpML business day convention string to aBusinessDayConvention
.LocalDate
convertDate(String dateStr)
Converts an FpML date to aLocalDate
.DayCount
convertDayCount(String fpmlDayCountName)
Converts an FpML day count string to aDayCount
.Frequency
convertFrequency(String multiplier, String unit)
Converts an FpML frequency string to aFrequency
.HolidayCalendarId
convertHolidayCalendar(String fpmlBusinessCenter)
Converts an FpML business center string to aHolidayCalendar
.Tenor
convertIndexTenor(String multiplier, String unit)
Converts an FpML tenor string to aTenor
.RollConvention
convertRollConvention(String fmplRollConventionName)
Converts an FpML roll convention string to aRollConvention
.XmlElement
getFpmlRoot()
Gets the FpML root element.List<String>
getOurPartyHrefIds()
Gets the party href/id references representing "our" party.ImmutableListMultimap<String,String>
getParties()
Gets the map of party identifiers keyed by href/id reference.ReferenceData
getReferenceData()
Gets the reference data.ImmutableMap<String,XmlElement>
getReferences()
Gets the map of href/id references.Optional<ZoneId>
getZoneId(String holidayCalendarId)
Returns theZoneId
matching this string representation of a holiday calendar id.XmlElement
lookupReference(XmlElement hrefEl)
Looks up an element by href/id reference.AdjustableDate
parseAdjustableDate(XmlElement baseEl)
Converts an FpML 'AdjustableDate' or 'AdjustableDate2' to anAdjustableDate
.AdjustableDate
parseAdjustedRelativeDateOffset(XmlElement baseEl)
Converts an FpML 'AdjustedRelativeDateOffset' to a resolvedLocalDate
.HolidayCalendarId
parseBusinessCenter(XmlElement baseEl)
Converts an FpML 'BusinessCenter' to aHolidayCalendar
.HolidayCalendarId
parseBusinessCenters(XmlElement baseEl)
Converts an FpML 'BusinessCentersOrReference.model' to aHolidayCalendar
.BusinessDayAdjustment
parseBusinessDayAdjustments(XmlElement baseEl)
Converts an FpML 'BusinessDayAdjustments' to aBusinessDayAdjustment
.BuySell
parseBuyerSeller(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
Converts an FpML 'BuyerSeller.model' to aBuySell
.Currency
parseCurrency(XmlElement baseEl)
Converts an FpML 'Currency' to aCurrency
.CurrencyAmount
parseCurrencyAmount(XmlElement baseEl)
Converts an FpML 'Money' to aCurrencyAmount
.LocalDate
parseDate(XmlElement baseEl)
Converts an FpML 'date' to aLocalDate
.DayCount
parseDayCountFraction(XmlElement baseEl)
Converts an FpML 'DayCountFraction' to aDayCount
.double
parseDecimal(XmlElement baseEl)
Converts an FpML 'decimal' to adouble
.Frequency
parseFrequency(XmlElement baseEl)
Converts an FpML frequency to aFrequency
.Index
parseIndex(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex.model' to anIndex
.List<Index>
parseIndexes(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex' with multiple tenors to anIndex
.Tenor
parseIndexTenor(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex' tenor to aTenor
.PayReceive
parsePayerReceiver(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
Converts an FpML 'PayerReceiver.model' to aPayReceive
.Period
parsePeriod(XmlElement baseEl)
Converts an FpML 'Period' to aPeriod
.PriceIndex
parsePriceIndex(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex.model' to aPriceIndex
.DaysAdjustment
parseRelativeDateOffsetDays(XmlElement baseEl)
Converts an FpML 'RelativeDateOffset' to aDaysAdjustment
.LocalTime
parseTime(XmlElement baseEl)
Converts an FpML 'hourMinuteTime' to aLocalTime
.TradeInfoBuilder
parseTradeInfo(XmlElement tradeEl)
Parses the trade header element.void
validateNotPresent(XmlElement baseEl, String elementName)
Validates that a specific element is not present.void
validateScheme(XmlElement baseEl, String schemeAttr, String... schemeValues)
Validates that the scheme attribute is known.
-
-
-
Field Detail
-
ID
public static final String ID
The 'id' attribute key.- See Also:
- Constant Field Values
-
HREF
public static final String HREF
The 'href' attribute key.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FpmlDocument
public FpmlDocument(XmlElement fpmlRootEl, Map<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>
.The created document will be in 'strict' mode, which means that any FpML elements unsupported in Strata will trigger errors during parsing.
- Parameters:
fpmlRootEl
- the source of the FpML XML documentreferences
- the map of id/href to referenced elementourPartySelector
- the selector used to find "our" party within the set of parties in the FpML documenttradeInfoParser
- the trade info parserrefData
- 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 ImmutableMap<String,XmlElement> getReferences()
Gets the map of href/id references.- Returns:
- the reference map
-
getParties
public ImmutableListMultimap<String,String> getParties()
Gets the map of party identifiers keyed by href/id reference.- Returns:
- the party map
-
getOurPartyHrefIds
public List<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:
ParseFailureException
- if unable to parse
-
parseBuyerSeller
public BuySell parseBuyerSeller(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
Converts an FpML 'BuyerSeller.model' to aBuySell
.The
TradeInfo
builder is updated with the counterparty.- Parameters:
baseEl
- the FpML payer receiver model elementtradeInfoBuilder
- the builder of the trade info- Returns:
- the pay/receive flag
- Throws:
ParseFailureException
- if unable to parse
-
parsePayerReceiver
public PayReceive parsePayerReceiver(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
Converts an FpML 'PayerReceiver.model' to aPayReceive
.The
TradeInfo
builder is updated with the counterparty.- Parameters:
baseEl
- the FpML payer receiver model elementtradeInfoBuilder
- the builder of the trade info- Returns:
- the pay/receive flag
- Throws:
ParseFailureException
- if unable to parse
-
parseAdjustedRelativeDateOffset
public AdjustableDate parseAdjustedRelativeDateOffset(XmlElement baseEl)
Converts an FpML 'AdjustedRelativeDateOffset' to a resolvedLocalDate
.- Parameters:
baseEl
- the FpML adjustable date element- Returns:
- the resolved date
- Throws:
ParseFailureException
- if unable to parse
-
parseRelativeDateOffsetDays
public DaysAdjustment parseRelativeDateOffsetDays(XmlElement baseEl)
Converts an FpML 'RelativeDateOffset' to aDaysAdjustment
.- Parameters:
baseEl
- the FpML adjustable date element- Returns:
- the days adjustment
- Throws:
ParseFailureException
- if unable to parse
-
parseAdjustableDate
public AdjustableDate parseAdjustableDate(XmlElement baseEl)
Converts an FpML 'AdjustableDate' or 'AdjustableDate2' to anAdjustableDate
.- Parameters:
baseEl
- the FpML adjustable date element- Returns:
- the adjustable date
- Throws:
ParseFailureException
- if unable to parse
-
parseBusinessDayAdjustments
public BusinessDayAdjustment parseBusinessDayAdjustments(XmlElement baseEl)
Converts an FpML 'BusinessDayAdjustments' to aBusinessDayAdjustment
.- Parameters:
baseEl
- the FpML business centers or reference element to parse- Returns:
- the business day adjustment
- Throws:
ParseFailureException
- if unable to parse
-
parseBusinessCenters
public HolidayCalendarId parseBusinessCenters(XmlElement baseEl)
Converts an FpML 'BusinessCentersOrReference.model' to aHolidayCalendar
.- Parameters:
baseEl
- the FpML business centers or reference element to parse- Returns:
- the holiday calendar
- Throws:
ParseFailureException
- if unable to parse
-
parseBusinessCenter
public HolidayCalendarId parseBusinessCenter(XmlElement baseEl)
Converts an FpML 'BusinessCenter' to aHolidayCalendar
.- Parameters:
baseEl
- the FpML calendar element to parse- Returns:
- the calendar
- Throws:
ParseFailureException
- if unable to parse
-
parsePriceIndex
public PriceIndex parsePriceIndex(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex.model' to aPriceIndex
.- Parameters:
baseEl
- the FpML floating rate model element to parse- Returns:
- the index
- Throws:
ParseFailureException
- if unable to parse
-
parseIndex
public Index parseIndex(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex.model' to anIndex
.- Parameters:
baseEl
- the FpML floating rate model element to parse- Returns:
- the index
- Throws:
ParseFailureException
- if unable to parse
-
parseIndexes
public List<Index> parseIndexes(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex' with multiple tenors to anIndex
.- Parameters:
baseEl
- the FpML floating rate index element to parse- Returns:
- the index
- Throws:
ParseFailureException
- if unable to parse
-
parseIndexTenor
public Tenor parseIndexTenor(XmlElement baseEl)
Converts an FpML 'FloatingRateIndex' tenor to aTenor
.- Parameters:
baseEl
- the FpML floating rate index element to parse- Returns:
- the period
- Throws:
ParseFailureException
- if unable to parse
-
parsePeriod
public Period parsePeriod(XmlElement baseEl)
Converts an FpML 'Period' to aPeriod
.- Parameters:
baseEl
- the FpML element to parse- Returns:
- the period
- Throws:
ParseFailureException
- if unable to parse
-
parseFrequency
public Frequency parseFrequency(XmlElement baseEl)
Converts an FpML frequency to aFrequency
.- Parameters:
baseEl
- the FpML element to parse- Returns:
- the frequency
- Throws:
ParseFailureException
- if unable to parse
-
parseCurrencyAmount
public CurrencyAmount parseCurrencyAmount(XmlElement baseEl)
Converts an FpML 'Money' to aCurrencyAmount
.- Parameters:
baseEl
- the FpML money element to parse- Returns:
- the currency amount
- Throws:
ParseFailureException
- if unable to parse
-
parseCurrency
public Currency parseCurrency(XmlElement baseEl)
Converts an FpML 'Currency' to aCurrency
.- Parameters:
baseEl
- the FpML currency element to parse- Returns:
- the currency
- Throws:
ParseFailureException
- if unable to parse
-
parseDayCountFraction
public DayCount parseDayCountFraction(XmlElement baseEl)
Converts an FpML 'DayCountFraction' to aDayCount
.- Parameters:
baseEl
- the FpML day count element to parse- Returns:
- the day count
- Throws:
ParseFailureException
- if unable to parse
-
parseDecimal
public double parseDecimal(XmlElement baseEl)
Converts an FpML 'decimal' to adouble
.- Parameters:
baseEl
- the FpML element to parse- Returns:
- the double
- Throws:
ParseFailureException
- if unable to parse
-
parseDate
public LocalDate parseDate(XmlElement baseEl)
Converts an FpML 'date' to aLocalDate
.- Parameters:
baseEl
- the FpML element to parse- Returns:
- the date
- Throws:
ParseFailureException
- if unable to parse
-
parseTime
public LocalTime parseTime(XmlElement baseEl)
Converts an FpML 'hourMinuteTime' to aLocalTime
.- Parameters:
baseEl
- the FpML element to parse- Returns:
- the time
- Throws:
ParseFailureException
- if unable to parse
-
convertDayCount
public DayCount convertDayCount(String fpmlDayCountName)
Converts an FpML day count string to aDayCount
.- Parameters:
fpmlDayCountName
- the day count name used by FpML- Returns:
- the day count
- Throws:
ParseFailureException
- if the day count is not known
-
convertBusinessDayConvention
public BusinessDayConvention convertBusinessDayConvention(String fmplBusinessDayConventionName)
Converts an FpML business day convention string to aBusinessDayConvention
.- Parameters:
fmplBusinessDayConventionName
- the business day convention name used by FpML- Returns:
- the business day convention
- Throws:
ParseFailureException
- if the business day convention is not known
-
convertRollConvention
public RollConvention convertRollConvention(String fmplRollConventionName)
Converts an FpML roll convention string to aRollConvention
.- Parameters:
fmplRollConventionName
- the roll convention name used by FpML- Returns:
- the roll convention
- Throws:
ParseFailureException
- if the roll convention is not known
-
convertHolidayCalendar
public HolidayCalendarId convertHolidayCalendar(String fpmlBusinessCenter)
Converts an FpML business center string to aHolidayCalendar
.- Parameters:
fpmlBusinessCenter
- the business center name used by FpML- Returns:
- the ParseFailureException calendar
- Throws:
IllegalArgumentException
- if the holiday calendar is not known
-
convertFrequency
public Frequency convertFrequency(String multiplier, String unit)
Converts an FpML frequency string to aFrequency
.- Parameters:
multiplier
- the multiplierunit
- the unit- Returns:
- the frequency
- Throws:
ParseFailureException
- if the frequency is not known
-
convertIndexTenor
public Tenor convertIndexTenor(String multiplier, String unit)
Converts an FpML tenor string to aTenor
.- Parameters:
multiplier
- the multiplierunit
- the unit- Returns:
- the tenor
- Throws:
ParseFailureException
- if the tenor is not known
-
convertDate
public LocalDate convertDate(String dateStr)
Converts an FpML date to aLocalDate
.- Parameters:
dateStr
- the business center name used by FpML- Returns:
- the holiday calendar
- Throws:
ParseFailureException
- if the date cannot be parsed
-
getZoneId
public Optional<ZoneId> getZoneId(String holidayCalendarId)
Returns theZoneId
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, String elementName)
Validates that a specific element is not present.- Parameters:
baseEl
- the FpML element to parseelementName
- the element name- Throws:
FpmlParseException
- if the element is found
-
validateScheme
public void validateScheme(XmlElement baseEl, String schemeAttr, String... schemeValues)
Validates that the scheme attribute is known.- Parameters:
baseEl
- the FpML element to parseschemeAttr
- the scheme attribute nameschemeValues
- 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
-
-