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); }
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 '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); }
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(); }
private ValueStepSequence parseAmountSchedule(XmlElement scheduleEl, double initialValue, FpmlDocument document) { Frequency freq = document.parseFrequency(scheduleEl.getChild("stepFrequency")); LocalDate start = document.parseDate(scheduleEl.getChild("firstNotionalStepDate")); LocalDate end = document.parseDate(scheduleEl.getChild("lastNotionalStepDate")); Optional<XmlElement> amountElOpt = scheduleEl.findChild("notionalStepAmount"); if (amountElOpt.isPresent()) { double amount = document.parseDecimal(amountElOpt.get()); return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)); } double rate = document.parseDecimal(scheduleEl.getChild("notionalStepRate")); String relativeTo = scheduleEl.findChild("stepRelativeTo").map(el -> el.getContent()).orElse("Previous"); if (relativeTo.equals("Previous")) { return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaMultiplier(rate)); } else if (relativeTo.equals("Initial")) { // data model does not support 'relative to initial' but can calculate amount here double amount = initialValue * rate; return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)); } else { throw new FpmlParseException(Messages.format( "Unknown 'stepRelativeTo' value '{}', expected 'Initial' or 'Previous'", relativeTo)); } }
calcEl.findChild("futureValueNotional").ifPresent(fvnEl -> { FutureValueNotional notional = FutureValueNotional.builder() .value(document.parseDecimal(fvnEl.getChild("amount"))) .dayCountDays(fvnEl.findChild("calculationPeriodNumberOfDays") .map(str -> (int) document.parseDecimal(str)) .orElse(null)) .valueDate(fvnEl.findChild("valueDate").map(str -> document.parseDate(str)).orElse(null))
private IborRateStubCalculation parseStubCalculation(XmlElement baseEl, FpmlDocument document) { Optional<XmlElement> rateOptEl = baseEl.findChild("stubRate"); if (rateOptEl.isPresent()) { return IborRateStubCalculation.ofFixedRate(document.parseDecimal(rateOptEl.get()));
private NotionalSchedule parseSwapNotionalSchedule(XmlElement legEl, XmlElement calcEl, FpmlDocument document) { // supported elements: // 'principalExchanges/initialExchange' // 'principalExchanges/finalExchange' // 'principalExchanges/intermediateExchange' // 'calculationPeriodAmount/calculation/notionalSchedule/notionalStepSchedule' // 'calculationPeriodAmount/calculation/notionalSchedule/notionalStepParameters' NotionalSchedule.Builder notionalScheduleBuilder = NotionalSchedule.builder(); // exchanges legEl.findChild("principalExchanges").ifPresent(el -> { notionalScheduleBuilder.initialExchange(Boolean.parseBoolean(el.getChild("initialExchange").getContent())); notionalScheduleBuilder.intermediateExchange( Boolean.parseBoolean(el.getChild("intermediateExchange").getContent())); notionalScheduleBuilder.finalExchange(Boolean.parseBoolean(el.getChild("finalExchange").getContent())); }); // notional schedule XmlElement notionalEl = calcEl.getChild("notionalSchedule"); XmlElement stepScheduleEl = notionalEl.getChild("notionalStepSchedule"); Optional<XmlElement> paramScheduleElOpt = notionalEl.findChild("notionalStepParameters"); double initialValue = document.parseDecimal(stepScheduleEl.getChild("initialValue")); ValueStepSequence seq = paramScheduleElOpt.map(el -> parseAmountSchedule(el, initialValue, document)).orElse(null); notionalScheduleBuilder.amount(parseSchedule(stepScheduleEl, initialValue, seq, document)); notionalScheduleBuilder.currency(document.parseCurrency(stepScheduleEl.getChild("currency"))); return notionalScheduleBuilder.build(); }
builder.firstIndexValue(document.parseDecimal(el)); });
iborRateBuilder.firstRegularRate(document.parseDecimal(el)); });
.orElse(null)); XmlElement fixedAmountCalcEl = periodicPaymentEl.getChild("fixedAmountCalculation"); double fixedRate = document.parseDecimal(fixedAmountCalcEl.getChild("fixedRate")); DayCount dayCount = fixedAmountCalcEl.findChild("dayCountFraction") .map(el -> document.parseDayCountFraction(el))
fraBuilder.notional(notional.getAmount()); fraBuilder.fixedRate(document.parseDecimal(fraEl.getChild("fixedRate")));
double rate = document.parseDecimal(rateEl.getChild("rate")); XmlElement pairEl = rateEl.getChild("quotedCurrencyPair"); Currency curr1 = document.parseCurrency(pairEl.getChild("currency1"));
termBuilder.notional(principal.getAmount()); termBuilder.rate(document.parseDecimal(termEl.getChild("fixedRate")));