Example #1
0
        //-------------------------------------------------------------------------
        protected internal virtual void testJacobian(LegalEntitySurvivalProbabilities curve, ImmutableCreditRatesProvider ratesProvider, IList <CdsIndexIsdaCreditCurveNode> nodes, double[] quotes)
        {
            int nNode = nodes.Count;
            IsdaCreditDiscountFactors df = (IsdaCreditDiscountFactors)curve.SurvivalProbabilities;
            int nCurveNode = df.ParameterCount;

            for (int i = 0; i < nCurveNode; ++i)
            {
                double[] quotesUp = Arrays.copyOf(quotes, nNode);
                double[] quotesDw = Arrays.copyOf(quotes, nNode);
                quotesUp[i] += EPS;
                quotesDw[i] -= EPS;
                ImmutableMarketDataBuilder builderCreditUp = MARKET_DATA.toBuilder();
                ImmutableMarketDataBuilder builderCreditDw = MARKET_DATA.toBuilder();
                for (int j = 0; j < nNode; ++j)
                {
                    builderCreditUp.addValue(nodes[j].ObservableId, quotesUp[j]);
                    builderCreditDw.addValue(nodes[j].ObservableId, quotesDw[j]);
                }
                ImmutableMarketData       marketDataUp = builderCreditUp.build();
                ImmutableMarketData       marketDataDw = builderCreditDw.build();
                IsdaCreditCurveDefinition definition   = IsdaCreditCurveDefinition.of(df.Curve.Name, df.Currency, df.ValuationDate, df.DayCount, nodes, false, false);
                IsdaCreditDiscountFactors ccUp         = (IsdaCreditDiscountFactors)CALIBRATOR.calibrate(definition, marketDataUp, ratesProvider, REF_DATA).SurvivalProbabilities;
                IsdaCreditDiscountFactors ccDw         = (IsdaCreditDiscountFactors)CALIBRATOR.calibrate(definition, marketDataDw, ratesProvider, REF_DATA).SurvivalProbabilities;
                for (int j = 0; j < nNode; ++j)
                {
                    double computed = df.Curve.Metadata.findInfo(CurveInfoType.JACOBIAN).get().JacobianMatrix.get(j, i);
                    double expected = 0.5 * (ccUp.Curve.YValues.get(j) - ccDw.Curve.YValues.get(j)) / EPS;
                    assertEquals(computed, expected, EPS * 10d);
                }
            }
        }
Example #2
0
        public virtual void test_zeroRatePointSensitivity_sensitivityCurrency()
        {
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, DFS.zeroRatePointSensitivity(DATE_AFTER, GBP));

            assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, GBP), expected);
        }
Example #3
0
        public virtual void test_consistency_singleName()
        {
            IsdaCreditCurveDefinition        curveDefinition     = IsdaCreditCurveDefinition.of(CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, CURVE_NODES_PS, true, true);
            LegalEntitySurvivalProbabilities creditCurveComputed = CALIBRATOR.calibrate(curveDefinition, MARKET_DATA_PS, RATES_PROVIDER, REF_DATA);
            NodalCurve curveComputed = (NodalCurve)creditCurveComputed.SurvivalProbabilities.findData(CURVE_NAME).get();
            double     computedIndex = curveComputed.Metadata.getInfo(CurveInfoType.CDS_INDEX_FACTOR);

            assertEquals(computedIndex, 93.0 / 97.0, TOL);
            IsdaCompliantCreditCurveCalibrator cdsCalibrator = FastCreditCurveCalibrator.standard();
            IList <CdsIsdaCreditCurveNode>     cdsNodes      = new List <CdsIsdaCreditCurveNode>();

            for (int i = 0; i < CURVE_NODES_PS.size(); ++i)
            {
                cdsNodes.Add(CdsIsdaCreditCurveNode.ofParSpread(CURVE_NODES_PS.get(i).Template, CURVE_NODES_PS.get(i).ObservableId, CURVE_NODES_PS.get(i).CdsIndexId));
                ParameterMetadata metadata = curveComputed.getParameterMetadata(i);
                assertTrue(metadata is ResolvedTradeParameterMetadata);
                ResolvedTradeParameterMetadata tradeMetadata = (ResolvedTradeParameterMetadata)metadata;
                assertTrue(tradeMetadata.Trade is ResolvedCdsIndexTrade);
            }
            IsdaCreditCurveDefinition        cdsCurveDefinition  = IsdaCreditCurveDefinition.of(CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, cdsNodes, true, false);
            LegalEntitySurvivalProbabilities creditCurveExpected = cdsCalibrator.calibrate(cdsCurveDefinition, MARKET_DATA_PS, RATES_PROVIDER, REF_DATA);
            NodalCurve curveExpected = (NodalCurve)creditCurveExpected.SurvivalProbabilities.findData(CURVE_NAME).get();

            assertTrue(DoubleArrayMath.fuzzyEquals(curveComputed.XValues.toArray(), curveExpected.XValues.toArray(), TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(curveComputed.YValues.toArray(), curveExpected.YValues.toArray(), TOL));
            assertEquals(curveComputed.Metadata.getInfo(CurveInfoType.JACOBIAN), curveExpected.Metadata.getInfo(CurveInfoType.JACOBIAN));
        }
        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));
        }
