/** * Obtains an instance of the parser, based on the specified selector. * <p> * The FpML parser has a number of plugin points that can be controlled: * <ul> * <li>the {@linkplain FpmlPartySelector party selector} * <li>the {@linkplain FpmlTradeInfoParserPlugin trade info parser} * <li>the {@linkplain FpmlParserPlugin trade parsers} * <li>the {@linkplain ReferenceData reference data} * </ul> * This method uses the {@linkplain FpmlTradeInfoParserPlugin#standard() standard} * trade info parser, the trade parsers registered in {@link FpmlParserPlugin} * configuration and the {@linkplain ReferenceData#standard() standard} reference data. * * @param ourPartySelector the selector used to find "our" party within the set of parties in the FpML document * @return the document parser */ public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector) { return of(ourPartySelector, FpmlTradeInfoParserPlugin.standard()); }
/** * Converts an FpML 'FloatingRateIndex.model' to an {@code Index}. * * @param baseEl the FpML floating rate model element to parse * @return the index * @throws RuntimeException if unable to parse */ public Index parseIndex(XmlElement baseEl) { List<Index> indexes = parseIndexes(baseEl); if (indexes.size() != 1) { throw new FpmlParseException("Expected one index but found " + indexes.size()); } return indexes.get(0); }
/** * Parses the trade header element. * <p> * This parses the trade date and identifier. * * @param tradeEl the trade element * @return the trade info builder * @throws RuntimeException if unable to parse */ public TradeInfoBuilder parseTradeInfo(XmlElement tradeEl) { XmlElement tradeHeaderEl = tradeEl.getChild("tradeHeader"); LocalDate tradeDate = parseDate(tradeHeaderEl.getChild("tradeDate")); return tradeInfoParser.parseTrade(this, tradeDate, parseAllTradeIds(tradeHeaderEl)); }
public void fra_interpolated() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-interpolated.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertFra(trades, true); }
public void documentFrequency() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertFrequency("1", "M"), Frequency.P1M); assertEquals(test.convertFrequency("12", "M"), Frequency.P12M); assertEquals(test.convertFrequency("1", "Y"), Frequency.P12M); assertEquals(test.convertFrequency("13", "Y"), Frequency.of(Period.ofYears(13))); }
public void documentTenor() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertIndexTenor("1", "M"), Tenor.TENOR_1M); assertEquals(test.convertIndexTenor("12", "M"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("1", "Y"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("13", "Y"), Tenor.of(Period.ofYears(13))); }
public void notFpml() { String location = "classpath:com/opengamma/strata/loader/fpml/not-fpml.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); FpmlDocumentParser parser = FpmlDocumentParser.of(FpmlPartySelector.any()); assertThrows( () -> parser.parseTrades(resource), FpmlParseException.class, "Unable to find FpML root element.*"); }
private FixedRateStubCalculation parseStubCalculationForFixed(XmlElement baseEl, FpmlDocument document) { Optional<XmlElement> rateOptEl = baseEl.findChild("stubRate"); if (rateOptEl.isPresent()) { return FixedRateStubCalculation.ofFixedRate(document.parseDecimal(rateOptEl.get())); } Optional<XmlElement> amountOptEl = baseEl.findChild("stubAmount"); if (amountOptEl.isPresent()) { return FixedRateStubCalculation.ofKnownAmount(document.parseCurrencyAmount(amountOptEl.get())); } throw new FpmlParseException("Invalid stub, fixed rate leg cannot have a floating rate stub"); }
/** * Converts an FpML 'BusinessCenter' to a {@code HolidayCalendar}. * * @param baseEl the FpML calendar element to parse * @return the calendar * @throws RuntimeException if unable to parse */ public HolidayCalendarId parseBusinessCenter(XmlElement baseEl) { validateScheme(baseEl, "businessCenterScheme", "http://www.fpml.org/coding-scheme/business-center"); return convertHolidayCalendar(baseEl.getContent()); }
/** * Converts an FpML 'DayCountFraction' to a {@code DayCount}. * * @param baseEl the FpML day count element to parse * @return the day count * @throws RuntimeException if unable to parse */ public DayCount parseDayCountFraction(XmlElement baseEl) { validateScheme( baseEl, "dayCountFractionScheme", "http://www.fpml.org/coding-scheme/day-count-fraction", // standard form "http://www.fpml.org/spec/2004/day-count-fraction"); // seen in the wild return convertDayCount(baseEl.getContent()); }
private ZoneId parseExpiryZone(XmlElement expirationTimeEl, FpmlDocument document) { String businessCenter = expirationTimeEl.getChild("businessCenter").getContent(); Optional<ZoneId> optionalZoneId = document.getZoneId(businessCenter); if (!optionalZoneId.isPresent()) { throw new FpmlParseException("Unknown businessCenter" + " attribute value: " + businessCenter); } return optionalZoneId.get(); }
@Override public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { document.parseTradeInfo(tradeEl); // expected to throw an exception throw new UnsupportedOperationException(); }
/** * Converts an FpML 'FloatingRateIndex' tenor to a {@code Tenor}. * * @param baseEl the FpML floating rate index element to parse * @return the period * @throws RuntimeException if unable to parse */ public Tenor parseIndexTenor(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period') String multiplier = baseEl.getChild("periodMultiplier").getContent(); String unit = baseEl.getChild("period").getContent(); return convertIndexTenor(multiplier, unit); }
/** * Converts an FpML 'date' to a {@code LocalDate}. * * @param baseEl the FpML element to parse * @return the date * @throws RuntimeException if unable to parse */ public LocalDate parseDate(XmlElement baseEl) { return convertDate(baseEl.getContent()); }
private LongShort parseLongShort(XmlElement swaptionEl, FpmlDocument document, TradeInfoBuilder tradeInfoBuilder) { BuySell buySell = document.parseBuyerSeller(swaptionEl, tradeInfoBuilder); return buySell.isBuy() ? LongShort.LONG : LongShort.SHORT; }
public void fra_wrapper1() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-wrapper1.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra_namespace() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-namespace.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra_wrapper2() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-wrapper2.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra_wrapper_clearingStatus() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-wrapper-clearing-status.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }