예제 #1
0
 public virtual void test_volatility()
 {
     for (int i = 0; i < NB_TEST; i++)
     {
         double expiryTime  = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]);
         double volExpected = SURFACE.zValue(expiryTime, TEST_STRIKE[i] - TEST_FORWARD[i]);
         double volComputed = VOLS.volatility(TEST_OPTION_EXPIRY[i], TEST_TENOR, TEST_STRIKE[i], TEST_FORWARD[i]);
         assertEquals(volComputed, volExpected, TOLERANCE_VOL);
     }
 }
예제 #2
0
        public virtual void test_volatility_sensitivity()
        {
            double eps   = 1.0e-6;
            int    nData = TIME.size();

            for (int i = 0; i < NB_TEST; i++)
            {
                double expiryTime = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]);
                SwaptionSensitivity            point      = SwaptionSensitivity.of(VOLS.Name, expiryTime, TEST_TENOR, TEST_STRIKE[i], TEST_FORWARD[i], GBP, TEST_SENSITIVITY[i]);
                CurrencyParameterSensitivities sensActual = VOLS.parameterSensitivity(point);
                CurrencyParameterSensitivity   sensi      = sensActual.getSensitivity(SURFACE.Name, GBP);
                DoubleArray computed = sensi.Sensitivity;

                IDictionary <DoublesPair, double> map = new Dictionary <DoublesPair, double>();
                for (int j = 0; j < nData; ++j)
                {
                    DoubleArray volDataUp            = VOL.subArray(0, nData).with(j, VOL.get(j) + eps);
                    DoubleArray volDataDw            = VOL.subArray(0, nData).with(j, VOL.get(j) - eps);
                    InterpolatedNodalSurface paramUp = InterpolatedNodalSurface.of(METADATA, TIME, SIMPLE_MONEYNESS, volDataUp, INTERPOLATOR_2D);
                    InterpolatedNodalSurface paramDw = InterpolatedNodalSurface.of(METADATA, TIME, SIMPLE_MONEYNESS, volDataDw, INTERPOLATOR_2D);
                    NormalSwaptionExpirySimpleMoneynessVolatilities provUp = NormalSwaptionExpirySimpleMoneynessVolatilities.of(CONVENTION, VAL_DATE_TIME, paramUp);
                    NormalSwaptionExpirySimpleMoneynessVolatilities provDw = NormalSwaptionExpirySimpleMoneynessVolatilities.of(CONVENTION, VAL_DATE_TIME, paramDw);
                    double volUp = provUp.volatility(TEST_OPTION_EXPIRY[i], TEST_TENOR, TEST_STRIKE[i], TEST_FORWARD[i]);
                    double volDw = provDw.volatility(TEST_OPTION_EXPIRY[i], TEST_TENOR, TEST_STRIKE[i], TEST_FORWARD[i]);
                    double fd    = 0.5 * (volUp - volDw) / eps;
                    map[DoublesPair.of(TIME.get(j), SIMPLE_MONEYNESS.get(j))] = fd;
                }
                IList <ParameterMetadata> list = sensi.ParameterMetadata;
                assertEquals(computed.size(), nData);
                for (int j = 0; j < list.Count; ++j)
                {
                    SwaptionSurfaceExpirySimpleMoneynessParameterMetadata metadata = (SwaptionSurfaceExpirySimpleMoneynessParameterMetadata)list[i];
                    double expected = map[DoublesPair.of(metadata.YearFraction, metadata.SimpleMoneyness)];
                    assertEquals(computed.get(i), expected, eps);
                }
            }
        }