Example #5
0
        //-------------------------------------------------------------------------
        // proper end-to-end FD tests are in pricer test
        public virtual void test_parameterSensitivity()
        {
            LegalEntitySurvivalProbabilities test  = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   point = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, ZeroRateSensitivity.of(USD, 1d, 1d));

            assertEquals(test.parameterSensitivity(point).size(), 1);
        }
Example #6
0
        public virtual void test_zeroRatePointSensitivity_sensitivityCurrency_yearFraction()
        {
            double yearFraction = DFS.relativeYearFraction(DATE_AFTER);
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, DFS.zeroRatePointSensitivity(yearFraction, GBP));

            assertEquals(test.zeroRatePointSensitivity(yearFraction, GBP), expected);
        }
Example #7
0
        private double getIndexFactor(ResolvedCds cds, CreditRatesProvider ratesProvider)
        {
            LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.LegalEntityId, cds.Currency);
            // instance is checked in pricer
            double indexFactor = ((IsdaCreditDiscountFactors)survivalProbabilities.SurvivalProbabilities).Curve.Metadata.getInfo(CurveInfoType.CDS_INDEX_FACTOR);

            return(indexFactor);
        }
Example #8
0
        //-------------------------------------------------------------------------
        public virtual void test_unitParameterSensitivity()
        {
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   sens     = test.zeroRatePointSensitivity(DATE_AFTER);
            CurrencyParameterSensitivities   expected = DFS.parameterSensitivity(DFS.zeroRatePointSensitivity(DATE_AFTER));

            assertEquals(test.parameterSensitivity(sens), expected);
        }
Example #9
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            LegalEntitySurvivalProbabilities test1 = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);

            coverImmutableBean(test1);
            LegalEntitySurvivalProbabilities test2 = LegalEntitySurvivalProbabilities.of(StandardId.of("OG", "CCC"), IsdaCreditDiscountFactors.of(GBP, VALUATION, CURVE_NAME, DoubleArray.of(5.0), DoubleArray.of(0.014), ACT_365F));

            coverBeanEquals(test1, test2);
        }
Example #10
0
        public virtual void test_zeroRate()
        {
            LegalEntitySurvivalProbabilities test = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            double relativeYearFraction           = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER);
            double discountFactor = test.survivalProbability(DATE_AFTER);
            double zeroRate       = test.zeroRate(relativeYearFraction);

            assertEquals(Math.Exp(-zeroRate * relativeYearFraction), discountFactor);
        }
Example #11
0
        //-------------------------------------------------------------------------
        public LegalEntitySurvivalProbabilities survivalProbabilities(StandardId legalEntityId, Currency currency)
        {
            LegalEntitySurvivalProbabilities survivalProbabilities = creditCurves.get(Pair.of(legalEntityId, currency));

            if (survivalProbabilities == null)
            {
                throw new System.ArgumentException("Unable to find credit curve: " + legalEntityId + ", " + currency);
            }
            return(survivalProbabilities);
        }
Example #12
0
        public virtual void test_of()
        {
            LegalEntitySurvivalProbabilities test = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);

            assertEquals(test.Currency, USD);
            assertEquals(test.LegalEntityId, LEGAL_ENTITY);
            assertEquals(test.ParameterKeys, TIME);
            assertEquals(test.SurvivalProbabilities, DFS);
            assertEquals(test.ValuationDate, VALUATION);
        }
        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));
        }
Example #14
0
        private Pair <CreditDiscountFactors, LegalEntitySurvivalProbabilities> reduceDiscountFactors(ResolvedCds cds, CreditRatesProvider ratesProvider)
        {
            Currency currency = cds.Currency;
            CreditDiscountFactors discountFactors = ratesProvider.discountFactors(currency);

            ArgChecker.isTrue(discountFactors.IsdaCompliant, "discount factors must be IsdaCompliantZeroRateDiscountFactors");
            LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.LegalEntityId, currency);

            ArgChecker.isTrue(survivalProbabilities.SurvivalProbabilities.IsdaCompliant, "survival probabilities must be IsdaCompliantZeroRateDiscountFactors");
            ArgChecker.isTrue(discountFactors.DayCount.Equals(survivalProbabilities.SurvivalProbabilities.DayCount), "day count conventions of discounting curve and credit curve must be the same");
            return(Pair.of(discountFactors, survivalProbabilities));
        }
