Package org.threeten.bp

Examples of org.threeten.bp.ZonedDateTime


   */
  @Deprecated
  @Override
  public BondIborSecurity toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> indexFixingTS, final String... yieldCurveNames) {
    ArgumentChecker.notNull(date, "date");
    final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, getSettlementDays(), getCalendar());
    return toDerivative(date, indexFixingTS, spot, yieldCurveNames);
  }
View Full Code Here


  }

  @Override
  public BondIborSecurity toDerivative(final ZonedDateTime date) {
    ArgumentChecker.notNull(date, "date");
    final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, getSettlementDays(), getCalendar());
    return toDerivative(date, ImmutableZonedDateTimeDoubleTimeSeries.of(DateUtils.getUTCDate(1800, 1, 1), 0.0), spot);
  }
View Full Code Here

  }

  @Override
  public BondIborSecurity toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> indexFixingTS) {
    ArgumentChecker.notNull(date, "date");
    final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, getSettlementDays(), getCalendar());
    return toDerivative(date, indexFixingTS, spot);
  }
View Full Code Here

        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;
View Full Code Here

   * 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());
    }
    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;
View Full Code Here

        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;
View Full Code Here

   * Test of the schedule generation, here we test the FRONTLONG stub case when the start date is an holiday:
   * 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 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;
View Full Code Here

   * Test of the schedule generation, here we test the FRONTLONG stub case when there is only one date generated in the schedule (the schedule contain two dates but the start date is not generated):
   * 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 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;
View Full Code Here

    final int index = -i - 2;
    final int length = nominalDates.length;
    Validate.isTrue(index >= 0, "Settlement date is before first accrual date");
    Validate.isTrue(index < length, "Settlement date is after maturity date");
    final double accruedInterest = getAccruedInterest(dayCount, index, length, nominalDates[index], settlementDate, nominalDates[index + 1], coupon, paymentsPerYear, isEndOfMonthConvention);
    ZonedDateTime exDividendDate = nominalDates[index + 1];
    for (int j = 0; j < exDividendDays; j++) {
      while (!calendar.isWorkingDay(exDividendDate.toLocalDate())) {
        exDividendDate = exDividendDate.minusDays(1);
      }
      exDividendDate = exDividendDate.minusDays(1);
    }
    if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
      return accruedInterest - coupon;
    }
    return accruedInterest;
  }
View Full Code Here

    Validate.isTrue(paymentsPerYear > 0);
    Validate.isTrue(exDividendDays >= 0);
    final int length = nominalDates.length;
    Validate.isTrue(index >= 0 && index < length);
    final double accruedInterest = getAccruedInterest(dayCount, index, length, nominalDates[index], settlementDate, nominalDates[index + 1], coupon, paymentsPerYear, isEndOfMonthConvention);
    ZonedDateTime exDividendDate = nominalDates[index + 1];
    for (int i = 0; i < exDividendDays; i++) {
      while (!calendar.isWorkingDay(exDividendDate.toLocalDate())) {
        exDividendDate = exDividendDate.minusDays(1);
      }
      exDividendDate = exDividendDate.minusDays(1);
    }
    if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
      return accruedInterest - coupon;
    }
    return accruedInterest;
  }
View Full Code Here

TOP

Related Classes of org.threeten.bp.ZonedDateTime

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.