private static PaymentSchedule parsePaymentSchedule(CsvRow row, String leg, Frequency accrualFrequency) { PaymentSchedule.Builder builder = PaymentSchedule.builder(); // basics builder.paymentFrequency(findValue(row, leg, PAYMENT_FREQUENCY_FIELD) .map(s -> Frequency.parse(s)) .orElse(accrualFrequency)); Optional<DaysAdjustment> offsetOpt = parseDaysAdjustment( row, leg, PAYMENT_OFFSET_DAYS_FIELD, PAYMENT_OFFSET_CAL_FIELD, PAYMENT_OFFSET_ADJ_CNV_FIELD, PAYMENT_OFFSET_ADJ_CAL_FIELD); builder.paymentDateOffset(offsetOpt.orElse(DaysAdjustment.NONE)); // optionals findValue(row, leg, PAYMENT_RELATIVE_TO_FIELD) .map(s -> PaymentRelativeTo.of(s)) .ifPresent(v -> builder.paymentRelativeTo(v)); findValue(row, leg, COMPOUNDING_METHOD_FIELD) .map(s -> CompoundingMethod.of(s)) .ifPresent(v -> builder.compoundingMethod(v)); findValue(row, leg, PAYMENT_FIRST_REGULAR_START_DATE_FIELD) .map(s -> LoaderUtils.parseDate(s)) .ifPresent(v -> builder.firstRegularStartDate(v)); findValue(row, leg, PAYMENT_LAST_REGULAR_END_DATE_FIELD) .map(s -> LoaderUtils.parseDate(s)) .ifPresent(v -> builder.lastRegularEndDate(v)); return builder.build(); }
public void test_createSchedule_sameFrequency() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); Schedule schedule = test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA); assertEquals(schedule, ACCRUAL_SCHEDULE); }
public void test_builder_ensureDefaults() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); assertEquals(test.getPaymentFrequency(), P1M); assertEquals(test.getBusinessDayAdjustment(), Optional.empty()); assertEquals(test.getPaymentDateOffset(), DaysAdjustment.ofBusinessDays(2, GBLO)); assertEquals(test.getPaymentRelativeTo(), PERIOD_END); assertEquals(test.getCompoundingMethod(), NONE); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(PaymentSchedule beanToCopy) { this.paymentFrequency = beanToCopy.getPaymentFrequency(); this.businessDayAdjustment = beanToCopy.businessDayAdjustment; this.paymentRelativeTo = beanToCopy.getPaymentRelativeTo(); this.paymentDateOffset = beanToCopy.getPaymentDateOffset(); this.compoundingMethod = beanToCopy.getCompoundingMethod(); this.firstRegularStartDate = beanToCopy.firstRegularStartDate; this.lastRegularEndDate = beanToCopy.lastRegularEndDate; }
private List<SwapPaymentPeriod> createPaymentPeriods(Schedule resolvedPayments, ReferenceData refData) { // resolve amount schedule against payment schedule DoubleArray amounts = amount.resolveValues(resolvedPayments); // resolve against reference data once DateAdjuster paymentDateAdjuster = paymentSchedule.getPaymentDateOffset().resolve(refData); // build up payment periods using schedule ImmutableList.Builder<SwapPaymentPeriod> paymentPeriods = ImmutableList.builder(); for (int index = 0; index < resolvedPayments.size(); index++) { SchedulePeriod paymentPeriod = resolvedPayments.getPeriod(index); LocalDate baseDate = paymentSchedule.getPaymentRelativeTo().selectBaseDate(paymentPeriod); LocalDate paymentDate = paymentDateAdjuster.adjust(baseDate); double amount = payReceive.normalize(amounts.get(index)); Payment payment = Payment.of(CurrencyAmount.of(currency, amount), paymentDate); paymentPeriods.add(KnownAmountSwapPaymentPeriod.of(payment, paymentPeriod)); } return paymentPeriods.build(); }
/** * Converts this swap leg to the equivalent {@code ResolvedSwapLeg}. * <p> * An {@link ResolvedSwapLeg} represents the same data as this leg, but with * a complete schedule of dates defined using {@link RatePaymentPeriod}. * * @return the equivalent resolved swap leg * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data * @throws RuntimeException if unable to resolve due to an invalid swap schedule or definition */ @Override public ResolvedSwapLeg resolve(ReferenceData refData) { DayCount dayCount = calculation.getDayCount(); Schedule resolvedAccruals = accrualSchedule.createSchedule(refData); Schedule resolvedPayments = paymentSchedule.createSchedule(resolvedAccruals, refData); List<RateAccrualPeriod> accrualPeriods = calculation.createAccrualPeriods(resolvedAccruals, resolvedPayments, refData); List<NotionalPaymentPeriod> payPeriods = paymentSchedule.createPaymentPeriods( resolvedAccruals, resolvedPayments, accrualPeriods, dayCount, notionalSchedule, payReceive, refData); LocalDate startDate = accrualPeriods.get(0).getStartDate(); ImmutableList<SwapPaymentEvent> payEvents = notionalSchedule.createEvents(payPeriods, startDate, refData); return new ResolvedSwapLeg(getType(), payReceive, payPeriods, payEvents, getCurrency()); }
/** * Converts this swap leg to the equivalent {@code ResolvedSwapLeg}. * <p> * An {@link ResolvedSwapLeg} represents the same data as this leg, but with * a complete schedule of dates defined using {@link KnownAmountSwapPaymentPeriod}. * * @param refData the reference data to use when resolving * @return the equivalent resolved swap leg * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data * @throws RuntimeException if unable to resolve due to an invalid swap schedule or definition */ @Override public ResolvedSwapLeg resolve(ReferenceData refData) { Schedule resolvedAccruals = accrualSchedule.createSchedule(refData); Schedule resolvedPayments = paymentSchedule.createSchedule(resolvedAccruals, refData); List<SwapPaymentPeriod> payPeriods = createPaymentPeriods(resolvedPayments, refData); return new ResolvedSwapLeg(getType(), payReceive, payPeriods, ImmutableList.of(), currency); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 863656438: // paymentFrequency return ((PaymentSchedule) bean).getPaymentFrequency(); case -1065319863: // businessDayAdjustment return ((PaymentSchedule) bean).businessDayAdjustment; case -1357627123: // paymentRelativeTo return ((PaymentSchedule) bean).getPaymentRelativeTo(); case -716438393: // paymentDateOffset return ((PaymentSchedule) bean).getPaymentDateOffset(); case -1376171496: // compoundingMethod return ((PaymentSchedule) bean).getCompoundingMethod(); case 2011803076: // firstRegularStartDate return ((PaymentSchedule) bean).firstRegularStartDate; case -1540679645: // lastRegularEndDate return ((PaymentSchedule) bean).lastRegularEndDate; } return super.propertyGet(bean, propertyName, quiet); }
PaymentSchedule.Builder paymentScheduleBuilder = PaymentSchedule.builder();
public void test_createSchedule_singleAccrualPeriod() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); Schedule schedule = test.createSchedule(ACCRUAL_SCHEDULE_SINGLE, REF_DATA); assertEquals(schedule, ACCRUAL_SCHEDULE_SINGLE); }
public void test_serialization() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P3M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); assertSerialization(test); }
public void test_createSchedule_term() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); Schedule schedule = test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA); assertEquals(schedule, ACCRUAL_SCHEDULE_TERM); }
public void test_collectIndices() { KnownAmountSwapLeg test = KnownAmountSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build()) .amount(ValueSchedule.of(123d)) .currency(GBP) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of()); assertEquals(test.allIndices(), ImmutableSet.of()); }
public void test_createSchedule_term_badFirstRegular() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .firstRegularStartDate(DATE_05_05) .build(); assertThrowsIllegalArg(() -> test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA)); }
public void test_collectIndices_simple() { RateCalculationSwapLeg test = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(PLUS_TWO_DAYS) .build()) .notionalSchedule(NotionalSchedule.of(GBP, 1000d)) .calculation(IborRateCalculation.builder() .dayCount(DayCounts.ACT_365F) .index(GBP_LIBOR_3M) .fixingDateOffset(MINUS_TWO_DAYS) .build()) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_3M)); assertEquals(test.allIndices(), ImmutableSet.of(GBP_LIBOR_3M)); assertEquals(test.allCurrencies(), ImmutableSet.of(GBP)); }
public void test_createSchedule_term_badLastRegular() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(TERM) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .lastRegularEndDate(DATE_05_05) .build(); assertThrowsIllegalArg(() -> test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA)); }
public void coverage() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); coverImmutableBean(test); PaymentSchedule test2 = PaymentSchedule.builder() .paymentFrequency(P3M) .businessDayAdjustment(BDA) .paymentDateOffset(DaysAdjustment.ofBusinessDays(3, GBLO)) .paymentRelativeTo(PERIOD_START) .compoundingMethod(STRAIGHT) .firstRegularStartDate(DATE_01_06) .lastRegularEndDate(DATE_02_05) .build(); coverBeanEquals(test, test2); }
public void test_createSchedule_dualStub() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P2M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); Schedule schedule = test.createSchedule(ACCRUAL_SCHEDULE_STUBS, REF_DATA); assertEquals(schedule, ACCRUAL_SCHEDULE_STUBS.toBuilder().frequency(P2M).build()); }
public void test_builder() { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, GBLO); PeriodicSchedule accrualSchedule = PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(bda) .build(); PaymentSchedule paymentSchedule = PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); ValueSchedule amountSchedule = ValueSchedule.of(123d); KnownAmountSwapLeg test = KnownAmountSwapLeg.builder() .payReceive(PAY) .accrualSchedule(accrualSchedule) .paymentSchedule(paymentSchedule) .amount(amountSchedule) .currency(GBP) .build(); assertEquals(test.getPayReceive(), PAY); assertEquals(test.getStartDate(), AdjustableDate.of(DATE_01_05, bda)); assertEquals(test.getEndDate(), AdjustableDate.of(DATE_04_05, bda)); assertEquals(test.getAccrualSchedule(), accrualSchedule); assertEquals(test.getPaymentSchedule(), paymentSchedule); assertEquals(test.getAmount(), amountSchedule); assertEquals(test.getCurrency(), GBP); assertEquals(test.allCurrencies(), ImmutableSet.of(GBP)); }
public void test_createSchedule_firstDate_invalidInitialStub() { PaymentSchedule test = PaymentSchedule.builder() .paymentFrequency(P2M) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .firstRegularStartDate(DATE_01_06) .build(); assertThrows(() -> test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA), ScheduleException.class); }