/** * Gets the discount factor for the specified date with z-spread. * <p> * The discount factor represents the time value of money for the specified currency * when comparing the valuation date to the specified date. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * If the valuation date is on or after the specified date, the discount factor is 1. * * @param date the date to discount to * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the discount factor * @throws RuntimeException if the value cannot be obtained */ public default double discountFactorWithSpread( LocalDate date, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double yearFraction = relativeYearFraction(date); return discountFactorWithSpread(yearFraction, zSpread, compoundedRateType, periodsPerYear); }
public void test_presentValueWithSpread() { double computed = PRICER.presentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected = FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, expected); }
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); }
/** * 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); }
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_explainPresentValueWithSpread() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FixedCouponBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PERIOD.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PAYMENT_PERIOD.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START); assertEquals(explain.get(ExplainKey.END_DATE).get(), END_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_ADJUSTED, END_ADJUSTED)); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR), NOTIONAL * TOL); }
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); }
/** * Computes the present value of the payment with z-spread by discounting. * <p> * The present value is zero if the payment date is before the valuation date. * <p> * The specified discount factors should be for the payment currency, however this is not validated. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * * @param payment the payment * @param discountFactors the discount factors to price against * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the present value */ public CurrencyAmount presentValueWithSpread( Payment payment, DiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (discountFactors.getValuationDate().isAfter(payment.getDate())) { return CurrencyAmount.zero(payment.getCurrency()); } double df = discountFactors.discountFactorWithSpread(payment.getDate(), zSpread, compoundedRateType, periodsPerYear); return payment.getValue().multipliedBy(df); }
.discountFactorWithSpread(period.getPaymentDate(), zSpread, compoundedRateType, periodsPerYear); return period.getFixedRate() * period.getNotional() * period.getYearFraction() * df;
IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.getDiscountFactors() .discountFactorWithSpread(bill.getNotional().getDate(), zSpread, compoundedRateType, periodsPerYear); RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider); double dfRepoSettle = repoDf.discountFactor(settlementDate);
/** * Calculates the present value of a bill product with z-spread. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or * periodic compounded rates of the issuer discounting curve. * * @param bill the product * @param provider the discounting 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 bill product */ public CurrencyAmount presentValueWithZSpread( ResolvedBill bill, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return CurrencyAmount.of(bill.getCurrency(), 0.0d); } IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.getDiscountFactors() .discountFactorWithSpread(bill.getNotional().getDate(), zSpread, compoundedRateType, periodsPerYear); return bill.getNotional().getValue().multipliedBy(dfMaturity); }
} else { builder.put(ExplainKey.DISCOUNT_FACTOR, discountFactors.getDiscountFactors() .discountFactorWithSpread(paymentDate, zSpread, compoundedRateType, periodsPerYear)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, discountFactors))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency,
period.getRateComputation(), period.getStartDate(), period.getEndDate(), ratesProvider); double df = issuerDiscountFactors.getDiscountFactors() .discountFactorWithSpread(period.getPaymentDate(), zSpread, compoundedRateType, periodsPerYear); ZeroRateSensitivity zeroSensi = issuerDiscountFactors.getDiscountFactors() .zeroRatePointSensitivityWithSpread(period.getPaymentDate(), zSpread, compoundedRateType, periodsPerYear);