Example #15
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         LegalEntitySurvivalProbabilities other = (LegalEntitySurvivalProbabilities)obj;
         return(JodaBeanUtils.equal(legalEntityId, other.legalEntityId) && JodaBeanUtils.equal(survivalProbabilities, other.survivalProbabilities));
     }
     return(false);
 }
        internal virtual Triple <CreditDiscountFactors, LegalEntitySurvivalProbabilities, double> reduceDiscountFactors(ResolvedCds cds, CreditRatesProvider ratesProvider)
        {
            Currency currency = cds.Currency;
            CreditDiscountFactors discountFactors = ratesProvider.discountFactors(currency);

            ArgChecker.isTrue(discountFactors.IsdaCompliant, "discount factors must be IsdaCompliantZeroRateDiscountFactors");
            LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.LegalEntityId, currency);

            ArgChecker.isTrue(survivalProbabilities.SurvivalProbabilities.IsdaCompliant, "survival probabilities must be IsdaCompliantZeroRateDiscountFactors");
            ArgChecker.isTrue(discountFactors.DayCount.Equals(survivalProbabilities.SurvivalProbabilities.DayCount), "day count conventions of discounting curve and credit curve must be the same");
            double indexFactor = ((IsdaCreditDiscountFactors)survivalProbabilities.SurvivalProbabilities).Curve.Metadata.getInfo(CurveInfoType.CDS_INDEX_FACTOR);

            return(Triple.of(discountFactors, survivalProbabilities, indexFactor));
        }
        public virtual void parSpreadTest()
        {
            LocalDate   valuationDate    = LocalDate.of(2013, 2, 27);
            DoubleArray ycTime           = DoubleArray.ofUnsafe(new double[] { 0.09041095890410959, 0.1726027397260274, 0.26301369863013696, 0.5123287671232877, 0.7616438356164383, 1.010958904109589, 2.008219178082192, 3.008219178082192, 4.008219178082192, 5.008219178082192, 6.008219178082192, 7.013698630136987, 8.01095890410959, 9.01095890410959, 10.01095890410959, 12.01917808219178, 15.016438356164384, 20.01917808219178, 25.021917808219175, 30.027397260273972 });
            DoubleArray ycRate           = DoubleArray.ofUnsafe(new double[] { 0.0020651105531615476, 0.0024506037920717797, 0.0028872269869485313, 0.004599628230463427, 0.006160809466806469, 0.0075703969168129295, 0.003965128877560435, 0.005059104202201957, 0.0069669135253734825, 0.009361825469323602, 0.011916895611422482, 0.014311922779901886, 0.016519187063048578, 0.018512121993907647, 0.020289623737560873, 0.02329885162861984, 0.026399509889410745, 0.029087919732133784, 0.03037740056662963, 0.03110021763406523 });
            IsdaCreditDiscountFactors yc = IsdaCreditDiscountFactors.of(EUR, valuationDate, CurveName.of("yc_usd"), ycTime, ycRate, ACT_365F);

            double[] timeNodeExp   = new double[] { 0.5616438356164384, 1.0575342465753426, 2.0575342465753423, 3.0602739726027397, 4.06027397260274, 5.06027397260274, 6.06027397260274, 7.063013698630137, 8.063013698630137, 9.063013698630137, 10.063013698630137 };
            double[] rateNodeExp   = new double[] { 0.00876054089781935, 0.011037345646850688, 0.015955126945240167, 0.020617953392829177, 0.025787811343896218, 0.030329992053915133, 0.03313419899444371, 0.03528129159875671, 0.03675340516560903, 0.037946169956317416, 0.038951101800190346 };
            double[] rateNodeExpMf = new double[] { 0.008754510260229803, 0.011030502992814844, 0.01594817866773906, 0.02060947097554756, 0.025776720596175737, 0.030316032527460755, 0.03311839631615255, 0.03526404051997617, 0.03673513322394772, 0.03792689865945585, 0.03893107891569398 };
            ImmutableCreditRatesProvider ratesProvider = ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).discountCurves(ImmutableMap.of(EUR, yc)).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, ConstantRecoveryRates.of(LEGAL_ENTITY, valuationDate, 0.25))).creditCurves(ImmutableMap.of()).build();
            LocalDate startDate = LocalDate.of(2012, 12, 20);

            LocalDate[] pillarDates = new LocalDate[] { LocalDate.of(2013, 9, 20), LocalDate.of(2014, 3, 20), LocalDate.of(2015, 3, 20), LocalDate.of(2016, 3, 20), LocalDate.of(2017, 3, 20), LocalDate.of(2018, 3, 20), LocalDate.of(2019, 3, 20), LocalDate.of(2020, 3, 20), LocalDate.of(2021, 3, 20), LocalDate.of(2022, 3, 20), LocalDate.of(2023, 3, 20) };
            int         nPillars    = pillarDates.Length;
            ImmutableMarketDataBuilder     builderCredit = ImmutableMarketData.builder(valuationDate);
            IList <CdsIsdaCreditCurveNode> nodes         = new List <CdsIsdaCreditCurveNode>(nPillars);

            double[] quotes = new double[] { 0.006485, 0.008163, 0.011763, 0.015136, 0.018787, 0.021905, 0.023797, 0.025211, 0.02617, 0.026928, 0.027549 };
            for (int i = 0; i < nPillars; ++i)
            {
                CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, Frequency.P3M, BUS_ADJ, CDS_SETTLE_STD);
                CdsTemplate   temp = DatesCdsTemplate.of(startDate, pillarDates[i], conv);
                QuoteId       id   = QuoteId.of(StandardId.of("OG", pillarDates[i].ToString()));
                nodes.Add(CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY));
                builderCredit.addValue(id, quotes[i]);
            }
            ImmutableMarketData              marketData      = builderCredit.build();
            IsdaCreditCurveDefinition        curveDefinition = IsdaCreditCurveDefinition.of(CurveName.of("zz"), EUR, valuationDate, ACT_365F, nodes, true, true);
            LegalEntitySurvivalProbabilities cc = BUILDER_ISDA.calibrate(curveDefinition, marketData, ratesProvider, REF_DATA);
            NodalCurve resCurve = ((IsdaCreditDiscountFactors)cc.SurvivalProbabilities).Curve;

            for (int i = 0; i < nPillars; ++i)
            {
                ParameterMetadata param = resCurve.getParameterMetadata(i);
                assertTrue(param is ResolvedTradeParameterMetadata);
                ResolvedTradeParameterMetadata tradeParam = (ResolvedTradeParameterMetadata)param;
                assertTrue(tradeParam.Trade is ResolvedCdsTrade);
            }
            assertTrue(DoubleArrayMath.fuzzyEquals(resCurve.XValues.toArray(), timeNodeExp, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(resCurve.YValues.toArray(), rateNodeExp, TOL));
            testJacobian(BUILDER_ISDA, cc, ratesProvider, nodes, quotes, 1d, EPS);
            LegalEntitySurvivalProbabilities ccMf = BUILDER_MARKIT.calibrate(curveDefinition, marketData, ratesProvider, REF_DATA);
            NodalCurve resCurveMf = ((IsdaCreditDiscountFactors)ccMf.SurvivalProbabilities).Curve;

            assertTrue(DoubleArrayMath.fuzzyEquals(resCurveMf.XValues.toArray(), timeNodeExp, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(resCurveMf.YValues.toArray(), rateNodeExpMf, TOL));
            testJacobian(BUILDER_MARKIT, ccMf, ratesProvider, nodes, quotes, 1d, EPS);
        }
Example #18
0
        public virtual void test_regression_single()
        {
            double[] expectedTimes = new double[] { 4.852054794520548 };
            double[] expectedRates = new double[] { 0.04666754810728295 };
            ImmutableList <CdsIndexIsdaCreditCurveNode> singleNode = CURVE_NODES.subList(1, 2);
            IsdaCreditCurveDefinition        curveDefinition       = IsdaCreditCurveDefinition.of(CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, singleNode, true, false);
            LegalEntitySurvivalProbabilities creditCurve           = CALIBRATOR.calibrate(curveDefinition, MARKET_DATA, RATES_PROVIDER, REF_DATA);
            NodalCurve curve = (NodalCurve)creditCurve.SurvivalProbabilities.findData(CURVE_NAME).get();

            assertTrue(DoubleArrayMath.fuzzyEquals(curve.XValues.toArray(), expectedTimes, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(curve.YValues.toArray(), expectedRates, TOL));
            assertTrue(curve.getParameterMetadata(0) is DatedParameterMetadata);
            double computedIndex = curve.Metadata.getInfo(CurveInfoType.CDS_INDEX_FACTOR);

            assertEquals(computedIndex, 93.0 / 97.0, TOL);
            testJacobian(creditCurve, RATES_PROVIDER, singleNode, PUF_QUOTES);
        }
        public virtual void test_getter()
        {
            ImmutableCreditRatesProvider test = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION).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)).build();

            assertEquals(test.discountFactors(USD), DSC_USD);
            assertEquals(test.discountFactors(JPY), DSC_JPY);
            assertEquals(test.survivalProbabilities(LEGAL_ENTITY_ABC, USD), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_USD));
            assertEquals(test.survivalProbabilities(LEGAL_ENTITY_ABC, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_JPY));
            assertEquals(test.survivalProbabilities(LEGAL_ENTITY_DEF, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_DEF, CRD_DEF));
            assertEquals(test.recoveryRates(LEGAL_ENTITY_ABC), RR_ABC);
            assertEquals(test.recoveryRates(LEGAL_ENTITY_DEF), RR_DEF);
            StandardId entity = StandardId.of("OG", "NONE");

            assertThrowsIllegalArg(() => test.discountFactors(EUR));
            assertThrowsIllegalArg(() => test.survivalProbabilities(LEGAL_ENTITY_DEF, USD));
            assertThrowsIllegalArg(() => test.survivalProbabilities(entity, USD));
            assertThrowsIllegalArg(() => test.recoveryRates(entity));
        }
