示例#1
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);
        }
示例#2
0
        internal virtual PointSensitivityBuilder riskyAnnuitySensitivity(ResolvedCds cds, CreditDiscountFactors discountFactors, LegalEntitySurvivalProbabilities survivalProbabilities, LocalDate referenceDate, LocalDate stepinDate, LocalDate effectiveStartDate)
        {
            double pv = 0d;
            PointSensitivityBuilder pvSensi = PointSensitivityBuilder.none();

            foreach (CreditCouponPaymentPeriod coupon in cds.PaymentPeriods)
            {
                if (stepinDate.isBefore(coupon.EndDate))
                {
                    double q = survivalProbabilities.survivalProbability(coupon.EffectiveEndDate);
                    PointSensitivityBuilder qSensi = survivalProbabilities.zeroRatePointSensitivity(coupon.EffectiveEndDate);
                    double p = discountFactors.discountFactor(coupon.PaymentDate);
                    PointSensitivityBuilder pSensi = discountFactors.zeroRatePointSensitivity(coupon.PaymentDate);
                    pv     += coupon.YearFraction * p * q;
                    pvSensi = pvSensi.combinedWith(pSensi.multipliedBy(coupon.YearFraction * q).combinedWith(qSensi.multipliedBy(coupon.YearFraction * p)));
                }
            }

            if (cds.PaymentOnDefault.AccruedInterest)
            {
                // This is needed so that the code is consistent with ISDA C when the Markit `fix' is used.
                LocalDate   start = cds.PaymentPeriods.size() == 1 ? effectiveStartDate : cds.AccrualStartDate;
                DoubleArray integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(discountFactors.relativeYearFraction(start), discountFactors.relativeYearFraction(cds.ProtectionEndDate), discountFactors.ParameterKeys, survivalProbabilities.ParameterKeys);
                foreach (CreditCouponPaymentPeriod coupon in cds.PaymentPeriods)
                {
                    Pair <double, PointSensitivityBuilder> pvAndSensi = singlePeriodAccrualOnDefaultSensitivity(coupon, effectiveStartDate, integrationSchedule, discountFactors, survivalProbabilities);
                    pv     += pvAndSensi.First;
                    pvSensi = pvSensi.combinedWith(pvAndSensi.Second);
                }
            }

            double df = discountFactors.discountFactor(referenceDate);
            PointSensitivityBuilder dfSensi = discountFactors.zeroRatePointSensitivity(referenceDate).multipliedBy(-pv / (df * df));

            pvSensi = pvSensi.multipliedBy(1d / df);

            return(dfSensi.combinedWith(pvSensi));
        }
示例#3
0
        // computes risky annuity
        internal virtual double riskyAnnuity(ResolvedCds cds, CreditDiscountFactors discountFactors, LegalEntitySurvivalProbabilities survivalProbabilities, LocalDate referenceDate, LocalDate stepinDate, LocalDate effectiveStartDate, PriceType priceType)
        {
            double pv = 0d;

            foreach (CreditCouponPaymentPeriod coupon in cds.PaymentPeriods)
            {
                if (stepinDate.isBefore(coupon.EndDate))
                {
                    double q = survivalProbabilities.survivalProbability(coupon.EffectiveEndDate);
                    double p = discountFactors.discountFactor(coupon.PaymentDate);
                    pv += coupon.YearFraction * p * q;
                }
            }

            if (cds.PaymentOnDefault.AccruedInterest)
            {
                // This is needed so that the code is consistent with ISDA C when the Markit `fix' is used.
                LocalDate   start = cds.PaymentPeriods.size() == 1 ? effectiveStartDate : cds.AccrualStartDate;
                DoubleArray integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(discountFactors.relativeYearFraction(start), discountFactors.relativeYearFraction(cds.ProtectionEndDate), discountFactors.ParameterKeys, survivalProbabilities.ParameterKeys);
                foreach (CreditCouponPaymentPeriod coupon in cds.PaymentPeriods)
                {
                    pv += singlePeriodAccrualOnDefault(coupon, effectiveStartDate, integrationSchedule, discountFactors, survivalProbabilities);
                }
            }
            // roll to the cash settle date
            double df = discountFactors.discountFactor(referenceDate);

            pv /= df;

            if (priceType.CleanPrice)
            {
                pv -= cds.accruedYearFraction(stepinDate);
            }

            return(pv);
        }
示例#4
0
        //-------------------------------------------------------------------------
        public virtual void test_survivalProbability()
        {
            LegalEntitySurvivalProbabilities test = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);

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