Examples of ISDADateCurve


Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

    }

    private HazardRateCurve calibrateCurve(final CreditDefaultSwapDefinition cds, final ISDAYieldCurveAndSpreadsProvider data) {
      final ZonedDateTime[] marketDates = data.getMarketDates();
      final double[] marketSpreads = data.getMarketSpreads();
      final ISDADateCurve yieldCurve = data.getYieldCurve();
      final double[] calibratedHazardRates = getCalibratedHazardRateTermStructure(_valuationDate, cds, marketDates, marketSpreads, yieldCurve, PRICE_TYPE);
      final double[] modifiedHazardRateCurve = new double[calibratedHazardRates.length + 1];
      final double[] times = new double[marketDates.length + 1];
      modifiedHazardRateCurve[0] = calibratedHazardRates[0];
      times[0] = 0.0;
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

      } else {
        name = curve.getName();
      }
      final double offset = message.getDouble(OFFSET_FIELD_NAME);
      final List<ZonedDateTime> dates = (List<ZonedDateTime>) deserializer.fieldValueToObject(message.getByName(DATES_FIELD_NAME));
      return new ISDADateCurve(name, dates.toArray(new ZonedDateTime[dates.size()]), ArrayUtils.toPrimitive(curve.getXData()), ArrayUtils.toPrimitive(curve.getYData()), offset);
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

    for (int i = 0; i < len; 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 ISDADateCurve yc = null;

    CALCULATOR.constructCreditDefaultSwapAccruedLegIntegrationSchedule(VALUATION_DATE, cds1, yc, hazardRateCurve, true);
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

      hrTimes[i] = DAY_COUNT.getDayCountFraction(BASE_DATE, hrDates[i]);
    }
    final HazardRateCurve hazardRateCurve = new HazardRateCurve(hrDates, hrTimes, HR_RATES, OFFSET);
    final ZonedDateTime startDate = getStartDate(cds);
    final ZonedDateTime endDate = cds.getMaturityDate();
    final ISDADateCurve yc = null;

    CALCULATOR.constructCreditDefaultSwapContingentLegIntegrationSchedule(VALUATION_DATE, startDate, endDate, cds, yc, hazardRateCurve);
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

    double presentValuePremiumLeg = 0.0;
    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;
            t = t1 - t0;
            final double lambda = Math.log(s0 / s1) / t;
            final double fwdRate = Math.log(df0 / df1) / t;
            final double lambdafwdRate = lambda + fwdRate + 1.0e-50;
            thisAccPV = lambda * accRate * s0 * df0 * ((t0 + 1.0 / (lambdafwdRate)) / (lambdafwdRate) - (t1 + 1.0 / (lambdafwdRate)) / (lambdafwdRate) * s1 / s0 * df1 / df0);
            myPV += thisAccPV;
            s0 = s1;
            df0 = df1;
            subStartDate = date;
          }
        }
      }
      thisPV += myPV;
    }
    presentValuePremiumLeg = thisPV;
    // TODO : Check this calculation - maybe move it out of this routine and into the PV calculation routine?
    // TODO : Note the cash settlement date is hardcoded at 3 days
    ZonedDateTime bdaCashSettlementDate = valuationDate.plusDays(SPOT_DAYS);
    if (ADJUST_CASH_SETTLEMENT_DATE) {
      bdaCashSettlementDate = BDA.adjustDate(cds.getCalendar(), bdaCashSettlementDate);
    }
    final double tSett = ACT_ACT.getDayCountFraction(valuationDate, bdaCashSettlementDate);
    final double valueDatePV = yieldCurve.getDiscountFactor(tSett);
    presentValuePremiumLeg /= valueDatePV;
    if (priceType == PriceType.CLEAN) {
      //TODO not looked at this yet
      // pass in stepinDate as 'today' 31/1/2013
      double ai = 0.0;
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

    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)
      final double interestRate = Math.log(discountFactorPrevious / discountFactor) / deltat;
      // Calculate the contribution of the interval deltat to the overall contingent leg integral
      presentValueContingentLeg += loss * (hazardRate / (hazardRate + interestRate)) * (1.0 - Math.exp(-(hazardRate + interestRate) * deltat)) * survivalProbabilityPrevious * discountFactorPrevious;
    }
    // TODO : Check this calculation - maybe move it out of this routine and into the PV calculation routine?
    // TODO : Note the cash settlement date is hardcoded at 3 days
    //final int spotDays = 5;
    //final ZonedDateTime cashSettleDate = valuationDate.plusDays(spotDays);
    //final double t = TimeCalculator.getTimeBetween(valuationDate, cashSettleDate, ACT_365);
    ZonedDateTime bdaCashSettlementDate = valuationDate.plusDays(SPOT_DAYS);
    if (ADJUST_CASH_SETTLEMENT_DATE) {
      bdaCashSettlementDate = BDA.adjustDate(cds.getCalendar(), valuationDate.plusDays(SPOT_DAYS));
    }
    final double t = TimeCalculator.getTimeBetween(valuationDate, bdaCashSettlementDate, ACT_365);
    final double valueDatePV = yieldCurve.getDiscountFactor(t);
    return cds.getNotional() * presentValueContingentLeg / valueDatePV;
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

  @Test
  public void testISDADateCurve() {
    final ZonedDateTime now = DateUtils.getUTCDate(2013, 1, 1);
    final ZonedDateTime[] dates = new ZonedDateTime[] { now, now.plusYears(1) };
    final ISDADateCurve c1 = new ISDADateCurve("Test", dates, new double[] { 0, 1 }, new double[] { 1, 2 }, 0);
    final ISDADateCurve c2 = cycleObject(ISDADateCurve.class, c1);
    assertEquals(c1, c2);
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

        restructuringClause, calendar, startDate, effectiveDate, maturityDate, stubType, couponFrequency, daycountFractionConvention, businessdayAdjustmentConvention, immAdjustMaturityDate,
        adjustEffectiveDate, adjustMaturityDate, notional, recoveryRate, includeAccruedPremium, protectionStart, parSpread);

    final PresentValueCreditDefaultSwap pvcds = new PresentValueCreditDefaultSwap();

    final ISDADateCurve curveISDADate = new ISDADateCurve("Test", BASE_DATE, CURVE_DATES, RATES, 0.0);

    // Set the tenors at which we have market observed par CDS spread quotes
    final int nbTenors = 10;
    final ZonedDateTime[] tenors = new ZonedDateTime[nbTenors];
    tenors[0] = DateUtils.getUTCDate(2008, 12, 20);
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

        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));
