BjerksundStenslandModel { protected double[] getBetaAdjoint(double r, double b, double sigmaSq) { double[] res = new double[4]; double w1 = 0.5 - b / sigmaSq; double w2 = 2 * r / sigmaSq; double w3 = w1 * w1; double w4 = w3 + w2; if (w4 < 0) { throw new MathException("beta will be complex (see Jira PLAT-2944)"); } double w5 = Math.sqrt(w4); double beta = w1 + w5; double w5Bar = 1.0; double w4Bar = 0.5 / w5 * w5Bar; double w3Bar = w4Bar; double w2Bar = w4Bar; double w1Bar = 1.0 + 2 * w1 * w3Bar; res[0] = beta; res[1] = 2 / sigmaSq * w2Bar; res[2] = -1 / sigmaSq * w1Bar; res[3] = b / sigmaSq / sigmaSq * w1Bar - w2 / sigmaSq * w2Bar; return res; }  Function1D<StandardOptionDataBundle, Double> getPricingFunction(final AmericanVanillaOptionDefinition definition); double price(double s0, double k, double r, double b, double t, double sigma, boolean isCall); double[] getPriceAdjoint(double s0, double k, double r, double b, double t, double sigma, boolean isCall); double[] getPriceDeltaGamma(double s0, double k, double r, double b, double t, double sigma, boolean isCall); double[] getPriceAndVega(double s0, double k, double r, double b, double t, double sigma, boolean isCall); Function1D<Double, double[]> getPriceAndVegaFunction(final double s0, final double k, final double r, final double b, final double t, final boolean isCall); double impliedVolatility(double price, double s0, double k, double r, double b, double t, boolean isCall); double impliedVolatility(double price, double s0, double k, double r, double b, double t, boolean isCall, double guess);  }
@Test public void betaTest() { final double r = 0.1; final double b = 0.04; final double sigma = 0.3; final double sigmaSq = sigma * sigma; final BjerksundStenslandModel bs = new BjerksundStenslandModel(); final double[] sense = bs.getBetaAdjoint(r, b, sigmaSq); final double[] parms = new double[] {r, b, sigmaSq }; final int n = parms.length; final double eps = 1e-5; for (int i = 0; i < n; i++) { final double[] temp = Arrays.copyOf(parms, n); temp[i] += eps; final double up = bs.getBetaAdjoint(temp[0], temp[1], temp[2])[0]; temp[i] -= 2 * eps; final double down = bs.getBetaAdjoint(temp[0], temp[1], temp[2])[0]; final double fd = (up - down) / 2 / eps; assertEquals(fd, sense[i + 1], Math.abs(fd) * 1e-8); } }