首先,我将快速构建债券,从 QuantLib 版本中的债券示例中复制一些代码(另外,免责声明:我没有尝试编译下面的代码)。有关所涉及类的更多详细信息,请参阅 QuantLib 文档。
让我们假设您所说的年度付款:
Schedule schedule(startDate, maturityDate, Period(Annual),
calendar, convention, convention,
DateGeneration::Backward, true);
为了说明,假设我们将使用美元 Libor 指数。它的未来定价是根据我们稍后设置的利率期限结构来预测的。
RelinkableHandle<YieldTermStructure> liborTermStructure;
boost::shared_ptr<IborIndex> libor(
new USDLibor(Period(1,Years),liborTermStructure));
现在建立债券,将保证金添加为 LIBOR 利率的利差:
FloatingRateBond bond(settlementDays, faceAmount,
schedule, libor, dayCounter,
convention, fixingDays,
// gearings
std::vector<Real>(1, 1.0),
// spreads
std::vector<Rate>(1, 0.001));
现在要获取您想要的优惠券,您只需设置相应的市场数据。要设置第一个现金流的比率,请存储 Libor 指数的过去固定值:
libor->addFixing(resetDate, 0.01);
为了设置未来的现金流,创建一条具有所需利率的平坦利率曲线(注意约定,使其与 Libor 指数相匹配):
boost::shared_ptr<YieldTermStructure> flatRate(
new FlatForward(today, 0.01, dayCounter, Simple, Annual));
liborTermStructure.linkTo(flatRate);
(您不一定限于统一利率;如果您可以引导 Libor 曲线,您可以使用该曲线来获得对未来优惠券的现实估计。)
此时,您应该能够提取债券息票并检查它们是否符合预期:
std::vector<boost::shared_ptr<CashFlow> > cashflows = bond.cashflows();
for (std::size_t i=0; i < cashflows.size(); ++i)
std::cout << cashflows[i]->date() << " "
<< cashflows[i]->amount() << "\n";
如果您还想调用诸如 之类的方法bond.cleanPrice()
,则需要告诉债券如何贴现现金流:
RelinkableHandle<YieldTermStructure> discountingTermStructure;
boost::shared_ptr<PricingEngine> bondEngine(
new DiscountingBondEngine(discountingTermStructure));
bond.setPricingEngine(bondEngine);
您可以使用贴现您用于预测的同一曲线...
discountingTermStructure.linkTo(flatRate);
...或创建和使用不同的。