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_of_CurrencyAmount() { NotionalSchedule test = NotionalSchedule.of(CA_GBP_1000); assertEquals(test.getCurrency(), GBP); assertEquals(test.getAmount(), ValueSchedule.of(1000d)); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.isInitialExchange(), false); assertEquals(test.isIntermediateExchange(), false); assertEquals(test.isFinalExchange(), false); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(NotionalSchedule beanToCopy) { this.currency = beanToCopy.getCurrency(); this.fxReset = beanToCopy.fxReset; this.amount = beanToCopy.getAmount(); this.initialExchange = beanToCopy.isInitialExchange(); this.intermediateExchange = beanToCopy.isIntermediateExchange(); this.finalExchange = beanToCopy.isFinalExchange(); }
private IntFunction<CurrencyAmount> getNotionalSupplierFunction( NotionalSchedule notionalSchedule, DoubleArray notionals, PayReceive payReceive) { boolean hasInitialFxNotional = notionalSchedule.getFxReset().isPresent() && notionalSchedule.getFxReset().get().getInitialNotionalValue().isPresent(); return index -> { if (hasInitialFxNotional && index == 0) { FxResetCalculation fxReset = notionalSchedule.getFxReset().get(); //If Fx reset leg with fixed initial notional then return the fixed amount in the payment currency double notional = payReceive.normalize(fxReset.getInitialNotionalValue().getAsDouble()); Currency currency = fxReset.getIndex().getCurrencyPair().other(fxReset.getReferenceCurrency()); return CurrencyAmount.of(currency, notional); } else { double notional = payReceive.normalize(notionals.get(index)); return CurrencyAmount.of(notionalSchedule.getCurrency(), notional); } }; }
public void test_serialization() { NotionalSchedule test = NotionalSchedule.of(GBP, 1000d); assertSerialization(test); }
/** * 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(); }
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); }
private String notional(SwapLeg leg) { if (leg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg rcLeg = (RateCalculationSwapLeg) leg; NotionalSchedule notionalSchedule = rcLeg.getNotionalSchedule(); ValueSchedule amount = notionalSchedule.getAmount(); double notional = amount.getInitialValue(); String vary = !amount.getSteps().isEmpty() || amount.getStepSequence().isPresent() ? " variable" : ""; Currency currency = notionalSchedule.getFxReset().map(fxr -> fxr.getReferenceCurrency()).orElse(rcLeg.getCurrency()); return SummarizerUtils.amount(currency, notional) + vary; } if (leg instanceof RatePeriodSwapLeg) { RatePeriodSwapLeg rpLeg = (RatePeriodSwapLeg) leg; return SummarizerUtils.amount(rpLeg.getPaymentPeriods().get(0).getNotionalAmount()); } return ""; }
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()); }
@Override @DerivedProperty public Currency getCurrency() { return notionalSchedule.getCurrency(); }
@ImmutableValidator private void validate() { ArgChecker.isFalse(underlyingSwap.isCrossCurrency(), "Underlying swap must not be cross currency"); for (SwapLeg swapLeg : underlyingSwap.getLegs()) { if (swapLeg.getType().equals(SwapLegType.FIXED)) { ArgChecker.isTrue(swapLeg.getPayReceive().isReceive(), "Underlying swap must receive the fixed leg"); } if (swapLeg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; ArgChecker.isTrue(Math.abs(leg.getNotionalSchedule().getAmount().getInitialValue()) == 1d, "Underlying swap must have a notional of 1"); } } }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { calculation.collectIndices(builder); notionalSchedule.getFxReset().ifPresent(fxReset -> builder.add(fxReset.getIndex())); }
public void test_of_null() { assertThrowsIllegalArg(() -> NotionalSchedule.of(null)); assertThrowsIllegalArg(() -> NotionalSchedule.of(null, 1000d)); assertThrowsIllegalArg(() -> NotionalSchedule.of(GBP, null)); assertThrowsIllegalArg(() -> NotionalSchedule.of(null, ValueSchedule.of(1000d))); assertThrowsIllegalArg(() -> NotionalSchedule.of(null, null)); }
/** * 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(); }
.paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(USD, 10d)) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.builder() .currency(USD) .amount(ValueSchedule.of(500d))
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((NotionalSchedule) bean).getCurrency(); case -449555555: // fxReset return ((NotionalSchedule) bean).fxReset; case -1413853096: // amount return ((NotionalSchedule) bean).getAmount(); case -511982201: // initialExchange return ((NotionalSchedule) bean).isInitialExchange(); case -2147112388: // intermediateExchange return ((NotionalSchedule) bean).isIntermediateExchange(); case -1048781383: // finalExchange return ((NotionalSchedule) bean).isFinalExchange(); } return super.propertyGet(bean, propertyName, quiet); }
ReferenceData refData) { DoubleArray notionals = notionalSchedule.getAmount().resolveValues(paymentSchedule); notionalSchedule.getFxReset().map(calc -> calc.resolve(refData)).orElse((i, p) -> Optional.empty());
private static RateCalculationSwapLeg parseLeg( CsvRow row, String leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount) { PayReceive payReceive = LoaderUtils.parsePayReceive(getValue(row, leg, DIRECTION_FIELD)); PeriodicSchedule accrualSch = parseAccrualSchedule(row, leg); PaymentSchedule paymentSch = parsePaymentSchedule(row, leg, accrualSch.getFrequency()); NotionalSchedule notionalSch = parseNotionalSchedule(row, leg); RateCalculation calc = parseRateCalculation( row, leg, index, defaultFixedLegDayCount, accrualSch.getBusinessDayAdjustment(), notionalSch.getCurrency()); return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(accrualSch) .paymentSchedule(paymentSch) .notionalSchedule(notionalSch) .calculation(calc) .build(); }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual( deliveryDate, underlyingSwap.getStartDate().getUnadjusted(), "deliveryDate", "underlyingSwap.startDate.unadjusted"); ArgChecker.isFalse(underlyingSwap.isCrossCurrency(), "Underlying swap must not be cross currency"); for (SwapLeg swapLeg : underlyingSwap.getLegs()) { if (swapLeg.getType().equals(SwapLegType.FIXED)) { ArgChecker.isTrue(swapLeg.getPayReceive().isReceive(), "Underlying swap must receive the fixed leg"); } if (swapLeg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; ArgChecker.isTrue(Math.abs(leg.getNotionalSchedule().getAmount().getInitialValue()) == 1d, "Underlying swap must have a notional of 1"); } } ArgChecker.inOrderOrEqual(lastTradeDate, deliveryDate, "lastTradeDate", "deliveryDate"); }
@Override public void collectCurrencies(ImmutableSet.Builder<Currency> builder) { builder.add(getCurrency()); calculation.collectCurrencies(builder); notionalSchedule.getFxReset().ifPresent(fxReset -> builder.add(fxReset.getReferenceCurrency())); }