### Question:
DiscountingPaymentPricer { 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); } DiscountingPaymentPricer(); CurrencyAmount presentValue(Payment payment, BaseProvider provider); CurrencyAmount presentValue(Payment payment, DiscountFactors discountFactors); double presentValueAmount(Payment payment, BaseProvider provider); CurrencyAmount presentValueWithSpread(
      Payment payment,
      DiscountFactors discountFactors,
      double zSpread,
      CompoundedRateType compoundedRateType,
      int periodsPerYear); ExplainMap explainPresentValue(Payment payment, BaseProvider provider); PointSensitivityBuilder presentValueSensitivity(Payment payment, BaseProvider provider); PointSensitivityBuilder presentValueSensitivity(Payment payment, DiscountFactors discountFactors); PointSensitivityBuilder presentValueSensitivityWithSpread(
      Payment payment,
      DiscountFactors discountFactors,
      double zSpread,
      CompoundedRateType compoundedRateType,
      int periodsPerYear); CurrencyAmount forecastValue(Payment payment, BaseProvider provider); double forecastValueAmount(Payment payment, BaseProvider provider); CashFlows cashFlows(Payment payment, BaseProvider provider); MultiCurrencyAmount currencyExposure(Payment payment, BaseProvider provider); CurrencyAmount currentCash(Payment payment, BaseProvider provider); static final DiscountingPaymentPricer DEFAULT; }### Answer:
@Test public void test_presentValueWithSpread_df_spread_continuous() { CurrencyAmount computed = PRICER .presentValueWithSpread(PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = NOTIONAL_USD * DF * Math.exp(-Z_SPREAD * relativeYearFraction); assertThat(computed.getAmount()).isCloseTo(expected, offset(NOTIONAL_USD * TOL)); }
@Test public void test_presentValueWithSpread_df_spread_periodic() { CurrencyAmount computed = PRICER.presentValueWithSpread( PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double rate = (Math.pow(DF, -1d / PERIOD_PER_YEAR / relativeYearFraction) - 1d) * PERIOD_PER_YEAR; double expected = NOTIONAL_USD * discountFactorFromPeriodicallyCompoundedRate(rate + Z_SPREAD, PERIOD_PER_YEAR, relativeYearFraction); assertThat(computed.getAmount()).isCloseTo(expected, offset(NOTIONAL_USD * TOL)); }
@Test public void test_presentValueWithSpread_df_ended_spread() { CurrencyAmount computed = PRICER.presentValueWithSpread(PAYMENT_PAST, DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, 3); assertThat(computed).isEqualTo(CurrencyAmount.zero(USD)); }