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);
        }
        public virtual void parellelCs01Test()
        {
            double         fromExcel = 4238.557409;
            CurrencyAmount fd        = CS01_FD.parallelCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyAmount analytic  = CS01_AN.parallelCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.Amount * ONE_BP, fromExcel, TOL * NOTIONAL);
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.Amount * ONE_BP, fd.Amount * ONE_BP, ONE_BP * NOTIONAL);
            // equivalence to market quote sensitivity for par spread quote
            PointSensitivities             point      = PRICER.presentValueOnSettleSensitivity(CDS1, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, LEGAL_ENTITY, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);
            double cs01FromQuoteSensi = quoteSensi.Sensitivities.get(0).Sensitivity.sum();

            assertEquals(cs01FromQuoteSensi * ONE_BP, analytic.Amount * ONE_BP, TOL * NOTIONAL);
        }
        public virtual void test_singleCreditCurveParameterSensitivity()
        {
            ZeroRateSensitivity            zeroPt   = ZeroRateSensitivity.of(USD, 10d, 5d);
            CreditCurveZeroRateSensitivity creditPt = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY_ABC, JPY, 2d, 3d);
            FxForwardSensitivity           fxPt     = FxForwardSensitivity.of(CurrencyPair.of(JPY, USD), USD, LocalDate.of(2017, 2, 14), 15d);
            CreditRatesProvider            test     = ImmutableCreditRatesProvider.builder().creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY_ABC, USD), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_USD), Pair.of(LEGAL_ENTITY_ABC, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_JPY), Pair.of(LEGAL_ENTITY_DEF, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_DEF, CRD_DEF))).discountCurves(ImmutableMap.of(USD, DSC_USD, JPY, DSC_JPY)).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY_ABC, RR_ABC, LEGAL_ENTITY_DEF, RR_DEF)).valuationDate(VALUATION).build();
            CurrencyParameterSensitivities computed = CurrencyParameterSensitivities.of(test.singleCreditCurveParameterSensitivity(zeroPt.combinedWith(creditPt).combinedWith(fxPt).build(), LEGAL_ENTITY_ABC, JPY));
            CurrencyParameterSensitivities expected = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_JPY).parameterSensitivity(creditPt);

            assertTrue(computed.equalWithTolerance(expected, 1.0e-14));
        }