ShiftedLogNormalTailExtrapolation { public static double price(final double forward, final double strike, final double timeToExpiry, final boolean isCall, final double mu, final double theta) { return BlackFormulaRepository.price(forward * Math.exp(mu), strike, timeToExpiry, theta, isCall); }  static double price(final double forward, final double strike, final double timeToExpiry, final boolean isCall, final double mu, final double theta); static double impliedVolatility(final double forward, final double strike, final double timeToExpiry, final double mu, final double theta); static double dualDelta(final double forward, final double strike, final double timeToExpiry, final boolean isCall, final double mu, final double theta); static double dVdK(final double forward, final double strike, final double timeToExpiry, final double mu, final double theta);  }
@Test public void leftTailPriceTest() { final int nl = LEFT_STRIKES.length; for (int i = 0; i < nl; i++) { double[] res = FITTER.fitTwoPrices(FORWARD, LEFT_STRIKES[i], LEFT_PRICES[i], EXPIRY, false); assertEquals(2, res.length); for (int j = 0; j < 2; j++) { double price = ShiftedLogNormalTailExtrapolation.price(FORWARD, LEFT_STRIKES[i][j], EXPIRY, false, res[0], res[1]); assertEquals(LEFT_PRICES[i][j], price, 1e-9); } double pOld = ShiftedLogNormalTailExtrapolation.price(FORWARD, 0.0, EXPIRY, false, res[0], res[1]); assertEquals(0.0, pOld, 0.0); for (int j = 1; j < 5; j++) { double k = FORWARD * (j / 10.); double price = ShiftedLogNormalTailExtrapolation.price(FORWARD, k, EXPIRY, false, res[0], res[1]); assertTrue(price > pOld); pOld = price; } } }
@Test public void rightTailPriceTest() { final int nl = RIGHT_STRIKES.length; for (int i = 0; i < nl; i++) { double[] res = FITTER.fitTwoPrices(FORWARD, RIGHT_STRIKES[i], RIGHT_PRICES[i], EXPIRY, true); assertEquals(2, res.length); for (int j = 0; j < 2; j++) { double price = ShiftedLogNormalTailExtrapolation.price(FORWARD, RIGHT_STRIKES[i][j], EXPIRY, true, res[0], res[1]); assertEquals(RIGHT_PRICES[i][j], price, 1e-9); } double pOld = ShiftedLogNormalTailExtrapolation.price(FORWARD, 2.0 * FORWARD, EXPIRY, true, res[0], res[1]); for (int j = 2; j < 6; j++) { double k = 2 * FORWARD * j; double price = ShiftedLogNormalTailExtrapolation.price(FORWARD, k, EXPIRY, true, res[0], res[1]); assertTrue(price < pOld); pOld = price; } } }