//-------------------------------------------------------------------------
        public virtual void test_jumpToDefault()
        {
            JumpToDefault computed = PRICER.jumpToDefault(TRADE, RATES_PROVIDER, REF_DATA);
            JumpToDefault expected = PRICER_PRODUCT.jumpToDefault(PRODUCT, RATES_PROVIDER, SETTLEMENT_DATE, REF_DATA);

            assertEquals(computed, expected);
        }
Example #2
0
        public virtual void endedTest()
        {
            LocalDate           valuationDate = PRODUCT.ProtectionEndDate.plusDays(1);
            CreditRatesProvider provider      = createCreditRatesProviderSingle(valuationDate, false);
            double price = PRICER.price(PRODUCT, provider, SETTLEMENT_STD, CLEAN, REF_DATA);

            assertEquals(price, 0d);
            CurrencyAmount pv = PRICER.presentValue(PRODUCT, provider, SETTLEMENT_STD, CLEAN, REF_DATA);

            assertEquals(pv, CurrencyAmount.zero(USD));
            assertThrowsIllegalArg(() => PRICER.parSpread(PRODUCT, provider, SETTLEMENT_STD, REF_DATA));
            CurrencyAmount rpv01 = PRICER.rpv01(PRODUCT, provider, SETTLEMENT_STD, CLEAN, REF_DATA);

            assertEquals(rpv01, CurrencyAmount.zero(USD));
            CurrencyAmount recovery01 = PRICER.recovery01(PRODUCT, provider, SETTLEMENT_STD, REF_DATA);

            assertEquals(recovery01, CurrencyAmount.zero(USD));
            PointSensitivityBuilder sensi = PRICER.presentValueSensitivity(PRODUCT, provider, SETTLEMENT_STD, REF_DATA);

            assertEquals(sensi, PointSensitivityBuilder.none());
            PointSensitivityBuilder sensiPrice = PRICER.priceSensitivity(PRODUCT, provider, SETTLEMENT_STD, REF_DATA);

            assertEquals(sensiPrice, PointSensitivityBuilder.none());
            assertThrowsIllegalArg(() => PRICER.parSpreadSensitivity(PRODUCT, provider, SETTLEMENT_STD, REF_DATA));
            JumpToDefault jumpToDefault = PRICER.jumpToDefault(PRODUCT, provider, SETTLEMENT_STD, REF_DATA);

            assertEquals(jumpToDefault, JumpToDefault.of(USD, ImmutableMap.of(INDEX_ID, 0d)));
            CurrencyAmount expectedLoss = PRICER.expectedLoss(PRODUCT, provider);

            assertEquals(expectedLoss, CurrencyAmount.zero(USD));
        }
        public virtual void test_of()
        {
            JumpToDefault test = JumpToDefault.of(GBP, ImmutableMap.of(ID_ABC, 1.1d, ID_DEF, 2.2d));

            assertEquals(test.Currency, GBP);
            assertEquals(test.Amounts.size(), 2);
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            JumpToDefault test = JumpToDefault.of(GBP, ImmutableMap.of(ID_ABC, 1.1d, ID_DEF, 2.2d));

            coverImmutableBean(test);
            JumpToDefault test2 = JumpToDefault.of(USD, ImmutableMap.of(ID_DEF, 2.3d));

            coverBeanEquals(test, test2);
        }
Example #5
0
        //-------------------------------------------------------------------------
        public virtual void jumpToDefaultTest()
        {
            JumpToDefault computed   = PRICER.jumpToDefault(PRODUCT, RATES_PROVIDER, SETTLEMENT_STD, REF_DATA);
            LocalDate     stepinDate = PRODUCT.StepinDateOffset.adjust(VALUATION_DATE, REF_DATA);
            double        dirtyPvMod = PRICER.presentValue(PRODUCT, RATES_PROVIDER, SETTLEMENT_STD, PriceType.DIRTY, REF_DATA).Amount / INDEX_FACTOR;
            double        accrued    = PRODUCT.accruedYearFraction(stepinDate) * PRODUCT.FixedRate * PRODUCT.BuySell.normalize(NOTIONAL);
            double        protection = PRODUCT.BuySell.normalize(NOTIONAL) * (1d - RECOVERY_RATE);
            double        expected   = (protection - accrued - dirtyPvMod) / ((double)LEGAL_ENTITIES.size());

            assertEquals(computed.Currency, USD);
            assertTrue(computed.Amounts.size() == 1);
            assertEquals(computed.Amounts.get(INDEX_ID), expected, NOTIONAL * TOL);
        }
