/src/quantlib/ql/instruments/bonds/convertiblebonds.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2005, 2006 Theo Boafo |
5 | | Copyright (C) 2006, 2007 StatPro Italia srl |
6 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <https://www.quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | /*! \file convertiblebonds.hpp |
22 | | \brief convertible bond class |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_convertible_bonds_hpp |
26 | | #define quantlib_convertible_bonds_hpp |
27 | | |
28 | | #include <ql/instruments/bond.hpp> |
29 | | #include <ql/instruments/callabilityschedule.hpp> |
30 | | #include <ql/instruments/dividendschedule.hpp> |
31 | | #include <ql/instruments/oneassetoption.hpp> |
32 | | #include <ql/quote.hpp> |
33 | | #include <ql/time/daycounter.hpp> |
34 | | #include <ql/time/schedule.hpp> |
35 | | |
36 | | namespace QuantLib { |
37 | | |
38 | | class IborIndex; |
39 | | class PricingEngine; |
40 | | |
41 | | //! %callability leaving to the holder the possibility to convert |
42 | | class SoftCallability : public Callability { |
43 | | public: |
44 | | SoftCallability(const Bond::Price& price, const Date& date, Real trigger) |
45 | 0 | : Callability(price, Callability::Call, date), trigger_(trigger) {} |
46 | 0 | Real trigger() const { return trigger_; } |
47 | | |
48 | | private: |
49 | | Real trigger_; |
50 | | }; |
51 | | |
52 | | |
53 | | //! base class for convertible bonds |
54 | | class ConvertibleBond : public Bond { |
55 | | public: |
56 | | class arguments; |
57 | | class engine; |
58 | 0 | Real conversionRatio() const { return conversionRatio_; } |
59 | 0 | const CallabilitySchedule& callability() const { return callability_; } |
60 | | |
61 | | protected: |
62 | | ConvertibleBond(ext::shared_ptr<Exercise> exercise, |
63 | | Real conversionRatio, |
64 | | const CallabilitySchedule& callability, |
65 | | const Date& issueDate, |
66 | | Natural settlementDays, |
67 | | const Schedule& schedule, |
68 | | Real redemption); |
69 | | void setupArguments(PricingEngine::arguments*) const override; |
70 | | |
71 | | private: |
72 | | ext::shared_ptr<Exercise> exercise_; |
73 | | Real conversionRatio_; |
74 | | CallabilitySchedule callability_; |
75 | | Real redemption_; |
76 | | }; |
77 | | |
78 | | |
79 | | //! convertible zero-coupon bond |
80 | | /*! \warning Most methods inherited from Bond (such as yield or |
81 | | the yield-based dirtyPrice and cleanPrice) refer to |
82 | | the underlying plain-vanilla bond and do not take |
83 | | convertibility and callability into account. |
84 | | */ |
85 | | class ConvertibleZeroCouponBond : public ConvertibleBond { |
86 | | public: |
87 | | ConvertibleZeroCouponBond(const ext::shared_ptr<Exercise>& exercise, |
88 | | Real conversionRatio, |
89 | | const CallabilitySchedule& callability, |
90 | | const Date& issueDate, |
91 | | Natural settlementDays, |
92 | | const DayCounter& dayCounter, |
93 | | const Schedule& schedule, |
94 | | Real redemption = 100); |
95 | | }; |
96 | | |
97 | | |
98 | | //! convertible fixed-coupon bond |
99 | | /*! \warning Most methods inherited from Bond (such as yield or |
100 | | the yield-based dirtyPrice and cleanPrice) refer to |
101 | | the underlying plain-vanilla bond and do not take |
102 | | convertibility and callability into account. |
103 | | */ |
104 | | class ConvertibleFixedCouponBond : public ConvertibleBond { |
105 | | public: |
106 | | ConvertibleFixedCouponBond(const ext::shared_ptr<Exercise>& exercise, |
107 | | Real conversionRatio, |
108 | | const CallabilitySchedule& callability, |
109 | | const Date& issueDate, |
110 | | Natural settlementDays, |
111 | | const std::vector<Rate>& coupons, |
112 | | const DayCounter& dayCounter, |
113 | | const Schedule& schedule, |
114 | | Real redemption = 100, |
115 | | const Period& exCouponPeriod = Period(), |
116 | | const Calendar& exCouponCalendar = Calendar(), |
117 | | BusinessDayConvention exCouponConvention = Unadjusted, |
118 | | bool exCouponEndOfMonth = false); |
119 | | }; |
120 | | |
121 | | |
122 | | //! convertible floating-rate bond |
123 | | /*! \warning Most methods inherited from Bond (such as yield or |
124 | | the yield-based dirtyPrice and cleanPrice) refer to |
125 | | the underlying plain-vanilla bond and do not take |
126 | | convertibility and callability into account. |
127 | | */ |
128 | | class ConvertibleFloatingRateBond : public ConvertibleBond { |
129 | | public: |
130 | | ConvertibleFloatingRateBond(const ext::shared_ptr<Exercise>& exercise, |
131 | | Real conversionRatio, |
132 | | const CallabilitySchedule& callability, |
133 | | const Date& issueDate, |
134 | | Natural settlementDays, |
135 | | const ext::shared_ptr<IborIndex>& index, |
136 | | Natural fixingDays, |
137 | | const std::vector<Spread>& spreads, |
138 | | const DayCounter& dayCounter, |
139 | | const Schedule& schedule, |
140 | | Real redemption = 100, |
141 | | const Period& exCouponPeriod = Period(), |
142 | | const Calendar& exCouponCalendar = Calendar(), |
143 | | BusinessDayConvention exCouponConvention = Unadjusted, |
144 | | bool exCouponEndOfMonth = false); |
145 | | }; |
146 | | |
147 | | |
148 | | class ConvertibleBond::arguments : public PricingEngine::arguments { |
149 | | public: |
150 | | arguments() |
151 | 0 | : conversionRatio(Null<Real>()), settlementDays(Null<Natural>()), redemption(Null<Real>()) {} |
152 | | |
153 | | ext::shared_ptr<Exercise> exercise; |
154 | | Real conversionRatio; |
155 | | std::vector<Date> callabilityDates; |
156 | | std::vector<Callability::Type> callabilityTypes; |
157 | | std::vector<Real> callabilityPrices; |
158 | | std::vector<Real> callabilityTriggers; |
159 | | Leg cashflows; |
160 | | Date issueDate; |
161 | | Date settlementDate; |
162 | | |
163 | | Natural settlementDays; |
164 | | Real redemption; |
165 | | void validate() const override; |
166 | | }; |
167 | | |
168 | | class ConvertibleBond::engine |
169 | | : public GenericEngine<ConvertibleBond::arguments, ConvertibleBond::results> {}; |
170 | | |
171 | | } |
172 | | |
173 | | #endif |