Example #20
0
        public virtual void test_regression()
        {
            double[] expectedTimes = new double[] { 2.852054794520548, 4.852054794520548, 6.854794520547945, 9.854794520547944 };
            double[] expectedRates = new double[] { 0.03240798261187516, 0.04858422754375164, 0.0616141083562273, 0.06235460926516589 };
            IsdaCreditCurveDefinition        curveDefinition = IsdaCreditCurveDefinition.of(CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, CURVE_NODES, true, false);
            LegalEntitySurvivalProbabilities creditCurve     = CALIBRATOR.calibrate(curveDefinition, MARKET_DATA, RATES_PROVIDER, REF_DATA);
            NodalCurve curve = (NodalCurve)creditCurve.SurvivalProbabilities.findData(CURVE_NAME).get();

            assertTrue(DoubleArrayMath.fuzzyEquals(curve.XValues.toArray(), expectedTimes, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(curve.YValues.toArray(), expectedRates, TOL));
            assertTrue(curve.getParameterMetadata(0) is DatedParameterMetadata);
            assertTrue(curve.getParameterMetadata(1) is DatedParameterMetadata);
            assertTrue(curve.getParameterMetadata(2) is DatedParameterMetadata);
            assertTrue(curve.getParameterMetadata(3) is DatedParameterMetadata);
            double computedIndex = curve.Metadata.getInfo(CurveInfoType.CDS_INDEX_FACTOR);

            assertEquals(computedIndex, 93.0 / 97.0, TOL);
            testJacobian(creditCurve, RATES_PROVIDER, CURVE_NODES, PUF_QUOTES);
        }
        public virtual void pufTest()
        {
            LocalDate   valuationDate    = LocalDate.of(2013, 4, 10);
            DoubleArray ycTime           = DoubleArray.ofUnsafe(new double[] { 0.09041095890410959, 0.1726027397260274, 0.2547945205479452, 0.5123287671232877, 0.7616438356164383, 1.010958904109589, 2.008219178082192, 3.008219178082192, 4.008219178082192, 5.008219178082192, 6.008219178082192, 7.013698630136987, 8.01095890410959, 9.01095890410959, 10.01095890410959, 12.01917808219178, 15.016438356164384, 20.01917808219178, 25.021917808219175, 30.027397260273972 });
            DoubleArray ycRate           = DoubleArray.ofUnsafe(new double[] { 0.0020205071813561414, 0.0024226927083852126, 0.00280147037504029, 0.004449041082144009, 0.005821804782808804, 0.007254879152733453, 0.00378133614924816, 0.004815163234294319, 0.006576302084547871, 0.00884241431837336, 0.011358805989279104, 0.013793391727035883, 0.016014197840890115, 0.01801564209277191, 0.019757164421290663, 0.022773295945438254, 0.025862337032619587, 0.02848646344754061, 0.029753383126110852, 0.03045277462637107 });
            IsdaCreditDiscountFactors yc = IsdaCreditDiscountFactors.of(EUR, valuationDate, CurveName.of("yc_usd"), ycTime, ycRate, ACT_365F);

            double[] timeNodeExp   = new double[] { 0.19452054794520549, 0.4465753424657534, 0.6958904109589041, 0.9424657534246575, 1.1945205479452055, 1.4465753424657535, 1.6958904109589041, 1.9424657534246574, 2.1945205479452055, 2.4465753424657533, 2.695890410958904, 2.9452054794520546, 3.197260273972603, 3.4493150684931506, 3.6986301369863015, 3.9452054794520546, 4.197260273972603, 4.449315068493151, 4.698630136986301, 4.945205479452055, 5.197260273972603, 5.449315068493151, 5.698630136986301, 5.945205479452055, 6.197260273972603, 6.449315068493151, 6.698630136986301, 6.947945205479452, 7.2, 7.4520547945205475, 7.701369863013698, 7.947945205479452, 8.2, 8.452054794520548, 8.7013698630137, 8.947945205479453, 9.2, 9.452054794520548, 9.7013698630137, 9.947945205479453, 10.2 };
            double[] rateNodeExp   = new double[] { 0.11219168510100914, 0.11085321179769615, 0.11753783265486063, 0.11806409789291543, 0.12007843111645247, 0.12273722191216528, 0.12541993298405366, 0.12773640093265545, 0.1290535220739981, 0.13294183149211675, 0.13659302947963856, 0.13988488561043758, 0.1429469312254705, 0.14606538453369572, 0.14916286828444447, 0.15219682906227, 0.1548315745851032, 0.158141193071526, 0.16163981714033765, 0.1650400193930357, 0.1682351993447916, 0.1683744003954113, 0.168657453080796, 0.16915067878510565, 0.1694852880010724, 0.16990705130936645, 0.1704456138969621, 0.17105852486248443, 0.1717088423125347, 0.1727906445582425, 0.17407566745397665, 0.17547300248653266, 0.17679395545074758, 0.17769841457372118, 0.1788064602071617, 0.18001498257267778, 0.18123747758791092, 0.18253661761388457, 0.18406319235262744, 0.18582983758830868, 0.18750386499176422 };
            double[] rateNodeExpMf = new double[] { 0.11107220823737506, 0.11011543264900588, 0.11685607164947402, 0.11742079953945683, 0.1194445192166302, 0.12220026187805585, 0.12494798294628297, 0.12731185688090763, 0.12860146674492023, 0.1325216904413876, 0.1362014254649678, 0.13951646788193767, 0.14254141853655264, 0.14567581048732742, 0.1487851622438674, 0.15182838855605538, 0.15442415754322128, 0.15774061191016645, 0.16124288871765308, 0.1646451035564102, 0.167796451103847, 0.16794456750248196, 0.16823438468063495, 0.1687328171292339, 0.16904360885724334, 0.16947020572961907, 0.17001201556723175, 0.17062724832190826, 0.17125190473373603, 0.17233319414449558, 0.17361785479583028, 0.1750136127341691, 0.17630530410589512, 0.17720871748506664, 0.17831270423353415, 0.17951604233911425, 0.18070939732103264, 0.18200162521943403, 0.18351891000003046, 0.1852740041292825, 0.18691086960422418 };
            ImmutableCreditRatesProvider ratesProvider = ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).discountCurves(ImmutableMap.of(EUR, yc)).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, ConstantRecoveryRates.of(LEGAL_ENTITY, valuationDate, 0.4))).creditCurves(ImmutableMap.of()).build();
            LocalDate startDate = LocalDate.of(2013, 3, 20);

            LocalDate[] pillarDate = new LocalDate[] { LocalDate.of(2013, 6, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2013, 12, 20), LocalDate.of(2014, 3, 20), LocalDate.of(2014, 6, 20), LocalDate.of(2014, 9, 20), LocalDate.of(2014, 12, 20), LocalDate.of(2015, 3, 20), LocalDate.of(2015, 6, 20), LocalDate.of(2015, 9, 20), LocalDate.of(2015, 12, 20), LocalDate.of(2016, 3, 20), LocalDate.of(2016, 6, 20), LocalDate.of(2016, 9, 20), LocalDate.of(2016, 12, 20), LocalDate.of(2017, 3, 20), LocalDate.of(2017, 6, 20), LocalDate.of(2017, 9, 20), LocalDate.of(2017, 12, 20), LocalDate.of(2018, 3, 20), LocalDate.of(2018, 6, 20), LocalDate.of(2018, 9, 20), LocalDate.of(2018, 12, 20), LocalDate.of(2019, 3, 20), LocalDate.of(2019, 6, 20), LocalDate.of(2019, 9, 20), LocalDate.of(2019, 12, 20), LocalDate.of(2020, 3, 20), LocalDate.of(2020, 6, 20), LocalDate.of(2020, 9, 20), LocalDate.of(2020, 12, 20), LocalDate.of(2021, 3, 20), LocalDate.of(2021, 6, 20), LocalDate.of(2021, 9, 20), LocalDate.of(2021, 12, 20), LocalDate.of(2022, 3, 20), LocalDate.of(2022, 6, 20), LocalDate.of(2022, 9, 20), LocalDate.of(2022, 12, 20), LocalDate.of(2023, 3, 20), LocalDate.of(2023, 6, 20) };
            int         nPillars   = pillarDate.Length;
            double      coupon     = 500d * ONE_BP;
            ImmutableMarketDataBuilder     builderCredit = ImmutableMarketData.builder(valuationDate);
            IList <CdsIsdaCreditCurveNode> nodes         = new List <CdsIsdaCreditCurveNode>(nPillars);

            double[] quotes = new double[] { 0.32, 0.69, 1.32, 1.79, 2.36, 3.01, 3.7, 4.39, 5.02, 5.93, 6.85, 7.76, 8.67, 9.6, 10.53, 11.45, 12.33, 13.29, 14.26, 15.2, 16.11, 16.62, 17.12, 17.62, 18.09, 18.55, 19, 19.44, 19.87, 20.33, 20.79, 21.24, 21.67, 22.04, 22.41, 22.77, 23.12, 23.46, 23.8, 24.14, 24.46 };
            for (int i = 0; i < nPillars; ++i)
            {
                CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, Frequency.P3M, BUS_ADJ, CDS_SETTLE_STD);
                CdsTemplate   temp = DatesCdsTemplate.of(startDate, pillarDate[i], conv);
                QuoteId       id   = QuoteId.of(StandardId.of("OG", pillarDate[i].ToString()));
                nodes.Add(CdsIsdaCreditCurveNode.ofPointsUpfront(temp, id, LEGAL_ENTITY, coupon));
                builderCredit.addValue(id, quotes[i] * ONE_PC);
            }
            ImmutableMarketData              marketData      = builderCredit.build();
            IsdaCreditCurveDefinition        curveDefinition = IsdaCreditCurveDefinition.of(CurveName.of("cc"), EUR, valuationDate, ACT_365F, nodes, true, false);
            LegalEntitySurvivalProbabilities cc = BUILDER_ISDA.calibrate(curveDefinition, marketData, ratesProvider, REF_DATA);
            NodalCurve resCurve = ((IsdaCreditDiscountFactors)cc.SurvivalProbabilities).Curve;

            assertTrue(DoubleArrayMath.fuzzyEquals(resCurve.XValues.toArray(), timeNodeExp, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(resCurve.YValues.toArray(), rateNodeExp, TOL));
            testJacobian(BUILDER_ISDA, cc, ratesProvider, nodes, quotes, ONE_PC, EPS);
            LegalEntitySurvivalProbabilities ccMf = BUILDER_MARKIT.calibrate(curveDefinition, marketData, ratesProvider, REF_DATA);
            NodalCurve resCurveMf = ((IsdaCreditDiscountFactors)ccMf.SurvivalProbabilities).Curve;

            assertTrue(DoubleArrayMath.fuzzyEquals(resCurveMf.XValues.toArray(), timeNodeExp, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(resCurveMf.YValues.toArray(), rateNodeExpMf, TOL));
            testJacobian(BUILDER_MARKIT, ccMf, ratesProvider, nodes, quotes, ONE_PC, EPS);
        }
Example #22
0
        public CurrencyParameterSensitivity singleCreditCurveParameterSensitivity(PointSensitivities pointSensitivities, StandardId legalEntityId, Currency currency)
        {
            CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty();

            foreach (PointSensitivity point in pointSensitivities.Sensitivities)
            {
                if (point is CreditCurveZeroRateSensitivity)
                {
                    CreditCurveZeroRateSensitivity pt = (CreditCurveZeroRateSensitivity)point;
                    if (pt.LegalEntityId.Equals(legalEntityId) && pt.Currency.Equals(currency))
                    {
                        LegalEntitySurvivalProbabilities factors = survivalProbabilities(pt.LegalEntityId, pt.CurveCurrency);
                        sens = sens.combinedWith(factors.parameterSensitivity(pt));
                    }
                }
            }
            ArgChecker.isTrue(sens.size() == 1, "sensitivity must be unique");
            return(sens.Sensitivities.get(0));
        }
Example #23
0
        //-------------------------------------------------------------------------
        public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities)
        {
            CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty();

            foreach (PointSensitivity point in pointSensitivities.Sensitivities)
            {
                if (point is CreditCurveZeroRateSensitivity)
                {
                    CreditCurveZeroRateSensitivity   pt      = (CreditCurveZeroRateSensitivity)point;
                    LegalEntitySurvivalProbabilities factors = survivalProbabilities(pt.LegalEntityId, pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
                else if (point is ZeroRateSensitivity)
                {
                    ZeroRateSensitivity   pt      = (ZeroRateSensitivity)point;
                    CreditDiscountFactors factors = discountFactors(pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
            }
            return(sens);
        }
        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));
        }
        //-------------------------------------------------------------------------
        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);
                }
            }
        }
