BjerksundStenslandModel { protected double[] getAlphaAdjoint(double k, double x, double beta) { double w1 = Math.pow(x, -beta); double w2 = x - k; double w3 = w2 * w1; double w2Bar = w1; double w1Bar = w2; double[] res = new double[4]; res[0] = w3; res[1] = -w2Bar; res[2] = w2Bar - beta * w1 / x * w1Bar; res[3] = -Math.log(x) * w3; 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 alphaTest() { final double k = 123; final double x = 204; final double beta = 2.3; final BjerksundStenslandModel bs = new BjerksundStenslandModel(); final double[] sense = bs.getAlphaAdjoint(k, x, beta); final double[] parms = new double[] {k, x, beta }; 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.getAlphaAdjoint(temp[0], temp[1], temp[2])[0]; temp[i] -= 2 * eps; final double down = bs.getAlphaAdjoint(temp[0], temp[1], temp[2])[0]; final double fd = (up - down) / 2 / eps; assertEquals(fd, sense[i + 1], Math.abs(fd) * 1e-8); } }