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));
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void test_trade()
        {
            CdsIndexIsdaCreditCurveNode node = CdsIndexIsdaCreditCurveNode.ofQuotedSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES, 0.01);
            double     rate                = 0.0125;
            double     quantity            = -1234.56;
            MarketData marketData          = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build();
            CdsIndexCalibrationTrade trade = node.trade(quantity, marketData, REF_DATA);
            CdsTrade      cdsTrade         = TEMPLATE.createTrade(INDEX_ID, VAL_DATE, SELL, -quantity, 0.01, REF_DATA);
            CdsIndex      cdsIndex         = CdsIndex.of(SELL, INDEX_ID, LEGAL_ENTITIES, TEMPLATE.Convention.Currency, -quantity, date(2015, 6, 20), date(2025, 6, 20), Frequency.P3M, TEMPLATE.Convention.SettlementDateOffset.Calendar, 0.01);
            CdsIndex      cdsIndexMod      = cdsIndex.toBuilder().paymentSchedule(cdsIndex.PaymentSchedule.toBuilder().rollConvention(RollConventions.DAY_20).startDateBusinessDayAdjustment(cdsIndex.PaymentSchedule.BusinessDayAdjustment).build()).build();
            CdsIndexTrade expected         = CdsIndexTrade.builder().product(cdsIndexMod).info(cdsTrade.Info).build();

            assertEquals(trade.UnderlyingTrade, expected);
            assertEquals(trade.Quote, CdsQuote.of(CdsQuoteConvention.QUOTED_SPREAD, rate));

            CdsIndexIsdaCreditCurveNode node1 = CdsIndexIsdaCreditCurveNode.ofParSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES);
            CdsTrade cdsTrade1 = TEMPLATE.createTrade(INDEX_ID, VAL_DATE, SELL, -quantity, rate, REF_DATA);
            CdsIndexCalibrationTrade trade1 = node1.trade(quantity, marketData, REF_DATA);
            CdsIndex      cdsIndex1         = CdsIndex.of(SELL, INDEX_ID, LEGAL_ENTITIES, TEMPLATE.Convention.Currency, -quantity, date(2015, 6, 20), date(2025, 6, 20), Frequency.P3M, TEMPLATE.Convention.SettlementDateOffset.Calendar, rate);
            CdsIndex      cdsIndexMod1      = cdsIndex1.toBuilder().paymentSchedule(cdsIndex.PaymentSchedule.toBuilder().rollConvention(RollConventions.DAY_20).startDateBusinessDayAdjustment(cdsIndex1.PaymentSchedule.BusinessDayAdjustment).build()).build();
            CdsIndexTrade expected1         = CdsIndexTrade.builder().product(cdsIndexMod1).info(cdsTrade1.Info).build();

            assertEquals(trade1.UnderlyingTrade, expected1);
            assertEquals(trade1.Quote, CdsQuote.of(CdsQuoteConvention.PAR_SPREAD, rate));
        }
        public virtual void test_ofMatrix_source()
        {
            FxRateLookup test       = FxRateLookup.ofMatrix(FxMatrixId.of(OBS_SOURCE));
            MarketData   marketData = ImmutableMarketData.builder(VAL_DATE).addValue(FxMatrixId.of(OBS_SOURCE), FxMatrix.of(GBP, USD, 1.5d)).build();

            assertEquals(test.fxRateProvider(marketData).fxRate(GBP, USD), 1.5d);
        }
        public virtual void test_ofRates_currency_source()
        {
            FxRateLookup test       = FxRateLookup.ofRates(EUR, OBS_SOURCE);
            MarketData   marketData = ImmutableMarketData.builder(VAL_DATE).addValue(FxRateId.of(GBP, USD, OBS_SOURCE), FxRate.of(GBP, USD, 1.5d)).build();

            assertEquals(test.fxRateProvider(marketData).fxRate(GBP, USD), 1.5d);
        }