Example #26
0
        private System.Func <double, double> getPriceFunction(int index, ResolvedCdsTrade cds, double flactionalSpread, double pointsUpfront, LocalDate valuationDate, NodalCurve creditCurve, CreditDiscountFactors discountFactors, RecoveryRates recoveryRates, ReferenceData refData)
        {
            ResolvedCds cdsProduct                 = cds.Product;
            Currency    currency                   = cdsProduct.Currency;
            StandardId  legalEntityId              = cdsProduct.LegalEntityId;
            Pair <StandardId, Currency>  pair      = Pair.of(legalEntityId, currency);
            ImmutableCreditRatesProvider ratesbase = ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).discountCurves(ImmutableMap.of(currency, discountFactors)).recoveryRateCurves(ImmutableMap.of(legalEntityId, recoveryRates)).build();

            System.Func <double, double> func = (double?x) =>
            {
                NodalCurve tempCreditCurve         = creditCurve.withParameter(index, x.Value);
                ImmutableCreditRatesProvider rates = ratesbase.toBuilder().creditCurves(ImmutableMap.of(pair, LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, tempCreditCurve)))).build();
                double price = TradePricer.price(cds, rates, flactionalSpread, PriceType.CLEAN, refData);
                return(price - pointsUpfront);
            };
            return(func);
        }
