@Override public LocalDate getStartDate() { return getUnadjustedStartDate(); }
public void test_findPeriod() { ResolvedFixedCouponBond test = sut(); ImmutableList<FixedCouponBondPaymentPeriod> payments = test.getPeriodicPayments(); assertEquals(test.findPeriod(test.getUnadjustedStartDate()), Optional.of(payments.get(0))); assertEquals(test.findPeriod(test.getUnadjustedEndDate().minusDays(1)), Optional.of(payments.get(payments.size() - 1))); assertEquals(test.findPeriod(LocalDate.MIN), Optional.empty()); assertEquals(test.findPeriod(LocalDate.MAX), Optional.empty()); }
/** * Calculates the accrued year fraction of the fixed coupon bond with the specified settlement date. * * @param bond the product * @param settlementDate the settlement date * @return the accrued year fraction of the product */ public double accruedYearFraction(ResolvedFixedCouponBond bond, LocalDate settlementDate) { if (bond.getUnadjustedStartDate().isAfter(settlementDate)) { return 0d; } FixedCouponBondPaymentPeriod period = bond.findPeriod(settlementDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range of bond")); LocalDate previousAccrualDate = period.getUnadjustedStartDate(); double accruedYearFraction = bond.yearFraction(previousAccrualDate, settlementDate); double result = 0d; if (settlementDate.isAfter(period.getDetachmentDate())) { result = accruedYearFraction - period.getYearFraction(); } else { result = accruedYearFraction; } return result; }
public void test_getters() { ResolvedFixedCouponBond test = sut(); ImmutableList<FixedCouponBondPaymentPeriod> payments = test.getPeriodicPayments(); assertEquals(test.getStartDate(), payments.get(0).getStartDate()); assertEquals(test.getEndDate(), payments.get(payments.size() - 1).getEndDate()); assertEquals(test.getUnadjustedStartDate(), payments.get(0).getUnadjustedStartDate()); assertEquals(test.getUnadjustedEndDate(), payments.get(payments.size() - 1).getUnadjustedEndDate()); assertEquals(test.hasExCouponPeriod(), true); }
@Override public double yearFraction(LocalDate firstDate, LocalDate secondDate, ScheduleInfo scheduleInfo) { assertEquals(scheduleInfo.getStartDate(), base.getUnadjustedStartDate()); assertEquals(scheduleInfo.getEndDate(), base.getUnadjustedEndDate()); assertEquals(scheduleInfo.getPeriodEndDate(firstDate), period.getUnadjustedEndDate()); assertEquals(scheduleInfo.getFrequency(), base.getFrequency()); assertEquals(scheduleInfo.isEndOfMonthConvention(), eom.get()); return 0.5; }
ArgChecker.inOrderOrEqual(getUnadjustedStartDate(), startDate, "bond.unadjustedStartDate", "startDate"); ArgChecker.inOrderOrEqual(startDate, endDate, "startDate", "endDate"); ArgChecker.inOrderOrEqual(endDate, getUnadjustedEndDate(), "endDate", "bond.unadjustedEndDate");