final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(
new ForwardSpreadedTermStructure(vars.riskFreeRate,
vars.creditSpread));
// zero-coupon
Schedule schedule = new MakeSchedule(vars.issueDate, vars.maturityDate,
new Period(Frequency.Once), vars.calendar,
BusinessDayConvention.Following).backwards().schedule();
final ConvertibleZeroCouponBond euZero = new ConvertibleZeroCouponBond(
euExercise, vars.conversionRatio, vars.no_dividends,
vars.no_callability, vars.creditSpread, vars.issueDate,
vars.settlementDays, vars.dayCounter, schedule, vars.redemption);
euZero.setPricingEngine(engine);
final ConvertibleZeroCouponBond amZero = new ConvertibleZeroCouponBond(
amExercise, vars.conversionRatio, vars.no_dividends,
vars.no_callability, vars.creditSpread, vars.issueDate,
vars.settlementDays, vars.dayCounter, schedule, vars.redemption);
amZero.setPricingEngine(engine);
final ZeroCouponBond zero = new ZeroCouponBond(vars.settlementDays,
vars.calendar, 100.0, vars.maturityDate,
BusinessDayConvention.Following, vars.redemption,
vars.issueDate);
final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);
zero.setPricingEngine(bondEngine);
double tolerance = 1.0e-2 * (vars.faceAmount / 100.0);
double error = Math.abs(euZero.NPV() - zero.settlementValue());
if (error > tolerance) {
fail("failed to reproduce zero-coupon bond price:"
+ "\n calculated: " + euZero.NPV()
+ "\n expected: " + zero.settlementValue()
+ "\n error: " + error);
}
error = Math.abs(amZero.NPV() - zero.settlementValue());
if (error > tolerance) {
fail("failed to reproduce zero-coupon bond price:"
+ "\n calculated: " + amZero.NPV()
+ "\n expected: " + zero.settlementValue()
+ "\n error: " + error);
}
// coupon
final double[] coupons = { 0.05 };
schedule = new MakeSchedule(vars.issueDate, vars.maturityDate,
new Period(vars.frequency), vars.calendar,
BusinessDayConvention.Following).backwards().schedule();
final ConvertibleFixedCouponBond euFixed = new ConvertibleFixedCouponBond(
euExercise, vars.conversionRatio, vars.no_dividends,