AnnuityCouponIborDefinition extends AnnuityCouponDefinition<CouponIborDefinition> { public static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final Period tenor, final double notional, final IborIndex index, final boolean isPayer, final Calendar calendar) { ArgumentChecker.notNull(settlementDate, "settlement date"); ArgumentChecker.notNull(index, "index"); ArgumentChecker.notNull(tenor, "tenor"); ArgumentChecker.isTrue(notional > 0, "notional <= 0"); final ZonedDateTime maturityDate = settlementDate.plus(tenor); return from(settlementDate, maturityDate, notional, index, isPayer, calendar); } AnnuityCouponIborDefinition(final CouponIborDefinition[] payments, final IborIndex iborIndex, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final Period tenor, final double notional, final IborIndex index, final boolean isPayer,
      final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index, final boolean isPayer,
      final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index, final boolean isPayer,
      final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final double notional, final IborIndex index,
      final boolean isPayer, final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final DayCount dayCount, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final double notional, final IborIndex index,
      final boolean isPayer, final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final DayCount dayCount, final Calendar calendar, final StubType stub); static AnnuityCouponIborDefinition fromAccrualUnadjusted(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index,
      final boolean isPayer, final Calendar calendar); static AnnuityCouponIborDefinition from(final AnnuityCouponIborSpreadDefinition annuity); AnnuityCouponIborDefinition trimStart(final ZonedDateTime trimDate); IborIndex getIborIndex(); Calendar getIborCalendar(); @Override Annuity<? extends Coupon> toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> indexFixingTS); @Override Annuity<? extends Coupon> toDerivative(final ZonedDateTime date); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void test() { final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length]; final double sign = IS_PAYER ? -1.0 : 1.0; CouponFixedDefinition coupon = new CouponFixedDefinition(CUR, PAYMENT_DATES[0], SETTLEMENT_DATE, PAYMENT_DATES[0], DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]), sign * NOTIONAL, 0.0); ZonedDateTime fixingDate = ScheduleCalculator.getAdjustedDate(SETTLEMENT_DATE, -SETTLEMENT_DAYS, CALENDAR); coupons[0] = CouponIborDefinition.from(coupon, fixingDate, INDEX, CALENDAR); for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) { coupon = new CouponFixedDefinition(CUR, PAYMENT_DATES[loopcpn], PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn], DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]), sign * NOTIONAL, 0.0); fixingDate = ScheduleCalculator.getAdjustedDate(PAYMENT_DATES[loopcpn - 1], -SETTLEMENT_DAYS, CALENDAR); coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX, CALENDAR); } final AnnuityCouponIborDefinition iborAnnuity = new AnnuityCouponIborDefinition(coupons, INDEX, CALENDAR); assertEquals(iborAnnuity.isPayer(), IS_PAYER); for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { assertEquals(iborAnnuity.getNthPayment(loopcpn), coupons[loopcpn]); assertEquals(iborAnnuity.getPayments()[loopcpn], coupons[loopcpn]); } final AnnuityCouponIborDefinition iborAnnuity2 = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER, CALENDAR); assertEquals(iborAnnuity, iborAnnuity2); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOneNullPayment() { final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length]; CouponFixedDefinition coupon = new CouponFixedDefinition(CUR, PAYMENT_DATES[0], SETTLEMENT_DATE, PAYMENT_DATES[0], DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]), NOTIONAL, 0.0); ZonedDateTime fixingDate = ScheduleCalculator.getAdjustedDate(SETTLEMENT_DATE, -SETTLEMENT_DAYS, CALENDAR); coupons[0] = null; for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) { coupon = new CouponFixedDefinition(CUR, PAYMENT_DATES[loopcpn], PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn], DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]), NOTIONAL, 0.0); fixingDate = ScheduleCalculator.getAdjustedDate(PAYMENT_DATES[loopcpn - 1], -SETTLEMENT_DAYS, CALENDAR); coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX, CALENDAR); } new AnnuityCouponIborDefinition(coupons, INDEX, CALENDAR); }
