/src/quantlib/ql/experimental/coupons/digitalcmsspreadcoupon.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2015 Peter Caspers |
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 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | #include <ql/cashflows/cashflowvectors.hpp> |
21 | | #include <ql/experimental/coupons/digitalcmsspreadcoupon.hpp> |
22 | | #include <utility> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | DigitalCmsSpreadCoupon::DigitalCmsSpreadCoupon( |
27 | | const ext::shared_ptr<CmsSpreadCoupon>& underlying, |
28 | | Rate callStrike, |
29 | | Position::Type callPosition, |
30 | | bool isCallATMIncluded, |
31 | | Rate callDigitalPayoff, |
32 | | Rate putStrike, |
33 | | Position::Type putPosition, |
34 | | bool isPutATMIncluded, |
35 | | Rate putDigitalPayoff, |
36 | | const ext::shared_ptr<DigitalReplication>& replication, |
37 | | bool nakedOption) |
38 | 0 | : DigitalCoupon(underlying, callStrike, callPosition, isCallATMIncluded, |
39 | 0 | callDigitalPayoff, putStrike, putPosition, |
40 | 0 | isPutATMIncluded, putDigitalPayoff, replication, nakedOption) {}Unexecuted instantiation: QuantLib::DigitalCmsSpreadCoupon::DigitalCmsSpreadCoupon(boost::shared_ptr<QuantLib::CmsSpreadCoupon> const&, double, QuantLib::Position::Type, bool, double, double, QuantLib::Position::Type, bool, double, boost::shared_ptr<QuantLib::DigitalReplication> const&, bool) Unexecuted instantiation: QuantLib::DigitalCmsSpreadCoupon::DigitalCmsSpreadCoupon(boost::shared_ptr<QuantLib::CmsSpreadCoupon> const&, double, QuantLib::Position::Type, bool, double, double, QuantLib::Position::Type, bool, double, boost::shared_ptr<QuantLib::DigitalReplication> const&, bool) |
41 | | |
42 | 0 | void DigitalCmsSpreadCoupon::accept(AcyclicVisitor& v) { |
43 | 0 | typedef DigitalCoupon super; |
44 | 0 | auto* v1 = dynamic_cast<Visitor<DigitalCmsSpreadCoupon>*>(&v); |
45 | 0 | if (v1 != nullptr) |
46 | 0 | v1->visit(*this); |
47 | 0 | else |
48 | 0 | super::accept(v); |
49 | 0 | } |
50 | | |
51 | | |
52 | | DigitalCmsSpreadLeg::DigitalCmsSpreadLeg(Schedule schedule, |
53 | | ext::shared_ptr<SwapSpreadIndex> index) |
54 | 0 | : schedule_(std::move(schedule)), index_(std::move(index)) {} |
55 | | |
56 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNotionals(Real notional) { |
57 | 0 | notionals_ = std::vector<Real>(1,notional); |
58 | 0 | return *this; |
59 | 0 | } |
60 | | |
61 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNotionals( |
62 | 0 | const std::vector<Real>& notionals) { |
63 | 0 | notionals_ = notionals; |
64 | 0 | return *this; |
65 | 0 | } |
66 | | |
67 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPaymentDayCounter( |
68 | 0 | const DayCounter& dayCounter) { |
69 | 0 | paymentDayCounter_ = dayCounter; |
70 | 0 | return *this; |
71 | 0 | } |
72 | | |
73 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPaymentAdjustment( |
74 | 0 | BusinessDayConvention convention) { |
75 | 0 | paymentAdjustment_ = convention; |
76 | 0 | return *this; |
77 | 0 | } |
78 | | |
79 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withFixingDays(Natural fixingDays) { |
80 | 0 | fixingDays_ = std::vector<Natural>(1,fixingDays); |
81 | 0 | return *this; |
82 | 0 | } |
83 | | |
84 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withFixingDays( |
85 | 0 | const std::vector<Natural>& fixingDays) { |
86 | 0 | fixingDays_ = fixingDays; |
87 | 0 | return *this; |
88 | 0 | } |
89 | | |
90 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withGearings(Real gearing) { |
91 | 0 | gearings_ = std::vector<Real>(1,gearing); |
92 | 0 | return *this; |
93 | 0 | } |
94 | | |
95 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withGearings( |
96 | 0 | const std::vector<Real>& gearings) { |
97 | 0 | gearings_ = gearings; |
98 | 0 | return *this; |
99 | 0 | } |
100 | | |
101 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withSpreads(Spread spread) { |
102 | 0 | spreads_ = std::vector<Spread>(1,spread); |
103 | 0 | return *this; |
104 | 0 | } |
105 | | |
106 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withSpreads( |
107 | 0 | const std::vector<Spread>& spreads) { |
108 | 0 | spreads_ = spreads; |
109 | 0 | return *this; |
110 | 0 | } |
111 | | |
112 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::inArrears(bool flag) { |
113 | 0 | inArrears_ = flag; |
114 | 0 | return *this; |
115 | 0 | } |
116 | | |
117 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallStrikes(Rate strike) { |
118 | 0 | callStrikes_ = std::vector<Rate>(1,strike); |
119 | 0 | return *this; |
120 | 0 | } |
121 | | |
122 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallStrikes( |
123 | 0 | const std::vector<Rate>& strikes) { |
124 | 0 | callStrikes_ = strikes; |
125 | 0 | return *this; |
126 | 0 | } |
127 | | |
128 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withLongCallOption(Position::Type type) { |
129 | 0 | longCallOption_ = type; |
130 | 0 | return *this; |
131 | 0 | } |
132 | | |
133 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallATM(bool flag) { |
134 | 0 | callATM_ = flag; |
135 | 0 | return *this; |
136 | 0 | } |
137 | | |
138 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallPayoffs(Rate payoff) { |
139 | 0 | callPayoffs_ = std::vector<Rate>(1,payoff); |
140 | 0 | return *this; |
141 | 0 | } |
142 | | |
143 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallPayoffs( |
144 | 0 | const std::vector<Rate>& payoffs) { |
145 | 0 | callPayoffs_ = payoffs; |
146 | 0 | return *this; |
147 | 0 | } |
148 | | |
149 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutStrikes(Rate strike) { |
150 | 0 | putStrikes_ = std::vector<Rate>(1,strike); |
151 | 0 | return *this; |
152 | 0 | } |
153 | | |
154 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutStrikes( |
155 | 0 | const std::vector<Rate>& strikes) { |
156 | 0 | putStrikes_ = strikes; |
157 | 0 | return *this; |
158 | 0 | } |
159 | | |
160 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withLongPutOption(Position::Type type) { |
161 | 0 | longPutOption_ = type; |
162 | 0 | return *this; |
163 | 0 | } |
164 | | |
165 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutATM(bool flag) { |
166 | 0 | putATM_ = flag; |
167 | 0 | return *this; |
168 | 0 | } |
169 | | |
170 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutPayoffs(Rate payoff) { |
171 | 0 | putPayoffs_ = std::vector<Rate>(1,payoff); |
172 | 0 | return *this; |
173 | 0 | } |
174 | | |
175 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutPayoffs( |
176 | 0 | const std::vector<Rate>& payoffs) { |
177 | 0 | putPayoffs_ = payoffs; |
178 | 0 | return *this; |
179 | 0 | } |
180 | | |
181 | | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withReplication( |
182 | 0 | const ext::shared_ptr<DigitalReplication>& replication) { |
183 | 0 | replication_ = replication; |
184 | 0 | return *this; |
185 | 0 | } |
186 | | |
187 | 0 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNakedOption(bool nakedOption) { |
188 | 0 | nakedOption_ = nakedOption; |
189 | 0 | return *this; |
190 | 0 | } |
191 | | |
192 | 0 | DigitalCmsSpreadLeg::operator Leg() const { |
193 | 0 | return FloatingDigitalLeg<SwapSpreadIndex, CmsSpreadCoupon, DigitalCmsSpreadCoupon>( |
194 | 0 | schedule_, notionals_, index_, paymentDayCounter_, |
195 | 0 | paymentAdjustment_, fixingDays_, |
196 | 0 | gearings_, spreads_, inArrears_, |
197 | 0 | callStrikes_, longCallOption_, |
198 | 0 | callATM_, callPayoffs_, |
199 | 0 | putStrikes_, longPutOption_, |
200 | 0 | putATM_, putPayoffs_, |
201 | 0 | replication_, nakedOption_); |
202 | 0 | } |
203 | | |
204 | | } |