* Test of the schedule generation, here we test the FRONTSHORT stub case when the start date is an holiday:
* Stub is at the start (front) of the cashflow schedule; first coupon is on the first IMM date after the effective date (short stub).
*/
@Test
public void testFrontShortFirstDateHoliday() {
final ZonedDateTime startDate = new IMMDates(2008).getImmDateSeptember();
final ZonedDateTime effectiveDate = startDate.plusDays(1);
LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithStubType(StubType.FRONTSHORT);
cds = new LegacyVanillaCreditDefaultSwapDefinition(cds.getBuySellProtection(),
cds.getProtectionBuyer(),
cds.getProtectionSeller(),
cds.getReferenceEntity(),
cds.getCurrency(),
cds.getDebtSeniority(),
cds.getRestructuringClause(),
new NoHolidayCalendar(),
startDate,
effectiveDate,
cds.getMaturityDate(),
cds.getStubType(),
cds.getCouponFrequency(),
cds.getDayCountFractionConvention(),
cds.getBusinessDayAdjustmentConvention(),
cds.getIMMAdjustMaturityDate(),
cds.getAdjustEffectiveDate(),
cds.getAdjustMaturityDate(),
cds.getNotional(),
cds.getRecoveryRate(),
cds.getIncludeAccruedPremium(),
cds.getProtectionStart(),
cds.getParSpread());
ZonedDateTime date = new IMMDates(cds.getStartDate().getYear()).getImmDateDecember();
List<ZonedDateTime> dates = new ArrayList<>();
dates.add(cds.getStartDate());
while (!date.isAfter(cds.getMaturityDate())) {
dates.add(date);
date = date.plusMonths(cds.getCouponFrequency().getPeriod().toTotalMonths());
}
ZonedDateTime[] expected1 = dates.toArray(new ZonedDateTime[dates.size()]);
ZonedDateTime[] expected2 = new ZonedDateTime[dates.size()];
ZonedDateTime[] expected3 = new ZonedDateTime[dates.size()];
ZonedDateTime[] expected4 = new ZonedDateTime[dates.size()];
//CALCULATOR not tested in this file
/*ZonedDateTime[] actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
assertDateArrayEquals(expected, actual);*/
ZonedDateTime[][] calculatedSchedule = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
ZonedDateTime[] extractCalculatedSchedule1 = new ZonedDateTime[calculatedSchedule.length];
ZonedDateTime[] extractCalculatedSchedule2 = new ZonedDateTime[calculatedSchedule.length];
ZonedDateTime[] extractCalculatedSchedule3 = new ZonedDateTime[calculatedSchedule.length];
ZonedDateTime[] extractCalculatedSchedule4 = new ZonedDateTime[calculatedSchedule.length];
for (int loop = 0; loop < calculatedSchedule.length; loop++) {
extractCalculatedSchedule1[loop] = calculatedSchedule[loop][0];
}
for (int loop = 1; loop < calculatedSchedule.length; loop++) {
extractCalculatedSchedule2[loop] = calculatedSchedule[loop][1];
extractCalculatedSchedule3[loop] = calculatedSchedule[loop][2];
extractCalculatedSchedule4[loop] = calculatedSchedule[loop][3];
}
ZonedDateTime prevDate = expected1[0];
ZonedDateTime prevDateAdj = prevDate;
for (int loop = 1; loop < calculatedSchedule.length; loop++) {
ZonedDateTime nextDate = expected1[loop];
ZonedDateTime nextDateAdj = expected1[loop];
// accStartDate
expected2[loop] = prevDateAdj;
// accEndDate
expected3[loop] = nextDateAdj;
// payDate
expected4[loop] = nextDateAdj;
prevDate = nextDate;
prevDateAdj = nextDateAdj;
}
if (cds.getProtectionStart()) {
expected3[expected1.length - 1] = prevDate.plusDays(1);
}
else
{
expected3[expected1.length - 1] = prevDate;
}
assertDateArrayEquals(expected1, extractCalculatedSchedule1);
assertDateArrayEquals(expected2, extractCalculatedSchedule2);
assertDateArrayEquals(expected3, extractCalculatedSchedule3);
assertDateArrayEquals(expected4, extractCalculatedSchedule4);
cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithStubType(StubType.FRONTSHORT);
cds = new LegacyVanillaCreditDefaultSwapDefinition(cds.getBuySellProtection(),
cds.getProtectionBuyer(),
cds.getProtectionSeller(),
cds.getReferenceEntity(),
cds.getCurrency(),
cds.getDebtSeniority(),
cds.getRestructuringClause(),
cds.getCalendar(),
startDate,
effectiveDate,
cds.getMaturityDate(),
cds.getStubType(),
cds.getCouponFrequency(),
cds.getDayCountFractionConvention(),
cds.getBusinessDayAdjustmentConvention(),
cds.getIMMAdjustMaturityDate(),
cds.getAdjustEffectiveDate(),
cds.getAdjustMaturityDate(),
cds.getNotional(),
cds.getRecoveryRate(),
cds.getIncludeAccruedPremium(),
cds.getProtectionStart(),
cds.getParSpread());
final BusinessDayConvention bdc = cds.getBusinessDayAdjustmentConvention();
final Calendar holidays = cds.getCalendar();
date = new IMMDates(cds.getStartDate().getYear()).getImmDateDecember();
dates = new ArrayList<>();
dates.add(cds.getStartDate());
while (!date.isAfter(cds.getMaturityDate())) {
dates.add(bdc.adjustDate(holidays, date));
date = date.plusMonths(cds.getCouponFrequency().getPeriod().toTotalMonths());