Package com.opengamma.financial.security.cds

Examples of com.opengamma.financial.security.cds.LegacyVanillaCDSSecurity$Meta


    assertNull(ids);
  }

  @Test
  public void testLegacyVanillaCDSSecurity() {
    final LegacyVanillaCDSSecurity security = ExposureFunctionTestHelper.getLegacyVanillaCDSSecurity();
    final List<ExternalId> ids = security.accept(EXPOSURE_FUNCTION);
    assertNull(ids);
  }
View Full Code Here


    assertEquals(ExternalId.of(SCHEME, "DE"), ids.get(0));
  }

  @Test
  public void testLegacyVanillaCDSSecurity() {
    final LegacyVanillaCDSSecurity security = ExposureFunctionTestHelper.getLegacyVanillaCDSSecurity();
    final List<ExternalId> ids = security.accept(EXPOSURE_FUNCTION);
    assertEquals(1, ids.size());
    assertEquals(ExternalId.of(SCHEME, "DE"), ids.get(0));
  }
View Full Code Here

    assertEquals(ExternalId.of(SCHEME, "LEGACY_RECOVERY_LOCK_CDS_DE"), ids.get(0));
  }

  @Test
  public void testLegacyVanillaCDSSecurity() {
    final LegacyVanillaCDSSecurity security = ExposureFunctionTestHelper.getLegacyVanillaCDSSecurity();
    final List<ExternalId> ids = security.accept(EXPOSURE_FUNCTION);
    assertEquals(1, ids.size());
    assertEquals(ExternalId.of(SCHEME, "LEGACY_VANILLA_CDS_DE"), ids.get(0));
  }
