示例#1
0
        public virtual void negativeRates()
        {
            double         shift   = 0.05;
            Curve          surface = ConstantCurve.of("shfit", shift);
            SabrParameters @params = SabrParameters.of(ALPHA_CURVE, BETA_CURVE, RHO_CURVE, NU_CURVE, surface, FORMULA);
            double         expiry  = 2.0;

            assertEquals(@params.alpha(expiry), ALPHA_CURVE.yValue(expiry));
            assertEquals(@params.beta(expiry), BETA_CURVE.yValue(expiry));
            assertEquals(@params.rho(expiry), RHO_CURVE.yValue(expiry));
            assertEquals(@params.nu(expiry), NU_CURVE.yValue(expiry));
            double strike  = -0.02;
            double forward = 0.015;
            double alpha   = ALPHA_CURVE.yValue(expiry);
            double beta    = BETA_CURVE.yValue(expiry);
            double rho     = RHO_CURVE.yValue(expiry);
            double nu      = NU_CURVE.yValue(expiry);

            assertEquals(@params.volatility(expiry, strike, forward), FORMULA.volatility(forward + shift, strike + shift, expiry, alpha, beta, rho, nu));
            double[] adjCmp = @params.volatilityAdjoint(expiry, 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]);
            }
        }
示例#2
0
        public virtual void getter()
        {
            assertEquals(PARAMETERS.AlphaCurve, ALPHA_CURVE);
            assertEquals(PARAMETERS.BetaCurve, BETA_CURVE);
            assertEquals(PARAMETERS.RhoCurve, RHO_CURVE);
            assertEquals(PARAMETERS.NuCurve, NU_CURVE);
            assertEquals(PARAMETERS.SabrVolatilityFormula, FORMULA);
            assertEquals(PARAMETERS.ShiftCurve.Name, CurveName.of("Zero shift"));
            assertEquals(PARAMETERS.DayCount, ACT_ACT_ISDA);
            assertEquals(PARAMETERS.ParameterCount, 9);
            double expiry = 2.0;
            double alpha  = ALPHA_CURVE.yValue(expiry);
            double beta   = BETA_CURVE.yValue(expiry);
            double rho    = RHO_CURVE.yValue(expiry);
            double nu     = NU_CURVE.yValue(expiry);

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

            assertEquals(PARAMETERS.volatility(expiry, strike, forward), FORMULA.volatility(forward, strike, expiry, alpha, beta, rho, nu));
            double[] adjCmp = PARAMETERS.volatilityAdjoint(expiry, 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]);
            }
            for (int i = 0; i < 9; ++i)
            {
                if (i < 2)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), ALPHA_CURVE.getParameterMetadata(i));
                    assertEquals(PARAMETERS.getParameter(i), ALPHA_CURVE.getParameter(i));
                }
                else if (i < 4)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), BETA_CURVE.getParameterMetadata(i - 2));
                    assertEquals(PARAMETERS.getParameter(i), BETA_CURVE.getParameter(i - 2));
                }
                else if (i < 6)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), RHO_CURVE.getParameterMetadata(i - 4));
                    assertEquals(PARAMETERS.getParameter(i), RHO_CURVE.getParameter(i - 4));
                }
                else if (i < 8)
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), NU_CURVE.getParameterMetadata(i - 6));
                    assertEquals(PARAMETERS.getParameter(i), NU_CURVE.getParameter(i - 6));
                }
                else
                {
                    assertEquals(PARAMETERS.getParameterMetadata(i), ParameterMetadata.empty());
                    assertEquals(PARAMETERS.getParameter(i), 0d);
                }
            }
        }