//------------------------------------------------------------------------- // proper end-to-end FD tests are elsewhere public virtual void test_parameterSensitivity() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity point = ZeroRateSensitivity.of(GBP, 1d, 1d); assertEquals(test.parameterSensitivity(point).size(), 1); }
//------------------------------------------------------------------------- public virtual void test_cloned() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity test = @base.cloned(); assertSame(test, @base); }
//------------------------------------------------------------------------- public virtual void test_build() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); PointSensitivities test = @base.build(); assertEquals(test.Sensitivities, ImmutableList.of(@base)); }
//------------------------------------------------------------------------- public virtual void test_withCurrency() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); assertSame(@base.withCurrency(GBP), @base); assertEquals(@base.withCurrency(USD), ZeroRateSensitivity.of(GBP, YEARFRAC, USD, 32d)); }
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_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, USD, -0d); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, PERIODIC, 2), expected); }
public virtual void test_zeroRatePointSensitivityWithSpread_smallYearFraction() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, -0d); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, SPREAD, CONTINUOUS, 0), expected); }
public CurrencyParameterSensitivities parameterSensitivity(ZeroRateSensitivity pointSens) { double yearFraction = pointSens.YearFraction; UnitParameterSensitivity unitSens = curve.yValueParameterSensitivity(yearFraction); CurrencyParameterSensitivity curSens = unitSens.multipliedBy(pointSens.Currency, pointSens.Sensitivity); return(CurrencyParameterSensitivities.of(curSens)); }
//------------------------------------------------------------------------- public virtual void test_withSensitivity() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 20d); ZeroRateSensitivity test = @base.withSensitivity(20d); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_mapSensitivity() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 1 / 32d); ZeroRateSensitivity test = @base.mapSensitivity(s => 1 / s); assertEquals(test, expected); }
//------------------------------------------------------------------------- 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); }
//------------------------------------------------------------------------- public virtual void test_currencyParameterSensitivity_val_date() { // Discount factor at valuation date is always 0, no sensitivity. SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity sens = test.zeroRatePointSensitivity(DATE_VAL); assertEquals(test.parameterSensitivity(sens), CurrencyParameterSensitivities.empty()); }
//------------------------------------------------------------------------- public virtual void coverage() { ZeroRateSensitivity test = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); coverImmutableBean(test); ZeroRateSensitivity test2 = ZeroRateSensitivity.of(USD, YEARFRAC2, 16d); coverBeanEquals(test, test2); }
//------------------------------------------------------------------------- public virtual void test_zeroRatePointSensitivity() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction)); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivity(DATE_AFTER), expected); }
public int compareKey(PointSensitivity other) { if (other is ZeroRateSensitivity) { ZeroRateSensitivity otherZero = (ZeroRateSensitivity)other; return(ComparisonChain.start().compare(curveCurrency, otherZero.curveCurrency).compare(currency, otherZero.currency).compare(yearFraction, otherZero.yearFraction).result()); } return(this.GetType().Name.CompareTo(other.GetType().Name)); }
public virtual void test_of() { ZeroRateSensitivity test = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); assertEquals(test.Currency, GBP); assertEquals(test.YearFraction, YEARFRAC); assertEquals(test.Sensitivity, 32d); assertEquals(test.Currency, GBP); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, USD, 0.0d); ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, CONTINUOUS, 0); assertTrue(computed.compareKey(expected) == 0); assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA_FD); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continuous() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = CURVE.yValue(relativeYearFraction) * Math.Exp(-SPREAD * relativeYearFraction); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 1), expected); }
public virtual void test_zeroRatePointSensitivity_sensitivityCurrency() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = CURVE.yValue(relativeYearFraction); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, USD), expected); }
//------------------------------------------------------------------------- public virtual void test_zeroRatePointSensitivityWithSpread_continous() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = Math.Exp(-relativeYearFraction * (CURVE.yValue(relativeYearFraction) + SPREAD)); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0), expected); }
//------------------------------------------------------------------------- public virtual void test_buildInto() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); MutablePointSensitivities combo = new MutablePointSensitivities(); MutablePointSensitivities test = @base.buildInto(combo); assertSame(test, combo); assertEquals(test.Sensitivities, ImmutableList.of(@base)); }
public virtual void test_combinedWith_mutable() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(@base); PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities()); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_unitParameterSensitivity() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity sens = test.zeroRatePointSensitivity(DATE_AFTER); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); CurrencyParameterSensitivities expected = CurrencyParameterSensitivities.of(CURVE.yValueParameterSensitivity(relativeYearFraction).multipliedBy(sens.Currency, sens.Sensitivity)); assertEquals(test.parameterSensitivity(sens), 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_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continous() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 0); assertTrue(computed.compareKey(expected) == 0); assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA); }
//------------------------------------------------------------------------- public virtual void test_combinedWith() { ZeroRateSensitivity base1 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity base2 = ZeroRateSensitivity.of(GBP, YEARFRAC2, 22d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(base1).add(base2); PointSensitivityBuilder test = base1.combinedWith(base2); assertEquals(test, expected); }
//------------------------------------------------------------------------- public CurrencyParameterSensitivities parameterSensitivity(ZeroRateSensitivity pointSens) { double yearFraction = pointSens.YearFraction; double rp = curve.yValue(yearFraction); double rcBar = 1.0; double rpBar = 1.0 / (1 + rp / frequency) * rcBar; UnitParameterSensitivity unitSens = curve.yValueParameterSensitivity(yearFraction).multipliedBy(rpBar); CurrencyParameterSensitivity curSens = unitSens.multipliedBy(pointSens.Currency, pointSens.Sensitivity); return(CurrencyParameterSensitivities.of(curSens)); }
//------------------------------------------------------------------------- public virtual void test_presentValueSensitivity_df() { PointSensitivities point = PRICER.presentValueSensitivity(PAYMENT, DISCOUNT_FACTORS).build(); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = -DF * relativeYearFraction * NOTIONAL_USD; ZeroRateSensitivity actual = (ZeroRateSensitivity)point.Sensitivities.get(0); assertEquals(actual.Currency, USD); assertEquals(actual.CurveCurrency, USD); assertEquals(actual.YearFraction, relativeYearFraction); assertEquals(actual.Sensitivity, expected, NOTIONAL_USD * TOL); }
//----------------------------------------------------------------------- public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { ZeroRateSensitivity other = (ZeroRateSensitivity)obj; return(JodaBeanUtils.equal(curveCurrency, other.curveCurrency) && JodaBeanUtils.equal(yearFraction, other.yearFraction) && JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(sensitivity, other.sensitivity)); } return(false); }
//------------------------------------------------------------------------- public virtual void test_presentValueSensitivityWithSpread_df_spread_continuous() { PointSensitivities point = PRICER.presentValueSensitivityWithSpread(PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0).build(); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = -DF *relativeYearFraction *NOTIONAL_USD *Math.Exp(-Z_SPREAD *relativeYearFraction); ZeroRateSensitivity actual = (ZeroRateSensitivity)point.Sensitivities.get(0); assertEquals(actual.Currency, USD); assertEquals(actual.CurveCurrency, USD); assertEquals(actual.YearFraction, relativeYearFraction); assertEquals(actual.Sensitivity, expected, NOTIONAL_USD * TOL); }