@Test public void dates() { final IborIndex fakeIborIndex12 = new IborIndex( CUR, LEG_PAYMENT_PERIOD, IBOR_SETTLEMENT_DAYS, LEG_DAY_COUNT, BUSINESS_DAY, IS_EOM, "Ibor"); final AnnuityCouponIborDefinition iborLeg = AnnuityCouponIborDefinition.from( START_DATE, MATURITY_DATE, NOTIONAL, fakeIborIndex12, IS_PAYER, CALENDAR); for (int loopcpn = 0; loopcpn < iborLeg.getNumberOfPayments(); loopcpn++) { assertEquals( iborLeg.getNthPayment(loopcpn).getAccrualStartDate(), CMS_LEG.getNthPayment(loopcpn).getAccrualStartDate()); assertEquals( iborLeg.getNthPayment(loopcpn).getAccrualEndDate(), CMS_LEG.getNthPayment(loopcpn).getAccrualEndDate()); assertEquals( iborLeg.getNthPayment(loopcpn).getPaymentYearFraction(), CMS_LEG.getNthPayment(loopcpn).getPaymentYearFraction()); assertEquals( iborLeg.getNthPayment(loopcpn).getPaymentDate(), CMS_LEG.getNthPayment(loopcpn).getPaymentDate()); assertEquals( iborLeg.getNthPayment(loopcpn).getFixingDate(), CMS_LEG.getNthPayment(loopcpn).getFixingDate()); } }
@Test public void testFrom() { final ZonedDateTime settleDate = DateUtils.getUTCDate(2014, 3, 20); final Period indexTenor = Period.ofMonths(3); final DayCount dayCount = DayCountFactory.INSTANCE.getDayCount("Actual/360"); final IborIndex index = new IborIndex(CUR, indexTenor, SETTLEMENT_DAYS, CALENDAR, dayCount, BUSINESS_DAY, IS_EOM); final AnnuityCouponIborDefinition iborAnnuity = AnnuityCouponIborDefinition.from(settleDate, Period.ofYears(1), NOTIONAL, index, IS_PAYER); 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 public void testToDerivativeAfterFixing() { final String fundingCurve = "Funding"; final String forwardCurve = "Forward"; final String[] curves = {fundingCurve, forwardCurve}; final Payment[] couponIborConverted = new Payment[PAYMENT_DATES.length]; ZonedDateTime date = REFERENCE_DATE.plusMonths(1); for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponIborConverted[loopcpn] = IBOR_ANNUITY.getNthPayment(loopcpn).toDerivative(date, FIXING_TS, curves); } GenericAnnuity<Payment> referenceAnnuity = new GenericAnnuity<Payment>(couponIborConverted); GenericAnnuity<? extends Payment> convertedDefinition = IBOR_ANNUITY.toDerivative(date, FIXING_TS, curves); assertEquals(referenceAnnuity, convertedDefinition); assertTrue(convertedDefinition.getNthPayment(0) instanceof CouponFixed); assertEquals( ((CouponFixed) convertedDefinition.getNthPayment(0)).getFixedRate(), FIXING_RATE, 0); for (int i = 1; i < PAYMENT_DATES.length; i++) { assertTrue(convertedDefinition.getNthPayment(i) instanceof CouponIbor); } date = REFERENCE_DATE; for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponIborConverted[loopcpn] = IBOR_ANNUITY.getNthPayment(loopcpn).toDerivative(date, FIXING_TS, curves); } referenceAnnuity = new GenericAnnuity<Payment>(couponIborConverted); convertedDefinition = IBOR_ANNUITY.toDerivative(date, FIXING_TS, curves); assertEquals(referenceAnnuity, convertedDefinition); assertTrue(convertedDefinition.getNthPayment(0) instanceof CouponFixed); assertEquals( ((CouponFixed) convertedDefinition.getNthPayment(0)).getFixedRate(), FIXING_RATE, 0); for (int i = 1; i < PAYMENT_DATES.length; i++) { assertTrue(convertedDefinition.getNthPayment(i) instanceof CouponIbor); } }
@Test public void test() { final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length]; final double sign = IS_PAYER ? -1.0 : 1.0; // 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]), sign * 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]), sign * 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); // assertEquals(iborAnnuity.getPayments(), coupons); 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); assertEquals(iborAnnuity, iborAnnuity2); }