/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ValueSchedule beanToCopy) { this.initialValue = beanToCopy.getInitialValue(); this.steps = ImmutableList.copyOf(beanToCopy.getSteps()); this.stepSequence = beanToCopy.stepSequence; }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -418368371: // initialValue return ((ValueSchedule) bean).getInitialValue(); case 109761319: // steps return ((ValueSchedule) bean).getSteps(); case 2141410989: // stepSequence return ((ValueSchedule) bean).stepSequence; } return super.propertyGet(bean, propertyName, quiet); }
private void summarizeMainLeg(IborCapFloorLeg mainLeg, StringBuilder buf) { buf.append(mainLeg.getIndex()); buf.append(' '); if (mainLeg.getCapSchedule().isPresent()) { buf.append("Cap "); buf.append(SummarizerUtils.percent(mainLeg.getCapSchedule().get().getInitialValue())); } if (mainLeg.getFloorSchedule().isPresent()) { buf.append("Floor "); buf.append(SummarizerUtils.percent(mainLeg.getFloorSchedule().get().getInitialValue())); } }
private void summarizeMainLeg(CmsLeg mainLeg, StringBuilder buf) { buf.append(mainLeg.getIndex()); buf.append(' '); if (mainLeg.getCapSchedule().isPresent()) { buf.append("Cap "); buf.append(SummarizerUtils.percent(mainLeg.getCapSchedule().get().getInitialValue())); } if (mainLeg.getFloorSchedule().isPresent()) { buf.append("Floor "); buf.append(SummarizerUtils.percent(mainLeg.getFloorSchedule().get().getInitialValue())); } }
public void test_constant_ALWAYS_0() { ValueSchedule test = ValueSchedule.ALWAYS_0; assertEquals(test.getInitialValue(), 0d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
public void test_constant_ALWAYS_1() { ValueSchedule test = ValueSchedule.ALWAYS_1; assertEquals(test.getInitialValue(), 1d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
public void test_of_int() { ValueSchedule test = ValueSchedule.of(10000d); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
public void test_of_intStepsArray_empty() { ValueSchedule test = ValueSchedule.of(10000d, new ValueStep[0]); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
public void test_of_intStepsList_empty() { ValueSchedule test = ValueSchedule.of(10000d, Lists.newArrayList()); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
public void test_of_intStepsList() { ValueSchedule test = ValueSchedule.of(10000d, Lists.newArrayList(STEP1, STEP2)); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of(STEP1, STEP2)); }
public void test_of_intStepsArray() { ValueSchedule test = ValueSchedule.of(10000d, STEP1, STEP2); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of(STEP1, STEP2)); }
public void test_builder_validEmpty() { ValueSchedule test = ValueSchedule.builder().build(); assertEquals(test.getInitialValue(), 0d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
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 public PortfolioItemSummary summarize() { // 5Y USD 2mm Rec USD-LIBOR-1100-1Y Cap 1% / Pay Premium : 21Jan17-21Jan22 StringBuilder buf = new StringBuilder(96); CmsLeg mainLeg = product.getCmsLeg(); buf.append(SummarizerUtils.datePeriod(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); buf.append(' '); buf.append(SummarizerUtils.amount(mainLeg.getCurrency(), mainLeg.getNotional().getInitialValue())); buf.append(' '); if (mainLeg.getPayReceive().isReceive()) { buf.append("Rec "); summarizeMainLeg(mainLeg, buf); buf.append(getPremium().isPresent() ? " / Pay Premium" : (product.getPayLeg().isPresent() ? " / Pay Periodic" : "")); } else { buf.append( getPremium().isPresent() ? "Rec Premium / Pay " : (product.getPayLeg().isPresent() ? "Rec Periodic / Pay " : "")); summarizeMainLeg(mainLeg, buf); } buf.append(" : "); buf.append(SummarizerUtils.dateRange(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); return SummarizerUtils.summary(this, ProductType.CMS, buf.toString(), mainLeg.getCurrency()); }
@Override public PortfolioItemSummary summarize() { // 5Y USD 2mm Rec USD-LIBOR-6M Cap 1% / Pay Premium : 21Jan17-21Jan22 StringBuilder buf = new StringBuilder(96); IborCapFloorLeg mainLeg = product.getCapFloorLeg(); buf.append(SummarizerUtils.datePeriod(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); buf.append(' '); buf.append(SummarizerUtils.amount(mainLeg.getCurrency(), mainLeg.getNotional().getInitialValue())); buf.append(' '); if (mainLeg.getPayReceive().isReceive()) { buf.append("Rec "); summarizeMainLeg(mainLeg, buf); buf.append(getPremium().isPresent() ? " / Pay Premium" : (product.getPayLeg().isPresent() ? " / Pay Periodic" : "")); } else { buf.append( getPremium().isPresent() ? "Rec Premium / Pay " : (product.getPayLeg().isPresent() ? "Rec Periodic / Pay " : "")); summarizeMainLeg(mainLeg, buf); } buf.append(" : "); buf.append(SummarizerUtils.dateRange(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); return SummarizerUtils.summary(this, ProductType.IBOR_CAP_FLOOR, buf.toString(), mainLeg.getCurrency()); }
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_sequence() { ValueStepSequence seq = ValueStepSequence.of( date(2016, 4, 20), date(2016, 10, 20), Frequency.P3M, ValueAdjustment.ofDeltaAmount(-100)); ValueSchedule test = ValueSchedule.of(10000d, seq); assertEquals(test.getInitialValue(), 10000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); assertEquals(test.getStepSequence(), Optional.of(seq)); }
public void test_builder_validFull() { ValueStepSequence seq = ValueStepSequence.of( date(2016, 4, 20), date(2016, 10, 20), Frequency.P3M, ValueAdjustment.ofDeltaAmount(-100)); ValueSchedule test = ValueSchedule.builder() .initialValue(2000d) .steps(STEP1, STEP2) .stepSequence(seq) .build(); assertEquals(test.getInitialValue(), 2000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of(STEP1, STEP2)); assertEquals(test.getStepSequence(), Optional.of(seq)); }
@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"); }