QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
iborcoupon.hpp
Go to the documentation of this file.
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
25/*! \file iborcoupon.hpp
26 \brief Coupon paying a Libor-type index
27*/
28
29#ifndef quantlib_ibor_coupon_hpp
30#define quantlib_ibor_coupon_hpp
31
35#include <ql/time/schedule.hpp>
36#include <ql/optional.hpp>
37
38namespace QuantLib {
39
40 //! %Coupon paying a Libor-type index
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());
56 //! \name Inspectors
57 //@{
58 const ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
59 //@}
60 //! \name FloatingRateCoupon interface
61 //@{
62 Date fixingDate() const override;
63 // implemented in order to manage the case of par coupon
64 Rate indexFixing() const override;
65 void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>&) override;
66 //@}
67 //! \name Visitability
68 //@{
69 void accept(AcyclicVisitor&) override;
70 //@}
71 /*! \name Internal calculations
72
73 You won't probably need these methods unless you're implementing
74 a coupon pricer.
75 */
76 //@{
77 //! Start of the deposit period underlying the index fixing
78 const Date& fixingValueDate() const;
79 //! End of the deposit period underlying the index fixing
80 const Date& fixingMaturityDate() const;
81 //! End of the deposit period underlying the coupon fixing
82 /*! This might be not the same as fixingMaturityDate if par coupons are used. */
83 const Date& fixingEndDate() const;
84 //! Period underlying the index fixing, as a year fraction
86 //! Period underlying the coupon fixing, as a year fraction
87 /*! This might be not the same as spanningTimeIndexMaturity if par coupons are used. */
88 Time spanningTime() const;
89 //@}
90
91 private:
92 friend class IborCouponPricer;
93 ext::shared_ptr<IborIndex> iborIndex_;
95 // computed by coupon pricer (depending on par coupon flag) and stored here
96 void initializeCachedData() const;
97 mutable bool cachedDataIsInitialized_ = false;
100
101 public:
102 // IborCoupon::Settings forward declaration
103 class Settings;
104 };
105
106
107 //! Per-session settings for IborCoupon class
108 class IborCoupon::Settings : public Singleton<IborCoupon::Settings> {
109 friend class Singleton<IborCoupon::Settings>;
110 private:
111 Settings() = default;
112
113 public:
114 //! When called, IborCoupons are created as indexed coupons instead of par coupons.
115 void createAtParCoupons();
116
117 //! When called, IborCoupons are created as par coupons instead of indexed coupons.
119
120 /*! If true the IborCoupons are created as par coupons and vice versa.
121 The default depends on the compiler flag QL_USE_INDEXED_COUPON and can be overwritten by
122 createAtParCoupons() and createIndexedCoupons() */
123 bool usingAtParCoupons() const;
124
125 private:
126 #ifndef QL_USE_INDEXED_COUPON
128 #else
129 bool usingAtParCoupons_ = false;
130 #endif
131 };
132
133 //! helper class building a sequence of capped/floored ibor-rate coupons
134 class IborLeg {
135 public:
136 IborLeg(Schedule schedule, ext::shared_ptr<IborIndex> index);
137 IborLeg& withNotionals(Real notional);
138 IborLeg& withNotionals(const std::vector<Real>& notionals);
139 IborLeg& withPaymentDayCounter(const DayCounter&);
140 IborLeg& withPaymentAdjustment(BusinessDayConvention);
141 IborLeg& withPaymentLag(Integer lag);
142 IborLeg& withPaymentCalendar(const Calendar&);
143 IborLeg& withFixingDays(Natural fixingDays);
144 IborLeg& withFixingDays(const std::vector<Natural>& fixingDays);
145 IborLeg& withGearings(Real gearing);
146 IborLeg& withGearings(const std::vector<Real>& gearings);
147 IborLeg& withSpreads(Spread spread);
148 IborLeg& withSpreads(const std::vector<Spread>& spreads);
149 IborLeg& withCaps(Rate cap);
150 IborLeg& withCaps(const std::vector<Rate>& caps);
151 IborLeg& withFloors(Rate floor);
152 IborLeg& withFloors(const std::vector<Rate>& floors);
153 IborLeg& inArrears(bool flag = true);
154 IborLeg& withZeroPayments(bool flag = true);
155 IborLeg& withExCouponPeriod(const Period&,
156 const Calendar&,
158 bool endOfMonth = false);
159 IborLeg& withIndexedCoupons(ext::optional<bool> b = true);
160 IborLeg& withAtParCoupons(bool b = true);
161 operator Leg() const;
162
163 private:
165 ext::shared_ptr<IborIndex> index_;
166 std::vector<Real> notionals_;
168 BusinessDayConvention paymentAdjustment_ = Following;
169 Integer paymentLag_ = 0;
171 std::vector<Natural> fixingDays_;
172 std::vector<Real> gearings_;
173 std::vector<Spread> spreads_;
174 std::vector<Rate> caps_, floors_;
175 bool inArrears_ = false, zeroPayments_ = false;
178 BusinessDayConvention exCouponAdjustment_ = Unadjusted;
179 bool exCouponEndOfMonth_ = false;
180 ext::optional<bool> useIndexedCoupons_;
181 };
182
183}
184
185#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:108
void createIndexedCoupons()
When called, IborCoupons are created as par coupons instead of indexed coupons.
Definition: iborcoupon.cpp:149
void createAtParCoupons()
When called, IborCoupons are created as indexed coupons instead of par coupons.
Definition: iborcoupon.cpp:145
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:91
ext::shared_ptr< IborIndex > iborIndex_
Definition: iborcoupon.hpp:93
void accept(AcyclicVisitor &) override
Definition: iborcoupon.cpp:136
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:131
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
Date fixingDate() const override
fixing date
Definition: iborcoupon.cpp:87
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:134
std::vector< Rate > caps_
Definition: iborcoupon.hpp:174
Calendar paymentCalendar_
Definition: iborcoupon.hpp:170
ext::optional< bool > useIndexedCoupons_
Definition: iborcoupon.hpp:180
std::vector< Real > notionals_
Definition: iborcoupon.hpp:166
std::vector< Spread > spreads_
Definition: iborcoupon.hpp:173
std::vector< Natural > fixingDays_
Definition: iborcoupon.hpp:171
Calendar exCouponCalendar_
Definition: iborcoupon.hpp:177
std::vector< Real > gearings_
Definition: iborcoupon.hpp:172
DayCounter paymentDayCounter_
Definition: iborcoupon.hpp:167
ext::shared_ptr< IborIndex > index_
Definition: iborcoupon.hpp:165
Payment schedule.
Definition: schedule.hpp:40
Basic support for the singleton pattern.
Definition: singleton.hpp:58
ext::function< Real(Real)> b
Coupon paying a variable index-based rate.
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
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
base class for Inter-Bank-Offered-Rate indexes
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
Maps optional to either the boost or std implementation.
date schedule
basic support for the singleton pattern