View Full Code Here

                                    final ComputationTarget target,
                                    final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
    ValueRequirement requirement = desiredValues.iterator().next();
    final Clock snapshotClock = executionContext.getValuationClock();
    final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
    final LegacyVanillaCDSSecurity security = (LegacyVanillaCDSSecurity) target.getSecurity();

    final CdsRecoveryRateIdentifier recoveryRateIdentifier = security.accept(new CreditSecurityToRecoveryRateVisitor(
        executionContext.getSecuritySource()));
    Object recoveryRateObject = inputs.getValue(new ValueRequirement("PX_LAST",
                                                                     ComputationTargetType.PRIMITIVE,
                                                                     recoveryRateIdentifier.getExternalId()));
    if (recoveryRateObject == null) {
      throw new OpenGammaRuntimeException("Could not get recovery rate");
      //s_logger.warn("Could not get recovery rate, defaulting to 0.4: " + recoveryRateIdentifier);
      //recoveryRateObject = 0.4;
    }
    final double recoveryRate = (Double) recoveryRateObject;

    CreditDefaultSwapSecurityConverterDeprecated converter = new CreditDefaultSwapSecurityConverterDeprecated(
        _holidaySource,
        _regionSource,
        recoveryRate);
    LegacyVanillaCreditDefaultSwapDefinition cds = converter.visitLegacyVanillaCDSSecurity(security);
    final StandardCDSQuotingConvention quoteConvention = StandardCDSQuotingConvention.parse(requirement.getConstraint(
        ISDAFunctionConstants.CDS_QUOTE_CONVENTION));
    final NodalTenorDoubleCurve spreadCurve = (NodalTenorDoubleCurve) inputs.getValue(ValueRequirementNames.BUCKETED_SPREADS);
    if (spreadCurve == null) {
      throw new OpenGammaRuntimeException("Bucketed spreads not available for " + getSpreadCurveIdentifier(security));
    }

    // get the isda curve
    final ISDACompliantYieldCurve yieldCurve = (ISDACompliantYieldCurve) inputs.getValue(ValueRequirementNames.YIELD_CURVE);
    if (yieldCurve == null) {
      throw new OpenGammaRuntimeException("Couldn't get isda curve");
    }

    final Double cdsQuoteDouble = (Double) inputs.getValue(MarketDataRequirementNames.MARKET_VALUE);
    if (cdsQuoteDouble == null) {
      throw new OpenGammaRuntimeException("Couldn't get spread for " + security);
    }
    final CDSAnalyticVisitor pricingVisitor = new CDSAnalyticVisitor(now.toLocalDate(),
                                                                     _holidaySource,
                                                                     _regionSource,
                                                                     recoveryRate);
    final CDSAnalytic pricingCDS = security.accept(pricingVisitor);
    final CDSQuoteConvention quote = SpreadCurveFunctions.getQuotes(security.getMaturityDate(),
                                                                    new double[]{cdsQuoteDouble},
                                                                    security.getParSpread(),
                                                                    quoteConvention,
                                                                    true)[0];
    final QuotedSpread quotedSpread = getQuotedSpread(quote,
                                                      security.isBuy() ? BuySellProtection.BUY : BuySellProtection.SELL,
                                                      yieldCurve,
                                                      pricingCDS,
                                                      security.getParSpread());

    ISDACompliantCreditCurve creditCurve;
    NodalTenorDoubleCurve modifiedSpreadCurve;
    NodalTenorDoubleCurve modifiedPillarCurve;

    if (IMMDateGenerator.isIMMDate(security.getMaturityDate())) {
      final String pillarString = requirement.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS);
      final ZonedDateTime[] bucketDates = SpreadCurveFunctions.getPillarDates(now, pillarString);
      final ZonedDateTime[] pillarDates = bucketDates;
      double[] spreads = SpreadCurveFunctions.getSpreadCurveNew(spreadCurve,
                                                                bucketDates,
                                                                security.getStartDate(),
                                                                quoteConvention);
      Tenor[] tenors = SpreadCurveFunctions.getBuckets(pillarString);
      modifiedSpreadCurve = new NodalTenorDoubleCurve(tenors, ArrayUtils.toObject(spreads), true);
      modifiedPillarCurve = modifiedSpreadCurve; // for IMM buckets and spreads are the same
      //final CDSQuoteConvention[] quotes = SpreadCurveFunctions.getQuotes(security.getMaturityDate(), spreads, security.getParSpread(), quoteConvention, false);

      // CDS analytics for credit curve
      final CDSAnalytic[] creditAnalytics = new CDSAnalytic[pillarDates.length];
      for (int i = 0; i < creditAnalytics.length; i++) {
        final CDSAnalyticVisitor curveVisitor = new CDSAnalyticVisitor(now.toLocalDate(),
                                                                       _holidaySource,
                                                                       _regionSource,
                                                                       security.getStartDate().toLocalDate(),
                                                                       pillarDates[i].toLocalDate(),
                                                                       recoveryRate);
        creditAnalytics[i] = security.accept(curveVisitor);
      }
      creditCurve = CREDIT_CURVE_BUILDER.calibrateCreditCurve(pricingCDS, quotedSpread, yieldCurve);

    } else {
      // non IMM date - pillars set to fixed set
      final String pillarString = NON_IMM_PILLAR_TENORS;
      final String bucketString = requirement.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS);
      final ZonedDateTime[] bucketDates = SpreadCurveFunctions.getPillarDates(now, bucketString);
      final ZonedDateTime[] pillarDates = SpreadCurveFunctions.getPillarDates(now, pillarString);
      double[] bucketSpreads = SpreadCurveFunctions.getSpreadCurveNew(spreadCurve,
                                                                      bucketDates,
                                                                      security.getStartDate(),
                                                                      quoteConvention);
      double[] pillarSpreads = SpreadCurveFunctions.getSpreadCurveNew(spreadCurve,
                                                                      pillarDates,
                                                                      security.getStartDate(),
                                                                      quoteConvention);
      Tenor[] bucketTenors = SpreadCurveFunctions.getBuckets(bucketString);
      Tenor[] pillarTenors = SpreadCurveFunctions.getBuckets(pillarString);
      modifiedSpreadCurve = new NodalTenorDoubleCurve(bucketTenors, ArrayUtils.toObject(bucketSpreads), true);
      modifiedPillarCurve = new NodalTenorDoubleCurve(pillarTenors, ArrayUtils.toObject(pillarSpreads), true);
      final CDSQuoteConvention[] quotes = SpreadCurveFunctions.getQuotes(security.getMaturityDate(),
                                                                         pillarSpreads,
                                                                         security.getParSpread(),
                                                                         quoteConvention,
                                                                         false);

      // CDS analytics for credit curve
      final CDSAnalytic[] creditAnalytics = new CDSAnalytic[pillarDates.length];
      for (int i = 0; i < creditAnalytics.length; i++) {
        final CDSAnalyticVisitor curveVisitor = new CDSAnalyticVisitor(now.toLocalDate(),
                                                                       _holidaySource,
                                                                       _regionSource,
                                                                       security.getStartDate().toLocalDate(),
                                                                       pillarDates[i].toLocalDate(), recoveryRate);
        creditAnalytics[i] = security.accept(curveVisitor);
      }
      creditCurve = CREDIT_CURVE_BUILDER.calibrateCreditCurve(creditAnalytics, quotes, yieldCurve);
    }

