コード例 #1
0
 /**
  * Get the CreditCurveIdentifier with name appended
  *
  * @param security
  */
 private static CreditCurveIdentifier getCreditCurveIdentifier(
     final CreditDefaultSwapSecurity security, final String name) {
   final CreditCurveIdentifier curveIdentifier =
       CreditCurveIdentifier.of(
           name + security.getReferenceEntity().getValue(),
           security.getNotional().getCurrency(),
           security.getDebtSeniority().toString(),
           security.getRestructuringClause().toString());
   return curveIdentifier;
 }
コード例 #2
0
  @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);
  }