Example #27
0
        /// <summary>
        /// The par spread quotes are converted to points upfronts or quoted spreads.
        /// <para>
        /// The relevant discount curve and recovery rate curve must be stored in {@code ratesProvider}.
        /// The credit curve is internally calibrated to par spread values.
        /// </para>
        /// <para>
        /// {@code trades} must be sorted in ascending order in maturity and coherent to {@code quotes}.
        /// </para>
        /// <para>
        /// The resultant quote is specified by {@code targetConvention}.
        ///
        /// </para>
        /// </summary>
        /// <param name="trades">  the trades </param>
        /// <param name="quotes">  the quotes </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="targetConvention">  the target convention </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the quotes </returns>
        public virtual IList <CdsQuote> quotesFromParSpread(IList <ResolvedCdsTrade> trades, IList <CdsQuote> quotes, CreditRatesProvider ratesProvider, CdsQuoteConvention targetConvention, ReferenceData refData)
        {
            ArgChecker.noNulls(trades, "trades");
            ArgChecker.noNulls(quotes, "quotes");
            ArgChecker.notNull(ratesProvider, "ratesProvider");
            ArgChecker.notNull(targetConvention, "targetConvention");
            ArgChecker.notNull(refData, "refData");

            int nNodes = trades.Count;

            ArgChecker.isTrue(quotes.Count == nNodes, "trades and quotes must be the same size");
            quotes.ForEach(q => ArgChecker.isTrue(q.QuoteConvention.Equals(CdsQuoteConvention.PAR_SPREAD), "quote must be par spread"));
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <StandardId> legalEntities = trades.Select(t => t.Product.LegalEntityId).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            StandardId legalEntityId = legalEntities.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(legalEntities.hasNext(), "legal entity must be common to trades");
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <Currency> currencies = trades.Select(t => t.Product.Currency).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Currency currency = currencies.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(currencies.hasNext(), "currency must be common to trades");

            LocalDate             valuationDate    = ratesProvider.ValuationDate;
            CreditDiscountFactors discountFactors  = ratesProvider.discountFactors(currency);
            RecoveryRates         recoveryRates    = ratesProvider.recoveryRates(legalEntityId);
            NodalCurve            creditCurve      = calibrator.calibrate(trades, DoubleArray.of(nNodes, q => quotes[q].QuotedValue), DoubleArray.filled(nNodes), CurveName.of("temp"), valuationDate, discountFactors, recoveryRates, refData);
            CreditRatesProvider   ratesProviderNew = ratesProvider.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, creditCurve)))).build();

            System.Func <ResolvedCdsTrade, CdsQuote> quoteValueFunction = createQuoteValueFunction(ratesProviderNew, targetConvention, refData);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ImmutableList <CdsQuote> result = trades.Select(c => quoteValueFunction(c)).collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList.copyOf));

            return(result);
        }
