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_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); }
public void test_presentValue_onFix() { double computedInterp = PRICER.presentValue(PERIOD_INTERP, IRP_ON_FIX, ICDF_ON_FIX); double computedMonthly = PRICER.presentValue(PERIOD_MONTHLY, IRP_ON_FIX, ICDF_ON_FIX); double index2 = IRP_ON_FIX.priceIndexValues(US_CPI_U).value(OBS_PLUS1); double df = ICDF_ON_FIX.discountFactor(END); double expectedInterp = (INDEX_END_1 * WEIGHT + (1d - WEIGHT) * index2) / 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); }
public void test_presentValue() { CurrencyAmount computed = PRICER.presentValue(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER); double expected = PERIOD_PRICER.presentValue(PRODUCT.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); int size = PRODUCT.getPeriodicPayments().size(); for (int i = 16; i < size; ++i) { CapitalIndexedBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValue(payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
public void test_presentValue_exCoupon() { CurrencyAmount computed = PRICER.presentValue(PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER); double expected = PERIOD_PRICER.presentValue( PRODUCT_EX_COUPON.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); int size = PRODUCT_EX_COUPON.getPeriodicPayments().size(); for (int i = 17; i < size; ++i) { // in ex-coupon period CapitalIndexedBondPaymentPeriod payment = PRODUCT_EX_COUPON.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValue(payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
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; }
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); }
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); }
private CurrencyParameterSensitivities fdSensitivity( CapitalIndexedBondPaymentPeriod period, ImmutableRatesProvider ratesProvider, LegalEntityDiscountingProvider issuerRatesProvider) { CurrencyParameterSensitivities sensi1 = FD_CAL.sensitivity( issuerRatesProvider, p -> CurrencyAmount.of( USD, PRICER.presentValue( period, ratesProvider, p.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.getIssuerId(), USD)))); CurrencyParameterSensitivities sensi2 = FD_CAL.sensitivity( ratesProvider, p -> CurrencyAmount.of( USD, PRICER.presentValue( period, p, issuerRatesProvider.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.getIssuerId(), USD)))); return sensi1.combinedWith(sensi2); }
public void test_presentValueFromCleanPrice_early() { CurrencyAmount computed = PRICER.presentValueFromCleanPrice( TRADE_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EARLY, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(16); double pvDiff = PERIOD_PRICER.presentValue(period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_EARLY); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = -pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice(RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPrice_late() { CurrencyAmount computed = PRICER.presentValueFromCleanPrice( TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); CurrencyAmount netAmount = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(17); double pvDiff = PERIOD_PRICER.presentValue(period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_LATE); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(period, ratesProvider, issuerDiscountFactors)));