public virtual void bucketedCs01SingleNodeCurveTest() { ImmutableCreditRatesProvider ratesProviderNoCredit = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).build(); QuoteId quoteId = QuoteId.of(StandardId.of("OG", END2.ToString())); CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(START, END2, CDS_CONV), quoteId, LEGAL_ENTITY); ImmutableMarketData marketData = ImmutableMarketData.builder(VALUATION_DATE).addValue(quoteId, DEAL_SPREAD * ONE_BP).build(); IsdaCreditCurveDefinition definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, ImmutableList.of(node), true, false); LegalEntitySurvivalProbabilities creditCurve = BUILDER.calibrate(definition, marketData, ratesProviderNoCredit, REF_DATA); ImmutableCreditRatesProvider ratesProvider = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY, USD), creditCurve)).build(); double[] expectedFd = new double[] { -6.876275937539589E-4, 1.1832215762730414E-4, 0.0012340982402658796, 0.002784985575488008, 0.005287295115619095, 2429.636217554099, 3101.303324461041 }; CurrencyParameterSensitivity analytic = CS01_AN.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), ratesProvider, REF_DATA); CurrencyParameterSensitivity fd = CS01_FD.bucketedCs01(CDS2, ImmutableList.copyOf(MARKET_CDS), ratesProvider, REF_DATA); assertEquals(fd.Currency, USD); assertEquals(fd.MarketDataName, CurveName.of("impliedSpreads")); assertEquals(fd.ParameterCount, NUM_MARKET_CDS); assertEquals(fd.ParameterMetadata, CDS_METADATA); assertTrue(DoubleArrayMath.fuzzyEquals(fd.Sensitivity.multipliedBy(ONE_BP).toArray(), expectedFd, NOTIONAL * TOL)); assertEquals(analytic.Currency, USD); assertEquals(analytic.MarketDataName, CurveName.of("impliedSpreads")); assertEquals(analytic.ParameterCount, NUM_MARKET_CDS); assertEquals(analytic.ParameterMetadata, CDS_METADATA); assertTrue(DoubleArrayMath.fuzzyEquals(analytic.Sensitivity.toArray(), fd.Sensitivity.toArray(), NOTIONAL * ONE_BP * 10d)); }
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)); }