public virtual void pricePufTest() { double premium = 150d * ONE_BP; Cds product = Cds.of(BUY, LEGAL_ENTITY, GBP, 1.0e6, START_DATE, END_DATE, Frequency.P3M, DEFAULT_CALENDAR, premium); TradeInfo info = TradeInfo.builder().tradeDate(TODAY).settlementDate(product.SettlementDateOffset.adjust(TODAY, REF_DATA)).build(); ResolvedCdsTrade trade = CdsTrade.builder().product(product).info(info).build().resolve(REF_DATA); NodalCurve cc = CALIB.calibrate(ImmutableList.of(trade), DoubleArray.of(0.0123), DoubleArray.of(0.0), CurveName.of("test"), TODAY, DSC_CURVE, REC_RATES, REF_DATA); CreditRatesProvider rates = RATES_PROVIDER.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY, GBP), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, IsdaCreditDiscountFactors.of(GBP, TODAY, cc)))).build(); double pointsUpFront = CONV.pointsUpfront(trade, rates, REF_DATA); double cleanPrice = CONV.cleanPrice(trade, rates, REF_DATA); double cleanPriceRe = CONV.cleanPriceFromPointsUpfront(pointsUpFront); assertEquals(cleanPrice, cleanPriceRe, TOL); }
private static ScenarioDefinition buildHistoricalScenarios(IDictionary <LocalDate, RatesCurveGroup> historicalCurves, IList <LocalDate> scenarioDates) { // extract the curves to perturb //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <Curve> usdDiscountCurves = scenarioDates.Select(date => historicalCurves[date]).Select(group => group.findDiscountCurve(Currency.USD).get()).collect(toImmutableList()); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <Curve> libor3mCurves = scenarioDates.Select(date => historicalCurves[date]).Select(group => group.findForwardCurve(IborIndices.USD_LIBOR_3M).get()).collect(toImmutableList()); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <Curve> libor6mCurves = scenarioDates.Select(date => historicalCurves[date]).Select(group => group.findForwardCurve(IborIndices.USD_LIBOR_6M).get()).collect(toImmutableList()); // create mappings which will cause the point shift perturbations generated above // to be applied to the correct curves PerturbationMapping <ParameterizedData> discountCurveMappings = PerturbationMapping.of(MarketDataFilter.ofName(CurveName.of("USD-Disc")), buildShifts(usdDiscountCurves)); PerturbationMapping <ParameterizedData> libor3mMappings = PerturbationMapping.of(MarketDataFilter.ofName(CurveName.of("USD-3ML")), buildShifts(libor3mCurves)); PerturbationMapping <ParameterizedData> libor6mMappings = PerturbationMapping.of(MarketDataFilter.ofName(CurveName.of("USD-6ML")), buildShifts(libor6mCurves)); // create a scenario definition from these mappings return(ScenarioDefinition.ofMappings(discountCurveMappings, libor3mMappings, libor6mMappings)); }
//------------------------------------------------------------------------- protected internal virtual void testCalibrationAgainstISDA(IsdaCompliantCreditCurveCalibrator builder, DayCount dayCount, Currency currency, double tol) { IsdaCdsProductPricer pricer = new IsdaCdsProductPricer(builder.AccrualOnDefaultFormula); for (int i = 0; i < NUM_TESTS; i++) { LegalEntitySurvivalProbabilities creditCurve = builder.calibrate(ImmutableList.copyOf(NODE_CDS[i]), CurveName.of("credit"), CDS_MARKET_DATA[i], YIELD_CURVES[i], dayCount, currency, false, false, REF_DATA); ResolvedCdsTrade[] expectedCds = EXP_NODE_CDS[i]; ImmutableCreditRatesProvider provider = YIELD_CURVES[i].toBuilder().creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY, EUR), creditCurve)).build(); double[] expected = builder.AccrualOnDefaultFormula == AccrualOnDefaultFormula.MARKIT_FIX ? EXP_PROB_MARKIT_FIX[i] : EXP_PROB_ISDA[i]; for (int k = 0; k < N_OBS; k++) { assertEquals(creditCurve.SurvivalProbabilities.discountFactor(OBS_TIMES[k]), expected[k], tol); } int m = expectedCds.Length; for (int j = 0; j < m; j++) { ResolvedCdsTrade cdsFromNode = NODE_CDS[i][j].trade(1d, CDS_MARKET_DATA[i], REF_DATA).UnderlyingTrade.resolve(REF_DATA); assertEquals(cdsFromNode.Product, expectedCds[j].Product); double price1 = pricer.price(cdsFromNode.Product, provider, SPREADS[i][j], cdsFromNode.Info.SettlementDate.get(), PriceType.CLEAN, REF_DATA); assertEquals(price1, 0.0, 5e-16); } } }
internal override DoubleArray computedBucketedCs01(ResolvedCdsTrade trade, IList <ResolvedCdsTrade> bucketCds, CreditRatesProvider ratesProvider, ReferenceData refData) { checkCdsBucket(trade, bucketCds); ResolvedCds product = trade.Product; Currency currency = product.Currency; StandardId legalEntityId = product.LegalEntityId; LocalDate valuationDate = ratesProvider.ValuationDate; int nBucket = bucketCds.Count; DoubleArray impSp = impliedSpread(bucketCds, ratesProvider, refData); NodalCurve creditCurveBase = Calibrator.calibrate(bucketCds, impSp, DoubleArray.filled(nBucket), CurveName.of("baseImpliedCreditCurve"), valuationDate, ratesProvider.discountFactors(currency), ratesProvider.recoveryRates(legalEntityId), refData); IsdaCreditDiscountFactors df = IsdaCreditDiscountFactors.of(currency, valuationDate, creditCurveBase); CreditRatesProvider ratesProviderBase = ratesProvider.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), LegalEntitySurvivalProbabilities.of(legalEntityId, df))).build(); double[][] res = new double[nBucket][]; PointSensitivities pointPv = Pricer.presentValueOnSettleSensitivity(trade, ratesProviderBase, refData); DoubleArray vLambda = ratesProviderBase.singleCreditCurveParameterSensitivity(pointPv, legalEntityId, currency).Sensitivity; for (int i = 0; i < nBucket; i++) { PointSensitivities pointSp = Pricer.parSpreadSensitivity(bucketCds[i], ratesProviderBase, refData); res[i] = ratesProviderBase.singleCreditCurveParameterSensitivity(pointSp, legalEntityId, currency).Sensitivity.toArray(); } DoubleMatrix jacT = MATRIX_ALGEBRA.getTranspose(DoubleMatrix.ofUnsafe(res)); LUDecompositionResult luRes = DECOMPOSITION.apply(jacT); DoubleArray vS = luRes.solve(vLambda); return(vS); }