BjerksundStenslandModel { protected double[] getLambdaAdjoint(double gamma, double r, double b, double sigmaSq) { double[] res = new double[5]; double temp = 0.5 * gamma * (gamma - 1); res[0] = -r + gamma * b + temp * sigmaSq; res[1] = b + (gamma - 0.5) * sigmaSq; res[2] = -1.0; res[3] = gamma; res[4] = temp; 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 lambdaTest() { final double[] gammaSet = new double[] {0, 1, 0.9, 2.3 }; final double r = 0.1; final double[] bSet = {-0.03, 0, 0.04, r }; final double sigma = 0.3; final double sigmaSq = sigma * sigma; final BjerksundStenslandModel bs = new BjerksundStenslandModel(); for (final double gamma : gammaSet) { for (final double b : bSet) { final double[] sense = bs.getLambdaAdjoint(gamma, r, b, sigmaSq); final double[] parms = new double[] {gamma, 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.getLambdaAdjoint(temp[0], temp[1], temp[2], temp[3])[0]; temp[i] -= 2 * eps; final double down = bs.getLambdaAdjoint(temp[0], temp[1], temp[2], temp[3])[0]; final double fd = (up - down) / 2 / eps; assertEquals(fd, sense[i + 1], Math.abs(fd) * 1e-8); } } } }