builder.currency(currency); builder.amount(ValueSchedule.of(LoaderUtils.parseDouble(getValueWithFallback(row, leg, NOTIONAL_FIELD)))); fxFixingRelativeToOpt.ifPresent(v -> fxResetBuilder.fixingRelativeTo(v)); fxResetAdjOpt.ifPresent(v -> fxResetBuilder.fixingDateOffset(v)); builder.fxReset(fxResetBuilder.build()); } else if (notionalCurrencyOpt.isPresent() || fxFixingRelativeToOpt.isPresent() || fxResetAdjOpt.isPresent()) { throw new IllegalArgumentException("Swap trade FX Reset must define field '" + leg + FX_RESET_INDEX_FIELD + "'"); .ifPresent(v -> builder.initialExchange(v)); findValue(row, leg, NOTIONAL_INTERMEDIATE_EXCHANGE_FIELD) .map(s -> LoaderUtils.parseBoolean(s)) .ifPresent(v -> builder.intermediateExchange(v)); findValue(row, leg, NOTIONAL_FINAL_EXCHANGE_FIELD) .map(s -> LoaderUtils.parseBoolean(s)) .ifPresent(v -> builder.finalExchange(v)); return builder.build();
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(GBP) .amount(ValueSchedule.of(1000d)) .fxReset(FxResetCalculation.builder() .referenceCurrency(EUR) .index(EUR_GBP_ECB) .fixingDateOffset(MINUS_TWO_DAYS) .build()) .initialExchange(true) .intermediateExchange(true) .finalExchange(true) .build()) .calculation(FixedRateCalculation.builder() .dayCount(ACT_365F)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(GBP) .amount(ValueSchedule.of(1000d, ValueStep.of(1, ValueAdjustment.ofReplace(1500d)))) .initialExchange(true) .intermediateExchange(true) .finalExchange(true) .build()) .calculation(IborRateCalculation.builder() .dayCount(ACT_365F)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(500d)) .finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(500d)) .finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
.currency(EUR) .amount(ValueSchedule.builder() .initialValue(50000000d) .stepSequence(ValueStepSequence.of( date(1995, 12, 14), date(1998, 12, 14), Frequency.P12M, ValueAdjustment.ofDeltaAmount(-10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder() .payReceive(PAY)
.build()) .notionalSchedule(NotionalSchedule.builder() .finalExchange(true) .initialExchange(true) .amount(ValueSchedule.of(NOTIONAL_EUR)) .currency(EUR) .build()) .calculation(IborRateCalculation.builder() .index(EUR_EURIBOR_3M) .build()) .notionalSchedule(NotionalSchedule.builder() .finalExchange(true) .initialExchange(true) .amount(ValueSchedule.of(NOTIONAL_USD)) .currency(USD) .build()) .calculation(IborRateCalculation.builder() .index(USD_LIBOR_3M)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(500d)) .finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
.build()) .notionalSchedule(NotionalSchedule.builder() .finalExchange(finalExchange) .initialExchange(initialExchange) .amount(ValueSchedule.of(NOTIONAL_EUR)) .currency(EUR) .build()) .calculation(IborRateCalculation.builder() .index(EUR_EURIBOR_3M) .build()) .notionalSchedule(NotionalSchedule.builder() .finalExchange(finalExchange) .initialExchange(initialExchange) .intermediateExchange(intermediateExchange) .amount(ValueSchedule.of(NOTIONAL_USD)) .currency(USD) .fxReset(FxResetCalculation.builder() .fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)) .referenceCurrency(EUR) .initialNotionalValue(initialNotional) .build()) .build()) .calculation(IborRateCalculation.builder() .index(USD_LIBOR_3M)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(getCurrency()) .finalExchange(notionalExchange) .initialExchange(notionalExchange) .amount(ValueSchedule.of(notional)).build()) .calculation(IborRateCalculation.builder() .index(index)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(GBP) .amount(ValueSchedule.of(1000d)) .finalExchange(true) .fxReset(FxResetCalculation.builder() .referenceCurrency(EUR) .index(EUR_GBP_ECB) .fixingDateOffset(MINUS_TWO_DAYS) .build()) .build()) .calculation(IborRateCalculation.builder() .dayCount(DayCounts.ACT_365F)
.build()) .notionalSchedule(NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(1d)) .finalExchange(true) .initialExchange(true) .build()) .calculation(IborRateCalculation.builder() .index(INDEX)
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()); }
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(); }
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 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 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(); }