View Full Code Here

Examples of com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve

    final double bumpInBp = yieldBump / 10000;
    switch(yieldBumpType) {
      case ADDITIVE:
      {
        bumpedYields[0] += bumpInBp;
        ISDADateCurve bumpedYieldCurve = new ISDADateCurve("Bumped", yieldCurve.getCurveDates(), yieldCurve.getTimePoints(), bumpedYields, yieldCurve.getOffset());
        calibrationData = new ISDAYieldCurveAndSpreadsProvider(marketTenors, marketSpreads, bumpedYieldCurve);
        hazardRateCurve = HAZARD_RATE_CALCULATOR.calibrateHazardRateCurve(cds, calibrationData, valuationDate);
        curveProvider = new ISDAYieldCurveAndHazardRateCurveProvider(bumpedYieldCurve, hazardRateCurve);
        double bumpedPresentValue = PV_CALCULATOR.getPresentValue(cds, curveProvider, valuationDate, priceType);
        bucketedIR01[0] = (bumpedPresentValue - presentValue) / yieldBump;
        for (int i = 1; i < nYields; i++) {
          bumpedYields[i - 1] -= bumpInBp;
          bumpedYields[i] += bumpInBp;
          bumpedYieldCurve = new ISDADateCurve("Bumped", yieldCurve.getCurveDates(), yieldCurve.getTimePoints(), bumpedYields, yieldCurve.getOffset());
          calibrationData = new ISDAYieldCurveAndSpreadsProvider(marketTenors, marketSpreads, bumpedYieldCurve);
          hazardRateCurve = HAZARD_RATE_CALCULATOR.calibrateHazardRateCurve(cds, calibrationData, valuationDate);
          curveProvider = new ISDAYieldCurveAndHazardRateCurveProvider(bumpedYieldCurve, hazardRateCurve);
          bumpedPresentValue = PV_CALCULATOR.getPresentValue(cds, curveProvider, valuationDate, priceType);
          bucketedIR01[i] = (bumpedPresentValue - presentValue) / yieldBump;
        }
        break;
      }
      case MULTIPLICATIVE:
        bumpedYields[0] *= 1 + bumpInBp;
        ISDADateCurve bumpedYieldCurve = new ISDADateCurve("Bumped", yieldCurve.getCurveDates(), yieldCurve.getTimePoints(), bumpedYields, yieldCurve.getOffset());
        calibrationData = new ISDAYieldCurveAndSpreadsProvider(marketTenors, marketSpreads, bumpedYieldCurve);
        hazardRateCurve = HAZARD_RATE_CALCULATOR.calibrateHazardRateCurve(cds, calibrationData, valuationDate);
        curveProvider = new ISDAYieldCurveAndHazardRateCurveProvider(bumpedYieldCurve, hazardRateCurve);
        double bumpedPresentValue = PV_CALCULATOR.getPresentValue(cds, curveProvider, valuationDate, priceType);
        bucketedIR01[0] = (bumpedPresentValue - presentValue) / yieldBump;
        for (int i = 1; i < nYields; i++) {
          bumpedYields[i - 1] /= 1 + bumpInBp;
          bumpedYields[i] *= 1 + bumpInBp;
          bumpedYieldCurve = new ISDADateCurve("Bumped", yieldCurve.getCurveDates(), yieldCurve.getTimePoints(), bumpedYields, yieldCurve.getOffset());
          calibrationData = new ISDAYieldCurveAndSpreadsProvider(marketTenors, marketSpreads, bumpedYieldCurve);
          hazardRateCurve = HAZARD_RATE_CALCULATOR.calibrateHazardRateCurve(cds, calibrationData, valuationDate);
          curveProvider = new ISDAYieldCurveAndHazardRateCurveProvider(bumpedYieldCurve, hazardRateCurve);
          bumpedPresentValue = PV_CALCULATOR.getPresentValue(cds, curveProvider, valuationDate, priceType);
          bucketedIR01[i] = (bumpedPresentValue - presentValue) / yieldBump;
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.