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

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


    CURVES = new ISDAYieldCurveAndHazardRateCurveProvider(YIELD_CURVE, HAZARD_RATE_CURVE);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void nullCdSTest() {
    final CreditDefaultSwapDefinition cds = null;
    CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, CURVES);
  }
View Full Code Here


    CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, CURVES);
  }

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

      expected[i * 2 + 1] = YC_DATES[i];
    }
    for (int i = 0; i < hrDates.length; i++) {
      expected[i * 2 + 2] = hrDates[i];
    }
    CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(true).withMaturityDate(VALUATION_DATE.plusYears(50));
    final ISDAYieldCurveAndHazardRateCurveProvider curves = new ISDAYieldCurveAndHazardRateCurveProvider(YIELD_CURVE, hazardRateCurve);
    ZonedDateTime[] actual = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, curves);
    expected[0] = cds.getStartDate();
    expected[expected.length - 1] = cds.getMaturityDate().plusDays(1);
    assertDateArrayEquals(expected, actual);
    assertDateArrayEquals(expected, DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, hazardRateCurve, false));
    cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(false).withMaturityDate(VALUATION_DATE.plusYears(50));
    actual = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, curves);
    expected[0] = cds.getStartDate();
    expected[expected.length - 1] = cds.getMaturityDate();
    assertDateArrayEquals(expected, actual);
    assertDateArrayEquals(expected, DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, hazardRateCurve, false));
  }
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(calibrationCDS, yieldCurve, runningDates, runningTenorsAsDoubles, runningHazardRates, priceType, marketSpreads[m]);
      }
      return hazardRates;
    }
View Full Code Here

    assertDateArrayEquals(expected, DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, hazardRateCurve, false));
  }

  @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[] actual = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, CURVES);
    ZonedDateTime[] expected = new ZonedDateTime[YC_DATES.length + 1];
    for (int i = 0; i < YC_DATES.length; i++) {
      expected[i + 1] = YC_DATES[i];
    }
    expected[0] = cds.getStartDate();
    expected[YC_DATES.length] = cds.getMaturityDate().plusDays(1);
    assertDateArrayEquals(expected, actual);
    assertDateArrayEquals(expected, DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_RATE_CURVE, false));
    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));
    actual = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, CURVES);
    expected = new ZonedDateTime[YC_DATES.length + 1];
    for (int i = 0; i < YC_DATES.length; i++) {
      expected[i + 1] = YC_DATES[i];
    }
    expected[0] = cds.getStartDate();
    expected[YC_DATES.length] = cds.getMaturityDate();
    assertDateArrayEquals(expected, actual);
    assertDateArrayEquals(expected, DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_RATE_CURVE, false));
  }
View Full Code Here

    final double strike = security.getStrike();
    final boolean isKnockOut = security.isKnockOut();
    final boolean isPayer = security.isPayer();
    final CDSOptionExerciseType optionExerciseType = convertExerciseType(security.getExerciseType());
    final FinancialSecurity underlyingSecurity = (FinancialSecurity) _securitySource.getSingle(ExternalIdBundle.of(security.getUnderlyingId())); //TODO version correction
    final CreditDefaultSwapDefinition underlyingCDS = underlyingSecurity.accept(_underlyingConverter);
    //    underlyingCDS = underlyingCDS.withMaturityDate(maturityDate.plusYears(10));
    //    underlyingCDS = underlyingCDS.withEffectiveDate(maturityDate.plusDays(1));
    //    underlyingCDS = underlyingCDS.withStartDate(maturityDate);
    return new CreditDefaultSwapOptionDefinition(buySellProtection, protectionBuyer, protectionSeller, currency, startDate, maturityDate, notional, strike,
        isKnockOut, isPayer, optionExerciseType, underlyingCDS);
