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_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_presentValueWithZSpread_exCoupon() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0); double expected = PERIOD_PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); 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.presentValueWithZSpread( payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
public void test_presentValueWithZSpread() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected = PERIOD_PRICER.presentValueWithZSpread(PRODUCT.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); int size = PRODUCT.getPeriodicPayments().size(); for (int i = 16; i < size; ++i) { CapitalIndexedBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValueWithZSpread( payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
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; }
public void test_presentValueWithZSpread_onFix() { double computedInterp = PRICER.presentValueWithZSpread( PERIOD_INTERP, IRP_ON_FIX, ICDF_ON_FIX, Z_SPREAD, CONTINUOUS, 0); double computedMonthly = PRICER.presentValueWithZSpread( PERIOD_MONTHLY, IRP_ON_FIX, ICDF_ON_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double index2 = IRP_ON_FIX.priceIndexValues(US_CPI_U).value(OBS_PLUS1); double expectedInterp = (INDEX_END_1 * WEIGHT + (1d - WEIGHT) * index2) / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_ON_FIX.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, CONTINUOUS, 0); double expectedMonthly = INDEX_END_1 / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_ON_FIX.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computedInterp, expectedInterp, TOL * expectedInterp); assertEquals(computedMonthly, expectedMonthly, TOL * expectedMonthly); }
public void test_presentValueWithZSpread_beforeStart() { double computedInterp = PRICER.presentValueWithZSpread( PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double computedMonthly = PRICER.presentValueWithZSpread( PERIOD_MONTHLY, IRP_BEFORE_START, ICDF_BEFORE_START, Z_SPREAD, CONTINUOUS, 0); double index1 = IRP_BEFORE_START.priceIndexValues(US_CPI_U).value(OBS); double index2 = IRP_BEFORE_START.priceIndexValues(US_CPI_U).value(OBS_PLUS1); double expectedInterp = (index1 * WEIGHT + (1d - WEIGHT) * index2) / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_BEFORE_START.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expectedMonthly = index1 / START_INDEX * REAL_COUPON * NOTIONAL * ICDF_BEFORE_START.getDiscountFactors().discountFactorWithSpread(END, Z_SPREAD, CONTINUOUS, 0); assertEquals(computedInterp, expectedInterp, TOL * expectedInterp); assertEquals(computedMonthly, expectedMonthly, TOL * expectedMonthly); }
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); }
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); }
private CurrencyParameterSensitivities fdSensitivityWithZSpread( CapitalIndexedBondPaymentPeriod period, ImmutableRatesProvider ratesProvider, LegalEntityDiscountingProvider issuerRatesProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { CurrencyParameterSensitivities sensi1 = FD_CAL.sensitivity( issuerRatesProvider, p -> CurrencyAmount.of(USD, PRICER.presentValueWithZSpread( period, ratesProvider, p.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.getIssuerId(), USD), zSpread, compoundedRateType, periodsPerYear))); CurrencyParameterSensitivities sensi2 = FD_CAL.sensitivity( ratesProvider, p -> CurrencyAmount.of( USD, PRICER.presentValueWithZSpread( period, p, issuerRatesProvider.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.getIssuerId(), USD), zSpread, compoundedRateType, periodsPerYear))); return sensi1.combinedWith(sensi2); }
public void test_presentValueFromCleanPriceWithZSpread_early() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread( TRADE_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EARLY, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(16); double pvDiff = PERIOD_PRICER.presentValueWithZSpread( period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0) * 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_presentValueFromCleanPriceWithZSpread_late() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread( TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount netAmount = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(17); double pvDiff = PERIOD_PRICER.presentValueWithZSpread( period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0) * 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.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)));