/** * 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 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 ""; }
@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);
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); }
public void test_of_CurrencyAndAmount() { NotionalSchedule test = NotionalSchedule.of(GBP, 1000d); 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); }
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()); }
public void test_of_CurrencyAndValueSchedule() { ValueSchedule valueSchedule = ValueSchedule.of(1000d, ValueStep.of(1, ValueAdjustment.ofReplace(2000d))); NotionalSchedule test = NotionalSchedule.of(GBP, valueSchedule); assertEquals(test.getCurrency(), GBP); assertEquals(test.getAmount(), valueSchedule); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.isInitialExchange(), false); assertEquals(test.isIntermediateExchange(), false); assertEquals(test.isFinalExchange(), false); }
@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"); } } }
@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"); }
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); }