private LocalTime parseExpiryTime(XmlElement expirationTimeEl, FpmlDocument document) { return document.parseTime(expirationTimeEl.getChild("hourMinuteTime")); }
private ValueSchedule parseSchedule(XmlElement scheduleEl, double initialValue, ValueStepSequence seq, FpmlDocument document) { List<XmlElement> stepEls = scheduleEl.getChildren("step"); ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (XmlElement stepEl : stepEls) { LocalDate stepDate = document.parseDate(stepEl.getChild("stepDate")); double stepValue = document.parseDecimal(stepEl.getChild("stepValue")); stepBuilder.add(ValueStep.of(stepDate, ValueAdjustment.ofReplace(stepValue))); } return ValueSchedule.builder().initialValue(initialValue).steps(stepBuilder.build()).stepSequence(seq).build(); }
public void test_of_ByteSource_parsedReferences() { ByteSource source = ByteSource.wrap(SAMPLE.getBytes(StandardCharsets.UTF_8)); XmlFile test = XmlFile.of(source, "key"); XmlElement root = test.getRoot(); assertEquals(root.getName(), "base"); assertEquals(root.getAttributes(), ATTR_MAP_EMPTY); assertEquals(root.getContent(), ""); assertEquals(root.getChildren().size(), 1); XmlElement child = root.getChild(0); assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI)); assertEquals(test.getReferences(), ImmutableMap.of("value", root.getChild(0))); }
private AdjustableDate parseExpiryDate(XmlElement europeanExerciseEl, FpmlDocument document) { XmlElement expirationDate = europeanExerciseEl.getChild("expirationDate"); return expirationDate.findChild("adjustableDate") .map(el -> document.parseAdjustableDate(el)).get(); }
public void test_ofChildren_one() { XmlElement test = XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_ONE); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_ONE); assertEquals(test.getAttribute("key"), "value"); assertEquals(test.findAttribute("key"), Optional.of("value")); assertEquals(test.findAttribute("none"), Optional.empty()); assertEquals(test.getChild(0), LEAF1); assertEquals(test.getChild("leaf1"), LEAF1); assertEquals(test.findChild("leaf1"), Optional.of(LEAF1)); assertEquals(test.getChildren("leaf1"), ImmutableList.of(LEAF1)); assertEquals(test.toString(), "<test key=\"value\" og=\"strata\">" + System.lineSeparator() + " <leaf1 ... />" + System.lineSeparator() + "</test>"); }
/** * 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 test_ofChildren_empty() { XmlElement test = XmlElement.ofChildren("test", CHILD_LIST_EMPTY); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test></test>"); }
/** * 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); }
public void test_of_ByteSource() { ByteSource source = ByteSource.wrap(SAMPLE.getBytes(StandardCharsets.UTF_8)); XmlFile test = XmlFile.of(source); XmlElement root = test.getRoot(); assertEquals(root.getName(), "base"); assertEquals(root.getAttributes(), ATTR_MAP_EMPTY); assertEquals(root.getContent(), ""); assertEquals(root.getChildren().size(), 1); XmlElement child = root.getChild(0); assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI)); assertEquals(test.getReferences(), ImmutableMap.of()); }
/** * Converts an FpML 'Period' to a {@code Period}. * * @param baseEl the FpML element to parse * @return the period * @throws RuntimeException if unable to parse */ public Period parsePeriod(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period') String multiplier = baseEl.getChild("periodMultiplier").getContent(); String unit = baseEl.getChild("period").getContent(); return Period.parse("P" + multiplier + unit); }
public void test_ofContent() { XmlElement test = XmlElement.ofContent("test", ATTR_MAP_EMPTY, "hello"); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), true); assertEquals(test.getContent(), "hello"); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test>hello</test>"); }
/** * Converts an FpML 'Money' to a {@code CurrencyAmount}. * * @param baseEl the FpML money element to parse * @return the currency amount * @throws RuntimeException if unable to parse */ public CurrencyAmount parseCurrencyAmount(XmlElement baseEl) { // FpML content: ('currency', 'amount') Currency currency = parseCurrency(baseEl.getChild("currency")); double amount = parseDecimal(baseEl.getChild("amount")); return CurrencyAmount.of(currency, amount); }
public void test_ofContent_empty() { XmlElement test = XmlElement.ofContent("test", ""); assertEquals(test.getName(), "test"); assertEquals(test.getAttributes(), ATTR_MAP_EMPTY); assertEquals(test.hasContent(), false); assertEquals(test.getContent(), ""); assertEquals(test.getChildren(), CHILD_LIST_EMPTY); assertThrowsIllegalArg(() -> test.getAttribute("notFound")); assertThrows(() -> test.getChild(0), IndexOutOfBoundsException.class); assertThrowsIllegalArg(() -> test.getChild("notFound")); assertEquals(test.findChild("notFound"), Optional.empty()); assertEquals(test.getChildren("notFound"), ImmutableList.of()); assertEquals(test.toString(), "<test></test>"); }
private ValueSchedule parseSchedule(XmlElement scheduleEl, FpmlDocument document) { // FpML content: ('initialValue', 'step*') // FpML 'step' content: ('stepDate', 'stepValue') double initialValue = document.parseDecimal(scheduleEl.getChild("initialValue")); return parseSchedule(scheduleEl, initialValue, null, document); }
public void test_of_ByteSource_namespace() { ByteSource source = ByteSource.wrap(SAMPLE_NAMESPACE.getBytes(StandardCharsets.UTF_8)); XmlFile test = XmlFile.of(source); XmlElement root = test.getRoot(); assertEquals(root.getName(), "base"); assertEquals(root.getAttributes(), ImmutableMap.of()); assertEquals(root.getContent(), ""); assertEquals(root.getChildren().size(), 2); XmlElement child1 = root.getChild(0); assertEquals(child1.getName(), "p"); assertEquals(child1.getContent(), "Some text"); assertEquals(child1.getAttributes(), ImmutableMap.of()); XmlElement child2 = root.getChild(1); assertEquals(child2.getName(), "leaf1"); assertEquals(child2.getContent(), "leaf"); assertEquals(child2.getAttributes(), ImmutableMap.of("foo", "bla", "og", "strata")); assertEquals(test.getReferences(), ImmutableMap.of()); }
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(); }
private AdjustablePayment parsePremium(XmlElement swaptionEl, FpmlDocument document, TradeInfoBuilder tradeInfoBuilder) { XmlElement premiumEl = swaptionEl.getChild("premium"); PayReceive payReceive = document.parsePayerReceiver(premiumEl, tradeInfoBuilder); XmlElement paymentAmountEl = premiumEl.getChild("paymentAmount"); CurrencyAmount ccyAmount = document.parseCurrencyAmount(paymentAmountEl); ccyAmount = payReceive.isPay() ? ccyAmount.negated() : ccyAmount; AdjustableDate paymentDate = premiumEl.findChild("paymentDate") .map(el -> document.parseAdjustableDate(el)).get(); return AdjustablePayment.of(ccyAmount, paymentDate); }
@Override public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { // supported elements: // 'nearLeg' // 'farLeg' TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl); XmlElement fxEl = tradeEl.getChild("fxSwap"); FxSingle nearLeg = parseLeg(fxEl.getChild("nearLeg"), document, tradeInfoBuilder); FxSingle farLeg = parseLeg(fxEl.getChild("farLeg"), document, tradeInfoBuilder); return FxSwapTrade.builder() .info(tradeInfoBuilder.build()) .product(FxSwap.of(nearLeg, farLeg)) .build(); }
private SwaptionSettlement parseSettlement(XmlElement swaptionEl, FpmlDocument document) { Optional<String> optionalCashSettlement = swaptionEl.findAttribute("cashSettlement"); if (optionalCashSettlement.isPresent()) { XmlElement cashSettlementEl = swaptionEl.getChild("cashSettlement"); CashSwaptionSettlementMethod method = parseCashSettlementMethod(cashSettlementEl); LocalDate settlementDate = document.parseAdjustedRelativeDateOffset(cashSettlementEl).getUnadjusted(); return CashSwaptionSettlement.of(settlementDate, method); } else { // treat physical as the default to match FpML examples return PhysicalSwaptionSettlement.DEFAULT; } }
/** * Converts an FpML 'FloatingRateIndex.model' to a {@code PriceIndex}. * * @param baseEl the FpML floating rate model element to parse * @return the index * @throws RuntimeException if unable to parse */ public PriceIndex parsePriceIndex(XmlElement baseEl) { XmlElement indexEl = baseEl.getChild("floatingRateIndex"); validateScheme(indexEl, "floatingRateIndexScheme", "http://www.fpml.org/coding-scheme/inflation-index-description"); FloatingRateName floatingName = FloatingRateName.of(indexEl.getContent()); return floatingName.toPriceIndex(); }