Ejemplo n.º 1
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));
        }
        protected internal virtual void testJacobian(IsdaCompliantCreditCurveCalibrator builder, LegalEntitySurvivalProbabilities curve, ImmutableCreditRatesProvider ratesProvider, IList <CdsIsdaCreditCurveNode> nodes, double[] quotes, double quoteScale, double eps)
        {
            LocalDate valuationDate      = curve.ValuationDate;
            int       nNode              = nodes.Count;
            IsdaCreditDiscountFactors df = (IsdaCreditDiscountFactors)curve.SurvivalProbabilities;
            CurveName name       = df.Curve.Name;
            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 / quoteScale;
                quotesDw[i] -= eps / quoteScale;
                ImmutableMarketDataBuilder builderCreditUp = ImmutableMarketData.builder(valuationDate);
                ImmutableMarketDataBuilder builderCreditDw = ImmutableMarketData.builder(valuationDate);
                for (int j = 0; j < nNode; ++j)
                {
                    builderCreditUp.addValue(nodes[j].ObservableId, quotesUp[j] * quoteScale);
                    builderCreditDw.addValue(nodes[j].ObservableId, quotesDw[j] * quoteScale);
                }
                ImmutableMarketData       marketDataUp = builderCreditUp.build();
                ImmutableMarketData       marketDataDw = builderCreditDw.build();
                IsdaCreditDiscountFactors ccUp         = (IsdaCreditDiscountFactors)builder.calibrate(nodes, name, marketDataUp, ratesProvider, curve.SurvivalProbabilities.DayCount, curve.Currency, false, false, REF_DATA).SurvivalProbabilities;
                IsdaCreditDiscountFactors ccDw         = (IsdaCreditDiscountFactors)builder.calibrate(nodes, name, marketDataDw, ratesProvider, curve.SurvivalProbabilities.DayCount, curve.Currency, false, false, 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);
                }
            }
        }
        //-------------------------------------------------------------------------
        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);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// The constructor with the accrual-on-default formula specified.
 /// </summary>
 /// <param name="formula">  the accrual-on-default formula </param>
 public CdsMarketQuoteConverter(AccrualOnDefaultFormula formula)
 {
     this.calibrator = new FastCreditCurveCalibrator(formula);
     this.pricer     = new IsdaCdsTradePricer(formula);
 }
Ejemplo n.º 5
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// The default constructor.
 /// <para>
 /// The original ISDA accrual-on-default formula (version 1.8.2 and lower) is used.
 /// </para>
 /// </summary>
 public CdsMarketQuoteConverter()
 {
     this.calibrator = FastCreditCurveCalibrator.standard();
     this.pricer     = IsdaCdsTradePricer.DEFAULT;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor with accrual-on-default formula.
 /// </summary>
 /// <param name="formula">  the accrual-on-default formula </param>
 public SpreadSensitivityCalculator(AccrualOnDefaultFormula formula)
 {
     this.pricer     = new IsdaCdsTradePricer(formula);
     this.calibrator = new FastCreditCurveCalibrator(formula);
 }