new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
BusinessDayConvention.ModifiedFollowing,
BusinessDayConvention.ModifiedFollowing,
DateGeneration.Rule.Backward, false);
final FloatingRateBond bond1 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
index, new ActualActual(ActualActual.Convention.ISMA),
BusinessDayConvention.ModifiedFollowing, fixingDays,
new Array(0), new Array(0),
new Array(0), new Array(0),
false,
100.0, new Date(30,Month.November,2004));
final PricingEngine bondEngine = new DiscountingBondEngine(riskFreeRate);
bond1.setPricingEngine(bondEngine);
PricerSetter.setCouponPricer(bond1.cashflows(),pricer);
final boolean indexedCoupon = new Settings().isUseIndexedCoupon();
final double cachedPrice1 = indexedCoupon ? 99.874645 : 99.874646;
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));
}
// different risk-free and discount curve
final FloatingRateBond bond2 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
index, new ActualActual(ActualActual.Convention.ISMA),
BusinessDayConvention.ModifiedFollowing, fixingDays,
new Array(0), new Array(0),
new Array(0), new Array(0),
false,
100.0, new Date(30,Month.November,2004));
final PricingEngine bondEngine2 = new DiscountingBondEngine(discountCurve);
bond2.setPricingEngine(bondEngine2);
PricerSetter.setCouponPricer(bond2.cashflows(),pricer);
final double cachedPrice2 = indexedCoupon ? 97.955904 : 97.955904; // yes, they are the same, according to QuantLib/C++
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));
}
// varying spread
final double [] spreads = new double[] { 0.001, 0.0012, 0.0014, 0.0016 };
final FloatingRateBond bond3 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
index, new ActualActual(ActualActual.Convention.ISMA),
BusinessDayConvention.ModifiedFollowing, fixingDays,
new Array(0), new Array(spreads),
new Array(0), new Array(0),
false,
100.0, new Date(30,Month.November,2004));
bond3.setPricingEngine(bondEngine2);
PricerSetter.setCouponPricer(bond3.cashflows(),pricer);
final double cachedPrice3 = indexedCoupon ? 98.495458 : 98.495459;
price = bond3.cleanPrice();
if (Math.abs(price-cachedPrice3) > tolerance) {
fail("failed to reproduce cached price:\n"
+ " calculated: " + price + "\n"
+ " expected: " + cachedPrice3 + "\n"
+ " error: " + (price-cachedPrice3));