Example #28
0
        /// <summary>
        /// Converts points upfront to quoted spread.
        /// <para>
        /// Thus {@code quote} must be {@code CdsQuoteConvention.POINTS_UPFRONT}.
        /// </para>
        /// <para>
        /// The relevant discount curve and recovery rate curve must be stored in {@code ratesProvider}.
        /// The credit curve is internally calibrated to convert one quote type to the other quote type.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="quote">  the quote </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the quote </returns>
        public virtual CdsQuote quotedSpreadFromPointsUpfront(ResolvedCdsTrade trade, CdsQuote quote, CreditRatesProvider ratesProvider, ReferenceData refData)
        {
            ArgChecker.notNull(trade, "trade");
            ArgChecker.notNull(quote, "quote");
            ArgChecker.notNull(ratesProvider, "ratesProvider");
            ArgChecker.notNull(refData, "refData");
            ArgChecker.isTrue(quote.QuoteConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT), "quote must be points upfront");

            ResolvedCds         product          = trade.Product;
            Currency            currency         = product.Currency;
            StandardId          legalEntityId    = product.LegalEntityId;
            LocalDate           valuationDate    = ratesProvider.ValuationDate;
            NodalCurve          creditCurve      = calibrator.calibrate(ImmutableList.of(trade), DoubleArray.of(product.FixedRate), DoubleArray.of(quote.QuotedValue), CurveName.of("temp"), valuationDate, ratesProvider.discountFactors(currency), ratesProvider.recoveryRates(legalEntityId), refData);
            CreditRatesProvider ratesProviderNew = ratesProvider.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, creditCurve)))).build();
            double sp = pricer.parSpread(trade, ratesProviderNew, refData);

            return(CdsQuote.of(CdsQuoteConvention.QUOTED_SPREAD, sp));
        }
