Пример #1
0
        static CreditDataSet()
        {
            ImmutableList.Builder <StandardId> builder = ImmutableList.builder();
            for (int i = 0; i < 97; ++i)
            {
                builder.add(StandardId.of("OG", i.ToString()));
            }
            LEGAL_ENTITIES = builder.build();
            double flatRate = 0.05;
            double t        = 20.0;
            IsdaCreditDiscountFactors yieldCurve = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);

            DISCOUNT_CURVE = yieldCurve.Curve;
            RecoveryRates recoveryRate = ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION_DATE, RECOVERY_RATE);
            // create the curve nodes and input market quotes
            ImmutableMarketDataBuilder marketQuoteBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                marketQuoteBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketQuotes             = marketQuoteBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, recoveryRate)).discountCurves(ImmutableMap.of(USD, yieldCurve)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);
            // calibrate
            LegalEntitySurvivalProbabilities calibrated = BUILDER.calibrate(definition, marketQuotes, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)calibrated.SurvivalProbabilities).Curve;

            CDS_CREDIT_CURVE    = underlyingCurve;
            INDEX_CREDIT_CURVE  = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));    // replace parameter metadata
            CDS_RECOVERY_RATE   = ConstantCurve.of(Curves.recoveryRates("CDS recovery rate", ACT_365F), RECOVERY_RATE);
            INDEX_RECOVERY_RATE = ConstantCurve.of(Curves.recoveryRates("Index recovery rate", ACT_365F), RECOVERY_RATE);
        }
        static SpreadSensitivityCalculatorTest()
        {
            double flatRate = 0.05;
            double t        = 20.0;

            YIELD_CURVE = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);
            ImmutableMarketDataBuilder dataBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                dataBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketData = dataBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);

            CREDIT_CURVE = BUILDER.calibrate(definition, marketData, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)CREDIT_CURVE.SurvivalProbabilities).Curve;
            NodalCurve curveWithFactor = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));     // replace parameter metadata

            CREDIT_CURVE_INDEX = LegalEntitySurvivalProbabilities.of(INDEX_ID, IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, curveWithFactor));
        }