QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cmscoupon.cpp
Go to the documentation of this file.
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 <http://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
25#include <utility>
26
27namespace 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 : FloatingRateCoupon(paymentDate, nominal, startDate, endDate,
43 fixingDays, swapIndex, gearing, spread,
44 refPeriodStart, refPeriodEnd,
45 dayCounter, isInArrears, exCouponDate),
46 swapIndex_(swapIndex) {}
47
49 auto* v1 = dynamic_cast<Visitor<CmsCoupon>*>(&v);
50 if (v1 != nullptr)
51 v1->visit(*this);
52 else
54 }
55
56
57 CmsLeg::CmsLeg(Schedule schedule, ext::shared_ptr<SwapIndex> swapIndex)
58 : schedule_(std::move(schedule)), swapIndex_(std::move(swapIndex)) {
59 QL_REQUIRE(swapIndex_, "no index provided");
60 }
61
63 notionals_ = std::vector<Real>(1, notional);
64 return *this;
65 }
66
67 CmsLeg& CmsLeg::withNotionals(const std::vector<Real>& notionals) {
68 notionals_ = notionals;
69 return *this;
70 }
71
73 paymentDayCounter_ = dayCounter;
74 return *this;
75 }
76
78 paymentAdjustment_ = convention;
79 return *this;
80 }
81
83 fixingDays_ = std::vector<Natural>(1, fixingDays);
84 return *this;
85 }
86
87 CmsLeg& CmsLeg::withFixingDays(const std::vector<Natural>& fixingDays) {
88 fixingDays_ = fixingDays;
89 return *this;
90 }
91
93 gearings_ = std::vector<Real>(1, gearing);
94 return *this;
95 }
96
97 CmsLeg& CmsLeg::withGearings(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
107 CmsLeg& CmsLeg::withSpreads(const std::vector<Spread>& spreads) {
108 spreads_ = spreads;
109 return *this;
110 }
111
113 caps_ = std::vector<Rate>(1, cap);
114 return *this;
115 }
116
117 CmsLeg& CmsLeg::withCaps(const std::vector<Rate>& caps) {
118 caps_ = caps;
119 return *this;
120 }
121
123 floors_ = std::vector<Rate>(1, floor);
124 return *this;
125 }
126
127 CmsLeg& CmsLeg::withFloors(const std::vector<Rate>& floors) {
128 floors_ = floors;
129 return *this;
130 }
131
133 inArrears_ = flag;
134 return *this;
135 }
136
138 zeroPayments_ = flag;
139 return *this;
140 }
141
143 const Period& period,
144 const Calendar& cal,
145 BusinessDayConvention convention,
146 bool endOfMonth) {
147 exCouponPeriod_ = period;
148 exCouponCalendar_ = cal;
149 exCouponAdjustment_ = convention;
150 exCouponEndOfMonth_ = endOfMonth;
151 return *this;
152 }
153
154 CmsLeg::operator Leg() const {
155 return FloatingLeg<SwapIndex, CmsCoupon, CappedFlooredCmsCoupon>(
156 schedule_, notionals_, swapIndex_, paymentDayCounter_,
157 paymentAdjustment_, fixingDays_, gearings_, spreads_,
158 caps_, floors_, inArrears_, zeroPayments_,
159 0, Calendar(),
160 exCouponPeriod_, exCouponCalendar_,
161 exCouponAdjustment_, exCouponEndOfMonth_);
162 }
163
164}
Floating rate coupon with additional cap/floor.
Cash flow vector builders.
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
calendar class
Definition: calendar.hpp:61
void accept(AcyclicVisitor &) override
Definition: cmscoupon.cpp:48
CmsCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< SwapIndex > &index, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const DayCounter &dayCounter=DayCounter(), bool isInArrears=false, const Date &exCouponDate=Date())
Definition: cmscoupon.cpp:29
helper class building a sequence of capped/floored cms-rate coupons
Definition: cmscoupon.hpp:70
BusinessDayConvention paymentAdjustment_
Definition: cmscoupon.hpp:99
std::vector< Rate > caps_
Definition: cmscoupon.hpp:103
BusinessDayConvention exCouponAdjustment_
Definition: cmscoupon.hpp:107
CmsLeg & withFloors(Rate floor)
Definition: cmscoupon.cpp:122
CmsLeg & withCaps(Rate cap)
Definition: cmscoupon.cpp:112
CmsLeg & withGearings(Real gearing)
Definition: cmscoupon.cpp:92
ext::shared_ptr< SwapIndex > swapIndex_
Definition: cmscoupon.hpp:96
std::vector< Real > notionals_
Definition: cmscoupon.hpp:97
std::vector< Spread > spreads_
Definition: cmscoupon.hpp:102
CmsLeg & withSpreads(Spread spread)
Definition: cmscoupon.cpp:102
CmsLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth)
Definition: cmscoupon.cpp:142
CmsLeg & withPaymentDayCounter(const DayCounter &)
Definition: cmscoupon.cpp:72
CmsLeg & inArrears(bool flag=true)
Definition: cmscoupon.cpp:132
bool exCouponEndOfMonth_
Definition: cmscoupon.hpp:108
CmsLeg & withZeroPayments(bool flag=true)
Definition: cmscoupon.cpp:137
std::vector< Natural > fixingDays_
Definition: cmscoupon.hpp:100
CmsLeg & withNotionals(Real notional)
Definition: cmscoupon.cpp:62
Period exCouponPeriod_
Definition: cmscoupon.hpp:105
Calendar exCouponCalendar_
Definition: cmscoupon.hpp:106
std::vector< Rate > floors_
Definition: cmscoupon.hpp:103
CmsLeg(Schedule schedule, ext::shared_ptr< SwapIndex > swapIndex)
Definition: cmscoupon.cpp:57
CmsLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: cmscoupon.cpp:77
CmsLeg & withFixingDays(Natural fixingDays)
Definition: cmscoupon.cpp:82
std::vector< Real > gearings_
Definition: cmscoupon.hpp:101
DayCounter paymentDayCounter_
Definition: cmscoupon.hpp:98
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
base floating-rate coupon class
void accept(AcyclicVisitor &) override
Payment schedule.
Definition: schedule.hpp:40
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
CMS coupon.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
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.
ext::shared_ptr< BlackVolTermStructure > v
swap-rate indexes