Package com.opengamma.analytics.financial.credit.schedulegeneration

Examples of com.opengamma.analytics.financial.credit.schedulegeneration.GenerateCreditDefaultSwapPremiumLegSchedule


    if (numSwaps == 0) {
      return;
    }

    final GenerateCreditDefaultSwapPremiumLegSchedule swapMaturities = new GenerateCreditDefaultSwapPremiumLegSchedule();

    final ZonedDateTime lastStubDate = cashDates[cashDates.length - 1];

    // Need to implement this if want to have swaps with maturities less than MM instruments
    // numSwaps = getNumberOfActiveSwaps(lastStubDate, swapDates, numSwaps);

    final ZonedDateTime[] unadjustedSwapDates = new ZonedDateTime[swapDates.length];
    final ZonedDateTime[] adjustedSwapDates = new ZonedDateTime[swapDates.length];

    final boolean[] onCycleSwapDates = new boolean[swapDates.length];
    final ZonedDateTime[] previousSwapDates = new ZonedDateTime[swapDates.length];

    for (int i = 0; i < numSwaps; i++) {
      unadjustedSwapDates[i] = swapDates[i];
      adjustedSwapDates[i] = swapMaturities.businessDayAdjustDate(swapDates[i], calendar, businessdayAdjustmentConvention);
    }

    int numIntervals = 0;
    int extraDays = 0;

    int compoundInterval = 0;
    int multiplier = 0;

    double intervalYears = 0.0;

    // Need to fix this - bit of a hack
    /*if (swapFixedLegCouponFrequency == PeriodFrequency.SEMI_ANNUAL)*/
    {
      intervalYears = 0.5;
      multiplier = 6;
    }

    /*if (swapFixedLegCouponFrequency == PeriodFrequency.QUARTERLY)*/
    {
      intervalYears = 0.25;
      multiplier = 3;
    }

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

    for (int i = 0; i < numSwaps; i++) {

      boolean onCycle = false;

      if (valueDate.getDayOfMonth() <= 28 && unadjustedSwapDates[i].getDayOfMonth() <= 28) {

        final ZonedDateTime fromDate = valueDate;
        final ZonedDateTime toDate = unadjustedSwapDates[i];

        final double fromToYears = TimeCalculator.getTimeBetween(fromDate, toDate, ACT_365);

        final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);
        int index = lowNumIntervals;

        compoundInterval = index * multiplier;

        ZonedDateTime currDate = fromDate.plusMonths(compoundInterval);
        ZonedDateTime lastDate = currDate;

        while (currDate.isAfter(fromDate) && !currDate.isAfter(toDate)) {
          ++index;
          lastDate = currDate;
          currDate = valueDate.plusMonths(index * multiplier);
        }

        numIntervals = index - 1;
        extraDays = (int) Math.abs(TimeCalculator.getTimeBetween(toDate, lastDate));

        if (extraDays == 0) {
          onCycle = true;
        } // end if extraDays

      } // end if dom <= 28

      onCycleSwapDates[i] = onCycle;

      ZonedDateTime prevDate;

      if (onCycleSwapDates[i]) {
        prevDate = valueDate.plusMonths(multiplier * (numIntervals - 1));
      } else {
        prevDate = unadjustedSwapDates[i].plusMonths(6 * (-1));
      }

      previousSwapDates[i] = prevDate;

    } // end loop over i

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

    final boolean oneAlreadyAdded = false;

    boolean isEndStub = false;

    int numDates;

    for (int i = 0; i < numSwaps; i++) {

      if (adjustedSwapDates[i].isAfter(cashDates[cashDates.length - 1])) {

        if (onCycleSwapDates[i]) {
          isEndStub = true;
        } else {
          // Need to fill this in - jpmcdsisendstub
        } // end if

        // need to add rate = 0 case

        if (isEndStub) {

          final ZonedDateTime fromDate = valueDate;
          final ZonedDateTime toDate = unadjustedSwapDates[i];

          final double fromToYears = TimeCalculator.getTimeBetween(fromDate, toDate, ACT_365);

          final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);
          int index = lowNumIntervals;

          compoundInterval = index * multiplier;

          ZonedDateTime currDate = fromDate.plusMonths(compoundInterval);
          ZonedDateTime lastDate = currDate;

          while (currDate.isAfter(fromDate) && !currDate.isAfter(toDate)) {
            ++index;
            lastDate = currDate;
            currDate = valueDate.plusMonths(index * multiplier);
          }

          numIntervals = index - 1;
          extraDays = (int) Math.abs(TimeCalculator.getTimeBetween(toDate, lastDate));
        } else {
          // Need to add this
        }

        if (extraDays > 0) {
          numDates = numIntervals + 2;
        } else {
          numDates = numIntervals + 1;
        }

        final ZonedDateTime[] dateList = new ZonedDateTime[numDates];

        if (isEndStub) {

          for (int j = 0; j < numDates - 1; j++) {
            dateList[j] = valueDate.plusMonths(j * multiplier);
          }

          dateList[numDates - 1] = unadjustedSwapDates[i];
        } else {
          // Need to add this
        }

        for (int j = 0; j < numDates - 1; j++) {
          dateList[j] = dateList[j + 1];
        }
        numDates--;

        //

        final ZonedDateTime[] adjustedDateList = new ZonedDateTime[numDates];

        for (int idx = 0; idx < numDates; idx++) {
          adjustedDateList[idx] = swapMaturities.businessDayAdjustDate(dateList[idx], calendar, businessdayAdjustmentConvention);
        }

        final double[] cashflowList = new double[numDates];

        ZonedDateTime prevDate = valueDate;
View Full Code Here


   * It calls PresentValueCreditDefaultSwap.calibrateAndGetPresentValue.
   */
  @Test
  public void testAccruedInterestZeroSpread() {
    final LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    GenerateCreditDefaultSwapPremiumLegSchedule premiumLegScheduleBuilder = new GenerateCreditDefaultSwapPremiumLegSchedule();
    final ZonedDateTime[][] premiumLegSchedule = premiumLegScheduleBuilder.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    final ZonedDateTime stepinDate = VALUATION_DATE.plusDays(1);
    final double accruedInterest = (cds.getNotional() * cds.getParSpread() / 10000.0) * CALCULATOR.calculateAccruedInterest(cds, premiumLegSchedule, stepinDate);
    final double cleanPrice = CALCULATOR.calibrateAndGetPresentValue(VALUATION_DATE, cds, MARKET_TENORS, ZERO_SPREADS, YIELD_CURVE, PriceType.CLEAN);
    final double dirtyPrice = CALCULATOR.calibrateAndGetPresentValue(VALUATION_DATE, cds, MARKET_TENORS, ZERO_SPREADS, YIELD_CURVE, PriceType.DIRTY);
    assertEquals(cleanPrice, dirtyPrice + accruedInterest, EPS);
View Full Code Here

   * It calls PresentValueCreditDefaultSwap.calculatePremiumLeg on PriceType.Clean and PriceType.Dirty
   */
  @Test
  public void testAccruedInterest() {
    final LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    GenerateCreditDefaultSwapPremiumLegSchedule premiumLegScheduleBuilder = new GenerateCreditDefaultSwapPremiumLegSchedule();
    final ZonedDateTime[][] premiumLegSchedule = premiumLegScheduleBuilder.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    final ZonedDateTime stepinDate = VALUATION_DATE.plusDays(1);
    final double accruedInterest = (cds.getNotional() * cds.getParSpread() / 10000.0) * CALCULATOR.calculateAccruedInterest(cds, premiumLegSchedule, stepinDate);
    final double dirtyPremiumLeg = -CALCULATOR.calculatePremiumLeg(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_CURVE, PriceType.DIRTY) * cds.getParSpread() / BP;
    final double riskyAnnuity = CALCULATOR.calculatePremiumLeg(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_CURVE, PriceType.CLEAN);
    final double cleanPremiumLeg = -cds.getParSpread() / BP * riskyAnnuity;
 
View Full Code Here

   * It calls PresentValueCreditDefaultSwap.calculatePremiumLeg on PriceType.Clean and PriceType.Dirty
   */
  @Test
  public void regressionTest() {
    final LegacyVanillaCreditDefaultSwapDefinition cds = CreditDefaultSwapDefinitionDataSets.getLegacyVanillaDefinition().withMaturityDate(VALUATION_DATE.plusYears(10));
    GenerateCreditDefaultSwapPremiumLegSchedule premiumLegScheduleBuilder = new GenerateCreditDefaultSwapPremiumLegSchedule();
    final ZonedDateTime[][] premiumLegSchedule = premiumLegScheduleBuilder.constructISDACompliantCreditDefaultSwapPremiumLegSchedule(cds);
    final ZonedDateTime stepinDate = VALUATION_DATE.plusDays(1);
    final double accruedInterest = (cds.getNotional() * cds.getParSpread() / 10000.0) * CALCULATOR.calculateAccruedInterest(cds, premiumLegSchedule, stepinDate);
    final double dirtyPremiumLeg = -CALCULATOR.calculatePremiumLeg(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_CURVE, PriceType.DIRTY) * cds.getParSpread() / BP;
    final double riskyAnnuity = CALCULATOR.calculatePremiumLeg(VALUATION_DATE, cds, YIELD_CURVE, HAZARD_CURVE, PriceType.CLEAN);
    final double cleanPremiumLeg = -cds.getParSpread() / BP * riskyAnnuity;
 
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.credit.schedulegeneration.GenerateCreditDefaultSwapPremiumLegSchedule

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.