double presentValueCoupon( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate1, LocalDate referenceDate2) { double pvDiff = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate1) && !period.getDetachmentDate().isAfter(referenceDate2)) { pvDiff += periodPricer.presentValue(period, ratesProvider, discountFactors); } } return pvDiff; }
double presentValueCouponWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate1, LocalDate referenceDate2, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double pvDiff = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate1) && !period.getDetachmentDate().isAfter(referenceDate2)) { pvDiff += periodPricer.presentValueWithZSpread( period, ratesProvider, discountFactors, zSpread, compoundedRateType, periodsPerYear); } } return pvDiff; }
PointSensitivityBuilder presentValueSensitivityCoupon( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate1, LocalDate referenceDate2) { PointSensitivityBuilder pvSensiDiff = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate1) && !period.getDetachmentDate().isAfter(referenceDate2)) { pvSensiDiff = pvSensiDiff.combinedWith(periodPricer.presentValueSensitivity(period, ratesProvider, discountFactors)); } } return pvSensiDiff; }
PointSensitivityBuilder presentValueSensitivityCouponWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate1, LocalDate referenceDate2, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { PointSensitivityBuilder pvSensiDiff = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate1) && !period.getDetachmentDate().isAfter(referenceDate2)) { pvSensiDiff = pvSensiDiff.combinedWith(periodPricer.presentValueSensitivityWithZSpread( period, ratesProvider, discountFactors, zSpread, compoundedRateType, periodsPerYear)); } } return pvSensiDiff; }
for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { CapitalIndexedBondPaymentPeriod period = bond.getPeriodicPayments().get(loopcpn); if ((bond.hasExCouponPeriod() && !settlementDate.isAfter(period.getDetachmentDate())) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(settlementDate))) { mdAtFirstCoupon += period.getRealCoupon() / Math.pow(factorOnPeriod, pow + 1) *
for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { CapitalIndexedBondPaymentPeriod period = bond.getPeriodicPayments().get(loopcpn); if ((bond.hasExCouponPeriod() && !settlementDate.isAfter(period.getDetachmentDate())) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(settlementDate))) { cvAtFirstCoupon += period.getRealCoupon() * (pow + factorToNext) * (pow + factorToNext + 1d) /
for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { CapitalIndexedBondPaymentPeriod period = bond.getPeriodicPayments().get(loopcpn); if ((bond.hasExCouponPeriod() && !settlementDate.isAfter(period.getDetachmentDate())) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(settlementDate))) { pvAtFirstCoupon += period.getRealCoupon() / Math.pow(factorOnPeriod, pow);
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((CapitalIndexedBondPaymentPeriod) bean).getCurrency(); case 1585636160: // notional return ((CapitalIndexedBondPaymentPeriod) bean).getNotional(); case 1842278244: // realCoupon return ((CapitalIndexedBondPaymentPeriod) bean).getRealCoupon(); case -2129778896: // startDate return ((CapitalIndexedBondPaymentPeriod) bean).getStartDate(); case -1607727319: // endDate return ((CapitalIndexedBondPaymentPeriod) bean).getEndDate(); case 1457691881: // unadjustedStartDate return ((CapitalIndexedBondPaymentPeriod) bean).getUnadjustedStartDate(); case 31758114: // unadjustedEndDate return ((CapitalIndexedBondPaymentPeriod) bean).getUnadjustedEndDate(); case -878940481: // detachmentDate return ((CapitalIndexedBondPaymentPeriod) bean).getDetachmentDate(); case 625350855: // rateComputation return ((CapitalIndexedBondPaymentPeriod) bean).getRateComputation(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(CapitalIndexedBondPaymentPeriod beanToCopy) { this.currency = beanToCopy.getCurrency(); this.notional = beanToCopy.getNotional(); this.realCoupon = beanToCopy.getRealCoupon(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.unadjustedStartDate = beanToCopy.getUnadjustedStartDate(); this.unadjustedEndDate = beanToCopy.getUnadjustedEndDate(); this.detachmentDate = beanToCopy.getDetachmentDate(); this.rateComputation = beanToCopy.getRateComputation(); }
public void test_builder_min() { CapitalIndexedBondPaymentPeriod test = CapitalIndexedBondPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .startDate(START) .endDate(END) .rateComputation(COMPUTE_MONTH) .realCoupon(REAL_COUPON) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getDetachmentDate(), END); assertEquals(test.getStartDate(), START); assertEquals(test.getEndDate(), END); assertEquals(test.getUnadjustedStartDate(), START); assertEquals(test.getUnadjustedEndDate(), END); assertEquals(test.getRateComputation(), COMPUTE_MONTH); assertEquals(test.getRealCoupon(), REAL_COUPON); }
public void test_accruedInterest_exCoupon_in() { CapitalIndexedBondPaymentPeriod period = PRODUCT_EX_COUPON.getPeriodicPayments().get(16); LocalDate refDate = period.getDetachmentDate(); double computed = PRODUCT_EX_COUPON.accruedInterest(refDate); Schedule sch = SCHEDULE.createSchedule(REF_DATA).toUnadjusted(); double factor = ACT_ACT_ICMA.relativeYearFraction(period.getUnadjustedStartDate(), refDate, sch); double factorTotal = ACT_ACT_ICMA.relativeYearFraction(period.getUnadjustedStartDate(), period.getUnadjustedEndDate(), sch); assertEquals(computed, (factor - factorTotal) * REAL_COUPON_VALUE * NOTIONAL * 2d, TOL * REAL_COUPON_VALUE * NOTIONAL); }
public void test_builder_full() { CapitalIndexedBondPaymentPeriod test = CapitalIndexedBondPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .detachmentDate(DETACHMENT) .startDate(START) .endDate(END) .unadjustedStartDate(START_UNADJ) .unadjustedEndDate(END_UNADJ) .rateComputation(COMPUTE_INTERP) .realCoupon(REAL_COUPON) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getDetachmentDate(), DETACHMENT); assertEquals(test.getStartDate(), START); assertEquals(test.getEndDate(), END); assertEquals(test.getUnadjustedStartDate(), START_UNADJ); assertEquals(test.getUnadjustedEndDate(), END_UNADJ); assertEquals(test.getRateComputation(), COMPUTE_INTERP); assertEquals(test.getRealCoupon(), REAL_COUPON); }
/** * Calculates the accrued interest of the bond with the specified date. * * @param referenceDate the reference date * @return the accrued interest of the product */ public double accruedInterest(LocalDate referenceDate) { if (getUnadjustedStartDate().isAfter(referenceDate)) { return 0d; } double notional = getNotional(); CapitalIndexedBondPaymentPeriod period = findPeriod(referenceDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range of bond")); LocalDate previousAccrualDate = period.getUnadjustedStartDate(); double realCoupon = period.getRealCoupon(); double couponPerYear = getFrequency().eventsPerYear(); double rate = realCoupon * couponPerYear; double accruedInterest = yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_COMPOUND) || yieldConvention.equals(CapitalIndexedBondYieldConvention.JP_IL_SIMPLE) ? yearFraction(previousAccrualDate, referenceDate, DayCounts.ACT_365F) * rate * notional : yearFraction(previousAccrualDate, referenceDate) * rate * notional; double result = 0d; if (hasExCouponPeriod() && !referenceDate.isBefore(period.getDetachmentDate())) { result = accruedInterest - notional * rate * yearFraction(previousAccrualDate, period.getUnadjustedEndDate()); } else { result = accruedInterest; } return result; }
PointSensitivityBuilder presentValueSensitivity( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pointNominal = periodPricer.presentValueSensitivity(bond.getNominalPayment(), ratesProvider, issuerDf); PointSensitivityBuilder pointCoupon = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pointCoupon = pointCoupon.combinedWith( periodPricer.presentValueSensitivity(period, ratesProvider, issuerDf)); } } return pointNominal.combinedWith(pointCoupon); }
CurrencyAmount presentValue( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); double pvNominal = periodPricer.presentValue(bond.getNominalPayment(), ratesProvider, issuerDf); double pvCoupon = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pvCoupon += periodPricer.presentValue(period, ratesProvider, issuerDf); } } return CurrencyAmount.of(bond.getCurrency(), pvCoupon + pvNominal); }
CurrencyAmount presentValueWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); double pvNominal = periodPricer.presentValueWithZSpread( bond.getNominalPayment(), ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); double pvCoupon = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pvCoupon += periodPricer.presentValueWithZSpread( period, ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); } } return CurrencyAmount.of(bond.getCurrency(), pvCoupon + pvNominal); }
PointSensitivityBuilder presentValueSensitivityWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pointNominal = periodPricer.presentValueSensitivityWithZSpread( bond.getNominalPayment(), ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); PointSensitivityBuilder pointCoupon = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pointCoupon = pointCoupon.combinedWith(periodPricer.presentValueSensitivityWithZSpread( period, ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear)); } } return pointNominal.combinedWith(pointCoupon); }