public virtual void test_parameterSensitivity_withSpread_full() { int periodPerYear = 2; double spread = 0.0011; // 11 bp ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double sensiValue = 25d; ZeroRateSensitivity point = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); point = point.multipliedBy(sensiValue); CurrencyParameterSensitivities sensiObject = test.parameterSensitivity(point); assertEquals(sensiObject.Sensitivities.size(), 1); DoubleArray sensi0 = sensiObject.Sensitivities.get(0).Sensitivity; double shift = 1.0E-6; for (int i = 0; i < X.size(); i++) { DoubleArray yP = Y.with(i, Y.get(i) + shift); InterpolatedNodalCurve curveP = InterpolatedNodalCurve.of(META_ZERO_PERIODIC, X, yP, INTERPOLATOR); double dfP = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, curveP).discountFactorWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); DoubleArray yM = Y.with(i, Y.get(i) - shift); InterpolatedNodalCurve curveM = InterpolatedNodalCurve.of(META_ZERO_PERIODIC, X, yM, INTERPOLATOR); double dfM = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, curveM).discountFactorWithSpread(DATE_AFTER, spread, PERIODIC, periodPerYear); assertEquals(sensi0.get(i), sensiValue * (dfP - dfM) / (2 * shift), TOLERANCE_DELTA_FD, "With spread - " + i); } }
//------------------------------------------------------------------------- public virtual void test_multipliedBy() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d * 3.5d); ZeroRateSensitivity test = @base.multipliedBy(3.5d); assertEquals(test, expected); }
/// <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)); }
//------------------------------------------------------------------------- //------------------------------------------------------------------------- public virtual void test_parameterSensitivity() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double sensiValue = 25d; ZeroRateSensitivity point = test.zeroRatePointSensitivity(DATE_AFTER); point = point.multipliedBy(sensiValue); CurrencyParameterSensitivities sensiObject = test.parameterSensitivity(point); assertEquals(sensiObject.size(), 1); CurrencyParameterSensitivity sensi1 = sensiObject.Sensitivities.get(0); assertEquals(sensi1.Currency, GBP); }