Examples of HazardRateCurve


Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    final double[] modifiedHazardRateCurve = new double[1];

    modifiedHazardRateCurve[0] = calibratedHazardRates[0];

    // Build a hazard rate curve object based on the input market data
    final HazardRateCurve calibratedHazardRateCurve = new HazardRateCurve(marketTenors, times, modifiedHazardRateCurve/*calibratedHazardRates*/, 0.0);

    // Calculate the points upfront
    final double pointsUpfront = creditDefaultSwap.getPresentValueLegacyCreditDefaultSwap(valuationDate, valuationCDS, yieldCurve, calibratedHazardRateCurve, priceType);

    // ----------------------------------------------------------------------------------------------------------------------------------------
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    for (int m = 1; m < modifiedHazardRateCurve.length; m++) {
      modifiedHazardRateCurve[m] = calibratedHazardRates[m - 1];
    }

    // Build a hazard rate curve object based on the input market data
    return new HazardRateCurve(marketTenors, times, modifiedHazardRateCurve, 0.0);
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    // Create a copy of the underlying CDS for the purposes of calibration of the hazard rate term structure
    final LegacyVanillaCreditDefaultSwapDefinition underlyingCalibrationCDS = (LegacyVanillaCreditDefaultSwapDefinition) cdsSwaption.getUnderlyingCDS();

    // Build a hazard rate curve object based on the input market data
    //final HazardRateCurve calibratedHazardRateCurve = creditDefaultSwap.calibrateHazardRateCurve(valuationDate, underlyingCalibrationCDS, calibrationTenors, marketSpreads, yieldCurve);
    final HazardRateCurve calibratedHazardRateCurve = cdsCalibrator.isdaCalibrateHazardRateCurve(valuationDate, underlyingCalibrationCDS, calibrationTenors, marketSpreads, yieldCurve);

    // ----------------------------------------------------------------------------------------------------------------------------------------

    // Get the underlying CDS in the swaption contract (don't really need to do this if we fix the LegacyVanilla issue above)
    final CreditDefaultSwapDefinition underlyingCDS = cdsSwaption.getUnderlyingCDS();
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    // Call the constructor to create a CDS present value object
    final PresentValueLegacyCreditDefaultSwap creditDefaultSwap = new PresentValueLegacyCreditDefaultSwap();

    // Build a hazard rate curve object based on the input market data
    final HazardRateCurve calibratedHazardRateCurve = cdsCalibrator.isdaCalibrateHazardRateCurve(valuationDate, valuationCDS, marketTenors, marketSpreads, yieldCurve);

    // Calculate the CDS PV using the just calibrated hazard rate term structure
    final double presentValue = creditDefaultSwap.getPresentValueLegacyCreditDefaultSwap(valuationDate, valuationCDS, yieldCurve, calibratedHazardRateCurve, priceType);

    return presentValue;
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    final ZonedDateTime[] premiumLegSchedule = PREMIUM_LEG_SCHEDULE.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    final ZonedDateTime[] accruedLegIntegrationSchedule = ACRRUED_INTEGRATION_SCHEDULE.constructCreditDefaultSwapAccruedLegIntegrationSchedule(cds, curves);
    final ZonedDateTime adjustedMaturityDate = PREMIUM_LEG_SCHEDULE.getAdjustedMaturityDate(cds);
    ArgumentChecker.isTrue(!valuationDate.isAfter(adjustedMaturityDate), "Valuation date {} must be on or before the adjusted maturity date {}", valuationDate, adjustedMaturityDate);
    final ISDADateCurve yieldCurve = curves.getYieldCurve();
    final HazardRateCurve hazardRateCurve = curves.getHazardRateCurve();
    // TODO : Check the effective date calc here
    // If the valuation date is exactly the adjusted maturity date then simply return zero
    /*
        if (valuationDate.equals(adjustedMaturityDate) || cds.getEffectiveDate().equals(adjustedMaturityDate)) {
          return 0.0;
        }
     */
    final ZonedDateTime today = valuationDate;
    final ZonedDateTime stepinDate = cds.getEffectiveDate(); //TODO this relies on the person that's set up the CDS to know that effective date = 1 day after valuation date by convention
    // The value date is when cash settlement is made
    // TODO : Add the extra logic for this calculation
    final ZonedDateTime matDate = cds.getMaturityDate();
    // TODO : Check valueDate >= today and stepinDate >= today
    if (today.isAfter(matDate) || stepinDate.isAfter(matDate)) {
      return 0;
    }
    double thisPV = 0.0;
    for (int i = 1; i < premiumLegSchedule.length; i++) {
      final int obsOffset = cds.getProtectionStart() ? -1 : 0;
      final ZonedDateTime accrualStartDate = premiumLegSchedule[i - 1];
      ZonedDateTime accrualEndDate = premiumLegSchedule[i];
      final ZonedDateTime discountDate = accrualEndDate;
      // The last coupon date has an extra day of accrued
      if (i == premiumLegSchedule.length - 1) {
        accrualEndDate = accrualEndDate.plusDays(1);
      }
      final double delta = accrualEndDate.isAfter(stepinDate) ? 1 : 0;
      final double accTime = ACT_360.getDayCountFraction(accrualStartDate, accrualEndDate);
      final ZonedDateTime offsetAccrual = accrualEndDate.plusDays(obsOffset);
      double tObsOffset = today.isAfter(offsetAccrual) ? -ACT_365.getDayCountFraction(offsetAccrual, today) : ACT_365.getDayCountFraction(today, offsetAccrual);
      if (Double.compare(tObsOffset, -0.0) == 0) {
        tObsOffset = 0;
      }
      double t = today.isAfter(discountDate) ? -ACT_365.getDayCountFraction(discountDate, today) : ACT_365.getDayCountFraction(today, discountDate);
      final double survival = hazardRateCurve.getSurvivalProbability(tObsOffset);
      final double discount = yieldCurve.getDiscountFactor(t);
      thisPV += delta * accTime * discount * survival;
      double myPV = 0.0;
      if (cds.getIncludeAccruedPremium()) {
        final ZonedDateTime offsetStepinDate = stepinDate.plusDays(obsOffset);            // stepinDate
        final ZonedDateTime offsetAccStartDate = accrualStartDate.plusDays(obsOffset);    // startDate
        final ZonedDateTime offsetAccEndDate = accrualEndDate.plusDays(obsOffset);        // endDate
        // TODO : Check endDate > startDate
        final ZonedDateTime[] truncatedDateList = ScheduleUtils.getTruncatedTimeLine(accruedLegIntegrationSchedule, offsetAccStartDate, offsetAccEndDate, true);
        ZonedDateTime subStartDate = offsetStepinDate.isAfter(offsetAccStartDate) ? offsetStepinDate : offsetAccStartDate;
        final double tAcc = ACT_365.getDayCountFraction(offsetAccStartDate, offsetAccEndDate);
        final double accRate = accTime / tAcc;
        if (today.equals(subStartDate)) {
          t = 0;
        } else {
          t = today.isBefore(subStartDate) ? ACT_365.getDayCountFraction(today, subStartDate) : -ACT_365.getDayCountFraction(subStartDate, today);
        }
        if (Double.compare(t, -0.0) == 0) {
          t = 0;
        }
        double s0 = hazardRateCurve.getSurvivalProbability(t);
        double df0 = yieldCurve.getDiscountFactor(t);
        for (int j = 1; j < truncatedDateList.length; ++j) {
          double thisAccPV = 0.0;
          final ZonedDateTime date = truncatedDateList[j];
          if (date.isAfter(offsetStepinDate)) {
            t = today.isBefore(date) ? ACT_365.getDayCountFraction(today, date) : -ACT_365.getDayCountFraction(date, today); //TimeCalculator.getTimeBetween(today, truncatedDateList[j], ACT_365);
            if (Double.compare(t, -0.0) == 0) {
              t = 0;
            }
            final double s1 = hazardRateCurve.getSurvivalProbability(t);
            final double df1 = yieldCurve.getDiscountFactor(t);
            final double t0 = (offsetAccStartDate.isBefore(subStartDate) ? ACT_365.getDayCountFraction(offsetAccStartDate, subStartDate)
                : ACT_365.getDayCountFraction(subStartDate, offsetAccStartDate)) + 0.5 / 365.0;
            final double t1 = (offsetAccStartDate.isBefore(date) ? ACT_365.getDayCountFraction(offsetAccStartDate, date)
                : ACT_365.getDayCountFraction(date, offsetAccStartDate)) + 0.5 / 365.0;
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    if (!startDate.isAfter(valuationDateM1)) {
      startDate = valuationDateM1;
    }
    final double[] contingentLegIntegrationSchedule = SCHEDULE_CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(valuationDate, startDate, clEndDate, cds, curves);
    // Get the survival probability at the first point in the integration schedule
    final HazardRateCurve hazardRateCurve = curves.getHazardRateCurve();
    double survivalProbability = hazardRateCurve.getSurvivalProbability(contingentLegIntegrationSchedule[0]);
    // Get the discount factor at the first point in the integration schedule
    final ISDADateCurve yieldCurve = curves.getYieldCurve();
    double discountFactor = yieldCurve.getDiscountFactor(contingentLegIntegrationSchedule[0]);
    final double loss = (1 - cds.getRecoveryRate());
    for (int i = 1; i < contingentLegIntegrationSchedule.length; ++i) {
      // Calculate the time between adjacent points in the integration schedule
      final double deltat = contingentLegIntegrationSchedule[i] - contingentLegIntegrationSchedule[i - 1];
      // Set the probability of survival up to the previous point in the integration schedule
      final double survivalProbabilityPrevious = survivalProbability;
      // Set the discount factor up to the previous point in the integration schedule
      final double discountFactorPrevious = discountFactor;
      // Get the survival probability at this point in the integration schedule
      survivalProbability = hazardRateCurve.getSurvivalProbability(contingentLegIntegrationSchedule[i]);
      // Get the discount factor at this point in the integration schedule
      discountFactor = yieldCurve.getDiscountFactor(contingentLegIntegrationSchedule[i]);
      // Calculate the forward hazard rate over the interval deltat (assumes the hazard rate is constant over this period)
      final double hazardRate = Math.log(survivalProbabilityPrevious / survivalProbability) / deltat;
      // Calculate the forward interest rate over the interval deltat (assumes the interest rate is constant over this period)
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

        runningTenorsAsDoubles[m] = ACT_365.getDayCountFraction(valuationDate, runningMarketTenors[m]);
        runningHazardRates[m] = calibratedHazardRateCurve[m];
      }

      // Now build a (running) hazard rate curve for the first i tenors where the hazard rate for tenor i is 'guess'
      HazardRateCurve runningHazardRateCurve = new HazardRateCurve(runningMarketTenors, runningTenorsAsDoubles, runningHazardRates, 0.0);

      // Now calculate the calibrated hazard rate for tenor i (given that the prior tenors have been calibrated) using the ISDA calibration routine
      calibratedHazardRateCurve[i] = isdaRootFinder(valuationDate, calibrationCDS, yieldCurve, runningHazardRateCurve, guess, PriceType.CLEAN);
    }

    // ----------------------------------------------------------------------------------------------------------------------------------------

    // Construct the curve from the calibrated hazard rates

    final double[] modifiedHazardRateCurve = new double[calibratedHazardRateCurve.length + 1];

    modifiedHazardRateCurve[0] = calibratedHazardRateCurve[0];

    for (int m = 1; m < modifiedHazardRateCurve.length; m++) {
      modifiedHazardRateCurve[m] = calibratedHazardRateCurve[m - 1];
    }

    // Now build the complete, calibrated hazard rate curve
    HazardRateCurve hazardRateCurve = new HazardRateCurve(marketTenors, tenorsAsDoubles, modifiedHazardRateCurve, 0.0);

    // ----------------------------------------------------------------------------------------------------------------------------------------

    return hazardRateCurve;
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

    }
    // End if

    // ----------------------------------------------------------------------------------------------------------------------------------------

    HazardRateCurve modifiedHazardRateCurve = modifyHazardRateCurve(hazardRateCurve, xPoints[2]);

    yPoints[2] = cdsBootstrapPointFunction(valuationDate, cds, yieldCurve, modifiedHazardRateCurve, priceType);

    if (yPoints[2] == 0.0 || (Math.abs(yPoints[2]) <= FACC && Math.abs(xPoints[2] - xPoints[0]) <= XACC)) {
      return xPoints[2];
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

        x3 = x2;
        f3 = f2;
      } else {
        xm = x1 - (f1 / f21) * x21 + ((f1 * f2) / (f31 * f32)) * x31 - ((f1 * f2) / (f21 * f32)) * x21;

        HazardRateCurve modifiedHazardRateCurve = modifyHazardRateCurve(hazardRateCurve, xm);

        // NOTE : Passing in the PriceType variable to this calculation
        fm = cdsBootstrapPointFunction(valuationDate, cds, yieldCurve, modifiedHazardRateCurve, PriceType.CLEAN);

        if (fm == 0.0 || (Math.abs(fm) <= facc && Math.abs(xm - x1) <= xacc)) {
          return xm;
        }

        if (fm * f1 < 0.0) {
          x3 = xm;
          f3 = fm;
        } else {
          x1 = xm;
          f1 = fm;
          x3 = x2;
          f3 = f2;
        } // End if fm*f1<0.0 else ...

      } // End if f3*f31 < ratio*f2*f21 || f21 == 0. || f31 == 0. || f32 == 0. else ...

      x2 = 0.5 * (x1 + x3);

      HazardRateCurve modifiedHazardRateCurve = modifyHazardRateCurve(hazardRateCurve, x2);

      f2 = cdsBootstrapPointFunction(valuationDate, cds, yieldCurve, modifiedHazardRateCurve, PriceType.CLEAN);

      if (f2 == 0.0 || (Math.abs(f2) <= facc && Math.abs(x2 - x1) <= xacc)) {
        return x2;
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.hazardratecurve.HazardRateCurve

        result[1] = 0.0;

        return result;
      }

      final HazardRateCurve modifiedHazardRateCurve = modifyHazardRateCurve(hazardRateCurve, xPoints[1]);

      yPoints[1] = cdsBootstrapPointFunction(valuationDate, cds, yieldCurve, modifiedHazardRateCurve, PriceType.CLEAN);

      if (yPoints[1] == 0.0 || (Math.abs(yPoints[1]) <= facc && Math.abs(xPoints[1] - xPoints[0]) <= xacc)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.