Example #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));
        }
Example #2
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;
 }
Example #3
0
            public Pricer(FastCreditCurveCalibrator outerInstance, ResolvedCds nodeCds, CreditDiscountFactors yieldCurve, DoubleArray creditCurveKnots, double fractionalSpread, double pointsUpfront, double lgd, LocalDate stepinDate, LocalDate effectiveStartDate, LocalDate settlementDate, double accruedYearFraction)
            {
                this.outerInstance = outerInstance;

                accYearFraction       = accruedYearFraction;
                cds                   = nodeCds;
                fracSpread            = fractionalSpread;
                puf                   = pointsUpfront;
                productEffectiveStart = yieldCurve.relativeYearFraction(effectiveStartDate);
                double protectionEnd = yieldCurve.relativeYearFraction(cds.ProtectionEndDate);

                // protection leg
                proLegIntPoints = DoublesScheduleGenerator.getIntegrationsPoints(productEffectiveStart, protectionEnd, yieldCurve.ParameterKeys, creditCurveKnots).toArray();
                nProPoints      = proLegIntPoints.Length;
                valuationDF     = yieldCurve.discountFactor(settlementDate);
                lgdDF           = lgd / valuationDF;
                proYieldCurveRT = new double[nProPoints];
                proDF           = new double[nProPoints];
                for (int i = 0; i < nProPoints; i++)
                {
                    proYieldCurveRT[i] = yieldCurve.zeroRate(proLegIntPoints[i]) * proLegIntPoints[i];
                    proDF[i]           = Math.Exp(-proYieldCurveRT[i]);
                }
                // premium leg
                nPayments = cds.PaymentPeriods.size();
                paymentDF = new double[nPayments];
                int indexTmp = -1;

                for (int i = 0; i < nPayments; i++)
                {
                    if (stepinDate.isBefore(cds.PaymentPeriods.get(i).EndDate))
                    {
                        paymentDF[i] = yieldCurve.discountFactor(cds.PaymentPeriods.get(i).PaymentDate);
                    }
                    else
                    {
                        indexTmp = i;
                    }
                }
                startPeriodIndex = indexTmp + 1;
                // accrual on default
                if (cds.PaymentOnDefault.AccruedInterest)
                {
                    LocalDate   tmp = nPayments == 1 ? effectiveStartDate : cds.AccrualStartDate;
                    DoubleArray integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(yieldCurve.relativeYearFraction(tmp), protectionEnd, yieldCurve.ParameterKeys, creditCurveKnots);
                    accRate          = new double[nPayments];
                    offsetAccStart   = new double[nPayments];
                    offsetAccEnd     = new double[nPayments];
                    premLegIntPoints = new double[nPayments][];
                    premDF           = new double[nPayments][];
                    rt     = new double[nPayments][];
                    premDt = new double[nPayments][];
                    for (int i = startPeriodIndex; i < nPayments; i++)
                    {
                        CreditCouponPaymentPeriod coupon = cds.PaymentPeriods.get(i);
                        offsetAccStart[i] = yieldCurve.relativeYearFraction(coupon.EffectiveStartDate);
                        offsetAccEnd[i]   = yieldCurve.relativeYearFraction(coupon.EffectiveEndDate);
                        accRate[i]        = coupon.YearFraction / yieldCurve.DayCount.relativeYearFraction(coupon.StartDate, coupon.EndDate);
                        double start = Math.Max(productEffectiveStart, offsetAccStart[i]);
                        if (start >= offsetAccEnd[i])
                        {
                            continue;
                        }
                        premLegIntPoints[i] = DoublesScheduleGenerator.truncateSetInclusive(start, offsetAccEnd[i], integrationSchedule).toArray();
                        int n = premLegIntPoints[i].Length;
                        rt[i]     = new double[n];
                        premDF[i] = new double[n];
                        for (int k = 0; k < n; k++)
                        {
                            rt[i][k]     = yieldCurve.zeroRate(premLegIntPoints[i][k]) * premLegIntPoints[i][k];
                            premDF[i][k] = Math.Exp(-rt[i][k]);
                        }
                        premDt[i] = new double[n - 1];

                        for (int k = 1; k < n; k++)
                        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double dt = premLegIntPoints[i][k] - premLegIntPoints[i][k - 1];
                            double dt = premLegIntPoints[i][k] - premLegIntPoints[i][k - 1];
                            premDt[i][k - 1] = dt;
                        }
                    }
                }
                else
                {
                    accRate          = null;
                    offsetAccStart   = null;
                    offsetAccEnd     = null;
                    premDF           = null;
                    premDt           = null;
                    rt               = null;
                    premLegIntPoints = null;
                }
            }