public void test_presentValueSensitivityWithZSpread_afterPay() { PointSensitivityBuilder computedInterp = PRICER.presentValueSensitivityWithZSpread( PERIOD_INTERP, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivityBuilder computedMonthly = PRICER.presentValueSensitivityWithZSpread( PERIOD_MONTHLY, IRP_AFTER_PAY, ICDF_AFTER_PAY, Z_SPREAD, CONTINUOUS, 0); assertEquals(computedInterp, PointSensitivityBuilder.none()); assertEquals(computedMonthly, PointSensitivityBuilder.none()); }
PointSensitivityBuilder presentValueSensitivityCouponWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate1, LocalDate referenceDate2, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { PointSensitivityBuilder pvSensiDiff = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate1) && !period.getDetachmentDate().isAfter(referenceDate2)) { pvSensiDiff = pvSensiDiff.combinedWith(periodPricer.presentValueSensitivityWithZSpread( period, ratesProvider, discountFactors, zSpread, compoundedRateType, periodsPerYear)); } } return pvSensiDiff; }
PointSensitivityBuilder presentValueSensitivityWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pointNominal = periodPricer.presentValueSensitivityWithZSpread( bond.getNominalPayment(), ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); PointSensitivityBuilder pointCoupon = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pointCoupon = pointCoupon.combinedWith(periodPricer.presentValueSensitivityWithZSpread( period, ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear)); } } return pointNominal.combinedWith(pointCoupon); }
public void test_presentValueSensitivityWithZSpread_onFix() { PointSensitivityBuilder pointInterp = PRICER.presentValueSensitivityWithZSpread(PERIOD_INTERP, IRP_ON_FIX, ICDF_ON_FIX, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computedInterp1 = LEDP_ON_FIX.parameterSensitivity(pointInterp.build()); CurrencyParameterSensitivities computedInterp2 = IRP_ON_FIX.parameterSensitivity(pointInterp.build()); PointSensitivityBuilder pointMonthly = PRICER.presentValueSensitivityWithZSpread( PERIOD_MONTHLY, IRP_ON_FIX, ICDF_ON_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities computedMonthly1 = LEDP_ON_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities computedMonthly2 = IRP_ON_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities expectedInterp = fdSensitivityWithZSpread(PERIOD_INTERP, IRP_ON_FIX, LEDP_ON_FIX, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities expectedMonthly = fdSensitivityWithZSpread(PERIOD_MONTHLY, IRP_ON_FIX, LEDP_ON_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertTrue(computedInterp1.combinedWith(computedInterp2).equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS)); assertTrue(computedMonthly1.combinedWith(computedMonthly2).equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS)); }
public void test_presentValueSensitivityWithZSpread_beforeStart() { PointSensitivityBuilder pointInterp = PRICER.presentValueSensitivityWithZSpread( PERIOD_INTERP, IRP_BEFORE_START, ICDF_BEFORE_START, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities computedInterp1 = LEDP_BEFORE_START.parameterSensitivity(pointInterp.build()); CurrencyParameterSensitivities computedInterp2 = IRP_BEFORE_START.parameterSensitivity(pointInterp.build()); PointSensitivityBuilder pointMonthly = PRICER.presentValueSensitivityWithZSpread( PERIOD_MONTHLY, IRP_BEFORE_START, ICDF_BEFORE_START, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computedMonthly1 = LEDP_BEFORE_START.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities computedMonthly2 = IRP_BEFORE_START.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities expectedInterp = fdSensitivityWithZSpread( PERIOD_INTERP, IRP_BEFORE_START, LEDP_BEFORE_START, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities expectedMonthly = fdSensitivityWithZSpread(PERIOD_MONTHLY, IRP_BEFORE_START, LEDP_BEFORE_START, Z_SPREAD, CONTINUOUS, 0); assertTrue(computedInterp1.combinedWith(computedInterp2).equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS)); assertTrue(computedMonthly1.combinedWith(computedMonthly2).equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS)); }
public void test_presentValueSensitivityWithZSpread_afterFix() { PointSensitivityBuilder pointInterp = PRICER.presentValueSensitivityWithZSpread( PERIOD_INTERP, IRP_AFTER_FIX, ICDF_AFTER_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities computedInterp1 = LEDP_AFTER_FIX.parameterSensitivity(pointInterp.build()); CurrencyParameterSensitivities computedInterp2 = IRP_AFTER_FIX.parameterSensitivity(pointInterp.build()); PointSensitivityBuilder pointMonthly = PRICER.presentValueSensitivityWithZSpread( PERIOD_MONTHLY, IRP_AFTER_FIX, ICDF_AFTER_FIX, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computedMonthly1 = LEDP_AFTER_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities computedMonthly2 = IRP_AFTER_FIX.parameterSensitivity(pointMonthly.build()); CurrencyParameterSensitivities expectedInterp = fdSensitivityWithZSpread(PERIOD_INTERP, IRP_AFTER_FIX, LEDP_AFTER_FIX, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities expectedMonthly = fdSensitivityWithZSpread(PERIOD_MONTHLY, IRP_AFTER_FIX, LEDP_AFTER_FIX, Z_SPREAD, CONTINUOUS, 0); assertTrue(computedInterp1.combinedWith(computedInterp2).equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS)); assertTrue(computedMonthly1.combinedWith(computedMonthly2).equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS)); }