private static SwapTrade parseVariableNotional(SwapTrade trade, List<CsvRow> variableRows) { // parse notionals ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (CsvRow row : variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(NOTIONAL_FIELD) .map(str -> LoaderUtils.parseDouble(str)) .ifPresent(notional -> stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(notional)))); } ImmutableList<ValueStep> varNotionals = stepBuilder.build(); if (varNotionals.isEmpty()) { return trade; } // adjust the trade, inserting the variable notionals ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder(); for (SwapLeg swapLeg : trade.getProduct().getLegs()) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; NotionalSchedule notionalSchedule = leg.getNotionalSchedule().toBuilder() .amount(ValueSchedule.of(leg.getNotionalSchedule().getAmount().getInitialValue(), varNotionals)) .build(); legBuilder.add(leg.toBuilder().notionalSchedule(notionalSchedule).build()); } return replaceLegs(trade, legBuilder.build()); }
.map(s -> LoaderUtils.parseBoolean(s)) .ifPresent(v -> builder.finalExchange(v)); return builder.build();
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(); }
.finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
ValueStep.of(date(1998, 12, 14), ValueAdjustment.ofReplace(10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder() .payReceive(PAY)
.finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
date(1995, 12, 14), date(1998, 12, 14), Frequency.P12M, ValueAdjustment.ofDeltaAmount(-10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder() .payReceive(PAY)
ValueStep.of(date(1998, 12, 14), ValueAdjustment.ofReplace(10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder() .payReceive(PAY)
.finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
.finalExchange(notionalExchange) .initialExchange(notionalExchange) .amount(ValueSchedule.of(notional)).build()) .calculation(IborRateCalculation.builder() .index(index)
.fixingDateOffset(MINUS_TWO_DAYS) .build()) .build()) .calculation(IborRateCalculation.builder() .dayCount(DayCounts.ACT_365F)
.finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
public void test_builder_FxResetSetsFlags() { FxResetCalculation fxReset = FxResetCalculation.builder() .referenceCurrency(GBP) .index(GBP_USD_WM) .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)) .build(); NotionalSchedule test = NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(2000d)) .intermediateExchange(true) .finalExchange(true) .fxReset(fxReset) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getAmount(), ValueSchedule.of(2000d)); assertEquals(test.getFxReset(), Optional.of(fxReset)); assertEquals(test.isInitialExchange(), false); assertEquals(test.isIntermediateExchange(), true); assertEquals(test.isFinalExchange(), true); }
public void test_builder_invalidCurrencyFxReset() { assertThrowsIllegalArg(() -> NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(2000d)) .fxReset(FxResetCalculation.builder() .referenceCurrency(USD) .index(GBP_USD_WM) .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)) .build()) .build()); assertThrowsIllegalArg(() -> NotionalSchedule.builder() .currency(EUR) .amount(ValueSchedule.of(2000d)) .fxReset(FxResetCalculation.builder() .referenceCurrency(USD) .index(GBP_USD_WM) .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)) .build()) .build()); }
public void coverage() { NotionalSchedule test = NotionalSchedule.of(GBP, 1000d); coverImmutableBean(test); NotionalSchedule test2 = NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(2000d)) .fxReset(FxResetCalculation.builder() .referenceCurrency(GBP) .index(GBP_USD_WM) .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)) .build()) .initialExchange(true) .intermediateExchange(true) .finalExchange(true) .build(); coverBeanEquals(test, test2); }
/** * Obtains an instance with a notional amount that can change over time. * * @param currency the currency of the notional and swap payments * @param amountSchedule the schedule describing how the notional changes over time * @return the notional amount */ public static NotionalSchedule of(Currency currency, ValueSchedule amountSchedule) { ArgChecker.notNull(currency, "currency"); ArgChecker.notNull(amountSchedule, "amountSchedule"); return NotionalSchedule.builder() .currency(currency) .amount(amountSchedule) .build(); }
/** * Obtains an instance with a single amount that does not change over time. * * @param currency the currency of the notional and swap payments * @param amount the single notional amount that does not change over time * @return the notional amount */ public static NotionalSchedule of(Currency currency, double amount) { ArgChecker.notNull(currency, "currency"); return NotionalSchedule.builder() .currency(currency) .amount(ValueSchedule.of(amount)) .build(); }
/** * Obtains an instance with a single amount that does not change over time. * * @param notional the single notional that does not change over time * @return the notional amount */ public static NotionalSchedule of(CurrencyAmount notional) { ArgChecker.notNull(notional, "notional"); return NotionalSchedule.builder() .currency(notional.getCurrency()) .amount(ValueSchedule.of(notional.getAmount())) .build(); }