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); }
private ImmutableList<String> findOurParty(FpmlPartySelector ourPartySelector) { // check for "any" selector to avoid logging message in normal case if (ourPartySelector == FpmlPartySelector.any()) { return ImmutableList.of(); } List<String> selected = ourPartySelector.selectParties(parties); if (!selected.isEmpty()) { for (String id : selected) { if (!parties.keySet().contains(id)) { throw new FpmlParseException(Messages.format( "Selector returned an ID '{}' that is not present in the document: {}", id, parties)); } } return ImmutableList.copyOf(selected); } log.warn("Failed to resolve \"our\" counterparty from FpML document, using leg defaults instead: " + parties); return ImmutableList.of(); }
@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 test_matching() { assertEquals(FpmlPartySelector.matching("a1").selectParties(MAP), ImmutableList.of("A")); assertEquals(FpmlPartySelector.matching("a2").selectParties(MAP), ImmutableList.of("A")); assertEquals(FpmlPartySelector.matching("b").selectParties(MAP), ImmutableList.of("B")); assertEquals(FpmlPartySelector.matching("c").selectParties(MAP), ImmutableList.of()); }
public void test_matchingRegex() { assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("a[12]")).selectParties(MAP), ImmutableList.of("A")); assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("b")).selectParties(MAP), ImmutableList.of("B")); assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("c[0-9]")).selectParties(MAP), ImmutableList.of("C1", "C2")); assertEquals(FpmlPartySelector.matchingRegex(Pattern.compile("d")).selectParties(MAP), ImmutableList.of()); }
public void bulletPayment_twoTradesTwoParties() { String location = "classpath:com/opengamma/strata/loader/fpml/bullet-payment-weird.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); FpmlPartySelector selector = FpmlPartySelector.matchingRegex(Pattern.compile("Party1[ab]")); List<Trade> trades = FpmlDocumentParser.of(selector).parseTrades(resource); assertEquals(trades.size(), 2); Trade trade0 = trades.get(0); assertEquals(trade0.getClass(), BulletPaymentTrade.class); BulletPaymentTrade bpTrade0 = (BulletPaymentTrade) trade0; assertEquals(bpTrade0.getInfo().getTradeDate(), Optional.of(date(2001, 4, 29))); assertEquals(bpTrade0.getInfo().getId().get().getValue(), "123"); BulletPayment bp0 = bpTrade0.getProduct(); assertEquals(bp0.getPayReceive(), PAY); assertEquals(bp0.getDate(), AdjustableDate.of(date(2001, 7, 27), BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO_USNY))); assertEquals(bp0.getValue(), CurrencyAmount.of(USD, 15000)); Trade trade1 = trades.get(1); assertEquals(trade1.getClass(), BulletPaymentTrade.class); BulletPaymentTrade bpTrade1 = (BulletPaymentTrade) trade1; assertEquals(bpTrade1.getInfo().getTradeDate(), Optional.of(date(2001, 4, 29))); assertEquals(bpTrade1.getInfo().getId().get().getValue(), "124"); BulletPayment bp1 = bpTrade1.getProduct(); assertEquals(bp1.getPayReceive(), RECEIVE); assertEquals(bp1.getDate(), AdjustableDate.of(date(2001, 8, 27), BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO_USNY))); assertEquals(bp1.getValue(), CurrencyAmount.of(USD, 15000)); }
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 test_any() { assertEquals(FpmlPartySelector.any().selectParties(MAP), ImmutableList.of()); }
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 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 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 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 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 document() { 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.getFpmlRoot(), rootEl); assertEquals(test.getParties(), ImmutableListMultimap.of()); assertEquals(test.getReferences(), ImmutableMap.of()); assertEquals(test.getOurPartyHrefIds(), ImmutableList.of()); assertThrows(() -> test.lookupReference(tradeEl), FpmlParseException.class, ".*reference not found.*"); assertThrows(() -> test.validateNotPresent(tradeEl, "tradeHeader"), FpmlParseException.class, ".*tradeHeader.*"); }
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 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 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 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 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_noParty() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.any()).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FraTrade.class); FraTrade fraTrade = (FraTrade) trade; assertEquals(fraTrade.getInfo().getTradeDate(), Optional.of(date(1991, 5, 14))); Fra fra = fraTrade.getProduct(); assertEquals(fra.getBuySell(), BUY); assertEquals(fra.getStartDate(), date(1991, 7, 17)); assertEquals(fra.getEndDate(), date(1992, 1, 17)); assertEquals(fra.getBusinessDayAdjustment(), Optional.empty()); assertEquals(fra.getPaymentDate().getUnadjusted(), date(1991, 7, 17)); assertEquals(fra.getPaymentDate().getAdjustment(), BusinessDayAdjustment.of(FOLLOWING, CHZU)); assertEquals(fra.getFixingDateOffset().getDays(), -2); assertEquals(fra.getFixingDateOffset().getCalendar(), GBLO); assertEquals(fra.getFixingDateOffset().getAdjustment(), BusinessDayAdjustment.NONE); assertEquals(fra.getDayCount(), ACT_360); assertEquals(fra.getCurrency(), CHF); assertEquals(fra.getNotional(), 25000000d); assertEquals(fra.getFixedRate(), 0.04d); assertEquals(fra.getIndex(), CHF_LIBOR_6M); assertEquals(fra.getIndexInterpolated(), Optional.empty()); assertEquals(fra.getDiscounting(), FraDiscountingMethod.ISDA); // check same when using a specific selector instead of FpmlPartySelector.any() List<Trade> trades2 = FpmlDocumentParser.of(allParties -> ImmutableList.of()).parseTrades(resource); assertEquals(trades2, trades); }