// plain
final Schedule sch = new Schedule(new Date(30,Month.November,2004),
new Date(30,Month.November,2008), new Period(Frequency.Semiannual),
new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);
final FixedRateBond bond1 = new FixedRateBond(settlementDays, faceAmount, sch,
new double [] { 0.02875 },
new ActualActual(ActualActual.Convention.ISMA),
BusinessDayConvention.ModifiedFollowing,
100.0, new Date(30,Month.November,2004));
final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);
bond1.setPricingEngine(bondEngine);
final double cachedPrice1 = 99.298100;
double price = bond1.cleanPrice();
if (Math.abs(price-cachedPrice1) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice1 + "\n"
+ " error: " + (price-cachedPrice1));
}
// varying coupons
final double [] couponRates = new double[] { 0.02875, 0.03, 0.03125, 0.0325 };
final FixedRateBond bond2 = new FixedRateBond(settlementDays, faceAmount, sch,
couponRates,
new ActualActual(ActualActual.Convention.ISMA),
BusinessDayConvention.ModifiedFollowing,
100.0, new Date(30,Month.November,2004));
bond2.setPricingEngine(bondEngine);
final double cachedPrice2 = 100.334149;
price = bond2.cleanPrice();
if (Math.abs(price-cachedPrice2) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice2 + "\n"
+ " error: " + (price-cachedPrice2));
}
// stub date
final Schedule sch3 = new Schedule(new Date(30,Month.November,2004),
new Date(30,Month.March,2009), new Period(Frequency.Semiannual),
new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
DateGeneration.Rule.Backward, false,
new Date(), new Date(30,Month.November,2008));
final FixedRateBond bond3 = new FixedRateBond(settlementDays, faceAmount, sch3,