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