/** * 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()); }
/** * Obtains an instance of the parser, based on the specified selector and trade info plugin. * <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 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 * @param tradeInfoParser the trade info parser * @return the document parser */ public static FpmlDocumentParser of( FpmlPartySelector ourPartySelector, FpmlTradeInfoParserPlugin tradeInfoParser) { return of(ourPartySelector, tradeInfoParser, FpmlParserPlugin.extendedEnum().lookupAllNormalized()); }
public void noTrades() { XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of()); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.any()).parseTrades(rootEl, ImmutableMap.of()); assertEquals(trades.size(), 0); }
@Test(dataProvider = "parse") public void parse(String location) { ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertEquals(trades.size(), 1); }
public void badSelector() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); FpmlDocumentParser parser = FpmlDocumentParser.of(allParties -> ImmutableList.of("rubbish")); assertThrows( () -> parser.parseTrades(resource), FpmlParseException.class, "Selector returned an ID .*"); }
public void unknownProduct() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement unknownEl = XmlElement.ofChildren("unknown", ImmutableList.of()); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableList.of(tradeHeaderEl, unknownEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocumentParser parser = FpmlDocumentParser.of(FpmlPartySelector.any()); assertThrows( () -> parser.parseTrades(rootEl, ImmutableMap.of()), FpmlParseException.class, ".*unknown.*"); }
public void fxSpot() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex01-fx-spot.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxSingleTrade.class); FxSingleTrade fxTrade = (FxSingleTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2001, 10, 23))); FxSingle fx = fxTrade.getProduct(); assertEquals(fx.getBaseCurrencyPayment(), Payment.of(GBP, 10000000, date(2001, 10, 25))); assertEquals(fx.getCounterCurrencyPayment(), Payment.of(USD, -14800000, date(2001, 10, 25))); }
public void fxForward_splitDate() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex03-fx-fwd-split-date.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxSingleTrade.class); FxSingleTrade fxTrade = (FxSingleTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2001, 11, 19))); FxSingle fx = fxTrade.getProduct(); assertEquals(fx.getBaseCurrencyPayment(), Payment.of(EUR, 10000000, date(2001, 12, 21))); assertEquals(fx.getCounterCurrencyPayment(), Payment.of(USD, -9175000, date(2001, 12, 22))); }
public void fxForward() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex03-fx-fwd.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxSingleTrade.class); FxSingleTrade fxTrade = (FxSingleTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2001, 11, 19))); FxSingle fx = fxTrade.getProduct(); assertEquals(fx.getBaseCurrencyPayment(), Payment.of(EUR, 10000000, date(2001, 12, 21))); assertEquals(fx.getCounterCurrencyPayment(), Payment.of(USD, -9175000, date(2001, 12, 21))); }
public void bulletPayment() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex28-bullet-payments.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), BulletPaymentTrade.class); BulletPaymentTrade bpTrade = (BulletPaymentTrade) trade; assertEquals(bpTrade.getInfo().getTradeDate(), Optional.of(date(2001, 4, 29))); BulletPayment bp = bpTrade.getProduct(); assertEquals(bp.getPayReceive(), PAY); assertEquals(bp.getDate(), AdjustableDate.of(date(2001, 7, 27), BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO_USNY))); assertEquals(bp.getValue(), CurrencyAmount.of(USD, 15000)); }
public void termDeposit() { String location = "classpath:com/opengamma/strata/loader/fpml/td-ex01-simple-term-deposit.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), TermDepositTrade.class); TermDepositTrade tdTrade = (TermDepositTrade) trade; assertEquals(tdTrade.getInfo().getTradeDate(), Optional.of(date(2002, 2, 14))); TermDeposit td = tdTrade.getProduct(); assertEquals(td.getBuySell(), BUY); assertEquals(td.getStartDate(), date(2002, 2, 14)); assertEquals(td.getEndDate(), date(2002, 2, 15)); assertEquals(td.getCurrency(), CHF); assertEquals(td.getNotional(), 25000000d); assertEquals(td.getRate(), 0.04); assertEquals(td.getDayCount(), ACT_360); }
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 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); }
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.*"); }
public void fxSwap() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex08-fx-swap.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxSwapTrade.class); FxSwapTrade fxTrade = (FxSwapTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2002, 1, 23))); FxSwap fx = fxTrade.getProduct(); FxSingle nearLeg = fx.getNearLeg(); assertEquals(nearLeg.getBaseCurrencyPayment(), Payment.of(GBP, 10000000, date(2002, 1, 25))); assertEquals(nearLeg.getCounterCurrencyPayment(), Payment.of(USD, -14800000, date(2002, 1, 25))); FxSingle farLeg = fx.getFarLeg(); assertEquals(farLeg.getBaseCurrencyPayment(), Payment.of(GBP, -10000000, date(2002, 2, 25))); assertEquals(farLeg.getCounterCurrencyPayment(), Payment.of(USD, 15000000, date(2002, 2, 25))); }
public void fxNdf() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex07-non-deliverable-forward.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxNdfTrade.class); FxNdfTrade fxTrade = (FxNdfTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2002, 1, 9))); FxNdf fx = fxTrade.getProduct(); assertEquals(fx.getSettlementCurrencyNotional(), CurrencyAmount.of(USD, 10000000)); assertEquals(fx.getAgreedFxRate(), FxRate.of(USD, INR, 43.4)); assertEquals(fx.getIndex(), ImmutableFxIndex.builder() .name("Reuters/RBIB/14:30") .currencyPair(CurrencyPair.of(USD, INR)) .fixingCalendar(USNY) .maturityDateOffset(DaysAdjustment.ofCalendarDays(-2)) .build()); assertEquals(fx.getPaymentDate(), date(2002, 4, 11)); }