Package com.opengamma.analytics.financial.credit.creditdefaultswap.definition.legacy

Examples of com.opengamma.analytics.financial.credit.creditdefaultswap.definition.legacy.LegacyVanillaCreditDefaultSwapDefinition


   * Test of the schedule generation, here we test the FRONTSHORT stub case :
   * 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 testFrontShort() {
    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(),
        cds.getStartDate(),
        cds.getEffectiveDate(),
        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()];
    /*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);
    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());
    }
    expected1 = dates.toArray(new ZonedDateTime[dates.size()]);
    //CALCULATOR not tested in this file
    /* actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
     assertDateArrayEquals(expected, actual);*/

    ZonedDateTime[][] calculatedScheduleAdjusted = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedScheduleAdjusted1 = new ZonedDateTime[calculatedScheduleAdjusted.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted2 = new ZonedDateTime[calculatedSchedule.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted3 = new ZonedDateTime[calculatedSchedule.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted4 = new ZonedDateTime[calculatedSchedule.length];
    for (int loop = 0; loop < calculatedSchedule.length; loop++) {
      extractCalculatedScheduleAdjusted1[loop] = calculatedScheduleAdjusted[loop][0];
    }

    for (int loop = 1; loop < calculatedSchedule.length; loop++) {
      extractCalculatedScheduleAdjusted2[loop] = calculatedScheduleAdjusted[loop][1];
      extractCalculatedScheduleAdjusted3[loop] = calculatedScheduleAdjusted[loop][2];
      extractCalculatedScheduleAdjusted4[loop] = calculatedScheduleAdjusted[loop][3];
    }

    prevDate = expected1[0];
    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;
View Full Code Here


   */
  @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());
    }
    expected1 = dates.toArray(new ZonedDateTime[dates.size()]);
    expected2 = new ZonedDateTime[dates.size()];
    expected3 = new ZonedDateTime[dates.size()];
    expected4 = new ZonedDateTime[dates.size()];

    //we don't want to test CALCULATOR in this file (for the moment ???)
    /* actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
     assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculatedScheduleAdjusted = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedScheduleAdjusted1 = new ZonedDateTime[calculatedScheduleAdjusted.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted2 = new ZonedDateTime[calculatedSchedule.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted3 = new ZonedDateTime[calculatedSchedule.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted4 = new ZonedDateTime[calculatedSchedule.length];
    for (int loop = 0; loop < calculatedSchedule.length; loop++) {
      extractCalculatedScheduleAdjusted1[loop] = calculatedScheduleAdjusted[loop][0];
    }

    for (int loop = 1; loop < calculatedSchedule.length; loop++) {
      extractCalculatedScheduleAdjusted2[loop] = calculatedScheduleAdjusted[loop][1];
      extractCalculatedScheduleAdjusted3[loop] = calculatedScheduleAdjusted[loop][2];
      extractCalculatedScheduleAdjusted4[loop] = calculatedScheduleAdjusted[loop][3];
    }

    prevDate = expected1[0];
    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;
View Full Code Here

   * Test of the schedule generation, here we test the FRONTLONG stub case:
   * Stub is at the end (back) of the cashflow schedule; last but one coupon is on the last scheduled coupon date before the maturity date (short stub)
   */
  @Test
  public void testFrontLong() {
    LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithStubType(StubType.FRONTLONG);
    cds = new LegacyVanillaCreditDefaultSwapDefinition(cds.getBuySellProtection(),
        cds.getProtectionBuyer(),
        cds.getProtectionSeller(),
        cds.getReferenceEntity(),
        cds.getCurrency(),
        cds.getDebtSeniority(),
        cds.getRestructuringClause(),
        new NoHolidayCalendar(),
        cds.getStartDate(),
        cds.getEffectiveDate(),
        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()).getImmDateNextMarch();
    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()];
    /*ZonedDateTime[] actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculated = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedSchedule1 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule2 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule3 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule4 = new ZonedDateTime[calculated.length];
    for (int loop = 0; loop < calculated.length; loop++) {
      extractCalculatedSchedule1[loop] = calculated[loop][0];
    }

    for (int loop = 1; loop < calculated.length; loop++) {
      extractCalculatedSchedule2[loop] = calculated[loop][1];
      extractCalculatedSchedule3[loop] = calculated[loop][2];
      extractCalculatedSchedule4[loop] = calculated[loop][3];
    }
    ZonedDateTime prevDate = expected1[0];
    ZonedDateTime prevDateAdj = prevDate;
    for (int loop = 1; loop < calculated.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);
    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());
    }
    expected1 = dates.toArray(new ZonedDateTime[dates.size()]);
    expected2 = new ZonedDateTime[dates.size()];
    expected3 = new ZonedDateTime[dates.size()];
    expected4 = new ZonedDateTime[dates.size()];
    /*actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculatedAdjusated = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedScheduleAdjusted1 = new ZonedDateTime[calculatedAdjusated.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted2 = new ZonedDateTime[calculatedAdjusated.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted3 = new ZonedDateTime[calculatedAdjusated.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted4 = new ZonedDateTime[calculatedAdjusated.length];
    for (int loop = 0; loop < calculatedAdjusated.length; loop++) {
      extractCalculatedScheduleAdjusted1[loop] = calculatedAdjusated[loop][0];
    }

    for (int loop = 1; loop < calculatedAdjusated.length; loop++) {
      extractCalculatedScheduleAdjusted2[loop] = calculatedAdjusated[loop][1];
      extractCalculatedScheduleAdjusted3[loop] = calculatedAdjusated[loop][2];
      extractCalculatedScheduleAdjusted4[loop] = calculatedAdjusated[loop][3];
    }

    prevDate = expected1[0];
    prevDateAdj = prevDate;
    for (int loop = 1; loop < calculatedAdjusated.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;
View Full Code Here

   */
  @Test
  public void testFrontLongFirstDateHoliday() {
    final ZonedDateTime startDate = new IMMDates(2008).getImmDateSeptember();
    final ZonedDateTime effectiveDate = startDate.plusDays(1);
    LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithStubType(StubType.FRONTLONG);
    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()];
    /*ZonedDateTime[] actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculated = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);

    ZonedDateTime[] extractCalculatedSchedule1 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule2 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule3 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule4 = new ZonedDateTime[calculated.length];
    for (int loop = 0; loop < calculated.length; loop++) {
      extractCalculatedSchedule1[loop] = calculated[loop][0];
    }

    for (int loop = 1; loop < calculated.length; loop++) {
      extractCalculatedSchedule2[loop] = calculated[loop][1];
      extractCalculatedSchedule3[loop] = calculated[loop][2];
      extractCalculatedSchedule4[loop] = calculated[loop][3];
    }

    ZonedDateTime prevDate = expected1[0];

    ZonedDateTime prevDateAdj = prevDate;
    for (int loop = 1; loop < calculated.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.FRONTLONG);
    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());
    }
    expected1 = dates.toArray(new ZonedDateTime[dates.size()]);
    expected2 = new ZonedDateTime[dates.size()];
    expected3 = new ZonedDateTime[dates.size()];
    expected4 = new ZonedDateTime[dates.size()];
    /*actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculatedAdjusted = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedScheduleAdjusted1 = new ZonedDateTime[calculatedAdjusted.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted2 = new ZonedDateTime[calculatedAdjusted.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted3 = new ZonedDateTime[calculatedAdjusted.length];
    ZonedDateTime[] extractCalculatedScheduleAdjusted4 = new ZonedDateTime[calculatedAdjusted.length];
    for (int loop = 0; loop < calculatedAdjusted.length; loop++) {
      extractCalculatedScheduleAdjusted1[loop] = calculatedAdjusted[loop][0];
    }

    for (int loop = 1; loop < calculatedAdjusted.length; loop++) {
      extractCalculatedScheduleAdjusted2[loop] = calculatedAdjusted[loop][1];
      extractCalculatedScheduleAdjusted3[loop] = calculatedAdjusted[loop][2];
      extractCalculatedScheduleAdjusted4[loop] = calculatedAdjusted[loop][3];
    }

    prevDate = expected1[0];
    prevDateAdj = prevDate;
    for (int loop = 1; loop < calculatedAdjusted.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;
View Full Code Here

  @Test
  public void testFrontOneDate() {
    final ZonedDateTime startDate = new IMMDates(2007).getImmDateJune();
    final ZonedDateTime effectiveDate = startDate.plusDays(1);
    final ZonedDateTime endDate = startDate.plusMonths(1);
    LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithStubType(StubType.FRONTLONG);
    cds = new LegacyVanillaCreditDefaultSwapDefinition(cds.getBuySellProtection(),
        cds.getProtectionBuyer(),
        cds.getProtectionSeller(),
        cds.getReferenceEntity(),
        cds.getCurrency(),
        cds.getDebtSeniority(),
        cds.getRestructuringClause(),
        new NoHolidayCalendar(),
        startDate,
        effectiveDate,
        endDate,
        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();
    final List<ZonedDateTime> dates = new ArrayList<>();
    dates.add(cds.getStartDate());
    while (!date.isAfter(cds.getMaturityDate())) {
      dates.add(date);
      date = date.plusMonths(cds.getCouponFrequency().getPeriod().toTotalMonths());
    }
    final ZonedDateTime[] expected1 = new ZonedDateTime[] {startDate, endDate };
    ZonedDateTime[] expected2 = new ZonedDateTime[2];
    ZonedDateTime[] expected3 = new ZonedDateTime[2];
    ZonedDateTime[] expected4 = new ZonedDateTime[2];
    /*final ZonedDateTime[] actual = CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    assertDateArrayEquals(expected, actual);*/
    ZonedDateTime[][] calculated = DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    ZonedDateTime[] extractCalculatedSchedule1 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule2 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule3 = new ZonedDateTime[calculated.length];
    ZonedDateTime[] extractCalculatedSchedule4 = new ZonedDateTime[calculated.length];
    for (int loop = 0; loop < calculated.length; loop++) {
      extractCalculatedSchedule1[loop] = calculated[loop][0];
    }

    for (int loop = 1; loop < calculated.length; loop++) {
      extractCalculatedSchedule2[loop] = calculated[loop][1];
      extractCalculatedSchedule3[loop] = calculated[loop][2];
      extractCalculatedSchedule4[loop] = calculated[loop][3];
    }

    ZonedDateTime prevDate = expected1[0];

    ZonedDateTime prevDateAdj = prevDate;
    for (int loop = 1; loop < calculated.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;
View Full Code Here

    final int numberofObligors = indexCDS.getUnderlyingPool().getNumberOfObligors();

    for (int i = 0; i < numberofObligors; i++) {

      // Extract out the CDS associated with obligor i
      LegacyVanillaCreditDefaultSwapDefinition cds = (LegacyVanillaCreditDefaultSwapDefinition) indexCDS.getUnderlyingCDS()[i];

      // Calculate the risky dV01 for obligor i
      final double riskydV01 = calculateRiskydV01(valuationDate, cds, breakevenSpreads[i], yieldCurves[i], hazardRateCurves[i]);

      // Add this to the running total
View Full Code Here

    // For each obligor in the underlying pool ...
    for (int i = 0; i < numberOfObligors; i++) {

      // ... build a CDS object for obligor i
      final LegacyVanillaCreditDefaultSwapDefinition cds = new LegacyVanillaCreditDefaultSwapDefinition(
          _buySellProtection,                             // Specified in the CDS index contract - applies to all underlying CDS's
          _protectionBuyer,                               // Specified in the CDS index contract
          _protectionSeller,                              // Specified in the CDS index contract
          _underlyingPool.getObligors()[i],               // Part of the information carried in the UnderlyingPool object - in principle can vary from obligor to obligor
          _underlyingPool.getCurrency()[i],               // Part of the information carried in the UnderlyingPool object - in principle can vary from obligor to obligor
View Full Code Here

    // Calibrate each of the underlying obligors
    for (int i = 0; i < numberOfObligors; i++) {

      // Create a copy of the underlying CDS for obligor i for the purposes of calibration of the hazard rate term structure
      final LegacyVanillaCreditDefaultSwapDefinition underlyingCalibrationCDS = (LegacyVanillaCreditDefaultSwapDefinition) indexCDS.getUnderlyingCDS()[i];

      final double[] obligorMarketSpreads = new double[calibrationTenors.length];

      // From the input matrix of spread data, extract out the spread term structure for obligor i
      for (int m = 0; m < calibrationTenors.length; m++) {
View Full Code Here

    final boolean adjustCashSettlementDate = security.isAdjustCashSettlementDate();
    final double coupon = security.getCoupon();
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor protectionBuyer = getObligorForProtectionBuyer(security.getProtectionBuyer());
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor protectionSeller = getObligorForProtectionSeller(security.getProtectionSeller());
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor referenceEntity = getObligorForReferenceEntity(security.getReferenceEntity());
    return new LegacyVanillaCreditDefaultSwapDefinition(buySellProtection, protectionBuyer, protectionSeller, referenceEntity, currency,
        debtSeniority, restructuringClause, calendar, startDate, effectiveDate, maturityDate, stubType,
        couponFrequency, dayCount, businessDayConvention, immAdjustMaturityDate, adjustEffectiveDate, adjustMaturityDate,
        amount, 0.5, includeAccruedPremium, protectionStart, coupon);
  }
View Full Code Here

    final StubType stubType = security.getStubType().toAnalyticsType();
    final double parSpread = security.getParSpread();
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor protectionBuyer = getObligorForProtectionBuyer(security.getProtectionBuyer());
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor protectionSeller = getObligorForProtectionSeller(security.getProtectionSeller());
    final com.opengamma.analytics.financial.credit.obligor.definition.Obligor referenceEntity = getObligorForReferenceEntity(security.getReferenceEntity());
    return new LegacyVanillaCreditDefaultSwapDefinition(buySellProtection, protectionBuyer, protectionSeller, referenceEntity, currency,
        debtSeniority, restructuringClause, calendar, startDate, effectiveDate, maturityDate, stubType,
        couponFrequency, dayCount, businessDayConvention, immAdjustMaturityDate, adjustEffectiveDate, adjustMaturityDate,
        amount, 0.5, includeAccruedPremium, protectionStart, parSpread);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.credit.creditdefaultswap.definition.legacy.LegacyVanillaCreditDefaultSwapDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.