View Full Code Here

    throws AsynchronousExecution {
    final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
    final ValueRequirement requirement = desiredValues.iterator().next();
    final ValueProperties properties = requirement.getConstraints().copy().get();

    final LegacyVanillaCDSSecurity security = (LegacyVanillaCDSSecurity) target.getSecurity();
    //LegacyVanillaCreditDefaultSwapDefinition cds = _converter.visitLegacyVanillaCDSSecurity(security);
    final ValueRequirement desiredValue = desiredValues.iterator().next(); // all same constraints

    final String quoteConventionString = desiredValue.getConstraint(ISDAFunctionConstants.CDS_QUOTE_CONVENTION);
    final StandardCDSQuotingConvention quoteConvention = StandardCDSQuotingConvention.parse(quoteConventionString);

    final CdsRecoveryRateIdentifier recoveryRateIdentifier = security.accept(new CreditSecurityToRecoveryRateVisitor(
        executionContext.getSecuritySource()));
    Object recoveryRateObject = inputs.getValue(new ValueRequirement("PX_LAST",
                                                                     ComputationTargetType.PRIMITIVE,
                                                                     recoveryRateIdentifier.getExternalId()));
    if (recoveryRateObject == null) {
      throw new OpenGammaRuntimeException("Could not get recovery rate");
      //s_logger.warn("Could not get recovery rate, defaulting to 0.4: " + recoveryRateIdentifier);
      //recoveryRateObject = 0.4;
    }
    final double recoveryRate = (Double) recoveryRateObject;

    // get the isda curve
    final Object isdaObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE);
    if (isdaObject == null) {
      throw new OpenGammaRuntimeException("Couldn't get isda curve");
    }
    final ISDACompliantYieldCurve yieldCurve = (ISDACompliantYieldCurve) isdaObject;

    // spreads
    NodalTenorDoubleCurve spreadObject = (NodalTenorDoubleCurve) inputs.getValue(ValueRequirementNames.BUCKETED_SPREADS);
    if (spreadObject == null) {
      throw new OpenGammaRuntimeException("Unable to get spreads");
    }
    final double[] spreads = ArrayUtils.toPrimitive(spreadObject.getYData());
    //final String pillarString = IMMDateGenerator.isIMMDate(security.getMaturityDate()) ? requirement.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS) : ISDACompliantCreditCurveFunction.NON_IMM_PILLAR_TENORS;
    final ZonedDateTime[] bucketDates = SpreadCurveFunctions.getPillarDates(now, spreadObject.getXData());
    final CDSQuoteConvention[] quotes = SpreadCurveFunctions.getQuotes(security.getMaturityDate(), spreads, security.getParSpread(), quoteConvention, false);

    // spreads
    NodalTenorDoubleCurve pillarObject = (NodalTenorDoubleCurve) inputs.getValue(ValueRequirementNames.PILLAR_SPREADS);
    if (pillarObject == null) {
      throw new OpenGammaRuntimeException("Unable to get pillars");
    }

    // CDS analytics for credit curve (possible performance improvement if earlier result obtained)
    //final LegacyVanillaCreditDefaultSwapDefinition curveCDS = cds.withStartDate(now);
    //security.setStartDate(now); // needed for curve instruments
    final CDSAnalytic[] bucketCDSs = new CDSAnalytic[bucketDates.length];
    for (int i = 0; i < bucketCDSs.length; i++) {
      //security.setMaturityDate(bucketDates[i]);
      final CDSAnalyticVisitor visitor = new CDSAnalyticVisitor(now.toLocalDate(), _holidaySource, _regionSource, security.getStartDate().toLocalDate(), bucketDates[i].toLocalDate(), recoveryRate);
      bucketCDSs[i] = security.accept(visitor);
    }

    final ZonedDateTime[] pillarDates = SpreadCurveFunctions.getPillarDates(now, pillarObject.getXData());
    final CDSAnalytic[] pillarCDSs = new CDSAnalytic[pillarDates.length];
    for (int i = 0; i < pillarCDSs.length; i++) {
      //security.setMaturityDate(bucketDates[i]);
      final CDSAnalyticVisitor visitor = new CDSAnalyticVisitor(now.toLocalDate(), _holidaySource, _regionSource, security.getStartDate().toLocalDate(), pillarDates[i].toLocalDate(), recoveryRate);
      pillarCDSs[i] = security.accept(visitor);
    }

    final ISDACompliantCreditCurve creditCurve = (ISDACompliantCreditCurve) inputs.getValue(ValueRequirementNames.HAZARD_RATE_CURVE);
    if (creditCurve == null) {
      throw new OpenGammaRuntimeException("Couldnt get credit curve");
    }

    //final CDSAnalytic analytic = CDSAnalyticConverter.create(cds, now.toLocalDate());
    final CDSAnalyticVisitor visitor = new CDSAnalyticVisitor(now.toLocalDate(), _holidaySource, _regionSource, recoveryRate);
    final CDSAnalytic analytic = security.accept(visitor);
    final BuySellProtection buySellProtection = security.isBuy() ? BuySellProtection.BUY : BuySellProtection.SELL;
    final Double cdsQuoteDouble = (Double) inputs.getValue(MarketDataRequirementNames.MARKET_VALUE);
    if (cdsQuoteDouble == null) {
      throw new OpenGammaRuntimeException("Couldn't get spread for " + security);
    }
    final CDSQuoteConvention quote = SpreadCurveFunctions.getQuotes(security.getMaturityDate(), new double[] {cdsQuoteDouble}, security.getParSpread(), quoteConvention, true)[0];

    final double notional = security.getNotional().getAmount();
    final double coupon = security.getParSpread() * ONE_BPS;
    final PointsUpFront puf = getPointsUpfront(quote, buySellProtection, yieldCurve, analytic, creditCurve);
    final double accruedPremium = analytic.getAccruedPremium(coupon) * notional;
    final int accruedDays = analytic.getAccuredDays();
    final double quotedSpread = getQuotedSpread(quote, puf, buySellProtection, yieldCurve, analytic).getQuotedSpread();
    final double upfrontAmount = getUpfrontAmount(analytic, puf, notional, buySellProtection);
