Example #1
0
        public virtual void negativeRates()
        {
            double  shift   = 0.05;
            Surface surface = ConstantSurface.of("shfit", shift);
            SabrInterestRateParameters @params = SabrInterestRateParameters.of(ALPHA_SURFACE, BETA_SURFACE, RHO_SURFACE, NU_SURFACE, surface, FORMULA);
            double expiry = 2.0;
            double tenor  = 3.0;

            assertEquals(@params.alpha(expiry, tenor), ALPHA_SURFACE.zValue(expiry, tenor));
            assertEquals(@params.beta(expiry, tenor), BETA_SURFACE.zValue(expiry, tenor));
            assertEquals(@params.rho(expiry, tenor), RHO_SURFACE.zValue(expiry, tenor));
            assertEquals(@params.nu(expiry, tenor), NU_SURFACE.zValue(expiry, tenor));
            double strike  = -0.02;
            double forward = 0.015;
            double alpha   = ALPHA_SURFACE.zValue(expiry, tenor);
            double beta    = BETA_SURFACE.zValue(expiry, tenor);
            double rho     = RHO_SURFACE.zValue(expiry, tenor);
            double nu      = NU_SURFACE.zValue(expiry, tenor);

            assertEquals(@params.volatility(expiry, tenor, strike, forward), FORMULA.volatility(forward + shift, strike + shift, expiry, alpha, beta, rho, nu));
            double[] adjCmp = @params.volatilityAdjoint(expiry, tenor, strike, forward).Derivatives.toArray();
            double[] adjExp = FORMULA.volatilityAdjoint(forward + shift, strike + shift, expiry, alpha, beta, rho, nu).Derivatives.toArray();
            for (int i = 0; i < 4; ++i)
            {
                assertEquals(adjCmp[i], adjExp[i]);
            }
        }
Example #2
0
        public virtual void hashEqualGetter()
        {
            assertEquals(PARAMETERS.AlphaSurface, ALPHA_SURFACE);
            assertEquals(PARAMETERS.BetaSurface, BETA_SURFACE);
            assertEquals(PARAMETERS.RhoSurface, RHO_SURFACE);
            assertEquals(PARAMETERS.NuSurface, NU_SURFACE);
            assertEquals(PARAMETERS.SabrVolatilityFormula, FORMULA);
            assertEquals(PARAMETERS.ShiftSurface.Name, SurfaceName.of("Zero shift"));
            double expiry = 2.0;
            double tenor  = 3.0;
            double alpha  = ALPHA_SURFACE.zValue(expiry, tenor);
            double beta   = BETA_SURFACE.zValue(expiry, tenor);
            double rho    = RHO_SURFACE.zValue(expiry, tenor);
            double nu     = NU_SURFACE.zValue(expiry, tenor);

            assertEquals(PARAMETERS.alpha(expiry, tenor), alpha);
            assertEquals(PARAMETERS.beta(expiry, tenor), beta);
            assertEquals(PARAMETERS.rho(expiry, tenor), rho);
            assertEquals(PARAMETERS.nu(expiry, tenor), nu);
            double strike  = 1.1;
            double forward = 1.05;

            assertEquals(PARAMETERS.volatility(expiry, tenor, strike, forward), FORMULA.volatility(forward, strike, expiry, alpha, beta, rho, nu));
            double[] adjCmp = PARAMETERS.volatilityAdjoint(expiry, tenor, strike, forward).Derivatives.toArray();
            double[] adjExp = FORMULA.volatilityAdjoint(forward, strike, expiry, alpha, beta, rho, nu).Derivatives.toArray();
            for (int i = 0; i < 6; ++i)
            {
                assertEquals(adjCmp[i], adjExp[i]);
            }
            SabrInterestRateParameters other = SabrInterestRateParameters.of(ALPHA_SURFACE, BETA_SURFACE, RHO_SURFACE, NU_SURFACE, FORMULA);

            assertEquals(PARAMETERS, other);
            assertEquals(PARAMETERS.GetHashCode(), other.GetHashCode());
        }