BarrierOptionPricer { public double inBarrier(final double spot, final double barrierLevel, final double strike, final double expiry, final double rate, final double carry, final double vol, final boolean isCall, final double rebate) { final double outPrice = outBarrierSpecial(spot, barrierLevel, strike, expiry, rate, carry, vol, isCall, rebate); final double bsPrice = blackPrice(spot, strike, expiry, rate, carry, vol, isCall); return bsPrice + Math.exp(-rate * expiry) * rebate - outPrice; } BarrierOptionPricer();  BarrierOptionPricer(final int numXNodes, final int numTNodes, final double lambda, final double bunching); double getPrice(final EuropeanVanillaOption option, final Barrier barrier, final double rebate, final double spot, final double costOfCarry, final double rate, final double sigma); double outBarrier(final double spot, final double barrierLevel, final double strike, final double expiry, final double rate, final double carry,
      final double vol, final boolean isCall, final double rebate); double inBarrier(final double spot, final double barrierLevel, final double strike, final double expiry, final double rate, final double carry,
      final double vol, final boolean isCall, final double rebate);  }
@Test public void inBarrierTest() { if (PRINT) { System.out.println("BarrierOptionPricerTest"); } for (int i = 0; i < 5; i++) { final double strike = SPOT * (0.9 + i * 0.1); for (int j = 0; j < 5; j++) { final double h = SPOT * (0.9 + j * 0.05); for (int k = 0; k < 2; k++) { final boolean isCall = k == 0; final BarrierType bt = SPOT > h ? BarrierType.DOWN : BarrierType.UP; final double anPrice = ANAL_PRICER.getPrice(new EuropeanVanillaOption(strike, EXPIRY, isCall), new Barrier(KnockType.IN, bt, ObservationType.CONTINUOUS, h), REBATE, SPOT, B, R, SIGMA); final double fdPrice = PRICER.inBarrier(SPOT, h, strike, EXPIRY, R, B, SIGMA, isCall, REBATE); if (PRINT) { final String call = isCall ? "call" : "put "; System.out.format(call + " x = %.0f h = %.0f\tprice = %.4f\tfdPrice = %.4f\n", strike, h, anPrice, fdPrice); } assertEquals(anPrice, fdPrice, 5e-2); } } } }