/** * Calculates the present value of a single payment period. * <p> * This returns the value of the period with discounting. * If the payment date of the period is in the past, zero is returned. * * @param period the period to price * @param ratesProvider the rates provider, used to determine price index values * @param issuerDiscountFactors the discount factor provider * @return the present value of the period */ public double presentValue( CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors) { double df = issuerDiscountFactors.discountFactor(period.getPaymentDate()); return df * forecastValue(period, ratesProvider); }
private double currentCashPayment( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate valuationDate) { double cash = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getPaymentDate().isEqual(valuationDate)) { cash += periodPricer.forecastValue(period, ratesProvider); } } return cash; }
public void test_accruedInterest_onPayment() { CapitalIndexedBondPaymentPeriod period = PRODUCT.getPeriodicPayments().get(16); LocalDate refDate = period.getPaymentDate(); double computed = PRODUCT.accruedInterest(refDate); assertEquals(computed, 0d, TOL * REAL_COUPON_VALUE * NOTIONAL); }
/** * Calculates the present value of a single payment period with z-spread. * <p> * This returns the value of the period with discounting. * If the payment date of the period is in the past, zero is returned. * * @param period the period to price * @param ratesProvider the rates provider, used to determine price index values * @param issuerDiscountFactors the discount factor provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the present value of the period */ public double presentValueWithZSpread( CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double df = issuerDiscountFactors.getDiscountFactors() .discountFactorWithSpread(period.getPaymentDate(), zSpread, compoundedRateType, periodsPerYear); return df * forecastValue(period, ratesProvider); }
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) * (pow + factorToNext) / couponPerYear;
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); ++pow;
public void test_explainPresentValueWithZSpread_past() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValueWithZSpread( PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ); assertEquals(explain.get(ExplainKey.END_DATE).get(), END); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_UNADJ, END_UNADJ)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); }
public void test_explainPresentValue_past() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValue(PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, builder); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ); assertEquals(explain.get(ExplainKey.END_DATE).get(), END); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_UNADJ, END_UNADJ)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); }
public void test_explainPresentValue() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValue(PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, builder); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ); assertEquals(explain.get(ExplainKey.END_DATE).get(), END); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_UNADJ, END_UNADJ)); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), ICDF_BEFORE_START.discountFactor(END)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), PRICER.forecastValue(PERIOD_INTERP, IRP_BEFORE_START), NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), PRICER.presentValue(PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START), NOTIONAL * TOL); }
public void test_explainPresentValueWithZSpread() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValueWithZSpread( PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "CapitalIndexedBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PERIOD_INTERP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PERIOD_INTERP.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START_UNADJ); assertEquals(explain.get(ExplainKey.END_DATE).get(), END); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END_UNADJ); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_UNADJ, END_UNADJ)); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), ICDF_BEFORE_START.discountFactor(END)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), PRICER.forecastValue(PERIOD_INTERP, IRP_BEFORE_START), NOTIONAL * TOL); assertEquals( explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), PRICER.presentValueWithZSpread( PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR), NOTIONAL * TOL); }
/** * Calculates the present value sensitivity of a single payment period. * <p> * The present value sensitivity of the period is the sensitivity of the present value to * the underlying curves. * * @param period the period to price * @param ratesProvider the rates provider, used to determine price index values * @param issuerDiscountFactors the discount factor provider * @return the present value curve sensitivity of the period */ public PointSensitivityBuilder presentValueSensitivity( CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors) { if (period.getPaymentDate().isBefore(ratesProvider.getValuationDate())) { return PointSensitivityBuilder.none(); } double rate = rateComputationFn.rate( period.getRateComputation(), period.getStartDate(), period.getEndDate(), ratesProvider); PointSensitivityBuilder rateSensi = rateComputationFn.rateSensitivity( period.getRateComputation(), period.getStartDate(), period.getEndDate(), ratesProvider); double df = issuerDiscountFactors.discountFactor(period.getPaymentDate()); PointSensitivityBuilder dfSensi = issuerDiscountFactors.zeroRatePointSensitivity(period.getPaymentDate()); double factor = period.getNotional() * period.getRealCoupon(); return rateSensi.multipliedBy(df * factor).combinedWith(dfSensi.multipliedBy((rate + 1d) * factor)); }
/** * Calculates the forecast value of a single payment period. * * @param period the period to price * @param ratesProvider the rates provider, used to determine price index values * @return the forecast value of the period */ public double forecastValue(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider) { if (period.getPaymentDate().isBefore(ratesProvider.getValuationDate())) { return 0d; } double rate = rateComputationFn.rate( period.getRateComputation(), period.getStartDate(), period.getEndDate(), ratesProvider); return period.getNotional() * period.getRealCoupon() * (rate + 1d); }
/** * Calculates the forecast value sensitivity of a single payment period. * <p> * The forecast value sensitivity of the period is the sensitivity of the present value to * the underlying curves. * * @param period the period to price * @param ratesProvider the rates provider, used to determine price index values * @return the forecast value sensitivity of the period */ public PointSensitivityBuilder forecastValueSensitivity( CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider) { if (period.getPaymentDate().isBefore(ratesProvider.getValuationDate())) { return PointSensitivityBuilder.none(); } PointSensitivityBuilder rateSensi = rateComputationFn.rateSensitivity( period.getRateComputation(), period.getStartDate(), period.getEndDate(), ratesProvider); return rateSensi.multipliedBy(period.getNotional() * period.getRealCoupon()); }
/** * Calculates the current cash of the bond product. * * @param bond the product * @param ratesProvider the rates provider, used to determine price index values * @param settlementDate the settlement date * @return the current cash of the product */ public CurrencyAmount currentCash( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate settlementDate) { LocalDate valuationDate = ratesProvider.getValuationDate(); Currency currency = bond.getCurrency(); CurrencyAmount currentCash = CurrencyAmount.zero(currency); if (settlementDate.isBefore(valuationDate)) { double cashCoupon = bond.hasExCouponPeriod() ? 0d : currentCashPayment(bond, ratesProvider, valuationDate); CapitalIndexedBondPaymentPeriod nominal = bond.getNominalPayment(); double cashNominal = nominal.getPaymentDate().isEqual(valuationDate) ? periodPricer.forecastValue(nominal, ratesProvider) : 0d; currentCash = currentCash.plus(CurrencyAmount.of(currency, cashCoupon + cashNominal)); } return currentCash; }
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); }
.realCoupon(REAL_COUPON) .build(); assertEquals(test.getPaymentDate(), END); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(2))), test); ImmutableSet.Builder<Index> builder = ImmutableSet.builder();
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); }
LocalDate paymentDate = period.getPaymentDate(); builder.put(ExplainKey.ENTRY_TYPE, "CapitalIndexedBondPaymentPeriod"); builder.put(ExplainKey.PAYMENT_DATE, paymentDate);