/// <summary>
        /// Compute the present value curve sensitivity of the payment with z-spread.
        /// <para>
        /// The present value sensitivity of the payment is the sensitivity of the
        /// present value to the discount factor curve.
        /// There is no sensitivity if the payment date is before the valuation date.
        /// </para>
        /// <para>
        /// The specified discount factors should be for the payment currency, however this is not validated.
        /// </para>
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        ///
        /// </para>
        /// </summary>
        /// <param name="payment">  the payment </param>
        /// <param name="discountFactors">  the discount factors to price against </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 point sensitivity of the present value </returns>
        public virtual PointSensitivityBuilder presentValueSensitivityWithSpread(Payment payment, DiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            if (discountFactors.ValuationDate.isAfter(payment.Date))
            {
                return(PointSensitivityBuilder.none());
            }
            ZeroRateSensitivity sensi = discountFactors.zeroRatePointSensitivityWithSpread(payment.Date, zSpread, compoundedRateType, periodsPerYear);

            return(sensi.multipliedBy(payment.Amount));
        }
Ejemplo n.º 2
0
        public virtual void presentValueSensitivity_zspread()
        {
            PointSensitivities sensiComputed = PRICER.presentValueSensitivityWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0);
            PointSensitivities sensiExpected = IssuerCurveZeroRateSensitivity.of(DSC_FACTORS_ISSUER.zeroRatePointSensitivityWithSpread(MATURITY_DATE, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0), GROUP_ISSUER).multipliedBy(NOTIONAL.Amount).build();

            assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV));
            CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(sensiComputed);
            CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p => PRICER.presentValueWithZSpread(BILL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0));

            assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT));
        }