HoLeeInterestRateModel implements DiscountBondModel<StandardDiscountBondModelDataBundle> { @Override public Function1D<StandardDiscountBondModelDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity) { Validate.notNull(time); Validate.notNull(maturity); return new Function1D<StandardDiscountBondModelDataBundle, Double>() { @Override public Double evaluate(final StandardDiscountBondModelDataBundle data) { Validate.notNull(data); final double t = DateUtils.getDifferenceInYears(data.getDate(), time); final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity); final double b = s - t; final double sigma = data.getShortRateVolatility(t); final double rT = data.getShortRate(t); final double rS = data.getShortRate(s); final double pT = Math.exp(-rT * t); final double pS = Math.exp(-rS * s); final double dlnPdt = -rT; final double lnA = Math.log(pS / pT) - b * dlnPdt - 0.5 * sigma * sigma * b * b; return Math.exp(lnA - b * rT); } }; }  @Override Function1D<StandardDiscountBondModelDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time, final ZonedDateTime maturity);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTime() { MODEL.getDiscountBondFunction(null, MATURITY); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullMaturity() { MODEL.getDiscountBondFunction(START, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { MODEL.getDiscountBondFunction(START, MATURITY).evaluate((StandardDiscountBondModelDataBundle) null); }
@Test public void test() { final double eps = 1e-9; assertEquals(MODEL.getDiscountBondFunction(START, START).evaluate(DATA), 1, 0); StandardDiscountBondModelDataBundle data = new StandardDiscountBondModelDataBundle(YieldCurve.from(ConstantDoublesCurve.from(0.)), new VolatilityCurve(ConstantDoublesCurve.from(0)), TODAY); assertEquals(MODEL.getDiscountBondFunction(START, MATURITY).evaluate(data), 1, 0); data = new StandardDiscountBondModelDataBundle(YieldCurve.from(ConstantDoublesCurve.from(0.)), SIGMA, TODAY); assertEquals(MODEL.getDiscountBondFunction(START, MATURITY).evaluate(data), Math.exp(-0.5 * VOL * VOL * YEARS * YEARS), 0); data = new StandardDiscountBondModelDataBundle(R, new VolatilityCurve(ConstantDoublesCurve.from(0)), TODAY); assertEquals(MODEL.getDiscountBondFunction(START, MATURITY).evaluate(data), Math.exp(-IR * YEARS), eps); }