public void test_presentValueWithSpread_df_ended_spread() { CurrencyAmount computed = PRICER.presentValueWithSpread(PAYMENT_PAST, DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, 3); assertEquals(computed, CurrencyAmount.zero(USD)); }
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); assertEquals(computed.getAmount(), expected, NOTIONAL_USD * TOL); }
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); assertEquals(computed.getAmount(), expected, NOTIONAL_USD * TOL); }
CurrencyAmount presentValueWithZSpread( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, provider); CurrencyAmount pvNominal = nominalPricer.presentValueWithSpread( bond.getNominalPayment(), issuerDf.getDiscountFactors(), zSpread, compoundedRateType, periodsPerYear); CurrencyAmount pvCoupon = presentValueCouponFromZSpread( bond, issuerDf, zSpread, compoundedRateType, periodsPerYear, referenceDate); return pvNominal.plus(pvCoupon); }
public void test_presentValueWithZSpread_continuous() { CurrencyAmount computed = PRICER.presentValueWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount expected = PRICER_NOMINAL.presentValueWithSpread( PRODUCT.getNominalPayment(), DSC_FACTORS_ISSUER, Z_SPREAD, CONTINUOUS, 0); int size = PRODUCT.getPeriodicPayments().size(); double pvcCupon = 0d; for (int i = 2; i < size; ++i) { FixedCouponBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); pvcCupon += PRICER_COUPON.presentValueWithSpread(payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER), Z_SPREAD, CONTINUOUS, 0); } expected = expected.plus(pvcCupon); assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * TOL); }
public void test_presentValueWithZSpread_periodic() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount expected = PRICER_NOMINAL.presentValueWithSpread( PRODUCT.getNominalPayment(), DSC_FACTORS_ISSUER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); int size = PRODUCT.getPeriodicPayments().size(); double pvcCupon = 0d; for (int i = 2; i < size; ++i) { FixedCouponBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); pvcCupon += PRICER_COUPON.presentValueWithSpread(payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); } expected = expected.plus(pvcCupon); assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * TOL); }
public void test_presentValueWithZSpread_periodic_noExcoupon() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount expected = PRICER_NOMINAL.presentValueWithSpread( PRODUCT.getNominalPayment(), DSC_FACTORS_ISSUER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); int size = PRODUCT.getPeriodicPayments().size(); double pvcCupon = 0d; for (int i = 2; i < size; ++i) { FixedCouponBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); pvcCupon += PRICER_COUPON.presentValueWithSpread(payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); } expected = expected.plus(pvcCupon); assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * TOL); }
public void test_presentValueWithZSpread_continuous_noExcoupon() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount expected = PRICER_NOMINAL.presentValueWithSpread( PRODUCT.getNominalPayment(), DSC_FACTORS_ISSUER, Z_SPREAD, CONTINUOUS, 0); int size = PRODUCT.getPeriodicPayments().size(); double pvcCupon = 0d; for (int i = 2; i < size; ++i) { FixedCouponBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); pvcCupon += PRICER_COUPON.presentValueWithSpread(payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER), Z_SPREAD, CONTINUOUS, 0); } expected = expected.plus(pvcCupon); assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * TOL); }