Package com.opengamma.analytics.financial.credit.schedulegeneration

Examples of com.opengamma.analytics.financial.credit.schedulegeneration.GenerateCreditDefaultSwapIntegrationSchedule


  /**
   * Deprecated methods in {@link GenerateCreditDefaultSwapIntegrationSchedule}
   */
  @Test
  public void regressionTest() {
    final GenerateCreditDefaultSwapIntegrationSchedule calculator = new GenerateCreditDefaultSwapIntegrationSchedule();
    final ZonedDateTime valDate = ZonedDateTime.of(2003, 1, 6, 12, 0, 0, 0, ZoneId.of("Z"));
    final ZonedDateTime baseDate = ZonedDateTime.of(2003, 3, 1, 12, 0, 0, 0, ZoneId.of("Z"));
    final ZonedDateTime[] hazDates = new ZonedDateTime[] {ZonedDateTime.of(2013, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2013, 6, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2013, 9, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2013, 12, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2014, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2015, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2016, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2018, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2023, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")) };
    final double[] hazTimes;
    final double[] hazRates = new double[] {0.01, 0.02, 0.04, 0.03, 0.06, 0.03, 0.05, 0.03, 0.02 };
    final ZonedDateTime[] ycDates = new ZonedDateTime[] {ZonedDateTime.of(2013, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2013, 6, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2013, 9, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2013, 12, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2014, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2015, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2016, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")), ZonedDateTime.of(2018, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")),
        ZonedDateTime.of(2023, 3, 1, 12, 0, 0, 0, ZoneId.of("Z")) };
    final double[] ycRates = new double[] {0.005, 0.006, 0.008, 0.009, 0.01, 0.012, 0.018, 0.02, 0.03 };
    final double offset = 1. / 365;
    final ISDADateCurve yieldCurve;
    final int n = hazDates.length;
    hazTimes = new double[n];
    for (int i = 0; i < n; i++) {
      hazTimes[i] = ACT.getDayCountFraction(baseDate, hazDates[i]);
    }
    yieldCurve = new ISDADateCurve("ISDA", baseDate, ycDates, ycRates, offset);
    final HazardRateCurve hazardRateCurve = new HazardRateCurve(hazDates, hazTimes, hazRates, offset);

    for (int j = 5; j < 21; j += 3) {
      final CreditDefaultSwapDefinition cds1 = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(valDate.plusYears(j));

      final LocalDate[] res1Deprecated = ISDACompliantScheduleGenerator.toLocalDate(calculator.constructCreditDefaultSwapAccruedLegIntegrationSchedule(valDate, cds1, yieldCurve, hazardRateCurve, true));
      final int nRes1Deprecated = res1Deprecated.length;

      final LocalDate startDateLocal = ISDACompliantScheduleGenerator.toLocalDate(new ZonedDateTime[] {cds1.getStartDate() })[0];
      /*
       * Note cds1.getProtectionStart() == ture by default, thus .plusDays(1) is needed
       */
      final LocalDate endDateLocal = ISDACompliantScheduleGenerator.toLocalDate(new ZonedDateTime[] {cds1.getMaturityDate().plusDays(1) })[0];
      final LocalDate baseDateLocal = ISDACompliantScheduleGenerator.toLocalDate(new ZonedDateTime[] {baseDate })[0];
      final LocalDate[] hazDatesLocal = ISDACompliantScheduleGenerator.toLocalDate(hazDates);
      final LocalDate[] ycDatesLocal = ISDACompliantScheduleGenerator.toLocalDate(ycDates);

      final LocalDate[] res1 = ISDACompliantScheduleGenerator.getIntegrationNodesAsDates(startDateLocal, endDateLocal, ycDatesLocal, hazDatesLocal);
      final int nRes1 = res1.length;
      //      for (int i = 0; i < nRes1Deprecated; ++i) {
      //        System.out.println(res1Deprecated[i]);
      //      }
      //      System.out.println("\n");
      //      for (int i = 0; i < nRes1; ++i) {
      //        System.out.println(res1[i]);
      //      }
      //      System.out.println("\n");

      assertEquals(nRes1Deprecated, nRes1);
      for (int i = 0; i < nRes1; ++i) {
        assertTrue(res1[i].equals(res1Deprecated[i]));
      }

      /*
       * Note that valuation date is used only for start date and end date
       * Other date points are computed with the base date contained in yield curve and hazard rate curve
       */
      final double[] res2Deprecated = calculator.constructCreditDefaultSwapContingentLegIntegrationSchedule(baseDate, cds1.getStartDate(), cds1.getMaturityDate().plusDays(1),
          cds1, yieldCurve, hazardRateCurve);
      final int nRes2Deprecated = res2Deprecated.length;

      final int m = ycDatesLocal.length;
      /*
 
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.credit.schedulegeneration.GenerateCreditDefaultSwapIntegrationSchedule

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.