/** * 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 PointSensitivityBuilder netAmountSensitivity( ResolvedCapitalIndexedBondSettlement settlement, RatesProvider ratesProvider) { BondPaymentPeriod settlePeriod = settlement.getPayment(); if (settlePeriod instanceof KnownAmountBondPaymentPeriod) { return PointSensitivityBuilder.none(); } else if (settlePeriod instanceof CapitalIndexedBondPaymentPeriod) { CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod) settlePeriod; return productPricer.getPeriodPricer().forecastValueSensitivity(casted, ratesProvider); } throw new UnsupportedOperationException("unsupported settlement type"); }
public void test_getter() { assertEquals(PRICER.getRateComputationFn(), RateComputationFn.standard()); }
public void test_presentValue_beforeStart() { double computedInterp = PRICER.presentValue(PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START); double computedMonthly = PRICER.presentValue(PERIOD_MONTHLY, IRP_BEFORE_START, ICDF_BEFORE_START); double computedFvInterp = PRICER.forecastValue(PERIOD_INTERP, IRP_BEFORE_START); double computedFvMonthly = PRICER.forecastValue(PERIOD_MONTHLY, IRP_BEFORE_START); double index1 = IRP_BEFORE_START.priceIndexValues(US_CPI_U).value(OBS); double index2 = IRP_BEFORE_START.priceIndexValues(US_CPI_U).value(OBS_PLUS1); double df = ICDF_BEFORE_START.discountFactor(END); double expectedFvInterp = (index1 * WEIGHT + (1d - WEIGHT) * index2) / START_INDEX * REAL_COUPON * NOTIONAL; double expectedFvMonthly = index1 / START_INDEX * REAL_COUPON * NOTIONAL; assertEquals(computedFvInterp, expectedFvInterp, TOL * expectedFvInterp); assertEquals(computedFvMonthly, expectedFvMonthly, TOL * expectedFvMonthly); assertEquals(computedInterp, expectedFvInterp * df, TOL * expectedFvInterp * df); assertEquals(computedMonthly, expectedFvMonthly * df, TOL * expectedFvMonthly * df); }
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); }
public void test_forecastValueSensitivity_onFix() { PointSensitivityBuilder pointInterp = PRICER.forecastValueSensitivity(PERIOD_INTERP, IRP_ON_FIX); CurrencyParameterSensitivities computedInterp = IRP_ON_FIX.parameterSensitivity(pointInterp.build()); PointSensitivityBuilder pointMonthly = PRICER.forecastValueSensitivity(PERIOD_MONTHLY, IRP_ON_FIX); CurrencyParameterSensitivities computedMonthly = IRP_ON_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities expectedInterp = FD_CAL.sensitivity(IRP_ON_FIX, p -> CurrencyAmount.of(USD, PRICER.forecastValue(PERIOD_INTERP, p))); CurrencyParameterSensitivities expectedMonthly = FD_CAL.sensitivity(IRP_ON_FIX, p -> CurrencyAmount.of(USD, PRICER.forecastValue(PERIOD_MONTHLY, p))); assertTrue(computedInterp.equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS)); assertTrue(computedMonthly.equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS)); }
public void test_presentValueWithZSpread_afterPay() { double computedInterp = PRICER.presentValueWithZSpread( PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double computedMonthly = PRICER.presentValueWithZSpread( PERIOD_MONTHLY, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, CONTINUOUS, 0); assertEquals(computedInterp, 0d, TOL); assertEquals(computedMonthly, 0d, TOL); }
public void test_presentValue_afterPay() { double computedInterp = PRICER.presentValue(PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY); double computedMonthly = PRICER.presentValue(PERIOD_MONTHLY, IRP_AFTER_PAY, ICDF_AFTER_PAY); assertEquals(computedInterp, 0d, TOL); assertEquals(computedMonthly, 0d, TOL); }
public void test_presentValueSensitivity_afterPay() { PointSensitivityBuilder computedInterp = PRICER.presentValueSensitivity(PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY); PointSensitivityBuilder computedMonthly = PRICER.presentValueSensitivity(PERIOD_MONTHLY, IRP_AFTER_PAY, ICDF_AFTER_PAY); assertEquals(computedInterp, PointSensitivityBuilder.none()); assertEquals(computedMonthly, PointSensitivityBuilder.none()); }
public void test_presentValueSensitivityWithZSpread_afterPay() { PointSensitivityBuilder computedInterp = PRICER.presentValueSensitivityWithZSpread( PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivityBuilder computedMonthly = PRICER.presentValueSensitivityWithZSpread( PERIOD_MONTHLY, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, CONTINUOUS, 0); assertEquals(computedInterp, PointSensitivityBuilder.none()); assertEquals(computedMonthly, PointSensitivityBuilder.none()); }
} else { builder.put(ExplainKey.DISCOUNT_FACTOR, issuerDiscountFactors.discountFactor(paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValueWithZSpread( period, ratesProvider, issuerDiscountFactors, zSpread, compoundedRateType, periodsPerYear)));
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_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_forecastValueSensitivity_afterFix() { PointSensitivityBuilder pointInterp = PRICER.forecastValueSensitivity(PERIOD_INTERP, IRP_AFTER_FIX); CurrencyParameterSensitivities computedInterp = IRP_AFTER_FIX.parameterSensitivity(pointInterp.build()); PointSensitivityBuilder pointMonthly = PRICER.forecastValueSensitivity(PERIOD_MONTHLY, IRP_AFTER_FIX); CurrencyParameterSensitivities computedMonthly = IRP_AFTER_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities expectedInterp = FD_CAL.sensitivity(IRP_AFTER_FIX, p -> CurrencyAmount.of(USD, PRICER.forecastValue(PERIOD_INTERP, p))); CurrencyParameterSensitivities expectedMonthly = FD_CAL.sensitivity(IRP_AFTER_FIX, p -> CurrencyAmount.of(USD, PRICER.forecastValue(PERIOD_MONTHLY, p))); assertTrue(computedInterp.equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS)); assertTrue(computedMonthly.equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS)); }
public void test_presentValueWithZSpread_afterFix() { double computedInterp = PRICER.presentValueWithZSpread( PERIOD_INTERP, IRP_AFTER_FIX, ICDF_AFTER_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double computedMonthly = PRICER.presentValueWithZSpread( PERIOD_MONTHLY, IRP_AFTER_FIX, ICDF_AFTER_FIX, Z_SPREAD, CONTINUOUS, 0); double expectedInterp = (INDEX_END_1 * WEIGHT + (1d - WEIGHT) * INDEX_END_2) / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_AFTER_FIX.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expectedMonthly = INDEX_END_1 / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_AFTER_FIX.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, CONTINUOUS, 0); assertEquals(computedInterp, expectedInterp, TOL * expectedInterp); assertEquals(computedMonthly, expectedMonthly, TOL * expectedMonthly); }
public void test_presentValue_afterFix() { double computedInterp = PRICER.presentValue(PERIOD_INTERP, IRP_AFTER_FIX, ICDF_AFTER_FIX); double computedMonthly = PRICER.presentValue(PERIOD_MONTHLY, IRP_AFTER_FIX, ICDF_AFTER_FIX); double df = ICDF_AFTER_FIX.discountFactor(END); double expectedInterp = (INDEX_END_1 * WEIGHT + (1d - WEIGHT) * INDEX_END_2) / START_INDEX * REAL_COUPON * NOTIONAL * df; double expectedMonthly = INDEX_END_1 / START_INDEX * REAL_COUPON * NOTIONAL * df; assertEquals(computedInterp, expectedInterp, TOL * expectedInterp); assertEquals(computedMonthly, expectedMonthly, TOL * expectedMonthly); }
} else { builder.put(ExplainKey.DISCOUNT_FACTOR, issuerDiscountFactors.discountFactor(paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(period, ratesProvider, issuerDiscountFactors)));
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); }
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; }