/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(CreditCouponPaymentPeriod beanToCopy) { this.currency = beanToCopy.getCurrency(); this.notional = beanToCopy.getNotional(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.unadjustedStartDate = beanToCopy.getUnadjustedStartDate(); this.unadjustedEndDate = beanToCopy.getUnadjustedEndDate(); this.effectiveStartDate = beanToCopy.getEffectiveStartDate(); this.effectiveEndDate = beanToCopy.getEffectiveEndDate(); this.paymentDate = beanToCopy.getPaymentDate(); this.fixedRate = beanToCopy.getFixedRate(); this.yearFraction = beanToCopy.getYearFraction(); }
/** * Finds the period that contains the specified date. * <p> * The search is performed using unadjusted dates. * * @param date the date to find the period for * @return the period, empty if not found * @throws IllegalArgumentException if more than one period matches */ public Optional<CreditCouponPaymentPeriod> findPeriod(LocalDate date) { return paymentPeriods.stream() .filter(p -> p.contains(date)) .reduce(ensureOnlyOne()); }
/** * Calculates the accrued premium per fractional spread for unit notional. * * @param stepinDate the step-in date * @return the accrued year fraction */ public double accruedYearFraction(LocalDate stepinDate) { if (stepinDate.isBefore(getAccrualStartDate())) { return 0d; } if (stepinDate.isEqual(getAccrualEndDate())) { return paymentPeriods.get(paymentPeriods.size() - 1).getYearFraction(); } CreditCouponPaymentPeriod period = findPeriod(stepinDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range")); return dayCount.relativeYearFraction(period.getStartDate(), stepinDate); }
public void test_builder() { CreditCouponPaymentPeriod test = CreditCouponPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .startDate(START_DATE) .endDate(END_DATE) .effectiveStartDate(EFF_START_DATE) .effectiveEndDate(EFF_END_DATE) .paymentDate(END_DATE) .fixedRate(COUPON) .yearFraction(YEAR_FRACTION) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getEffectiveStartDate(), EFF_START_DATE); assertEquals(test.getEffectiveEndDate(), EFF_END_DATE); assertEquals(test.getStartDate(), START_DATE); assertEquals(test.getEndDate(), END_DATE); assertEquals(test.getFixedRate(), COUPON); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getPaymentDate(), END_DATE); assertEquals(test.getYearFraction(), YEAR_FRACTION); }
coupon.getEffectiveStartDate().isBefore(effectiveStartDate) ? effectiveStartDate : coupon.getEffectiveStartDate(); if (!start.isBefore(coupon.getEffectiveEndDate())) { return 0d; // this coupon has already expired discountFactors.relativeYearFraction(coupon.getEffectiveEndDate()), integrationSchedule); double b0 = Math.exp(-rt0 - ht0); double effStart = discountFactors.relativeYearFraction(coupon.getEffectiveStartDate()); double t0 = t0Knot - effStart + omega; double pv = 0d; discountFactors.getDayCount().relativeYearFraction(coupon.getStartDate(), coupon.getEndDate()); return coupon.getYearFraction() * pv / yearFractionCurve;
PointSensitivityBuilder pvSensi = PointSensitivityBuilder.none(); for (CreditCouponPaymentPeriod coupon : cds.getPaymentPeriods()) { if (stepinDate.isBefore(coupon.getEndDate())) { double q = survivalProbabilities.survivalProbability(coupon.getEffectiveEndDate()); PointSensitivityBuilder qSensi = survivalProbabilities.zeroRatePointSensitivity(coupon.getEffectiveEndDate()); double p = discountFactors.discountFactor(coupon.getPaymentDate()); PointSensitivityBuilder pSensi = discountFactors.zeroRatePointSensitivity(coupon.getPaymentDate()); pv += coupon.getYearFraction() * p * q; pvSensi = pvSensi.combinedWith(pSensi.multipliedBy(coupon.getYearFraction() * q) .combinedWith(qSensi.multipliedBy(coupon.getYearFraction() * p)));
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); }
.protectionStart(BEGINNING) .paymentPeriods(PAYMENTS) .protectionEndDate(PAYMENTS.get(PAYMENTS.size() - 1).getEffectiveEndDate()) .settlementDateOffset(SETTLE_DAY_ADJ) .stepinDateOffset(STEPIN_DAY_ADJ) .protectionStart(ProtectionStartOfDay.NONE) .paymentPeriods(PAYMENTS) .protectionEndDate(PAYMENTS.get(PAYMENTS.size() - 1).getEffectiveEndDate()) .settlementDateOffset(SETTLE_DAY_ADJ) .stepinDateOffset(STEPIN_DAY_ADJ)
public void test_contains() { CreditCouponPaymentPeriod test = CreditCouponPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .startDate(START_DATE) .endDate(END_DATE) .effectiveStartDate(EFF_START_DATE) .effectiveEndDate(EFF_END_DATE) .paymentDate(END_DATE) .fixedRate(COUPON) .yearFraction(YEAR_FRACTION) .build(); assertTrue(test.contains(START_DATE)); assertTrue(test.contains(START_DATE.plusMonths(1))); assertFalse(test.contains(END_DATE)); assertFalse(test.contains(START_DATE.minusDays(1))); }
public void test_serialization() { CreditCouponPaymentPeriod test = CreditCouponPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .startDate(START_DATE) .endDate(END_DATE) .effectiveStartDate(EFF_START_DATE) .effectiveEndDate(EFF_END_DATE) .paymentDate(END_DATE) .fixedRate(COUPON) .yearFraction(YEAR_FRACTION) .build(); assertSerialization(test); }
/** * Obtains the accrual start date. * <p> * In general this is different from the protection start date. * Use {@code stepinDateOffset} to compute the protection start date. * * @return the accrual start date */ public LocalDate getAccrualStartDate() { return paymentPeriods.get(0).getStartDate(); }
/** * Obtains the accrual end date. * * @return the accrual end date */ public LocalDate getAccrualEndDate() { return paymentPeriods.get(paymentPeriods.size() - 1).getEndDate(); }
public double rpv01(NodalCurve creditCurve, PriceType cleanOrDirty) { double pv = 0.0; for (int i = startPeriodIndex; i < nPayments; i++) { CreditCouponPaymentPeriod coupon = cds.getPaymentPeriods().get(i); double yc = offsetAccEnd[i]; double q = Math.exp(-creditCurve.yValue(yc) * yc); pv += coupon.getYearFraction() * paymentDF[i] * q; } if (cds.getPaymentOnDefault().isAccruedInterest()) { double accPV = 0.0; for (int i = startPeriodIndex; i < nPayments; i++) { accPV += calculateSinglePeriodAccrualOnDefault(i, creditCurve); } pv += accPV; } pv /= valuationDF; if (cleanOrDirty == PriceType.CLEAN) { pv -= accYearFraction; } return pv; }
/** * Obtains the currency. * * @return the currency */ public Currency getCurrency() { return paymentPeriods.get(0).getCurrency(); }
/** * Obtains the fixed coupon rate. * * @return the fixed rate */ public double getFixedRate() { return paymentPeriods.get(0).getFixedRate(); }
int indexTmp = -1; for (int i = 0; i < nPayments; i++) { if (stepinDate.isBefore(cds.getPaymentPeriods().get(i).getEndDate())) { paymentDF[i] = yieldCurve.discountFactor(cds.getPaymentPeriods().get(i).getPaymentDate()); } else { indexTmp = i; for (int i = startPeriodIndex; i < nPayments; i++) { CreditCouponPaymentPeriod coupon = cds.getPaymentPeriods().get(i); offsetAccStart[i] = yieldCurve.relativeYearFraction(coupon.getEffectiveStartDate()); offsetAccEnd[i] = yieldCurve.relativeYearFraction(coupon.getEffectiveEndDate()); accRate[i] = coupon.getYearFraction() / yieldCurve.getDayCount().relativeYearFraction(coupon.getStartDate(), coupon.getEndDate()); double start = Math.max(productEffectiveStart, offsetAccStart[i]); if (start >= offsetAccEnd[i]) {
if (stepinDate.isBefore(coupon.getEndDate())) { double q = survivalProbabilities.survivalProbability(coupon.getEffectiveEndDate()); double p = discountFactors.discountFactor(coupon.getPaymentDate()); pv += coupon.getYearFraction() * p * q;
public void test_builder() { ResolvedCdsIndex test = ResolvedCdsIndex.builder() .buySell(BUY) .dayCount(ACT_360) .cdsIndexId(INDEX_ID) .legalEntityIds(LEGAL_ENTITIES) .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.getCdsIndexId(), INDEX_ID); assertEquals(test.getLegalEntityIds(), LEGAL_ENTITIES); 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); }
public void test_serialization() { 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(); assertSerialization(test); }
/** * Calculates the accrued premium per fractional spread for unit notional. * * @param stepinDate the step-in date * @return the accrued year fraction */ public double accruedYearFraction(LocalDate stepinDate) { if (stepinDate.isBefore(getAccrualStartDate())) { return 0d; } if (stepinDate.isEqual(getAccrualEndDate())) { return paymentPeriods.get(paymentPeriods.size() - 1).getYearFraction(); } CreditCouponPaymentPeriod period = findPeriod(stepinDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range")); return dayCount.relativeYearFraction(period.getStartDate(), stepinDate); }