/** * Converts an FpML 'BusinessDayAdjustments' to a {@code BusinessDayAdjustment}. * * @param baseEl the FpML business centers or reference element to parse * @return the business day adjustment * @throws RuntimeException if unable to parse */ public BusinessDayAdjustment parseBusinessDayAdjustments(XmlElement baseEl) { // FpML content: ('businessDayConvention', 'BusinessCentersOrReference.model?') BusinessDayConvention bdc = convertBusinessDayConvention( baseEl.getChild("businessDayConvention").getContent()); Optional<XmlElement> centersEl = baseEl.findChild("businessCenters"); Optional<XmlElement> centersRefEl = baseEl.findChild("businessCentersReference"); HolidayCalendarId calendar = (centersEl.isPresent() || centersRefEl.isPresent() ? parseBusinessCenters(baseEl) : HolidayCalendarIds.NO_HOLIDAYS); return BusinessDayAdjustment.of(bdc, calendar); }
/** * Converts an FpML 'RelativeDateOffset' to a {@code DaysAdjustment}. * * @param baseEl the FpML adjustable date element * @return the days adjustment * @throws RuntimeException if unable to parse */ public DaysAdjustment parseRelativeDateOffsetDays(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period', 'dayType?', // 'businessDayConvention', 'BusinessCentersOrReference.model?' // 'dateRelativeTo', 'adjustedDate') // The 'dateRelativeTo' element is not used here // The 'adjustedDate' element is ignored Period period = parsePeriod(baseEl); if (period.toTotalMonths() != 0) { throw new FpmlParseException("Expected days-based period but found " + period); } Optional<XmlElement> dayTypeEl = baseEl.findChild("dayType"); boolean calendarDays = period.isZero() || (dayTypeEl.isPresent() && dayTypeEl.get().getContent().equals("Calendar")); BusinessDayConvention fixingBdc = convertBusinessDayConvention( baseEl.getChild("businessDayConvention").getContent()); HolidayCalendarId calendar = parseBusinessCenters(baseEl); if (calendarDays) { return DaysAdjustment.ofCalendarDays( period.getDays(), BusinessDayAdjustment.of(fixingBdc, calendar)); } else { return DaysAdjustment.ofBusinessDays(period.getDays(), calendar); } }