protected void checkCdsBucket(ResolvedCdsTrade trade, List<ResolvedCdsTrade> bucketCds) { Iterator<StandardId> legalEntities = bucketCds.stream().map(t -> t.getProduct().getLegalEntityId()).collect(Collectors.toSet()).iterator(); ArgChecker.isTrue(legalEntities.next().equals(trade.getProduct().getLegalEntityId()), "legal entity must be common"); ArgChecker.isFalse(legalEntities.hasNext(), "legal entity must be common"); Iterator<Currency> currencies = bucketCds.stream().map(t -> t.getProduct().getCurrency()).collect(Collectors.toSet()).iterator(); ArgChecker.isTrue(currencies.next().equals(trade.getProduct().getCurrency()), "currency must be common"); ArgChecker.isFalse(currencies.hasNext(), "currency must be common"); }
@Override public CurrencyAmount parallelCs01( ResolvedCdsTrade trade, List<ResolvedCdsTrade> bucketCds, CreditRatesProvider ratesProvider, ReferenceData refData) { DoubleArray temp = computedBucketedCs01(trade, bucketCds, ratesProvider, refData); return CurrencyAmount.of(trade.getProduct().getCurrency(), temp.sum()); }
private ImmutableList<ResolvedCdsTrade> getBucketCds(ResolvedCds product, CreditRatesProvider ratesProvider) { CreditDiscountFactors creditCurve = ratesProvider.survivalProbabilities(product.getLegalEntityId(), product.getCurrency()).getSurvivalProbabilities(); int nNodes = creditCurve.getParameterCount(); Builder<ResolvedCdsTrade> builder = ImmutableList.builder(); for (int i = 0; i < nNodes; ++i) { ParameterMetadata metadata = creditCurve.getParameterMetadata(i); ArgChecker.isTrue(metadata instanceof ResolvedTradeParameterMetadata, "ParameterMetadata of credit curve must be ResolvedTradeParameterMetadata"); ResolvedTradeParameterMetadata tradeMetadata = (ResolvedTradeParameterMetadata) metadata; ResolvedTrade trade = tradeMetadata.getTrade(); ArgChecker.isTrue(trade instanceof ResolvedCdsTrade, "ResolvedTrade must be ResolvedCdsTrade"); builder.add((ResolvedCdsTrade) trade); } return builder.build(); }
private CurrencyParameterSensitivity bucketedCs01( ResolvedCdsTrade trade, List<ResolvedCdsTrade> bucketCds, List<ResolvedTradeParameterMetadata> metadata, CreditRatesProvider ratesProvider, ReferenceData refData) { DoubleArray sensiValue = computedBucketedCs01(trade, bucketCds, ratesProvider, refData); return CurrencyParameterSensitivity.of( CurveName.of("impliedSpreads"), metadata, trade.getProduct().getCurrency(), sensiValue); }
/** * Calculates the expected loss of the CDS product. * <p> * The expected loss is the (undiscounted) expected default settlement value paid by the protection seller. * The resulting value is always positive. * * @param cds the product * @param ratesProvider the rates provider * @return the expected loss */ public CurrencyAmount expectedLoss( ResolvedCds cds, CreditRatesProvider ratesProvider) { if (isExpired(cds, ratesProvider)) { return CurrencyAmount.of(cds.getCurrency(), 0d); } double recoveryRate = recoveryRate(cds, ratesProvider); Pair<CreditDiscountFactors, LegalEntitySurvivalProbabilities> rates = reduceDiscountFactors(cds, ratesProvider); double survivalProbability = rates.getSecond().survivalProbability(cds.getProtectionEndDate()); double el = (1d - recoveryRate) * (1d - survivalProbability); return CurrencyAmount.of(cds.getCurrency(), Math.abs(cds.getNotional()) * el); }
private double getIndexFactor(ResolvedCds cds, CreditRatesProvider ratesProvider) { LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.getLegalEntityId(), cds.getCurrency()); // instance is checked in pricer double indexFactor = ((IsdaCreditDiscountFactors) survivalProbabilities.getSurvivalProbabilities()) .getCurve() .getMetadata() .getInfo(CurveInfoType.CDS_INDEX_FACTOR); return indexFactor; }
/** * Calculates the risky PV01 of the CDS product. * <p> * RPV01 is defined as minus of the present value sensitivity to coupon rate. * * @param cds the product * @param ratesProvider the rates provider * @param referenceDate the reference date * @param priceType the price type * @param refData the reference date * @return the RPV01 */ public CurrencyAmount rpv01( ResolvedCds cds, CreditRatesProvider ratesProvider, LocalDate referenceDate, PriceType priceType, ReferenceData refData) { double riskyAnnuity = riskyAnnuity(cds, ratesProvider, referenceDate, priceType, refData); return CurrencyAmount.of(cds.getCurrency(), cds.getBuySell().normalize(cds.getNotional()) * riskyAnnuity); }
/** * Calculates the present value of the CDS product. * <p> * The present value of the product is based on {@code referenceDate}. * This is typically the valuation date, or cash settlement date if the product is associated with a {@code Trade}. * <p> * This method can calculate the clean or dirty present value, see {@link PriceType}. * If calculating the clean value, the accrued interest is calculated based on the step-in date. * * @param cds the product * @param ratesProvider the rates provider * @param referenceDate the reference date * @param priceType the price type * @param refData the reference data * @return the present value */ public CurrencyAmount presentValue( ResolvedCds cds, CreditRatesProvider ratesProvider, LocalDate referenceDate, PriceType priceType, ReferenceData refData) { double price = price(cds, ratesProvider, referenceDate, priceType, refData); return CurrencyAmount.of(cds.getCurrency(), cds.getBuySell().normalize(cds.getNotional()) * price); }
Currency currency = cdsProduct.getCurrency(); StandardId legalEntityId = cdsProduct.getLegalEntityId(); Pair<StandardId, Currency> pair = Pair.of(legalEntityId, currency);
private Pair<CreditDiscountFactors, LegalEntitySurvivalProbabilities> reduceDiscountFactors( ResolvedCds cds, CreditRatesProvider ratesProvider) { Currency currency = cds.getCurrency(); CreditDiscountFactors discountFactors = ratesProvider.discountFactors(currency); ArgChecker.isTrue(discountFactors.isIsdaCompliant(), "discount factors must be IsdaCompliantZeroRateDiscountFactors"); LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.getLegalEntityId(), currency); ArgChecker.isTrue(survivalProbabilities.getSurvivalProbabilities().isIsdaCompliant(), "survival probabilities must be IsdaCompliantZeroRateDiscountFactors"); ArgChecker.isTrue(discountFactors.getDayCount().equals(survivalProbabilities.getSurvivalProbabilities().getDayCount()), "day count conventions of discounting curve and credit curve must be the same"); return Pair.of(discountFactors, survivalProbabilities); }
/** * Calculates the recovery01 of the CDS product. * <p> * The recovery01 is defined as the present value sensitivity to the recovery rate. * Since the ISDA standard model requires the recovery rate to be constant throughout the lifetime of the CDS, * one currency amount is returned by this method. * * @param cds the product * @param ratesProvider the rates provider * @param referenceDate the reference date * @param refData the reference data * @return the recovery01 */ public CurrencyAmount recovery01( ResolvedCds cds, CreditRatesProvider ratesProvider, LocalDate referenceDate, ReferenceData refData) { if (isExpired(cds, ratesProvider)) { return CurrencyAmount.of(cds.getCurrency(), 0d); } LocalDate stepinDate = cds.getStepinDateOffset().adjust(ratesProvider.getValuationDate(), refData); LocalDate effectiveStartDate = cds.calculateEffectiveStartDate(stepinDate); validateRecoveryRates(cds, ratesProvider); Pair<CreditDiscountFactors, LegalEntitySurvivalProbabilities> rates = reduceDiscountFactors(cds, ratesProvider); double protectionFull = protectionFull(cds, rates.getFirst(), rates.getSecond(), referenceDate, effectiveStartDate); return CurrencyAmount.of(cds.getCurrency(), -cds.getBuySell().normalize(cds.getNotional()) * protectionFull); }
/** * Calculates the expected loss of the CDS index product. * <p> * The expected loss is the (undiscounted) expected default settlement value paid by the protection seller. * The resulting value is always positive. * * @param cdsIndex the product * @param ratesProvider the rates provider * @return the expected loss */ public CurrencyAmount expectedLoss( ResolvedCdsIndex cdsIndex, CreditRatesProvider ratesProvider) { if (isExpired(cdsIndex, ratesProvider)) { return CurrencyAmount.of(cdsIndex.getCurrency(), 0d); } ResolvedCds cds = cdsIndex.toSingleNameCds(); double recoveryRate = underlyingPricer.recoveryRate(cds, ratesProvider); Triple<CreditDiscountFactors, LegalEntitySurvivalProbabilities, Double> rates = reduceDiscountFactors(cds, ratesProvider); double survivalProbability = rates.getSecond().survivalProbability(cds.getProtectionEndDate()); double el = (1d - recoveryRate) * (1d - survivalProbability) * rates.getThird(); return CurrencyAmount.of(cds.getCurrency(), Math.abs(cds.getNotional()) * el); }
public void test_builder() { ResolvedCds test = ResolvedCds.builder() .buySell(BUY) .dayCount(ACT_360) .legalEntityId(LEGAL_ENTITY) .paymentOnDefault(ACCRUED_PREMIUM) .protectionStart(BEGINNING) .paymentPeriods(PAYMENTS) .protectionEndDate(PAYMENTS.get(PAYMENTS.size() - 1).getEffectiveEndDate()) .settlementDateOffset(SETTLE_DAY_ADJ) .stepinDateOffset(STEPIN_DAY_ADJ) .build(); assertEquals(test.getBuySell(), BUY); assertEquals(test.getCurrency(), USD); assertEquals(test.getAccrualStartDate(), PAYMENTS.get(0).getStartDate()); assertEquals(test.getAccrualEndDate(), PAYMENTS.get(42).getEndDate()); assertEquals(test.getDayCount(), ACT_360); assertEquals(test.getFixedRate(), COUPON); assertEquals(test.getLegalEntityId(), LEGAL_ENTITY); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getPaymentOnDefault(), ACCRUED_PREMIUM); assertEquals(test.getPaymentPeriods(), PAYMENTS); assertEquals(test.getProtectionEndDate(), PAYMENTS.get(42).getEffectiveEndDate()); assertEquals(test.getSettlementDateOffset(), SETTLE_DAY_ADJ); assertEquals(test.getProtectionStart(), BEGINNING); assertEquals(test.getStepinDateOffset(), STEPIN_DAY_ADJ); }
Triple<CreditDiscountFactors, LegalEntitySurvivalProbabilities, Double> reduceDiscountFactors( ResolvedCds cds, CreditRatesProvider ratesProvider) { Currency currency = cds.getCurrency(); CreditDiscountFactors discountFactors = ratesProvider.discountFactors(currency); ArgChecker.isTrue(discountFactors.isIsdaCompliant(), "discount factors must be IsdaCompliantZeroRateDiscountFactors"); LegalEntitySurvivalProbabilities survivalProbabilities = ratesProvider.survivalProbabilities(cds.getLegalEntityId(), currency); ArgChecker.isTrue(survivalProbabilities.getSurvivalProbabilities().isIsdaCompliant(), "survival probabilities must be IsdaCompliantZeroRateDiscountFactors"); ArgChecker.isTrue(discountFactors.getDayCount().equals(survivalProbabilities.getSurvivalProbabilities().getDayCount()), "day count conventions of discounting curve and credit curve must be the same"); double indexFactor = ((IsdaCreditDiscountFactors) survivalProbabilities.getSurvivalProbabilities()) .getCurve().getMetadata().getInfo(CurveInfoType.CDS_INDEX_FACTOR); return Triple.of(discountFactors, survivalProbabilities, indexFactor); }
Currency currency = cds.getCurrency(); if (isExpired(cds, ratesProvider)) { return JumpToDefault.of(currency, ImmutableMap.of(legalEntityId, 0d));
Currency currency = product.getCurrency(); StandardId legalEntityId = product.getLegalEntityId(); LocalDate valuationDate = ratesProvider.getValuationDate();
Currency currency = product.getCurrency(); StandardId legalEntityId = product.getLegalEntityId(); LocalDate valuationDate = ratesProvider.getValuationDate();
/** * Calculates the risky PV01 of the CDS index product. * <p> * RPV01 is defined as minus of the present value sensitivity to coupon rate. * * @param cdsIndex the product * @param ratesProvider the rates provider * @param referenceDate the reference date * @param priceType the price type * @param refData the reference date * @return the RPV01 */ public CurrencyAmount rpv01( ResolvedCdsIndex cdsIndex, CreditRatesProvider ratesProvider, LocalDate referenceDate, PriceType priceType, ReferenceData refData) { if (isExpired(cdsIndex, ratesProvider)) { return CurrencyAmount.of(cdsIndex.getCurrency(), 0d); } ResolvedCds cds = cdsIndex.toSingleNameCds(); LocalDate stepinDate = cds.getStepinDateOffset().adjust(ratesProvider.getValuationDate(), refData); LocalDate effectiveStartDate = cds.calculateEffectiveStartDate(stepinDate); Triple<CreditDiscountFactors, LegalEntitySurvivalProbabilities, Double> rates = reduceDiscountFactors(cds, ratesProvider); double riskyAnnuity = underlyingPricer.riskyAnnuity( cds, rates.getFirst(), rates.getSecond(), referenceDate, stepinDate, effectiveStartDate, priceType); double amount = cds.getBuySell().normalize(cds.getNotional()) * riskyAnnuity * rates.getThird(); return CurrencyAmount.of(cds.getCurrency(), amount); }
underlyingPricer.protectionFull(cds, rates.getFirst(), rates.getSecond(), referenceDate, effectiveStartDate); double amount = -cds.getBuySell().normalize(cds.getNotional()) * protectionFull * rates.getThird(); return CurrencyAmount.of(cds.getCurrency(), amount);
double amount = cds.getBuySell().normalize(cds.getNotional()) * rates.getThird() * (protectionLeg - rpv01 * cds.getFixedRate()); return CurrencyAmount.of(cds.getCurrency(), amount);