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

Examples of com.opengamma.analytics.financial.credit.creditdefaultswap.definition.vanilla.CreditDefaultSwapDefinition


  //TODO test short dates

  @Test(enabled = false)
  public void timeBDeprecated() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final double startTime = System.currentTimeMillis();
    int j = 0;
    for (int i = 0; i < 1000000; i++) {
      DEPRECATED_CALCULATOR.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
      j++;
View Full Code Here


    for (int i = 0; i < HR_DATES.length; i++) {
      hrDates[i] = HR_DATES[i].plusDays(12);
      hrTimes[i] = DAY_COUNT.getDayCountFraction(BASE_DATE, hrDates[i]);
    }
    final HazardRateCurve hazardRateCurve = new HazardRateCurve(hrDates, hrTimes, HR_RATES, OFFSET);
    CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(true).withMaturityDate(VALUATION_DATE.plusYears(50));
    final ISDAYieldCurveAndHazardRateCurveProvider curves = new ISDAYieldCurveAndHazardRateCurveProvider(YIELD_CURVE, hazardRateCurve);
    ZonedDateTime startDate = getStartDate(cds);
    ZonedDateTime endDate = cds.getMaturityDate();
    double[] actual = CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, curves);
    double[] dep = DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, hazardRateCurve);
    int nActual = actual.length;
    int nDep = dep.length;
    assertEquals(nDep, nActual);
    for (int i = 0; i < nDep; ++i) {
      assertEquals(actual[i], dep[i]);
    }
    cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(false).withMaturityDate(VALUATION_DATE.plusYears(50));
    startDate = getStartDate(cds);
    endDate = cds.getMaturityDate();
    actual = CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, curves);
    dep = DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, hazardRateCurve);
    nActual = actual.length;
    nDep = dep.length;
    assertEquals(nDep, nActual);
View Full Code Here

    }
  }

  @Test
  public void testCDSWithinCurves() {
    CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(true)
        .withMaturityDate(YC_DATES[YC_DATES.length - 1].minusMonths(1))
        .withEffectiveDate(VALUATION_DATE.minusMonths(1).plusDays(1))
        .withStartDate(VALUATION_DATE.minusMonths(1));
    final ISDAYieldCurveAndHazardRateCurveProvider curves = new ISDAYieldCurveAndHazardRateCurveProvider(YIELD_CURVE, HAZARD_RATE_CURVE);
    ZonedDateTime startDate = getStartDate(cds);
    ZonedDateTime endDate = cds.getMaturityDate();
    double[] actual = CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, CURVES);
    double[] dep = DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, HAZARD_RATE_CURVE);
    int nActual = actual.length;
    int nDep = dep.length;
    assertEquals(nDep, nActual);
    for (int i = 0; i < nDep; ++i) {
      assertEquals(actual[i], dep[i]);
    }
    cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(false)
        .withMaturityDate(YC_DATES[YC_DATES.length - 1].minusMonths(1))
        .withEffectiveDate(VALUATION_DATE.minusMonths(1).plusDays(1))
        .withStartDate(VALUATION_DATE.minusMonths(1));
    startDate = getStartDate(cds);
    endDate = cds.getMaturityDate();
    actual = CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, CURVES);
    dep = DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, HAZARD_RATE_CURVE);
    nActual = actual.length;
    nDep = dep.length;
    assertEquals(nDep, nActual);
View Full Code Here

      final double[] runningTenorsAsDoubles = new double[m1];
      System.arraycopy(tenorsAsDoubles, 0, runningTenorsAsDoubles, 0, m1);
      // Construct a temporary vector of the hazard rates corresponding to the first m tenors (note size of array)
      final double[] runningHazardRates = new double[m1];
      System.arraycopy(hazardRates, 0, runningHazardRates, 0, m1);
      final CreditDefaultSwapDefinition calibrationCDS = getCDSWithSpread((cds.withMaturityDate(marketDates[m])), marketSpreads[m]);
      // Compute the calibrated hazard rate for tenor[m] (using the calibrated hazard rates for tenors 1, ..., m - 1)
      hazardRates[m] = calibrateHazardRate(valuationDate, calibrationCDS, yieldCurve, runningDates, runningTenorsAsDoubles, runningHazardRates, priceType, marketSpreads[m]);
    }
    return hazardRates;
  }
View Full Code Here

    }
  }

  @Test
  public void regressionTest() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final double[] deprecatedResult = DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, HAZARD_RATE_CURVE);
    final double[] result = CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, CURVES);
    assertArrayEquals(deprecatedResult, result, EPS);
  }
View Full Code Here

    assertArrayEquals(deprecatedResult, result, EPS);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void nullCdSTest() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final CreditDefaultSwapDefinition nCdS = null;
    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, nCdS, CURVES);
  }
View Full Code Here

    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, nCdS, CURVES);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void nullCurveTest() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final ISDAYieldCurveAndHazardRateCurveProvider cv = null;
    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, cv);
  }
View Full Code Here

    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, cv);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void endBeforeStartTest() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, endDate, startDate, cds, CURVES);
  }
View Full Code Here

  //    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(endDate, startDate, VALUATION_DATE, cds, CURVES);
  //  }

  @Test(enabled = false)
  public void timeBDeprecated() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final double startTime = System.currentTimeMillis();
    int j = 0;
    for (int i = 0; i < 1000000; i++) {
      DEPRECATED_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, YIELD_CURVE, HAZARD_RATE_CURVE);
      j++;
View Full Code Here

    System.out.println("Deprecated:\t" + (endTime - startTime) / j * 100);
  }

  @Test(enabled = false)
  public void timeARefactored() {
    final CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final double startTime = System.currentTimeMillis();
    int j = 0;
    for (int i = 0; i < 5000000; i++) {
      CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, CURVES);
      j++;
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.credit.creditdefaultswap.definition.vanilla.CreditDefaultSwapDefinition

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.