Esempio n. 1
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 expiry = VOLS.relativeTime(TEST_OPTION_EXPIRY[i]);
                BondFutureOptionSensitivity  point      = BondFutureOptionSensitivity.of(VOLS.Name, expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i], USD, TEST_SENSITIVITY[i]);
                CurrencyParameterSensitivity sensActual = VOLS.parameterSensitivity(point).Sensitivities.get(0);
                double[] computed = sensActual.Sensitivity.toArray();
                for (int j = 0; j < nData; j++)
                {
                    DoubleArray volDataUp            = VOL.with(j, VOL.get(j) + eps);
                    DoubleArray volDataDw            = VOL.with(j, VOL.get(j) - eps);
                    InterpolatedNodalSurface paramUp = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, volDataUp, INTERPOLATOR_2D);
                    InterpolatedNodalSurface paramDw = InterpolatedNodalSurface.of(METADATA, TIME, MONEYNESS, volDataDw, INTERPOLATOR_2D);
                    BlackBondFutureExpiryLogMoneynessVolatilities provUp = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, paramUp);
                    BlackBondFutureExpiryLogMoneynessVolatilities provDw = BlackBondFutureExpiryLogMoneynessVolatilities.of(VAL_DATE_TIME, paramDw);
                    double volUp = provUp.volatility(expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]);
                    double volDw = provDw.volatility(expiry, TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]);
                    double fd    = 0.5 * (volUp - volDw) / eps;
                    assertEquals(computed[j], fd, eps);
                }
            }
        }
Esempio n. 2
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, Math.Log(TEST_STRIKE_PRICE[i] / TEST_FUTURE_PRICE[i]));
         double volComputed = VOLS.volatility(TEST_OPTION_EXPIRY[i], TEST_FUTURE_EXPIRY[i], TEST_STRIKE_PRICE[i], TEST_FUTURE_PRICE[i]);
         assertEquals(volComputed, volExpected, TOLERANCE_VOL);
     }
 }