Ejemplo n.º 5
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);
        }
        //-------------------------------------------------------------------------
        public virtual void test_trade()
        {
            CdsIsdaCreditCurveNode node    = CdsIsdaCreditCurveNode.ofQuotedSpread(TEMPLATE, QUOTE_ID, LEGAL_ENTITY, 0.01);
            double              rate       = 0.0125;
            double              quantity   = -1234.56;
            MarketData          marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build();
            CdsCalibrationTrade trade      = node.trade(quantity, marketData, REF_DATA);
            CdsTrade            expected   = TEMPLATE.createTrade(LEGAL_ENTITY, VAL_DATE, SELL, -quantity, 0.01, REF_DATA);

            assertEquals(trade.UnderlyingTrade, expected);
            assertEquals(trade.Quote, CdsQuote.of(CdsQuoteConvention.QUOTED_SPREAD, rate));

            CdsIsdaCreditCurveNode node1  = CdsIsdaCreditCurveNode.ofParSpread(TEMPLATE, QUOTE_ID, LEGAL_ENTITY);
            CdsTrade            expected1 = TEMPLATE.createTrade(LEGAL_ENTITY, VAL_DATE, SELL, -quantity, rate, REF_DATA);
            CdsCalibrationTrade trade1    = node1.trade(quantity, marketData, REF_DATA);

            assertEquals(trade1.UnderlyingTrade, expected1);
            assertEquals(trade1.Quote, CdsQuote.of(CdsQuoteConvention.PAR_SPREAD, 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));
        }
        public virtual void test_bondDiscountingProvider()
        {
            ImmutableMap <SecurityId, RepoGroup>               repoSecurityGroups = ImmutableMap.of(SEC_A1, GROUP_REPO_X);
            ImmutableMap <LegalEntityId, RepoGroup>            repoGroups         = ImmutableMap.of(ISSUER_B, GROUP_REPO_X);
            ImmutableMap <Pair <RepoGroup, Currency>, CurveId> repoCurves         = ImmutableMap.of(Pair.of(GROUP_REPO_X, USD), CURVE_ID_USD1);

            ImmutableMap <LegalEntityId, LegalEntityGroup>            issuerGroups = ImmutableMap.of(ISSUER_A, GROUP_ISSUER_M);
            ImmutableMap <Pair <LegalEntityGroup, Currency>, CurveId> issuerCurves = ImmutableMap.of(Pair.of(GROUP_ISSUER_M, USD), CURVE_ID_USD3);

            LegalEntityDiscountingMarketDataLookup test = LegalEntityDiscountingMarketDataLookup.of(repoSecurityGroups, repoGroups, repoCurves, issuerGroups, issuerCurves);
            LocalDate  valDate     = date(2015, 6, 30);
            Curve      repoCurve   = ConstantCurve.of(Curves.discountFactors(CURVE_ID_USD1.CurveName, ACT_360), 1d);
            Curve      issuerCurve = ConstantCurve.of(Curves.discountFactors(CURVE_ID_USD3.CurveName, ACT_360), 2d);
            MarketData md          = ImmutableMarketData.of(valDate, ImmutableMap.of(CURVE_ID_USD1, repoCurve, CURVE_ID_USD3, issuerCurve));
            LegalEntityDiscountingProvider provider = test.discountingProvider(md);

            assertEquals(provider.ValuationDate, valDate);
            assertEquals(provider.findData(CURVE_ID_USD1.CurveName), repoCurve);
            assertEquals(provider.findData(CURVE_ID_USD3.CurveName), issuerCurve);
            assertEquals(provider.findData(CurveName.of("Rubbish")), null);
            // check repo
            RepoCurveDiscountFactors rcdf = provider.repoCurveDiscountFactors(SEC_A1, ISSUER_A, USD);
            SimpleDiscountFactors    rdf  = (SimpleDiscountFactors)rcdf.DiscountFactors;

            assertEquals(rdf.Curve.Name, repoCurve.Name);
            assertEquals(rcdf, provider.repoCurveDiscountFactors(SEC_B1, ISSUER_B, USD));
            assertThrowsIllegalArg(() => provider.repoCurveDiscountFactors(SEC_A1, ISSUER_A, GBP));
            assertThrowsIllegalArg(() => provider.repoCurveDiscountFactors(SEC_C1, ISSUER_C, USD));
            // check issuer
            IssuerCurveDiscountFactors icdf = provider.issuerCurveDiscountFactors(ISSUER_A, USD);
            SimpleDiscountFactors      idf  = (SimpleDiscountFactors)icdf.DiscountFactors;

            assertEquals(idf.Curve.Name, issuerCurve.Name);
            assertThrowsIllegalArg(() => provider.issuerCurveDiscountFactors(ISSUER_A, GBP));
            assertThrowsIllegalArg(() => provider.issuerCurveDiscountFactors(ISSUER_C, USD));
        }