static MarketQuoteSensitivityCalculatorTest()
        {
            CurrencyParameterSensitivity sensi1    = CurrencyParameterSensitivity.of(CURVE_NAME_1, USD, SENSI_1);
            CurrencyParameterSensitivity sensi2    = CurrencyParameterSensitivity.of(CURVE_NAME_2, GBP, SENSI_2);
            ZeroRateDiscountFactors      dscIssuer = ZeroRateDiscountFactors.of(USD, DATE, CURVE_1);
            ZeroRateDiscountFactors      dscRepo   = ZeroRateDiscountFactors.of(GBP, DATE, CURVE_2);

            PARAMETER_SENSITIVITIES = CurrencyParameterSensitivities.of(sensi1, sensi2);
            PROVIDER = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, USD), dscIssuer)).issuerCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO_SECURITY, GBP), dscRepo)).repoCurveSecurityGroups(ImmutableMap.of(ID_SECURITY, GROUP_REPO_SECURITY)).build();
        }
        public virtual void test_singleDiscountCurveParameterSensitivity()
        {
            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.singleDiscountCurveParameterSensitivity(zeroPt.combinedWith(creditPt).combinedWith(fxPt).build(), USD));
            CurrencyParameterSensitivities expected = DSC_USD.parameterSensitivity(zeroPt);

            assertTrue(computed.equalWithTolerance(expected, 1.0e-14));
        }
        public virtual void parellelCs01FromNodesTest()
        {
            double         fromExcel = 4238.557409;
            CurrencyAmount fd        = CS01_FD.parallelCs01(CDS1, RATES_PROVIDER, REF_DATA);
            CurrencyAmount analytic  = CS01_AN.parallelCs01(CDS1, 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 parellelCs01WithNodesIndexTest()
        {
            CurrencyAmount fdSingle       = CS01_FD.parallelCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyAmount analyticSingle = CS01_AN.parallelCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyAmount fd             = CS01_FD.parallelCs01(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyAmount analytic       = CS01_AN.parallelCs01(CDS_INDEX, RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.Amount, fdSingle.Amount * INDEX_FACTOR, TOL * NOTIONAL);
            assertEquals(analytic.Amount, analyticSingle.Amount * INDEX_FACTOR, TOL * NOTIONAL);
            assertEquals(analytic.Currency, USD);
            // equivalence to market quote sensitivity for par spread quote
            PointSensitivities             point      = PRICER_INDEX.presentValueOnSettleSensitivity(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, INDEX_ID, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);
            double cs01FromQuoteSensi = quoteSensi.Sensitivities.get(0).Sensitivity.sum();

            assertEquals(cs01FromQuoteSensi, analytic.Amount, TOL * NOTIONAL);
        }
        public virtual void bucketedCs01Test()
        {
            double[] expectedFd                   = new double[] { 0.02446907003406107, 0.1166137422736746, 0.5196553952424576, 1.4989046391578054, 3.5860718603647483, 4233.77162264947, 0.0 };
            CurrencyParameterSensitivity fd       = CS01_FD.bucketedCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analytic = CS01_AN.bucketedCs01(CDS1, ImmutableList.copyOf(MARKET_CDS), RATES_PROVIDER, 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));
            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);

            assertTrue(DoubleArrayMath.fuzzyEquals(quoteSensi.Sensitivities.get(0).Sensitivity.toArray(), analytic.Sensitivity.toArray(), NOTIONAL * TOL));
        }
        public virtual void bucketedCs01WithNodesIndexTest()
        {
            CurrencyParameterSensitivity fdSingle       = CS01_FD.bucketedCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analyticSingle = CS01_AN.bucketedCs01(CDS2, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity fd             = CS01_FD.bucketedCs01(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity analytic       = CS01_AN.bucketedCs01(CDS_INDEX, RATES_PROVIDER, REF_DATA);

            assertEquals(fd.Currency, USD);
            assertEquals(fd.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(fd.ParameterCount, NUM_MARKET_CDS);
            assertEquals(fd.ParameterMetadata, CDS_INDEX_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(fd.Sensitivity.toArray(), fdSingle.Sensitivity.multipliedBy(INDEX_FACTOR).toArray(), NOTIONAL * TOL));
            assertEquals(analytic.Currency, USD);
            assertEquals(analytic.MarketDataName, CurveName.of("impliedSpreads"));
            assertEquals(analytic.ParameterCount, NUM_MARKET_CDS);
            assertEquals(analytic.ParameterMetadata, CDS_INDEX_METADATA);
            assertTrue(DoubleArrayMath.fuzzyEquals(analytic.Sensitivity.toArray(), analyticSingle.Sensitivity.multipliedBy(INDEX_FACTOR).toArray(), NOTIONAL * TOL));
            PointSensitivities             point      = PRICER_INDEX.presentValueOnSettleSensitivity(CDS_INDEX, RATES_PROVIDER, REF_DATA);
            CurrencyParameterSensitivity   paramSensi = RATES_PROVIDER.singleCreditCurveParameterSensitivity(point, INDEX_ID, USD);
            CurrencyParameterSensitivities quoteSensi = QUOTE_CAL.sensitivity(CurrencyParameterSensitivities.of(paramSensi), RATES_PROVIDER);

            assertTrue(DoubleArrayMath.fuzzyEquals(quoteSensi.Sensitivities.get(0).Sensitivity.toArray(), analytic.Sensitivity.toArray(), NOTIONAL * TOL));
        }
Пример #7
0
        // calculates market quote bucketed IR01 for one scenario
        internal CurrencyParameterSensitivities ir01MarketQuoteBucketed(ResolvedCdsIndexTrade trade, CreditRatesProvider ratesProvider, ReferenceData refData)
        {
            PointSensitivities             pointSensitivity     = tradePricer.presentValueOnSettleSensitivity(trade, ratesProvider, refData);
            CurrencyParameterSensitivity   parameterSensitivity = ratesProvider.singleDiscountCurveParameterSensitivity(pointSensitivity, trade.Product.Currency);
            CurrencyParameterSensitivities irSensitivity        = MARKET_QUOTE_SENS.sensitivity(CurrencyParameterSensitivities.of(parameterSensitivity), ratesProvider);

            return(irSensitivity.multipliedBy(ONE_BASIS_POINT));
        }