/src/quantlib/ql/cashflows/cmscoupon.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright (C) 2006 Giorgio Facchinetti |
3 | | Copyright (C) 2006 Mario Pucci |
4 | | Copyright (C) 2006, 2007 StatPro Italia srl |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
18 | | or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | #include <ql/cashflows/capflooredcoupon.hpp> |
22 | | #include <ql/cashflows/cashflowvectors.hpp> |
23 | | #include <ql/cashflows/cmscoupon.hpp> |
24 | | #include <ql/indexes/swapindex.hpp> |
25 | | #include <utility> |
26 | | |
27 | | namespace QuantLib { |
28 | | |
29 | | CmsCoupon::CmsCoupon(const Date& paymentDate, |
30 | | Real nominal, |
31 | | const Date& startDate, |
32 | | const Date& endDate, |
33 | | Natural fixingDays, |
34 | | const ext::shared_ptr<SwapIndex>& swapIndex, |
35 | | Real gearing, |
36 | | Spread spread, |
37 | | const Date& refPeriodStart, |
38 | | const Date& refPeriodEnd, |
39 | | const DayCounter& dayCounter, |
40 | | bool isInArrears, |
41 | | const Date& exCouponDate) |
42 | 0 | : FloatingRateCoupon(paymentDate, nominal, startDate, endDate, |
43 | 0 | fixingDays, swapIndex, gearing, spread, |
44 | 0 | refPeriodStart, refPeriodEnd, |
45 | 0 | dayCounter, isInArrears, exCouponDate), |
46 | 0 | swapIndex_(swapIndex) {} Unexecuted instantiation: QuantLib::CmsCoupon::CmsCoupon(QuantLib::Date const&, double, QuantLib::Date const&, QuantLib::Date const&, unsigned int, boost::shared_ptr<QuantLib::SwapIndex> const&, double, double, QuantLib::Date const&, QuantLib::Date const&, QuantLib::DayCounter const&, bool, QuantLib::Date const&) Unexecuted instantiation: QuantLib::CmsCoupon::CmsCoupon(QuantLib::Date const&, double, QuantLib::Date const&, QuantLib::Date const&, unsigned int, boost::shared_ptr<QuantLib::SwapIndex> const&, double, double, QuantLib::Date const&, QuantLib::Date const&, QuantLib::DayCounter const&, bool, QuantLib::Date const&) |
47 | | |
48 | 0 | void CmsCoupon::accept(AcyclicVisitor& v) { |
49 | 0 | auto* v1 = dynamic_cast<Visitor<CmsCoupon>*>(&v); |
50 | 0 | if (v1 != nullptr) |
51 | 0 | v1->visit(*this); |
52 | 0 | else |
53 | 0 | FloatingRateCoupon::accept(v); |
54 | 0 | } |
55 | | |
56 | | |
57 | | CmsLeg::CmsLeg(Schedule schedule, ext::shared_ptr<SwapIndex> swapIndex) |
58 | 0 | : schedule_(std::move(schedule)), swapIndex_(std::move(swapIndex)) { |
59 | 0 | QL_REQUIRE(swapIndex_, "no index provided"); |
60 | 0 | } |
61 | | |
62 | 0 | CmsLeg& CmsLeg::withNotionals(Real notional) { |
63 | 0 | notionals_ = std::vector<Real>(1, notional); |
64 | 0 | return *this; |
65 | 0 | } |
66 | | |
67 | 0 | CmsLeg& CmsLeg::withNotionals(const std::vector<Real>& notionals) { |
68 | 0 | notionals_ = notionals; |
69 | 0 | return *this; |
70 | 0 | } |
71 | | |
72 | 0 | CmsLeg& CmsLeg::withPaymentDayCounter(const DayCounter& dayCounter) { |
73 | 0 | paymentDayCounter_ = dayCounter; |
74 | 0 | return *this; |
75 | 0 | } |
76 | | |
77 | 0 | CmsLeg& CmsLeg::withPaymentAdjustment(BusinessDayConvention convention) { |
78 | 0 | paymentAdjustment_ = convention; |
79 | 0 | return *this; |
80 | 0 | } |
81 | | |
82 | 0 | CmsLeg& CmsLeg::withFixingDays(Natural fixingDays) { |
83 | 0 | fixingDays_ = std::vector<Natural>(1, fixingDays); |
84 | 0 | return *this; |
85 | 0 | } |
86 | | |
87 | 0 | CmsLeg& CmsLeg::withFixingDays(const std::vector<Natural>& fixingDays) { |
88 | 0 | fixingDays_ = fixingDays; |
89 | 0 | return *this; |
90 | 0 | } |
91 | | |
92 | 0 | CmsLeg& CmsLeg::withGearings(Real gearing) { |
93 | 0 | gearings_ = std::vector<Real>(1, gearing); |
94 | 0 | return *this; |
95 | 0 | } |
96 | | |
97 | 0 | CmsLeg& CmsLeg::withGearings(const std::vector<Real>& gearings) { |
98 | 0 | gearings_ = gearings; |
99 | 0 | return *this; |
100 | 0 | } |
101 | | |
102 | 0 | CmsLeg& CmsLeg::withSpreads(Spread spread) { |
103 | 0 | spreads_ = std::vector<Spread>(1, spread); |
104 | 0 | return *this; |
105 | 0 | } |
106 | | |
107 | 0 | CmsLeg& CmsLeg::withSpreads(const std::vector<Spread>& spreads) { |
108 | 0 | spreads_ = spreads; |
109 | 0 | return *this; |
110 | 0 | } |
111 | | |
112 | 0 | CmsLeg& CmsLeg::withCaps(Rate cap) { |
113 | 0 | caps_ = std::vector<Rate>(1, cap); |
114 | 0 | return *this; |
115 | 0 | } |
116 | | |
117 | 0 | CmsLeg& CmsLeg::withCaps(const std::vector<Rate>& caps) { |
118 | 0 | caps_ = caps; |
119 | 0 | return *this; |
120 | 0 | } |
121 | | |
122 | 0 | CmsLeg& CmsLeg::withFloors(Rate floor) { |
123 | 0 | floors_ = std::vector<Rate>(1, floor); |
124 | 0 | return *this; |
125 | 0 | } |
126 | | |
127 | 0 | CmsLeg& CmsLeg::withFloors(const std::vector<Rate>& floors) { |
128 | 0 | floors_ = floors; |
129 | 0 | return *this; |
130 | 0 | } |
131 | | |
132 | 0 | CmsLeg& CmsLeg::inArrears(bool flag) { |
133 | 0 | inArrears_ = flag; |
134 | 0 | return *this; |
135 | 0 | } |
136 | | |
137 | 0 | CmsLeg& CmsLeg::withZeroPayments(bool flag) { |
138 | 0 | zeroPayments_ = flag; |
139 | 0 | return *this; |
140 | 0 | } |
141 | | |
142 | | CmsLeg& CmsLeg::withExCouponPeriod( |
143 | | const Period& period, |
144 | | const Calendar& cal, |
145 | | BusinessDayConvention convention, |
146 | 0 | bool endOfMonth) { |
147 | 0 | exCouponPeriod_ = period; |
148 | 0 | exCouponCalendar_ = cal; |
149 | 0 | exCouponAdjustment_ = convention; |
150 | 0 | exCouponEndOfMonth_ = endOfMonth; |
151 | 0 | return *this; |
152 | 0 | } |
153 | | |
154 | 0 | CmsLeg::operator Leg() const { |
155 | 0 | return FloatingLeg<SwapIndex, CmsCoupon, CappedFlooredCmsCoupon>( |
156 | 0 | schedule_, notionals_, swapIndex_, paymentDayCounter_, |
157 | 0 | paymentAdjustment_, fixingDays_, gearings_, spreads_, |
158 | 0 | caps_, floors_, inArrears_, zeroPayments_, |
159 | 0 | 0, Calendar(), |
160 | 0 | exCouponPeriod_, exCouponCalendar_, |
161 | 0 | exCouponAdjustment_, exCouponEndOfMonth_); |
162 | 0 | } |
163 | | |
164 | | } |