static BondDataSets() { for (int i = 0; i < NB_BOND_USD; ++i) { LocalDate endDate = START_DATE_USD[i].plus(BOND_TENOR_USD[i]); PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE_USD[i], endDate, Frequency.P6M, BUSINESS_ADJUST_USD, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID[i])).dayCount(DAY_COUNT_USD).fixedRate(RATE_USD[i]).legalEntityId(ISSUER_ID_USD).currency(USD).notional(NOTIONAL_USD).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS_USD).yieldConvention(YIELD_CONVENTION_USD).exCouponPeriod(EX_COUPON_USD).build(); BOND_USD[i] = product; } for (int i = 0; i < NB_BOND_EUR; ++i) { LocalDate endDate = START_DATE_EUR[i].plus(BOND_TENOR_EUR[i]); PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE_EUR[i], endDate, Frequency.P12M, BUSINESS_ADJUST_EUR, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID_EUR[i])).dayCount(DAY_COUNT_EUR).fixedRate(RATE_EUR[i]).legalEntityId(ISSUER_ID_EUR).currency(EUR).notional(NOTIONAL_EUR).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS_EUR).yieldConvention(YIELD_CONVENTION_EUR).exCouponPeriod(EX_COUPON_EUR).build(); BOND_EUR[i] = product; } }
//------------------------------------------------------------------------- public virtual void test_accruedInterest() { // settle before start LocalDate settleDate1 = START_DATE.minusDays(5); double accruedInterest1 = PRICER.accruedInterest(PRODUCT, settleDate1); assertEquals(accruedInterest1, 0d); // settle between endDate and endDate -lag LocalDate settleDate2 = date(2015, 10, 8); double accruedInterest2 = PRICER.accruedInterest(PRODUCT, settleDate2); assertEquals(accruedInterest2, -4.0 / 365.0 * FIXED_RATE * NOTIONAL, EPS); // normal LocalDate settleDate3 = date(2015, 4, 18); // not adjusted ResolvedFixedCouponBond product = FixedCouponBond.builder().securityId(SECURITY_ID).dayCount(DAY_COUNT).fixedRate(FIXED_RATE).legalEntityId(ISSUER_ID).currency(EUR).notional(NOTIONAL).accrualSchedule(PERIOD_SCHEDULE).settlementDateOffset(DATE_OFFSET).yieldConvention(YIELD_CONVENTION).exCouponPeriod(DaysAdjustment.NONE).build().resolve(REF_DATA); double accruedInterest3 = PRICER.accruedInterest(product, settleDate3); assertEquals(accruedInterest3, 6.0 / 365.0 * FIXED_RATE * NOTIONAL, EPS); }