Example #29
0
        //-------------------------------------------------------------------------
        private static CreditRatesProvider createCreditRatesProviderSingle(LocalDate valuationDate, bool isSingle)
        {
            IsdaCreditDiscountFactors yc = IsdaCreditDiscountFactors.of(USD, valuationDate, NODAL_YC);
            CreditDiscountFactors     cc = isSingle ? IsdaCreditDiscountFactors.of(USD, valuationDate, NODAL_CC_SINGLE) : IsdaCreditDiscountFactors.of(USD, valuationDate, NODAL_CC);
            ConstantRecoveryRates     rr = ConstantRecoveryRates.of(INDEX_ID, valuationDate, RECOVERY_RATE);

            return(ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).creditCurves(ImmutableMap.of(Pair.of(INDEX_ID, USD), LegalEntitySurvivalProbabilities.of(INDEX_ID, cc))).discountCurves(ImmutableMap.of(USD, yc)).recoveryRateCurves(ImmutableMap.of(INDEX_ID, rr)).build());
        }
Example #30
0
        //-------------------------------------------------------------------------
        public virtual void test_survivalProbability()
        {
            LegalEntitySurvivalProbabilities test = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);

            assertEquals(test.survivalProbability(DATE_AFTER), DFS.discountFactor(DATE_AFTER));
        }