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); }
/** * Parses FpML from the specified source, extracting the trades. * <p> * This parses the specified byte source which must be an XML document. * <p> * Sometimes, the FpML document is embedded in a non-FpML wrapper. * This method will intelligently find the FpML document at the root or within one or two levels * of wrapper by searching for an element that contains both {@code <trade>} and {@code <party>}. * * @param source the source of the FpML XML document * @return the parsed trades * @throws RuntimeException if a parse error occurred */ public List<Trade> parseTrades(ByteSource source) { XmlFile xmlFile = XmlFile.of(source, FpmlDocument.ID); XmlElement root = findFpmlRoot(xmlFile.getRoot()); return parseTrades(root, xmlFile.getReferences()); }
@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 badTradeDate() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000/06/30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeTypeEl = XmlElement.ofContent("foo", "fakeTradeType"); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableList.of(tradeHeaderEl, tradeTypeEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlParserPlugin tradeParser = new FpmlParserPlugin() { @Override public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { document.parseTradeInfo(tradeEl); // expected to throw an exception throw new UnsupportedOperationException(); } @Override public String getName() { return "foo"; } }; FpmlDocumentParser parser = FpmlDocumentParser.of(FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), ImmutableMap.of("foo", tradeParser)); assertThrows( () -> parser.parseTrades(rootEl, ImmutableMap.of()), DateTimeParseException.class, ".*2000/06/30.*"); }
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)); }