final double tolerance = 1.0e-6;
// plain
final ZeroCouponBond bond1 = new ZeroCouponBond(settlementDays,
new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
faceAmount,
new Date(30,Month.November,2008),
BusinessDayConvention.ModifiedFollowing,
100.0, new Date(30,Month.November,2004));
final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);
bond1.setPricingEngine(bondEngine);
final double cachedPrice1 = 88.551726;
double price = bond1.getCleanPrice();
if (Math.abs(price-cachedPrice1) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice1 + "\n"
+ " error: " + (price-cachedPrice1));
}
final ZeroCouponBond bond2 = new ZeroCouponBond(settlementDays,
new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
faceAmount,
new Date(30,Month.November,2007),
BusinessDayConvention.ModifiedFollowing,
100.0, new Date(30,Month.November,2004));
bond2.setPricingEngine(bondEngine);
final double cachedPrice2 = 91.278949;
price = bond2.getCleanPrice();
if (Math.abs(price-cachedPrice2) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice2 + "\n"
+ " error: " + (price-cachedPrice2));
}
final ZeroCouponBond bond3 = new ZeroCouponBond(settlementDays,
new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
faceAmount,
new Date(30,Month.November,2006),
BusinessDayConvention.ModifiedFollowing,
100.0, new Date(30,Month.November,2004));
bond3.setPricingEngine(bondEngine);
final double cachedPrice3 = 94.098006;
price = bond3.getCleanPrice();
if (Math.abs(price-cachedPrice3) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice3 + "\n"
+ " error: " + (price-cachedPrice3));