//----------------------------------------------------------------------- public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { VolatilityAndBucketedSensitivities other = (VolatilityAndBucketedSensitivities)obj; return(JodaBeanUtils.equal(volatility, other.volatility) && JodaBeanUtils.equal(sensitivities, other.sensitivities)); } return(false); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test() public virtual void test() { VolatilityAndBucketedSensitivities @object = VolatilityAndBucketedSensitivities.of(VOL, SENSITIVITIES); assertEquals(VOL, @object.Volatility); assertEquals(SENSITIVITIES, @object.Sensitivities); VolatilityAndBucketedSensitivities other = VolatilityAndBucketedSensitivities.of(VOL, DoubleMatrix.of(2, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6)); assertEquals(@object, other); assertEquals(@object.GetHashCode(), other.GetHashCode()); other = VolatilityAndBucketedSensitivities.of(VOL + 0.01, SENSITIVITIES); assertFalse(other.Equals(@object)); other = VolatilityAndBucketedSensitivities.of(VOL, SENSITIVITIES2); assertFalse(other.Equals(@object)); }
/// <summary> /// Tests the interpolation and its derivative with respect to the data by comparison to finite difference. /// </summary> public virtual void volatilityAjoint() { double forward = 1.40; double[] timeToExpiry = new double[] { 0.75, 1.00, 2.50 }; double[] strike = new double[] { 1.50, 1.70, 2.20 }; double[] tolerance = new double[] { 3e-2, 1e-1, 1e-5 }; int nbTest = strike.Length; double shift = 0.00001; for (int looptest = 0; looptest < nbTest; looptest++) { double vol = SMILE_TERM.volatility(timeToExpiry[looptest], strike[looptest], forward); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] bucketTest = new double[TIME_TO_EXPIRY.size()][2 * DELTA.size() + 1]; double[][] bucketTest = RectangularArrays.ReturnRectangularDoubleArray(TIME_TO_EXPIRY.size(), 2 * DELTA.size() + 1); VolatilityAndBucketedSensitivities volComputed = SMILE_TERM.volatilityAndSensitivities(timeToExpiry[looptest], strike[looptest], forward); DoubleMatrix bucketSensi = volComputed.Sensitivities; assertEquals(volComputed.Volatility, vol, 1.0E-10, "Smile by delta term structure: volatility adjoint"); SmileDeltaParameters[] volData = new SmileDeltaParameters[TIME_TO_EXPIRY.size()]; double[] volBumped = new double[2 * DELTA.size() + 1]; for (int loopexp = 0; loopexp < TIME_TO_EXPIRY.size(); loopexp++) { for (int loopsmile = 0; loopsmile < 2 * DELTA.size() + 1; loopsmile++) { Array.Copy(SMILE_TERM.VolatilityTerm.toArray(), 0, volData, 0, TIME_TO_EXPIRY.size()); Array.Copy(SMILE_TERM.VolatilityTerm.get(loopexp).Volatility.toArray(), 0, volBumped, 0, 2 * DELTA.size() + 1); volBumped[loopsmile] += shift; volData[loopexp] = SmileDeltaParameters.of(TIME_TO_EXPIRY.get(loopexp), DELTA, DoubleArray.copyOf(volBumped)); InterpolatedStrikeSmileDeltaTermStructure smileTermBumped = InterpolatedStrikeSmileDeltaTermStructure.of(ImmutableList.copyOf(volData), ACT_360); bucketTest[loopexp][loopsmile] = (smileTermBumped.volatility(timeToExpiry[looptest], strike[looptest], forward) - volComputed.Volatility) / shift; assertEquals(bucketSensi.get(loopexp, loopsmile), bucketTest[loopexp][loopsmile], tolerance[looptest], "Smile by delta term structure: (test: " + looptest + ") volatility bucket sensitivity " + loopexp + " - " + loopsmile); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void testNullSensitivities() public virtual void testNullSensitivities() { VolatilityAndBucketedSensitivities.of(VOL, null); }