QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
iborcoupon.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007, 2011 Ferdinando Ametrano
5 Copyright (C) 2007 Giorgio Facchinetti
6 Copyright (C) 2007 Cristina Duminuco
7 Copyright (C) 2007 StatPro Italia srl
8 Copyright (C) 2017 Joseph Jeisman
9 Copyright (C) 2017 Fabrice Lecuyer
10
11 This file is part of QuantLib, a free-software/open-source library
12 for financial quantitative analysts and developers - http://quantlib.org/
13
14 QuantLib is free software: you can redistribute it and/or modify it
15 under the terms of the QuantLib license. You should have received a
16 copy of the license along with this program; if not, please email
17 <quantlib-dev@lists.sf.net>. The license is also available online at
18 <http://quantlib.org/license.shtml>.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the license for more details.
23*/
24
29#ifndef quantlib_ibor_coupon_hpp
30#define quantlib_ibor_coupon_hpp
31
32#include <ql/cashflows/floatingratecoupon.hpp>
33#include <ql/indexes/iborindex.hpp>
34#include <ql/patterns/singleton.hpp>
35#include <ql/time/schedule.hpp>
36#include <ql/optional.hpp>
37
38namespace QuantLib {
39
42 public:
43 IborCoupon(const Date& paymentDate,
45 const Date& startDate,
46 const Date& endDate,
48 const ext::shared_ptr<IborIndex>& index,
49 Real gearing = 1.0,
50 Spread spread = 0.0,
51 const Date& refPeriodStart = Date(),
52 const Date& refPeriodEnd = Date(),
54 bool isInArrears = false,
55 const Date& exCouponDate = Date());
57
58 const ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
60
62 // implemented in order to manage the case of par coupon
63 Rate indexFixing() const override;
64 void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>&) override;
66
68 void accept(AcyclicVisitor&) override;
70
77 const Date& fixingValueDate() const;
79 const Date& fixingMaturityDate() const;
81
82 const Date& fixingEndDate() const;
86
87 Time spanningTime() const;
89
90 private:
91 friend class IborCouponPricer;
92 ext::shared_ptr<IborIndex> iborIndex_;
94 // computed by coupon pricer (depending on par coupon flag) and stored here
95 void initializeCachedData() const;
96 mutable bool cachedDataIsInitialized_ = false;
99
100 public:
101 // IborCoupon::Settings forward declaration
102 class Settings;
103 };
104
105
107 class IborCoupon::Settings : public Singleton<IborCoupon::Settings> {
108 friend class Singleton<IborCoupon::Settings>;
109 private:
110 Settings() = default;
111
112 public:
114 void createAtParCoupons();
115
118
122 bool usingAtParCoupons() const;
123
124 private:
125 #ifndef QL_USE_INDEXED_COUPON
127 #else
128 bool usingAtParCoupons_ = false;
129 #endif
130 };
131
133 class IborLeg {
134 public:
135 IborLeg(Schedule schedule, ext::shared_ptr<IborIndex> index);
136 IborLeg& withNotionals(Real notional);
137 IborLeg& withNotionals(const std::vector<Real>& notionals);
138 IborLeg& withPaymentDayCounter(const DayCounter&);
139 IborLeg& withPaymentAdjustment(BusinessDayConvention);
140 IborLeg& withPaymentLag(Natural lag);
141 IborLeg& withPaymentCalendar(const Calendar&);
142 IborLeg& withFixingDays(Natural fixingDays);
143 IborLeg& withFixingDays(const std::vector<Natural>& fixingDays);
144 IborLeg& withGearings(Real gearing);
145 IborLeg& withGearings(const std::vector<Real>& gearings);
146 IborLeg& withSpreads(Spread spread);
147 IborLeg& withSpreads(const std::vector<Spread>& spreads);
148 IborLeg& withCaps(Rate cap);
149 IborLeg& withCaps(const std::vector<Rate>& caps);
150 IborLeg& withFloors(Rate floor);
151 IborLeg& withFloors(const std::vector<Rate>& floors);
152 IborLeg& inArrears(bool flag = true);
153 IborLeg& withZeroPayments(bool flag = true);
154 IborLeg& withExCouponPeriod(const Period&,
155 const Calendar&,
157 bool endOfMonth = false);
158 IborLeg& withIndexedCoupons(ext::optional<bool> b = true);
159 IborLeg& withAtParCoupons(bool b = true);
160 operator Leg() const;
161
162 private:
164 ext::shared_ptr<IborIndex> index_;
165 std::vector<Real> notionals_;
167 BusinessDayConvention paymentAdjustment_ = Following;
168 Natural paymentLag_ = 0;
170 std::vector<Natural> fixingDays_;
171 std::vector<Real> gearings_;
172 std::vector<Spread> spreads_;
173 std::vector<Rate> caps_, floors_;
174 bool inArrears_ = false, zeroPayments_ = false;
177 BusinessDayConvention exCouponAdjustment_ = Unadjusted;
178 bool exCouponEndOfMonth_ = false;
179 ext::optional<bool> useIndexedCoupons_;
180 };
181
182}
183
184#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
calendar class
Definition: calendar.hpp:61
Date exCouponDate() const override
returns the date that the cash flow trades exCoupon
Definition: coupon.hpp:57
virtual Real nominal() const
Definition: coupon.hpp:100
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
base floating-rate coupon class
Natural fixingDays() const
fixing days
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
DayCounter dayCounter() const override
day counter for accrual calculation
const ext::shared_ptr< InterestRateIndex > & index() const
floating index
Spread spread() const
spread paid over the fixing of the underlying index
bool isInArrears() const
whether or not the coupon fixes in arrears
Per-session settings for IborCoupon class.
Definition: iborcoupon.hpp:107
void createIndexedCoupons()
When called, IborCoupons are created as par coupons instead of indexed coupons.
Definition: iborcoupon.cpp:145
void createAtParCoupons()
When called, IborCoupons are created as indexed coupons instead of par coupons.
Definition: iborcoupon.cpp:141
Coupon paying a Libor-type index
Definition: iborcoupon.hpp:41
void initializeCachedData() const
Definition: iborcoupon.cpp:56
Time spanningTimeIndexMaturity() const
Period underlying the index fixing, as a year fraction.
Definition: iborcoupon.cpp:82
Rate indexFixing() const override
fixing of the underlying index
Definition: iborcoupon.cpp:87
ext::shared_ptr< IborIndex > iborIndex_
Definition: iborcoupon.hpp:92
void accept(AcyclicVisitor &) override
Definition: iborcoupon.cpp:132
const Date & fixingValueDate() const
Start of the deposit period underlying the index fixing.
Definition: iborcoupon.cpp:62
const ext::shared_ptr< IborIndex > & iborIndex() const
Definition: iborcoupon.hpp:58
void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &) override
Definition: iborcoupon.cpp:127
const Date & fixingEndDate() const
End of the deposit period underlying the coupon fixing.
Definition: iborcoupon.cpp:67
const Date & fixingMaturityDate() const
End of the deposit period underlying the index fixing.
Definition: iborcoupon.cpp:72
Time spanningTime() const
Period underlying the coupon fixing, as a year fraction.
Definition: iborcoupon.cpp:77
base pricer for capped/floored Ibor coupons
helper class building a sequence of capped/floored ibor-rate coupons
Definition: iborcoupon.hpp:133
std::vector< Rate > caps_
Definition: iborcoupon.hpp:173
Calendar paymentCalendar_
Definition: iborcoupon.hpp:169
ext::optional< bool > useIndexedCoupons_
Definition: iborcoupon.hpp:179
std::vector< Real > notionals_
Definition: iborcoupon.hpp:165
std::vector< Spread > spreads_
Definition: iborcoupon.hpp:172
std::vector< Natural > fixingDays_
Definition: iborcoupon.hpp:170
Calendar exCouponCalendar_
Definition: iborcoupon.hpp:176
std::vector< Real > gearings_
Definition: iborcoupon.hpp:171
DayCounter paymentDayCounter_
Definition: iborcoupon.hpp:166
ext::shared_ptr< IborIndex > index_
Definition: iborcoupon.hpp:164
Payment schedule.
Definition: schedule.hpp:40
Basic support for the singleton pattern.
Definition: singleton.hpp:58
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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