//------------------------------------------------------------------------- public virtual void test_build() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); PointSensitivities test = @base.build(); assertEquals(test.Sensitivities, ImmutableList.of(@base)); }
//------------------------------------------------------------------------- public virtual void test_cloned() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity test = @base.cloned(); assertSame(test, @base); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value sensitivity to the SABR model parameters of the swaption product. /// <para> /// The sensitivity of the present value to the SABR model parameters, alpha, beta, rho and nu. /// /// </para> /// </summary> /// <param name="swaption"> the swaption product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="swaptionVolatilities"> the volatilities </param> /// <returns> the point sensitivity to the SABR model parameters </returns> public virtual PointSensitivityBuilder presentValueSensitivityModelParamsSabr(ResolvedSwaption swaption, RatesProvider ratesProvider, SabrSwaptionVolatilities swaptionVolatilities) { validate(swaption, ratesProvider, swaptionVolatilities); double expiry = swaptionVolatilities.relativeTime(swaption.Expiry); ResolvedSwap underlying = swaption.Underlying; ResolvedSwapLeg fixedLeg = this.fixedLeg(underlying); double tenor = swaptionVolatilities.tenor(fixedLeg.StartDate, fixedLeg.EndDate); double shift = swaptionVolatilities.shift(expiry, tenor); double pvbp = SwapPricer.LegPricer.pvbp(fixedLeg, ratesProvider); double strike = SwapPricer.LegPricer.couponEquivalent(fixedLeg, ratesProvider, pvbp); if (expiry < 0d) { // Option has expired already return(PointSensitivityBuilder.none()); } double forward = SwapPricer.parRate(underlying, ratesProvider); double volatility = swaptionVolatilities.volatility(expiry, tenor, strike, forward); DoubleArray derivative = swaptionVolatilities.volatilityAdjoint(expiry, tenor, strike, forward).Derivatives; // Backward sweep double vega = Math.Abs(pvbp) * BlackFormulaRepository.vega(forward + shift, strike + shift, expiry, volatility) * swaption.LongShort.sign(); // sensitivities Currency ccy = fixedLeg.Currency; SwaptionVolatilitiesName name = swaptionVolatilities.Name; return(PointSensitivityBuilder.of(SwaptionSabrSensitivity.of(name, expiry, tenor, ALPHA, ccy, vega * derivative.get(2)), SwaptionSabrSensitivity.of(name, expiry, tenor, BETA, ccy, vega * derivative.get(3)), SwaptionSabrSensitivity.of(name, expiry, tenor, RHO, ccy, vega * derivative.get(4)), SwaptionSabrSensitivity.of(name, expiry, tenor, NU, ccy, vega * derivative.get(5)))); }
//------------------------------------------------------------------------- public virtual void test_withSensitivity() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity expected = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 20d); SwaptionSabrSensitivity test = @base.withSensitivity(20d); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_multipliedBy() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity expected = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d * 3.5d); SwaptionSabrSensitivity test = @base.multipliedBy(3.5d); assertEquals(test, expected); }
public int compareKey(PointSensitivity other) { if (other is SwaptionSabrSensitivity) { SwaptionSabrSensitivity otherSwpt = (SwaptionSabrSensitivity)other; return(ComparisonChain.start().compare(volatilitiesName, otherSwpt.volatilitiesName).compare(currency, otherSwpt.currency).compare(expiry, otherSwpt.expiry).compare(tenor, otherSwpt.tenor).compare(sensitivityType, otherSwpt.sensitivityType).result()); } return(this.GetType().Name.CompareTo(other.GetType().Name)); }
//------------------------------------------------------------------------- public virtual void test_convertedTo() { FxRate rate = FxRate.of(GBP, USD, 1.5d); SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity expected = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, USD, 32d * 1.5d); assertEquals(@base.convertedTo(USD, rate), expected); assertEquals(@base.convertedTo(GBP, rate), @base); }
public virtual void test_combinedWith_mutable() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(@base); PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities()); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_combinedWith() { SwaptionSabrSensitivity base1 = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity base2 = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 22d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(base1).add(base2); PointSensitivityBuilder test = base1.combinedWith(base2); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_withCurrency() { SwaptionSabrSensitivity @base = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); assertSame(@base.withCurrency(GBP), @base); SwaptionSabrSensitivity expected = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, USD, 32d); SwaptionSabrSensitivity test = @base.withCurrency(USD); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_of() { SwaptionSabrSensitivity test = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); assertEquals(test.VolatilitiesName, NAME); assertEquals(test.Expiry, EXPIRY); assertEquals(test.Tenor, TENOR); assertEquals(test.SensitivityType, SabrParameterType.ALPHA); assertEquals(test.Currency, GBP); assertEquals(test.Sensitivity, 32d); }
//------------------------------------------------------------------------- public virtual void coverage() { SwaptionSabrSensitivity test = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); coverImmutableBean(test); SwaptionSabrSensitivity test2 = SwaptionSabrSensitivity.of(NAME2, EXPIRY + 1, TENOR + 1, SabrParameterType.BETA, GBP, 2d); coverBeanEquals(test, test2); ZeroRateSensitivity test3 = ZeroRateSensitivity.of(USD, 0.5d, 2d); coverBeanEquals(test, test3); }
//----------------------------------------------------------------------- public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { SwaptionSabrSensitivity other = (SwaptionSabrSensitivity)obj; return(JodaBeanUtils.equal(volatilitiesName, other.volatilitiesName) && JodaBeanUtils.equal(expiry, other.expiry) && JodaBeanUtils.equal(tenor, other.tenor) && JodaBeanUtils.equal(sensitivityType, other.sensitivityType) && JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(sensitivity, other.sensitivity)); } return(false); }
private void assertSensitivity(PointSensitivities points, SabrParameterType type, double expected, double tol) { foreach (PointSensitivity point in points.Sensitivities) { SwaptionSabrSensitivity sens = (SwaptionSabrSensitivity)point; assertEquals(sens.Currency, USD); assertEquals(sens.VolatilitiesName, VOLS.Name); assertEquals(sens.Tenor, (double)TENOR_YEAR); if (sens.SensitivityType == type) { assertEquals(sens.Sensitivity, expected, NOTIONAL * tol); return; } } fail("Did not find sensitivity: " + type + " in " + points); }
//------------------------------------------------------------------------- public virtual void test_compareKey() { SwaptionSabrSensitivity a1 = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity a2 = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity b = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, USD, 32d); SwaptionSabrSensitivity c = SwaptionSabrSensitivity.of(NAME, EXPIRY + 1, TENOR, SabrParameterType.ALPHA, GBP, 32d); SwaptionSabrSensitivity d = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR + 1, SabrParameterType.ALPHA, GBP, 32d); ZeroRateSensitivity other = ZeroRateSensitivity.of(GBP, 2d, 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) < 0, true); assertEquals(a1.compareKey(b) < 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(a1.compareKey(d) < 0, true); assertEquals(a1.compareKey(other) < 0, true); assertEquals(other.compareKey(a1) > 0, true); }
public virtual void test_parameterSensitivity_multi() { double[] points1 = new double[] { 2.24, 3.45, -2.12, -0.56 }; double[] points2 = new double[] { -0.145, 1.01, -5.0, -11.0 }; double[] points3 = new double[] { 1.3, -4.32, 2.1, -7.18 }; SabrParametersSwaptionVolatilities prov = SabrParametersSwaptionVolatilities.of(NAME, CONV, DATE_TIME, PARAM); double expiryTime0 = prov.relativeTime(TEST_OPTION_EXPIRY[0]); double expiryTime3 = prov.relativeTime(TEST_OPTION_EXPIRY[3]); for (int i = 0; i < NB_TEST; i++) { PointSensitivities sensi1 = PointSensitivities.of(SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], ALPHA, USD, points1[0]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], BETA, USD, points1[1]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], RHO, USD, points1[2]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], NU, USD, points1[3])); PointSensitivities sensi2 = PointSensitivities.of(SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], ALPHA, USD, points2[0]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], BETA, USD, points2[1]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], RHO, USD, points2[2]), SwaptionSabrSensitivity.of(NAME, expiryTime0, TEST_TENOR[i], NU, USD, points2[3])); PointSensitivities sensi3 = PointSensitivities.of(SwaptionSabrSensitivity.of(NAME, expiryTime3, TEST_TENOR[i], ALPHA, USD, points3[0]), SwaptionSabrSensitivity.of(NAME, expiryTime3, TEST_TENOR[i], BETA, USD, points3[1]), SwaptionSabrSensitivity.of(NAME, expiryTime3, TEST_TENOR[i], RHO, USD, points3[2]), SwaptionSabrSensitivity.of(NAME, expiryTime3, TEST_TENOR[i], NU, USD, points3[3])); PointSensitivities sensis = sensi1.combinedWith(sensi2).combinedWith(sensi3).normalized(); CurrencyParameterSensitivities computed = prov.parameterSensitivity(sensis); CurrencyParameterSensitivities expected = prov.parameterSensitivity(sensi1).combinedWith(prov.parameterSensitivity(sensi2)).combinedWith(prov.parameterSensitivity(sensi3)); DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.AlphaSurface.Name, USD).Sensitivity.toArray(), expected.getSensitivity(PARAM.AlphaSurface.Name, USD).Sensitivity.toArray(), TOLERANCE_VOL); DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.BetaSurface.Name, USD).Sensitivity.toArray(), expected.getSensitivity(PARAM.BetaSurface.Name, USD).Sensitivity.toArray(), TOLERANCE_VOL); DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.RhoSurface.Name, USD).Sensitivity.toArray(), expected.getSensitivity(PARAM.RhoSurface.Name, USD).Sensitivity.toArray(), TOLERANCE_VOL); DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.NuSurface.Name, USD).Sensitivity.toArray(), expected.getSensitivity(PARAM.NuSurface.Name, USD).Sensitivity.toArray(), TOLERANCE_VOL); } }
public virtual void test_parameterSensitivity() { double alphaSensi = 2.24, betaSensi = 3.45, rhoSensi = -2.12, nuSensi = -0.56; SabrParametersSwaptionVolatilities prov = SabrParametersSwaptionVolatilities.of(NAME, CONV, DATE_TIME, PARAM); for (int i = 0; i < NB_TEST; i++) { double expiryTime = prov.relativeTime(TEST_OPTION_EXPIRY[i]); PointSensitivities point = PointSensitivities.of(SwaptionSabrSensitivity.of(NAME, expiryTime, TEST_TENOR[i], ALPHA, USD, alphaSensi), SwaptionSabrSensitivity.of(NAME, expiryTime, TEST_TENOR[i], BETA, USD, betaSensi), SwaptionSabrSensitivity.of(NAME, expiryTime, TEST_TENOR[i], RHO, USD, rhoSensi), SwaptionSabrSensitivity.of(NAME, expiryTime, TEST_TENOR[i], NU, USD, nuSensi)); CurrencyParameterSensitivities sensiComputed = prov.parameterSensitivity(point); UnitParameterSensitivity alphaSensitivities = prov.Parameters.AlphaSurface.zValueParameterSensitivity(expiryTime, TEST_TENOR[i]); UnitParameterSensitivity betaSensitivities = prov.Parameters.BetaSurface.zValueParameterSensitivity(expiryTime, TEST_TENOR[i]); UnitParameterSensitivity rhoSensitivities = prov.Parameters.RhoSurface.zValueParameterSensitivity(expiryTime, TEST_TENOR[i]); UnitParameterSensitivity nuSensitivities = prov.Parameters.NuSurface.zValueParameterSensitivity(expiryTime, TEST_TENOR[i]); CurrencyParameterSensitivity alphaSensiObj = sensiComputed.getSensitivity(SwaptionSabrRateVolatilityDataSet.META_ALPHA.SurfaceName, USD); CurrencyParameterSensitivity betaSensiObj = sensiComputed.getSensitivity(SwaptionSabrRateVolatilityDataSet.META_BETA_USD.SurfaceName, USD); CurrencyParameterSensitivity rhoSensiObj = sensiComputed.getSensitivity(SwaptionSabrRateVolatilityDataSet.META_RHO.SurfaceName, USD); CurrencyParameterSensitivity nuSensiObj = sensiComputed.getSensitivity(SwaptionSabrRateVolatilityDataSet.META_NU.SurfaceName, USD); DoubleArray alphaNodeSensiComputed = alphaSensiObj.Sensitivity; DoubleArray betaNodeSensiComputed = betaSensiObj.Sensitivity; DoubleArray rhoNodeSensiComputed = rhoSensiObj.Sensitivity; DoubleArray nuNodeSensiComputed = nuSensiObj.Sensitivity; assertEquals(alphaSensitivities.Sensitivity.size(), alphaNodeSensiComputed.size()); assertEquals(betaSensitivities.Sensitivity.size(), betaNodeSensiComputed.size()); assertEquals(rhoSensitivities.Sensitivity.size(), rhoNodeSensiComputed.size()); assertEquals(nuSensitivities.Sensitivity.size(), nuNodeSensiComputed.size()); for (int k = 0; k < alphaNodeSensiComputed.size(); ++k) { assertEquals(alphaNodeSensiComputed.get(k), alphaSensitivities.Sensitivity.get(k) * alphaSensi, TOLERANCE_VOL); } for (int k = 0; k < betaNodeSensiComputed.size(); ++k) { assertEquals(betaNodeSensiComputed.get(k), betaSensitivities.Sensitivity.get(k) * betaSensi, TOLERANCE_VOL); } for (int k = 0; k < rhoNodeSensiComputed.size(); ++k) { assertEquals(rhoNodeSensiComputed.get(k), rhoSensitivities.Sensitivity.get(k) * rhoSensi, TOLERANCE_VOL); } for (int k = 0; k < nuNodeSensiComputed.size(); ++k) { assertEquals(nuNodeSensiComputed.get(k), nuSensitivities.Sensitivity.get(k) * nuSensi, TOLERANCE_VOL); } } }
public virtual void test_serialization() { SwaptionSabrSensitivity test = SwaptionSabrSensitivity.of(NAME, EXPIRY, TENOR, SabrParameterType.ALPHA, GBP, 32d); assertSerialization(test); }