@Test public void testFrom() { final ZonedDateTime settleDate = DateUtils.getUTCDate(2014, 3, 20); final Period indexTenor = Period.ofMonths(3); final DayCount dayCount = DayCounts.ACT_360; final IborIndex index = new IborIndex(CUR, indexTenor, SETTLEMENT_DAYS, dayCount, BUSINESS_DAY, IS_EOM, "Ibor"); final AnnuityCouponIborDefinition iborAnnuity = AnnuityCouponIborDefinition.from(settleDate, Period.ofYears(1), NOTIONAL, index, IS_PAYER, CALENDAR); final ZonedDateTime[] paymentDates = new ZonedDateTime[] {DateUtils.getUTCDate(2014, 6, 20), DateUtils.getUTCDate(2014, 9, 22), DateUtils.getUTCDate(2014, 12, 22), DateUtils.getUTCDate(2015, 03, 20) }; final ZonedDateTime[] fixingDates = new ZonedDateTime[] {DateUtils.getUTCDate(2014, 3, 18), DateUtils.getUTCDate(2014, 6, 18), DateUtils.getUTCDate(2014, 9, 18), DateUtils.getUTCDate(2014, 12, 18) }; final ZonedDateTime[] startPeriodDates = new ZonedDateTime[] {DateUtils.getUTCDate(2014, 3, 20), DateUtils.getUTCDate(2014, 6, 20), DateUtils.getUTCDate(2014, 9, 22), DateUtils.getUTCDate(2014, 12, 22) }; final ZonedDateTime[] endPeriodDates = new ZonedDateTime[] {DateUtils.getUTCDate(2014, 6, 20), DateUtils.getUTCDate(2014, 9, 22), DateUtils.getUTCDate(2014, 12, 22), DateUtils.getUTCDate(2015, 03, 23) }; for (int loopcpn = 0; loopcpn < iborAnnuity.getPayments().length; loopcpn++) { assertEquals(paymentDates[loopcpn], iborAnnuity.getNthPayment(loopcpn).getPaymentDate()); assertEquals(fixingDates[loopcpn], iborAnnuity.getNthPayment(loopcpn).getFixingDate()); assertEquals(startPeriodDates[loopcpn], iborAnnuity.getNthPayment(loopcpn).getFixingPeriodStartDate()); assertEquals(endPeriodDates[loopcpn], iborAnnuity.getNthPayment(loopcpn).getFixingPeriodEndDate()); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullSettlementDate1() { AnnuityCouponIborDefinition.from(null, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullSettlementDate2() { AnnuityCouponIborDefinition.from(null, MATURITY_DATE, NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullPeriod() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, (Period) null, NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullMaturityDate1() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, (ZonedDateTime) null, NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNegativeNotional1() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, -NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNegativeNotional2() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, MATURITY_DATE, -NOTIONAL, INDEX, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullIndex1() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, null, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullIndex2() { AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, null, IS_PAYER, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStaticConstructionNullAnnuity() { AnnuityCouponIborDefinition.from(null); }
@Test public void testNoSpread() { final AnnuityCouponIborDefinition definition = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, IS_PAYER, CALENDAR); final CouponIborDefinition[] noSpreadCoupons = definition.getPayments(); final int n = noSpreadCoupons.length; final double spread = 0.01; final CouponIborSpreadDefinition[] spreadCoupons = new CouponIborSpreadDefinition[n]; for (int i = 0; i < n; i++) { final CouponIborDefinition coupon = noSpreadCoupons[i]; spreadCoupons[i] = new CouponIborSpreadDefinition(coupon.getCurrency(), coupon.getPaymentDate(), coupon.getAccrualStartDate(), coupon.getAccrualEndDate(), coupon.getPaymentYearFraction(), coupon.getNotional(), coupon.getFixingDate(), coupon.getIndex(), spread, coupon.getCalendar()); } assertEquals(definition, AnnuityCouponIborDefinition.from(new AnnuityCouponIborSpreadDefinition(spreadCoupons, CALENDAR))); }