//------------------------------------------------------------------------- public virtual void test_multipliedBy() { IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE); double rate = 2.4d; IssuerCurveZeroRateSensitivity test = @base.multipliedBy(rate); IssuerCurveZeroRateSensitivity expected = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE * rate); assertEquals(test, expected); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value sensitivity of a single fixed coupon payment period. /// <para> /// The present value sensitivity of the period is the sensitivity of the present value to /// the underlying curves. /// /// </para> /// </summary> /// <param name="period"> the period to price </param> /// <param name="discountFactors"> the discount factor provider </param> /// <returns> the present value curve sensitivity of the period </returns> public virtual PointSensitivityBuilder presentValueSensitivity(FixedCouponBondPaymentPeriod period, IssuerCurveDiscountFactors discountFactors) { if (period.PaymentDate.isBefore(discountFactors.ValuationDate)) { return(PointSensitivityBuilder.none()); } IssuerCurveZeroRateSensitivity dscSensi = discountFactors.zeroRatePointSensitivity(period.PaymentDate); return(dscSensi.multipliedBy(period.FixedRate * period.Notional * period.YearFraction)); }
/// <summary> /// Calculates the present value sensitivity of a single fixed coupon payment period with z-spread. /// <para> /// The z-spread is a parallel shift applied to continuously compounded rates or periodic /// compounded rates of the discounting curve. /// </para> /// <para> /// The present value sensitivity of the period is the sensitivity of the present value to /// the underlying curves. /// /// </para> /// </summary> /// <param name="period"> the period to price </param> /// <param name="discountFactors"> the discount factor provider </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <returns> the present value curve sensitivity of the period </returns> public virtual PointSensitivityBuilder presentValueSensitivityWithSpread(FixedCouponBondPaymentPeriod period, IssuerCurveDiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (period.PaymentDate.isBefore(discountFactors.ValuationDate)) { return(PointSensitivityBuilder.none()); } ZeroRateSensitivity zeroSensi = discountFactors.DiscountFactors.zeroRatePointSensitivityWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear); IssuerCurveZeroRateSensitivity dscSensi = IssuerCurveZeroRateSensitivity.of(zeroSensi, discountFactors.LegalEntityGroup); return(dscSensi.multipliedBy(period.FixedRate * period.Notional * period.YearFraction)); }
/// <summary> /// Calculates the present value sensitivity of a single payment period with z-spread. /// <para> /// The present value sensitivity of the period is the sensitivity of the present value to /// the underlying curves. /// /// </para> /// </summary> /// <param name="period"> the period to price </param> /// <param name="ratesProvider"> the rates provider, used to determine price index values </param> /// <param name="issuerDiscountFactors"> the discount factor provider </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <returns> the present value curve sensitivity of the period </returns> public virtual PointSensitivityBuilder presentValueSensitivityWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (period.PaymentDate.isBefore(ratesProvider.ValuationDate)) { return(PointSensitivityBuilder.none()); } double rate = rateComputationFn.rate(period.RateComputation, period.StartDate, period.EndDate, ratesProvider); PointSensitivityBuilder rateSensi = rateComputationFn.rateSensitivity(period.RateComputation, period.StartDate, period.EndDate, ratesProvider); double df = issuerDiscountFactors.DiscountFactors.discountFactorWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear); ZeroRateSensitivity zeroSensi = issuerDiscountFactors.DiscountFactors.zeroRatePointSensitivityWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear); IssuerCurveZeroRateSensitivity dfSensi = IssuerCurveZeroRateSensitivity.of(zeroSensi, issuerDiscountFactors.LegalEntityGroup); double factor = period.Notional * period.RealCoupon; return(rateSensi.multipliedBy(df * factor).combinedWith(dfSensi.multipliedBy((rate + 1d) * factor))); }