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