BarrierOptionPricer { public double getPrice(final EuropeanVanillaOption option, final Barrier barrier, final double rebate, final double spot, final double costOfCarry, final double rate, final double sigma) { Validate.notNull(option, "option"); Validate.notNull(barrier, "barrier"); final boolean isKnockIn = (barrier.getKnockType() == KnockType.IN); final boolean isDown = (barrier.getBarrierType() == BarrierType.DOWN); if (isDown && spot <= barrier.getBarrierLevel() || !isDown && spot >= barrier.getBarrierLevel()) { if (isKnockIn) { return blackPrice(spot, option.getStrike(), option.getTimeToExpiry(), rate, costOfCarry, sigma, option.isCall()); } return rebate; } if (isKnockIn) { return inBarrier(spot, barrier.getBarrierLevel(), option.getStrike(), option.getTimeToExpiry(), rate, costOfCarry, sigma, option.isCall(), rebate); } return outBarrier(spot, barrier.getBarrierLevel(), option.getStrike(), option.getTimeToExpiry(), rate, costOfCarry, sigma, option.isCall(), rebate); } 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 debugTest() { final double spot = 10.0; final double expiry = 2.0; final boolean isCall = true; final double strike = 13.0; final double barrerLevel = 17.0; final double rebate = 1.0; final double r = 0.0; final double b = 0.0; final double sigma = 0.3; final EuropeanVanillaOption option = new EuropeanVanillaOption(strike, expiry, isCall); final Barrier barrier = new Barrier(KnockType.OUT, BarrierType.UP, ObservationType.CONTINUOUS, barrerLevel); final BarrierOptionPricer pricer = new BarrierOptionPricer(100, 50, 0.5, 0.1); if (PRINT) { final double p1 = ANAL_PRICER.getPrice(option, barrier, rebate, spot, b, r, sigma); final double p2 = pricer.getPrice(option, barrier, rebate, spot, b, r, sigma); final double error = 1e6 * (p1 - p2) / p1; System.out.println(p1 + "\t" + p2 + "\t" + error); } }