View Full Code Here

    YIELD_CURVE = new ISDADateCurve("ISDA", BASE_DATE, YC_DATES, YC_RATES, OFFSET);
  }

  @Test
  public void accLegRegrTest() {
    final CreditDefaultSwapDefinition cds1 = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final CreditDefaultSwapDefinition cds2 = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(false);
    final ZonedDateTime[] hrDates = new ZonedDateTime[HR_DATES.length];
    final double[] hrTimes = new double[HR_TIMES.length];
    final int len = HR_DATES.length;
    for (int j = 1; j < 15; j += 3) {
      for (int i = 0; i < len; i++) {
        hrDates[i] = HR_DATES[i].plusDays(j);
        hrTimes[i] = DAY_COUNT.getDayCountFraction(BASE_DATE, hrDates[i]);
      }
      final HazardRateCurve hazardRateCurve = new HazardRateCurve(hrDates, hrTimes, HR_RATES, OFFSET);

      ZonedDateTime[] res1 = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds1, YIELD_CURVE, hazardRateCurve, true);
      final ZonedDateTime[] expected = new ZonedDateTime[hrDates.length - 1 + YC_DATES.length - 1 + 2];
      for (int i = 0; i < YC_DATES.length - 1; i++) {
        expected[i * 2 + 1] = YC_DATES[i];
      }
      for (int i = 0; i < hrDates.length - 1; i++) {
        expected[i * 2 + 2] = hrDates[i];
      }
      expected[0] = cds1.getStartDate();
      expected[expected.length - 1] = cds1.getMaturityDate().plusDays(1);
      assertDateArrayEquals(expected, res1);
      ZonedDateTime[] res2 = CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds2, YIELD_CURVE, hazardRateCurve, false);
      expected[expected.length - 1] = cds2.getMaturityDate().plusDays(0);
      assertDateArrayEquals(expected, res2);
      //    DEPRECATED_CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds2, YIELD_CURVE, hazardRateCurve, true);

      //    final int nRes = res1.length;
      //    for (int i = 0; i < nRes; ++i) {
View Full Code Here

  @Test
  public void testAccLegWithFixedCurve() {
    final HazardRateCurve hrCurve = new HazardRateCurve(HR_DATES, HR_TIMES, HR_RATES, OFFSET);
    for (int j = 1; j < 15; j += 3) {
      for (int k = 1; k < 25; k += 4) {
        CreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(true)
            .withMaturityDate(YC_DATES[YC_DATES.length - 1].minusMonths(j))
            .withEffectiveDate(VALUATION_DATE.minusMonths(j).plusDays(k))
            .withStartDate(VALUATION_DATE.minusMonths(j));
        ZonedDateTime[] expected = new ZonedDateTime[YC_DATES.length + 1];
        for (int i = 0; i < YC_DATES.length; i++) {
          expected[i + 1] = YC_DATES[i];
        }
        expected[0] = cds.getStartDate();
        expected[YC_DATES.length] = cds.getMaturityDate().plusDays(1);
        assertDateArrayEquals(expected, CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, hrCurve, false));
        cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinitionWithProtectionStart(false)
            .withMaturityDate(YC_DATES[YC_DATES.length - 1].minusMonths(j))
            .withEffectiveDate(VALUATION_DATE.minusMonths(j).plusDays(k))
            .withStartDate(VALUATION_DATE.minusMonths(j));
        expected = new ZonedDateTime[YC_DATES.length + 1];
        for (int i = 0; i < YC_DATES.length; i++) {
          expected[i + 1] = YC_DATES[i];
        }
        expected[0] = cds.getStartDate();
        expected[YC_DATES.length] = cds.getMaturityDate();
        assertDateArrayEquals(expected, CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds, YIELD_CURVE, hrCurve, true));
      }
    }
  }
View Full Code Here

    }
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void accLegNullCdsTest() {
    final CreditDefaultSwapDefinition cds1 = null;
    final ZonedDateTime[] hrDates = new ZonedDateTime[HR_DATES.length];
    final double[] hrTimes = new double[HR_TIMES.length];
    final int len = HR_DATES.length;
    for (int i = 0; i < len; i++) {
      hrDates[i] = HR_DATES[i].plusDays(12);
View Full Code Here

    CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds1, YIELD_CURVE, hazardRateCurve, true);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void accLegNullYieldTest() {
    final CreditDefaultSwapDefinition cds1 = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    final ZonedDateTime[] hrDates = new ZonedDateTime[HR_DATES.length];
    final double[] hrTimes = new double[HR_TIMES.length];
    final int len = HR_DATES.length;
    for (int i = 0; i < len; i++) {
      hrDates[i] = HR_DATES[i].plusDays(12);
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.