1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 Toyin Akin
5 Copyright (C) 2007, 2009 StatPro Italia srl
6 Copyright (C) 2008 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file bondhelpers.hpp
23 \brief bond rate helpers
24*/
25
26#ifndef quantlib_bond_helpers_hpp
27#define quantlib_bond_helpers_hpp
28
29#include <ql/termstructures/yield/ratehelpers.hpp>
30#include <ql/instruments/bonds/fixedratebond.hpp>
31#include <ql/instruments/bonds/cpibond.hpp>
32#include <ql/cashflows/cpicoupon.hpp>
33
34namespace QuantLib {
35
36 //! Bond helper for curve bootstrap
37 /*! \warning This class assumes that the reference date
38 does not change between calls of setTermStructure().
39 */
40 class BondHelper : public RateHelper {
41 public:
42 /*! \warning Setting a pricing engine to the passed bond from
43 external code will cause the bootstrap to fail or
44 to give wrong results. It is advised to discard
45 the bond after creating the helper, so that the
46 helper has sole ownership of it.
47 */
48 BondHelper(const Handle<Quote>& price,
49 const ext::shared_ptr<Bond>& bond,
50 Bond::Price::Type priceType = Bond::Price::Clean);
51
52 //! \name RateHelper interface
53 //@{
54 Real impliedQuote() const override;
55 void setTermStructure(YieldTermStructure*) override;
56 //@}
57 //! \name Additional inspectors
58 //@{
59 ext::shared_ptr<Bond> bond() const;
60
61 Bond::Price::Type priceType() const;
62 //@}
63 //! \name Visitability
64 //@{
65 void accept(AcyclicVisitor&) override;
66 //@}
67 protected:
68 ext::shared_ptr<Bond> bond_;
69 RelinkableHandle<YieldTermStructure> termStructureHandle_;
70 Bond::Price::Type priceType_;
71 };
72
73
74 //! Fixed-coupon bond helper for curve bootstrap
75 class FixedRateBondHelper : public BondHelper {
76 public:
77 FixedRateBondHelper(const Handle<Quote>& price,
78 Natural settlementDays,
79 Real faceAmount,
80 const Schedule& schedule,
81 const std::vector<Rate>& coupons,
82 const DayCounter& dayCounter,
83 BusinessDayConvention paymentConv = Following,
84 Real redemption = 100.0,
85 const Date& issueDate = Date(),
86 const Calendar& paymentCalendar = Calendar(),
87 const Period& exCouponPeriod = Period(),
88 const Calendar& exCouponCalendar = Calendar(),
89 BusinessDayConvention exCouponConvention = Unadjusted,
90 bool exCouponEndOfMonth = false,
91 Bond::Price::Type priceType = Bond::Price::Clean);
92
93 //! \name Additional inspectors
94 //@{
95 ext::shared_ptr<FixedRateBond> fixedRateBond() const;
96 //@}
97 //! \name Visitability
98 //@{
99 void accept(AcyclicVisitor&) override;
100 //@}
101 protected:
102 ext::shared_ptr<FixedRateBond> fixedRateBond_;
103 };
104
105
106 //! CPI bond helper for curve bootstrap
107 class CPIBondHelper : public BondHelper {
108 public:
109 CPIBondHelper(const Handle<Quote>& price,
110 Natural settlementDays,
111 Real faceAmount,
112 bool growthOnly,
113 Real baseCPI,
114 const Period& observationLag,
115 const ext::shared_ptr<ZeroInflationIndex>& cpiIndex,
116 CPI::InterpolationType observationInterpolation,
117 const Schedule& schedule,
118 const std::vector<Rate>& fixedRate,
119 const DayCounter& accrualDayCounter,
120 BusinessDayConvention paymentConvention = Following,
121 const Date& issueDate = Date(),
122 const Calendar& paymentCalendar = Calendar(),
123 const Period& exCouponPeriod = Period(),
124 const Calendar& exCouponCalendar = Calendar(),
125 BusinessDayConvention exCouponConvention = Unadjusted,
126 bool exCouponEndOfMonth = false,
127 Bond::Price::Type priceType = Bond::Price::Clean);
128
129 //! \name Additional inspectors
130 //@{
131 ext::shared_ptr<CPIBond> cpiBond() const;
132 //@}
133 //! \name Visitability
134 //@{
135 void accept(AcyclicVisitor&) override;
136 //@}
137 protected:
138 ext::shared_ptr<CPIBond> cpiBond_;
139 };
140
141
142 // inline
143
144 inline ext::shared_ptr<Bond> BondHelper::bond() const {
145 return bond_;
146 }
147
148 inline Bond::Price::Type BondHelper::priceType() const {
149 return priceType_;
150 }
151
152 inline ext::shared_ptr<FixedRateBond>
153 FixedRateBondHelper::fixedRateBond() const {
154 return fixedRateBond_;
155 }
156
157 inline ext::shared_ptr<CPIBond>
158 CPIBondHelper::cpiBond() const {
159 return cpiBond_;
160 }
161
162}
163
164#endif
165

source code of quantlib/ql/termstructures/yield/bondhelpers.hpp