QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
digitalcmscoupon.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Cristina Duminuco
5 Copyright (C) 2007 Giorgio Facchinetti
6 Copyright (C) 2007 StatPro Italia srl
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 <http://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#include <ql/cashflows/cashflowvectors.hpp>
23#include <ql/cashflows/digitalcmscoupon.hpp>
24#include <utility>
25
26namespace QuantLib {
27
29 const ext::shared_ptr<CmsCoupon>& underlying,
30 Rate callStrike,
31 Position::Type callPosition,
32 bool isCallATMIncluded,
33 Rate callDigitalPayoff,
34 Rate putStrike,
35 Position::Type putPosition,
36 bool isPutATMIncluded,
37 Rate putDigitalPayoff,
38 const ext::shared_ptr<DigitalReplication>& replication,
39 bool nakedOption)
40 : DigitalCoupon(underlying, callStrike, callPosition, isCallATMIncluded,
41 callDigitalPayoff, putStrike, putPosition,
42 isPutATMIncluded, putDigitalPayoff, replication, nakedOption) {}
43
45 typedef DigitalCoupon super;
46 auto* v1 = dynamic_cast<Visitor<DigitalCmsCoupon>*>(&v);
47 if (v1 != nullptr)
48 v1->visit(*this);
49 else
50 super::accept(v);
51 }
52
53
54 DigitalCmsLeg::DigitalCmsLeg(Schedule schedule, ext::shared_ptr<SwapIndex> index)
55 : schedule_(std::move(schedule)), index_(std::move(index)) {}
56
58 notionals_ = std::vector<Real>(1,notional);
59 return *this;
60 }
61
63 const std::vector<Real>& notionals) {
64 notionals_ = notionals;
65 return *this;
66 }
67
69 const DayCounter& dayCounter) {
70 paymentDayCounter_ = dayCounter;
71 return *this;
72 }
73
75 BusinessDayConvention convention) {
76 paymentAdjustment_ = convention;
77 return *this;
78 }
79
81 fixingDays_ = std::vector<Natural>(1,fixingDays);
82 return *this;
83 }
84
86 const std::vector<Natural>& fixingDays) {
87 fixingDays_ = fixingDays;
88 return *this;
89 }
90
92 gearings_ = std::vector<Real>(1,gearing);
93 return *this;
94 }
95
97 const std::vector<Real>& gearings) {
98 gearings_ = gearings;
99 return *this;
100 }
101
103 spreads_ = std::vector<Spread>(1,spread);
104 return *this;
105 }
106
108 const std::vector<Spread>& spreads) {
109 spreads_ = spreads;
110 return *this;
111 }
112
114 inArrears_ = flag;
115 return *this;
116 }
117
119 callStrikes_ = std::vector<Rate>(1,strike);
120 return *this;
121 }
122
124 const std::vector<Rate>& strikes) {
125 callStrikes_ = strikes;
126 return *this;
127 }
128
130 longCallOption_ = type;
131 return *this;
132 }
133
135 callATM_ = flag;
136 return *this;
137 }
138
140 callPayoffs_ = std::vector<Rate>(1,payoff);
141 return *this;
142 }
143
145 const std::vector<Rate>& payoffs) {
146 callPayoffs_ = payoffs;
147 return *this;
148 }
149
151 putStrikes_ = std::vector<Rate>(1,strike);
152 return *this;
153 }
154
156 const std::vector<Rate>& strikes) {
157 putStrikes_ = strikes;
158 return *this;
159 }
160
162 longPutOption_ = type;
163 return *this;
164 }
165
167 putATM_ = flag;
168 return *this;
169 }
170
172 putPayoffs_ = std::vector<Rate>(1,payoff);
173 return *this;
174 }
175
177 const std::vector<Rate>& payoffs) {
178 putPayoffs_ = payoffs;
179 return *this;
180 }
181
183 const ext::shared_ptr<DigitalReplication>& replication) {
184 replication_ = replication;
185 return *this;
186 }
187
189 replication_ = ext::make_shared<DigitalReplication>();
190 return *this;
191 }
192
194 nakedOption_ = nakedOption;
195 return *this;
196 }
197
198 DigitalCmsLeg::operator Leg() const {
199 return FloatingDigitalLeg<SwapIndex, CmsCoupon, DigitalCmsCoupon>(
200 schedule_, notionals_, index_, paymentDayCounter_,
201 paymentAdjustment_, fixingDays_,
202 gearings_, spreads_, inArrears_,
203 callStrikes_, longCallOption_,
204 callATM_, callPayoffs_,
205 putStrikes_, longPutOption_,
206 putATM_, putPayoffs_,
207 replication_, nakedOption_);
208 }
209
210}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
day counter class
Definition: daycounter.hpp:44
void accept(AcyclicVisitor &) override
DigitalCmsCoupon(const ext::shared_ptr< CmsCoupon > &underlying, Rate callStrike=Null< Rate >(), Position::Type callPosition=Position::Long, bool isCallATMIncluded=false, Rate callDigitalPayoff=Null< Rate >(), Rate putStrike=Null< Rate >(), Position::Type putPosition=Position::Long, bool isPutATMIncluded=false, Rate putDigitalPayoff=Null< Rate >(), const ext::shared_ptr< DigitalReplication > &replication={}, bool nakedOption=false)
helper class building a sequence of digital ibor-rate coupons
DigitalCmsLeg & withPaymentAdjustment(BusinessDayConvention)
BusinessDayConvention paymentAdjustment_
DigitalCmsLeg & withLongPutOption(Position::Type)
DigitalCmsLeg & inArrears(bool flag=true)
std::vector< Rate > putStrikes_
DigitalCmsLeg & withSpreads(Spread spread)
DigitalCmsLeg & withPutATM(bool flag=true)
DigitalCmsLeg & withPutPayoffs(Rate payoff)
DigitalCmsLeg & withGearings(Real gearing)
DigitalCmsLeg & withLongCallOption(Position::Type)
DigitalCmsLeg & withCallATM(bool flag=true)
DigitalCmsLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Rate > callStrikes_
DigitalCmsLeg(Schedule schedule, ext::shared_ptr< SwapIndex > index)
DigitalCmsLeg & withReplication()
std::vector< Real > notionals_
std::vector< Spread > spreads_
std::vector< Rate > callPayoffs_
DigitalCmsLeg & withFixingDays(Natural fixingDays)
DigitalCmsLeg & withNakedOption(bool nakedOption=true)
DigitalCmsLeg & withCallStrikes(Rate strike)
DigitalCmsLeg & withCallPayoffs(Rate payoff)
std::vector< Natural > fixingDays_
ext::shared_ptr< DigitalReplication > replication_
std::vector< Rate > putPayoffs_
DigitalCmsLeg & withNotionals(Real notional)
DigitalCmsLeg & withPutStrikes(Rate strike)
std::vector< Real > gearings_
Digital-payoff coupon.
Payment schedule.
Definition: schedule.hpp:40
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.