Example #6
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the jump-to-default of the CDS product.
        /// <para>
        /// The jump-to-default is the value of the product in case of immediate default.
        ///
        /// </para>
        /// </summary>
        /// <param name="cds">  the product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="referenceDate">  the reference date </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the jump-to-default </returns>
        public virtual JumpToDefault jumpToDefault(ResolvedCds cds, CreditRatesProvider ratesProvider, LocalDate referenceDate, ReferenceData refData)
        {
            StandardId legalEntityId = cds.LegalEntityId;
            Currency   currency      = cds.Currency;

            if (isExpired(cds, ratesProvider))
            {
                return(JumpToDefault.of(currency, ImmutableMap.of(legalEntityId, 0d)));
            }
            LocalDate stepinDate         = cds.StepinDateOffset.adjust(ratesProvider.ValuationDate, refData);
            LocalDate effectiveStartDate = cds.calculateEffectiveStartDate(stepinDate);
            double    recoveryRate       = this.recoveryRate(cds, ratesProvider);
            Pair <CreditDiscountFactors, LegalEntitySurvivalProbabilities> rates = reduceDiscountFactors(cds, ratesProvider);
            double protectionFull = this.protectionFull(cds, rates.First, rates.Second, referenceDate, effectiveStartDate);
            double lgd            = 1d - recoveryRate;
            double rpv01          = riskyAnnuity(cds, rates.First, rates.Second, referenceDate, stepinDate, effectiveStartDate, PriceType.CLEAN);
            double jtd            = lgd - (lgd * protectionFull - cds.FixedRate * rpv01);

            return(JumpToDefault.of(currency, ImmutableMap.of(legalEntityId, cds.BuySell.normalize(cds.Notional) * jtd)));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the jump-to-default of the CDS index product.
        /// <para>
        /// The jump-to-default is the value of the product in case of immediate default of a constituent single name.
        /// </para>
        /// <para>
        /// Under the homogeneous pool assumption, the jump-to-default values are the same for all of the undefaulted names,
        /// and zero for defaulted names. Thus the resulting object contains a single number.
        ///
        /// </para>
        /// </summary>
        /// <param name="cdsIndex">  the product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="referenceDate">  the reference date </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the recovery01 </returns>
        public virtual JumpToDefault jumpToDefault(ResolvedCdsIndex cdsIndex, CreditRatesProvider ratesProvider, LocalDate referenceDate, ReferenceData refData)
        {
            StandardId indexId  = cdsIndex.CdsIndexId;
            Currency   currency = cdsIndex.Currency;

            if (isExpired(cdsIndex, ratesProvider))
            {
                return(JumpToDefault.of(currency, ImmutableMap.of(indexId, 0d)));
            }
            ResolvedCds cds                = cdsIndex.toSingleNameCds();
            LocalDate   stepinDate         = cds.StepinDateOffset.adjust(ratesProvider.ValuationDate, refData);
            LocalDate   effectiveStartDate = cds.calculateEffectiveStartDate(stepinDate);
            double      recoveryRate       = underlyingPricer.recoveryRate(cds, ratesProvider);
            Triple <CreditDiscountFactors, LegalEntitySurvivalProbabilities, double> rates = reduceDiscountFactors(cds, ratesProvider);
            double protectionFull = underlyingPricer.protectionFull(cds, rates.First, rates.Second, referenceDate, effectiveStartDate);
            double rpv01          = underlyingPricer.riskyAnnuity(cds, rates.First, rates.Second, referenceDate, stepinDate, effectiveStartDate, PriceType.CLEAN);
            double lgd            = 1d - recoveryRate;
            double numTotal       = cdsIndex.LegalEntityIds.size();
            double jtd            = (lgd - (lgd * protectionFull - cds.FixedRate * rpv01)) / numTotal;

            return(JumpToDefault.of(currency, ImmutableMap.of(indexId, cds.BuySell.normalize(cds.Notional) * jtd)));
        }