@Test public void testStaticConstruction() { AnnuityCouponIborDefinition definition1 = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER); AnnuityCouponIborDefinition definition2 = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, IS_PAYER); assertEquals(definition1, definition2); assertEquals(IS_PAYER, definition1.isPayer()); definition2 = AnnuityCouponIborDefinition.from( SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, !IS_PAYER); assertFalse(definition1.equals(definition2)); definition2 = AnnuityCouponIborDefinition.from( SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, !IS_PAYER); assertFalse(definition1.equals(definition2)); definition1 = AnnuityCouponIborDefinition.fromAccrualUnadjusted( SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, IS_PAYER); definition2 = AnnuityCouponIborDefinition.fromAccrualUnadjusted( SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, !IS_PAYER); assertFalse(definition1.equals(definition2)); }
@Test public void testEqualHash() { final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length]; // First coupon uses settlement date 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, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS); coupons[0] = CouponIborDefinition.from(coupon, fixingDate, INDEX); 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], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS); coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX); } final AnnuityCouponIborDefinition iborAnnuity = new AnnuityCouponIborDefinition(coupons); final AnnuityCouponIborDefinition iborAnnuity2 = new AnnuityCouponIborDefinition(coupons); assertEquals(iborAnnuity, iborAnnuity2); assertEquals(iborAnnuity.hashCode(), iborAnnuity2.hashCode()); AnnuityCouponIborDefinition modifiedIborAnnuity = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER); assertFalse(iborAnnuity.equals(modifiedIborAnnuity)); final CouponIborDefinition[] couponsModified = new CouponIborDefinition[PAYMENT_DATES.length]; CouponFixedDefinition couponModified = new CouponFixedDefinition( CUR, PAYMENT_DATES[0], SETTLEMENT_DATE, PAYMENT_DATES[0], DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]), NOTIONAL, 0.0); fixingDate = ScheduleCalculator.getAdjustedDate( SETTLEMENT_DATE, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS); couponsModified[0] = CouponIborDefinition.from(couponModified, fixingDate, INDEX); for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponModified = new CouponFixedDefinition( CUR, PAYMENT_DATES[loopcpn], PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn], DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]), NOTIONAL + 5.0, 0.0); fixingDate = ScheduleCalculator.getAdjustedDate( PAYMENT_DATES[loopcpn - 1], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS); couponsModified[loopcpn] = CouponIborDefinition.from(couponModified, fixingDate, INDEX); } modifiedIborAnnuity = new AnnuityCouponIborDefinition(couponsModified); assertFalse(iborAnnuity.equals(modifiedIborAnnuity)); }