PointSensitivityBuilder presentValueSensitivityWithZSpread( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, provider); PointSensitivityBuilder pvNominal = presentValueSensitivityNominalFromZSpread( bond, issuerDf, zSpread, compoundedRateType, periodsPerYear); PointSensitivityBuilder pvCoupon = presentValueSensitivityCouponFromZSpread( bond, issuerDf, zSpread, compoundedRateType, periodsPerYear, referenceDate); return pvNominal.combinedWith(pvCoupon); }
/** * Calculates the present value sensitivity of the fixed coupon bond trade with z-spread. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * Coupon payments of the underlying product are considered based on the settlement date of the trade. * * @param trade the trade * @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 curve sensitivity of the trade */ public PointSensitivities presentValueSensitivityWithZSpread( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { LocalDate settlementDate = settlementDate(trade, provider.getValuationDate()); PointSensitivityBuilder sensiProduct = productPricer.presentValueSensitivityWithZSpread( trade.getProduct(), provider, zSpread, compoundedRateType, periodsPerYear, settlementDate); return presentValueSensitivityFromProductPresentValueSensitivity(trade, provider, sensiProduct).build(); }
public void test_presentValueSensitivityWithZSpread_continuous_noExcoupon() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p -> PRICER.presentValueWithZSpread(PRODUCT_NO_EXCOUPON, p, Z_SPREAD, CONTINUOUS, 0)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
public void test_presentValueSensitivityWithZSpread_continuous() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity( PROVIDER, p -> PRICER.presentValueWithZSpread(PRODUCT, p, Z_SPREAD, CONTINUOUS, 0)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
public void test_presentValueSensitivityWithZSpread_periodic() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread( PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p -> PRICER.presentValueWithZSpread(PRODUCT, p, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
public void test_presentValueSensitivityWithZSpread_periodic_noExcoupon() { PointSensitivityBuilder point = PRICER.presentValueSensitivityWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p -> PRICER.presentValueWithZSpread(PRODUCT_NO_EXCOUPON, p, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertTrue(computed.equalWithTolerance(expected, 20d * NOTIONAL * EPS)); }
PointSensitivityBuilder dirtyPriceSensitivityWithZspread( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { RepoCurveDiscountFactors repoDf = repoCurveDf(bond, provider); double df = repoDf.discountFactor(referenceDate); CurrencyAmount pv = presentValueWithZSpread(bond, provider, zSpread, compoundedRateType, periodsPerYear); double notional = bond.getNotional(); PointSensitivityBuilder pvSensi = presentValueSensitivityWithZSpread( bond, provider, zSpread, compoundedRateType, periodsPerYear).multipliedBy(1d / df / notional); RepoCurveZeroRateSensitivity dfSensi = repoDf.zeroRatePointSensitivity(referenceDate) .multipliedBy(-pv.getAmount() / df / df / notional); return pvSensi.combinedWith(dfSensi); }