BjerksundStenslandModel { protected double[] getI2Adjoint(double k, double r, double b, double sigma, double t) { return getIAdjoint(k, r, b, sigma, t, false); }  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 i2Test() { final double k = 100.04; final double r = 0.1; final double[] bb = new double[] {-0.03, 0.04 }; final double sigma = 0.3; final double t = 1.3; final BjerksundStenslandModel bs = new BjerksundStenslandModel(); for (final double b : bb) { final double[] sense = bs.getI2Adjoint(k, r, b, sigma, t); final double[] parms = new double[] {k, r, b, sigma, t }; 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.getI2Adjoint(temp[0], temp[1], temp[2], temp[3], temp[4])[0]; temp[i] -= 2 * eps; final double down = bs.getI2Adjoint(temp[0], temp[1], temp[2], temp[3], temp[4])[0]; final double fd = (up - down) / 2 / eps; assertEquals(fd, sense[i + 1], Math.abs(fd) * 1e-7); } } }