View Full Code Here

    return specs;
  }

  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final LegacyVanillaCDSSecurity cds = (LegacyVanillaCDSSecurity) target.getSecurity();
    final Currency ccy = cds.getNotional().getCurrency();
    final CreditCurveIdentifier isdaIdentifier = getISDACurveIdentifier(cds);
    final CreditCurveIdentifier spreadIdentifier = getSpreadCurveIdentifier(cds);

    final String isdaOffset = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_OFFSET);
    if (isdaOffset == null) {
      return null;
    }

    final String isdaCurveDate = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_CURVE_DATE);
    if (isdaCurveDate == null) {
      return null;
    }

    final String isdaCurveMethod = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_IMPLEMENTATION);
    if (isdaCurveMethod == null) {
      return null;
    }

    // isda curve
    final ValueProperties isdaProperties = ValueProperties.builder()
        .with(ValuePropertyNames.CURVE, isdaIdentifier.toString())
        .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME)
        .with(ISDAFunctionConstants.ISDA_CURVE_OFFSET, isdaOffset)
        .with(ISDAFunctionConstants.ISDA_CURVE_DATE, isdaCurveDate)
        .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, isdaCurveMethod)
        .get();
    final ValueRequirement isdaRequirment = new ValueRequirement(ValueRequirementNames.YIELD_CURVE, ComputationTargetType.CURRENCY, ccy.getUniqueId(), isdaProperties);

    final String quoteConvention = desiredValue.getConstraint(ISDAFunctionConstants.CDS_QUOTE_CONVENTION);
    if (quoteConvention == null) {
      return null;
    }

    final String bucketTenors = desiredValue.getConstraint(ISDAFunctionConstants.ISDA_BUCKET_TENORS);
    if (bucketTenors == null) {
      return null;
    }

    //market  spreads
    final ValueProperties spreadProperties = ValueProperties.builder()
        .with(ISDAFunctionConstants.CDS_QUOTE_CONVENTION, quoteConvention)
        .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, ISDAFunctionConstants.ISDA_METHOD_NAME)
        .with(ISDAFunctionConstants.ISDA_CURVE_OFFSET, isdaOffset)
        .with(ISDAFunctionConstants.ISDA_CURVE_DATE, isdaCurveDate)
        .with(ISDAFunctionConstants.ISDA_IMPLEMENTATION, isdaCurveMethod)
        .with(ISDAFunctionConstants.ISDA_BUCKET_TENORS, bucketTenors)
        .get();
    final ValueRequirement spreadRequirment = new ValueRequirement(ValueRequirementNames.BUCKETED_SPREADS, target.toSpecification(), spreadProperties);
    final ValueRequirement pillarRequirment = new ValueRequirement(ValueRequirementNames.PILLAR_SPREADS, target.toSpecification(), spreadProperties);
    final ValueRequirement creditCurveRequirement = new ValueRequirement(ValueRequirementNames.HAZARD_RATE_CURVE, target.toSpecification(), spreadProperties);

    // get individual spread for this cds (ignore business day adjustment on either)
    final Period period = Period.between(cds.getStartDate().toLocalDate().withDayOfMonth(20), cds.getMaturityDate().toLocalDate().withDayOfMonth(20));
    final ValueRequirement cdsSpreadRequirement = new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, ExternalId.of("Tenor", period.toString()));

    final CdsRecoveryRateIdentifier recoveryRateIdentifier = cds.accept(new CreditSecurityToRecoveryRateVisitor(context.getSecuritySource()));
    final ValueRequirement recoveryRateRequirement = new ValueRequirement("PX_LAST", ComputationTargetType.PRIMITIVE, recoveryRateIdentifier.getExternalId());

    return Sets.newHashSet(isdaRequirment, spreadRequirment, cdsSpreadRequirement, creditCurveRequirement, pillarRequirment, recoveryRateRequirement);
  }
View Full Code Here

    final boolean adjustMaturityDate = false;
    final InterestRateNotional notional = security.getNotional();
    final boolean includeAccruedPremium = false;
    final boolean protectionStart = false;
    final double parSpread = security.getIndexCoupon();
    final LegacyVanillaCDSSecurity cds = new LegacyVanillaCDSSecurity(
        isBuy,
        protectionSeller,
        protectionBuyer,
        referenceEntity,
        debtSeniority,
        restructuringClause,
        REGION,
        startDate,
        effectiveDate,
        maturityDate,
        stubType,
        couponFrequency,
        dayCount,
        businessDayConvention,
        immAdjustMaturityDate,
        adjustEffectiveDate,
        adjustMaturityDate,
        notional,
        includeAccruedPremium,
        protectionStart,
        parSpread);
    return cds.accept(_converter);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.security.cds.LegacyVanillaCDSSecurity$Meta

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.