/src/quantlib/ql/termstructures/yield/bondhelpers.hpp
Line | Count | Source |
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 | | <https://www.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 | | |
34 | | namespace 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 | | 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 Visitability |
94 | | //@{ |
95 | | void accept(AcyclicVisitor&) override; |
96 | | //@} |
97 | | }; |
98 | | |
99 | | |
100 | | //! CPI bond helper for curve bootstrap |
101 | | class CPIBondHelper : public BondHelper { |
102 | | public: |
103 | | CPIBondHelper(const Handle<Quote>& price, |
104 | | Natural settlementDays, |
105 | | Real faceAmount, |
106 | | Real baseCPI, |
107 | | const Period& observationLag, |
108 | | const ext::shared_ptr<ZeroInflationIndex>& cpiIndex, |
109 | | CPI::InterpolationType observationInterpolation, |
110 | | Schedule schedule, |
111 | | const std::vector<Rate>& fixedRate, |
112 | | const DayCounter& accrualDayCounter, |
113 | | BusinessDayConvention paymentConvention = Following, |
114 | | const Date& issueDate = Date(), |
115 | | const Calendar& paymentCalendar = Calendar(), |
116 | | const Period& exCouponPeriod = Period(), |
117 | | const Calendar& exCouponCalendar = Calendar(), |
118 | | BusinessDayConvention exCouponConvention = Unadjusted, |
119 | | bool exCouponEndOfMonth = false, |
120 | | Bond::Price::Type priceType = Bond::Price::Clean); |
121 | | |
122 | | /*! \deprecated Use the overload without the growthOnly parameter. |
123 | | Deprecated in version 1.40. |
124 | | */ |
125 | | [[deprecated("Use the overload without the growthOnly parameter")]] |
126 | | CPIBondHelper(const Handle<Quote>& price, |
127 | | Natural settlementDays, |
128 | | Real faceAmount, |
129 | | bool growthOnly, |
130 | | Real baseCPI, |
131 | | const Period& observationLag, |
132 | | const ext::shared_ptr<ZeroInflationIndex>& cpiIndex, |
133 | | CPI::InterpolationType observationInterpolation, |
134 | | Schedule schedule, |
135 | | const std::vector<Rate>& fixedRate, |
136 | | const DayCounter& accrualDayCounter, |
137 | | BusinessDayConvention paymentConvention = Following, |
138 | | const Date& issueDate = Date(), |
139 | | const Calendar& paymentCalendar = Calendar(), |
140 | | const Period& exCouponPeriod = Period(), |
141 | | const Calendar& exCouponCalendar = Calendar(), |
142 | | BusinessDayConvention exCouponConvention = Unadjusted, |
143 | | bool exCouponEndOfMonth = false, |
144 | | Bond::Price::Type priceType = Bond::Price::Clean); |
145 | | |
146 | | //! \name Visitability |
147 | | //@{ |
148 | | void accept(AcyclicVisitor&) override; |
149 | | //@} |
150 | | }; |
151 | | |
152 | | |
153 | | // inline |
154 | | |
155 | 0 | inline ext::shared_ptr<Bond> BondHelper::bond() const { |
156 | 0 | return bond_; |
157 | 0 | } |
158 | | |
159 | 0 | inline Bond::Price::Type BondHelper::priceType() const { |
160 | 0 | return priceType_; |
161 | 0 | } |
162 | | |
163 | | |
164 | | } |
165 | | |
166 | | #endif |