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
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
40 //! %Coupon paying a Libor-type index
41 class IborCoupon : public FloatingRateCoupon {
42 public:
43 IborCoupon(const Date& paymentDate,
44 Real nominal,
45 const Date& startDate,
46 const Date& endDate,
47 Natural fixingDays,
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(),
53 const DayCounter& dayCounter = DayCounter(),
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 // implemented in order to manage the case of par coupon
63 Rate indexFixing() const override;
64 void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>&) override;
65 //@}
66 //! \name Visitability
67 //@{
68 void accept(AcyclicVisitor&) override;
69 //@}
70 /*! \name Internal calculations
71
72 You won't probably need these methods unless you're implementing
73 a coupon pricer.
74 */
75 //@{
76 //! Start of the deposit period underlying the index fixing
77 const Date& fixingValueDate() const;
78 //! End of the deposit period underlying the index fixing
79 const Date& fixingMaturityDate() const;
80 //! End of the deposit period underlying the coupon fixing
81 /*! This might be not the same as fixingMaturityDate if par coupons are used. */
82 const Date& fixingEndDate() const;
83 //! Period underlying the index fixing, as a year fraction
84 Time spanningTimeIndexMaturity() const;
85 //! Period underlying the coupon fixing, as a year fraction
86 /*! This might be not the same as spanningTimeIndexMaturity if par coupons are used. */
87 Time spanningTime() const;
88 //@}
89
90 private:
91 friend class IborCouponPricer;
92 ext::shared_ptr<IborIndex> iborIndex_;
93 Date fixingDate_;
94 // computed by coupon pricer (depending on par coupon flag) and stored here
95 void initializeCachedData() const;
96 mutable bool cachedDataIsInitialized_ = false;
97 mutable Date fixingValueDate_, fixingEndDate_, fixingMaturityDate_;
98 mutable Time spanningTime_, spanningTimeIndexMaturity_;
99
100 public:
101 // IborCoupon::Settings forward declaration
102 class Settings;
103 };
104
105
106 //! Per-session settings for IborCoupon class
107 class IborCoupon::Settings : public Singleton<IborCoupon::Settings> {
108 friend class Singleton<IborCoupon::Settings>;
109 private:
110 Settings() = default;
111
112 public:
113 //! When called, IborCoupons are created as indexed coupons instead of par coupons.
114 void createAtParCoupons();
115
116 //! When called, IborCoupons are created as par coupons instead of indexed coupons.
117 void createIndexedCoupons();
118
119 /*! If true the IborCoupons are created as par coupons and vice versa.
120 The default depends on the compiler flag QL_USE_INDEXED_COUPON and can be overwritten by
121 createAtParCoupons() and createIndexedCoupons() */
122 bool usingAtParCoupons() const;
123
124 private:
125 #ifndef QL_USE_INDEXED_COUPON
126 bool usingAtParCoupons_ = true;
127 #else
128 bool usingAtParCoupons_ = false;
129 #endif
130 };
131
132 //! helper class building a sequence of capped/floored ibor-rate coupons
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&,
156 BusinessDayConvention,
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:
163 Schedule schedule_;
164 ext::shared_ptr<IborIndex> index_;
165 std::vector<Real> notionals_;
166 DayCounter paymentDayCounter_;
167 BusinessDayConvention paymentAdjustment_ = Following;
168 Natural paymentLag_ = 0;
169 Calendar paymentCalendar_;
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;
175 Period exCouponPeriod_;
176 Calendar exCouponCalendar_;
177 BusinessDayConvention exCouponAdjustment_ = Unadjusted;
178 bool exCouponEndOfMonth_ = false;
179 ext::optional<bool> useIndexedCoupons_;
180 };
181
182}
183
184#endif
185

source code of quantlib/ql/cashflows/iborcoupon.hpp