/** * Get the RPV01 of the premium leg - i.e. the value of the leg per point of spread (expressed as * a fraction, so 1bs is 0.0001) * * <p>This exists to duplicate the function of the same name from PresentValueCreditDefaultSwap. * <b>Note</b> this version agrees with the ISDA c library. * * @param valuationDate The valuation date - this is taken to be the same as today * @param cds Description of the CDS * @param yieldCurve The discount curve * @param hazardRateCurve The survival curve * @param priceType Clean or dirty * @return The RPV01 of the premium leg * @deprecated use calculateRPV01 */ @Deprecated public double calculatePremiumLeg( final ZonedDateTime valuationDate, final CreditDefaultSwapDefinition cds, final ISDADateCurve yieldCurve, final HazardRateCurve hazardRateCurve, final PriceType priceType) { ArgumentChecker.notNull(valuationDate, "null valuationDate"); ArgumentChecker.notNull(cds, "null cds"); ArgumentChecker.notNull(yieldCurve, "null yieldCurve"); ArgumentChecker.notNull(hazardRateCurve, "null hazardRateCurve"); ArgumentChecker.notNull(priceType, "null priceType"); final LocalDate valueDate = valuationDate.toLocalDate(); final LocalDate today = valueDate; final LocalDate stepinDate = cds.getEffectiveDate().toLocalDate(); final LocalDate startDate = cds.getStartDate().toLocalDate(); final LocalDate endDate = cds.getMaturityDate().toLocalDate(); return cds.getNotional() * pvPremiumLegPerUnitSpread( today, stepinDate, valueDate, startDate, endDate, cds.getIncludeAccruedPremium(), cds.getCouponFrequency().getPeriod(), cds.getStubType(), ISDACompliantDateYieldCurve.fromISDADateCurve(yieldCurve), ISDACompliantDateCreditCurve.fromHazardRateCurve(hazardRateCurve), cds.getProtectionStart(), priceType); }
@Test public void testNonOverlappingHazardRateAndYieldCurveDates() { final ZonedDateTime[] hrDates = new ZonedDateTime[HR_DATES.length]; final double[] hrTimes = new double[HR_TIMES.length]; 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); final ZonedDateTime[] expected = new ZonedDateTime[hrDates.length + YC_DATES.length + 2]; for (int i = 0; i < YC_DATES.length; i++) { 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)); }
@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)); }
/** * Get the value of the contingent (or protection) leg * * <p>This exists to duplicate the function of the same name from PresentValueCreditDefaultSwap. * <b>Note</b> this version agrees with the ISDA c library. * * @param valuationDate The valuation date - this is taken to be the same as today * @param cds Description of the CDS * @param yieldCurve The discount curve * @param hazardRateCurve The survival curve * @return Present Value of protection (or contingent) leg * @deprecated use calculateProtectionLeg */ @Deprecated public double calculateContingentLeg( final ZonedDateTime valuationDate, final CreditDefaultSwapDefinition cds, final ISDADateCurve yieldCurve, final HazardRateCurve hazardRateCurve) { ArgumentChecker.notNull(valuationDate, "null valuationDate"); ArgumentChecker.notNull(cds, "null cds"); ArgumentChecker.notNull(yieldCurve, "null yieldCurve"); ArgumentChecker.notNull(hazardRateCurve, "null hazardRateCurve"); final LocalDate valueDate = valuationDate.toLocalDate(); final LocalDate today = valueDate; final LocalDate stepinDate = cds.getEffectiveDate().toLocalDate(); final LocalDate startDate = cds.getStartDate().toLocalDate(); final LocalDate endDate = cds.getMaturityDate().toLocalDate(); final double rr = cds.getRecoveryRate(); final boolean protectionStart = cds.getProtectionStart(); return cds.getNotional() * calculateProtectionLeg( today, stepinDate, valueDate, startDate, endDate, ISDACompliantDateYieldCurve.fromISDADateCurve(yieldCurve), ISDACompliantDateCreditCurve.fromHazardRateCurve(hazardRateCurve), rr, protectionStart); }