QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
multipleresetscoupon.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) 2008 Toyin Akin
5 Copyright (C) 2021 Marcin Rybacki
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file multipleresetscoupon.hpp
22 \brief Coupon compounding or averaging multiple fixings
23*/
24
25#ifndef quantlib_multiple_resets_coupon_hpp
26#define quantlib_multiple_resets_coupon_hpp
27
31#include <ql/time/schedule.hpp>
32#include <vector>
33
34namespace QuantLib {
35
36 class IborIndex;
37
38 //! multiple-reset coupon
39 /*! %Coupon paying a rate calculated by compounding or averaging
40 multiple fixings during its accrual period.
41 */
43 public:
44 /*! \param resetSchedule the schedule for the multiple resets. The first and last
45 dates are also the start and end dates of the coupon.
46 Each period specified by the schedule is the underlying
47 period for one fixing; the corresponding fixing date is
48 the passed number of fixing days before the start of
49 the period.
50 \param couponSpread an optional spread added to the final coupon rate.
51 \param rateSpread an optional spread added to each of the underlying fixings.
52 \param gearing an optional multiplier for the final coupon rate.
53 */
54 MultipleResetsCoupon(const Date& paymentDate,
56 const Schedule& resetSchedule,
58 const ext::shared_ptr<IborIndex>& index,
59 Real gearing = 1.0,
60 Rate couponSpread = 0.0,
61 Rate rateSpread = 0.0,
62 const Date& refPeriodStart = Date(),
63 const Date& refPeriodEnd = Date(),
65 const Date& exCouponDate = Date());
66
67 /*! \deprecated Use the other constructor.
68 Deprecated in version 1.37.
69 */
70 [[deprecated("Use the other constructor")]]
71 MultipleResetsCoupon(const Date& paymentDate,
73 const Date& startDate,
74 const Date& endDate,
76 const ext::shared_ptr<IborIndex>& index,
77 Real gearing = 1.0,
78 Rate couponSpread = 0.0,
79 Rate rateSpread = 0.0,
80 const Date& refPeriodStart = Date(),
81 const Date& refPeriodEnd = Date(),
83 const Date& exCouponDate = Date());
84
85 //! \name Inspectors
86 //@{
87 //! fixing dates for the rates to be compounded
88 const std::vector<Date>& fixingDates() const { return fixingDates_; }
89 //! accrual (compounding) periods
90 const std::vector<Time>& dt() const { return dt_; }
91 //! value dates for the rates to be compounded
92 const std::vector<Date>& valueDates() const { return valueDates_; }
93 //! rate spread
94 Spread rateSpread() const { return rateSpread_; }
95 //@}
96 //! \name FloatingRateCoupon interface
97 //@{
98 //! the date when the coupon is fully determined
99 Date fixingDate() const override { return fixingDates_.back(); }
100 //@}
101 //! \name Visitability
102 //@{
103 void accept(AcyclicVisitor&) override;
104 //@}
105 private:
106 Date fixingDate(const Date& valueDate) const;
107
108 std::vector<Date> valueDates_, fixingDates_;
110 std::vector<Time> dt_;
112 };
113
114 /*! \deprecated Renamed to MultipleResetsCoupon.
115 Deprecated in version 1.37.
116 */
117 [[deprecated("Renamed to MultipleResetsCoupon")]]
119
120
122 public:
123 Rate swapletPrice() const override;
124 Real capletPrice(Rate effectiveCap) const override;
125 Rate capletRate(Rate effectiveCap) const override;
126 Real floorletPrice(Rate effectiveFloor) const override;
127 Rate floorletRate(Rate effectiveFloor) const override;
128 void initialize(const FloatingRateCoupon& coupon) override;
129
130 protected:
132 std::vector<Real> subPeriodFixings_;
133 };
134
135 /*! \deprecated Renamed to MultipleResetsPricer.
136 Deprecated in version 1.37.
137 */
138 [[deprecated("Renamed to MultipleResetsPricer")]]
140
142 public:
143 Real swapletRate() const override;
144 };
145
146 /*! \deprecated Renamed to AveragingMultipleResetsPricer.
147 Deprecated in version 1.37.
148 */
149 [[deprecated("Renamed to AveragingMultipleResetsPricer")]]
151
153 public:
154 Real swapletRate() const override;
155 };
156
157 /*! \deprecated Renamed to CompoundingMultipleResetsPricer.
158 Deprecated in version 1.37.
159 */
160 [[deprecated("Renamed to CompoundingMultipleResetsPricer")]]
162
163
164 //! helper class building a sequence of multiple-reset coupons
166 public:
167 /*! \param fullResetSchedule the full schedule specifying reset periods for all coupons.
168 \param index the index whose fixings will be used; it should have the
169 same tenor as the resets.
170 \param resetsPerCoupon the number of resets for each coupon; the number of periods
171 in the schedule should be divided exactly by this number.
172 */
173 MultipleResetsLeg(Schedule fullResetSchedule,
174 ext::shared_ptr<IborIndex> index,
175 Size resetsPerCoupon);
177 MultipleResetsLeg& withNotionals(const std::vector<Real>& notionals);
183 MultipleResetsLeg& withFixingDays(const std::vector<Natural>& fixingDays);
185 MultipleResetsLeg& withGearings(const std::vector<Real>& gearings);
187 MultipleResetsLeg& withCouponSpreads(const std::vector<Spread>& spreads);
189 MultipleResetsLeg& withRateSpreads(const std::vector<Spread>& spreads);
191 const Calendar&,
193 bool endOfMonth = false);
195 operator Leg() const;
196
197 private:
199 ext::shared_ptr<IborIndex> index_;
201 std::vector<Real> notionals_;
206 std::vector<Natural> fixingDays_;
207 std::vector<Real> gearings_;
208 std::vector<Spread> couponSpreads_;
209 std::vector<Spread> rateSpreads_;
215 };
216
217
218 /*! \deprecated Use MultipleResetsLeg instead.
219 Deprecated in version 1.37.
220 */
221 class [[deprecated("Use MultipleResetsLeg instead")]] SubPeriodsLeg {
222 public:
223 SubPeriodsLeg(Schedule schedule, ext::shared_ptr<IborIndex> index);
224 SubPeriodsLeg& withNotionals(Real notional);
225 SubPeriodsLeg& withNotionals(const std::vector<Real>& notionals);
226 SubPeriodsLeg& withPaymentDayCounter(const DayCounter&);
227 SubPeriodsLeg& withPaymentAdjustment(BusinessDayConvention);
228 SubPeriodsLeg& withPaymentCalendar(const Calendar&);
229 SubPeriodsLeg& withPaymentLag(Integer lag);
230 SubPeriodsLeg& withFixingDays(Natural fixingDays);
231 SubPeriodsLeg& withFixingDays(const std::vector<Natural>& fixingDays);
232 SubPeriodsLeg& withGearings(Real gearing);
233 SubPeriodsLeg& withGearings(const std::vector<Real>& gearings);
234 SubPeriodsLeg& withCouponSpreads(Spread spread);
235 SubPeriodsLeg& withCouponSpreads(const std::vector<Spread>& spreads);
236 SubPeriodsLeg& withRateSpreads(Spread spread);
237 SubPeriodsLeg& withRateSpreads(const std::vector<Spread>& spreads);
238 SubPeriodsLeg& withExCouponPeriod(const Period&,
239 const Calendar&,
241 bool endOfMonth = false);
242 SubPeriodsLeg& withAveragingMethod(RateAveraging::Type averagingMethod);
243 operator Leg() const;
244
245 private:
247 ext::shared_ptr<IborIndex> index_;
248 std::vector<Real> notionals_;
251 BusinessDayConvention paymentAdjustment_ = Following;
253 std::vector<Natural> fixingDays_;
254 std::vector<Real> gearings_;
255 std::vector<Spread> couponSpreads_;
256 std::vector<Spread> rateSpreads_;
257 RateAveraging::Type averagingMethod_ = RateAveraging::Compound;
260 BusinessDayConvention exCouponAdjustment_ = Unadjusted;
261 bool exCouponEndOfMonth_ = false;
262 };
263}
264
265#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
generic pricer for floating-rate coupons
Spread rateSpread() const
rate spread
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
void accept(AcyclicVisitor &) override
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
Date fixingDate() const override
the date when the coupon is fully determined
helper class building a sequence of multiple-reset coupons
BusinessDayConvention paymentAdjustment_
MultipleResetsLeg & withPaymentLag(Integer lag)
BusinessDayConvention exCouponAdjustment_
std::vector< Spread > couponSpreads_
MultipleResetsLeg & withPaymentCalendar(const Calendar &)
MultipleResetsLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
MultipleResetsLeg & withNotionals(Real notional)
MultipleResetsLeg & withPaymentDayCounter(const DayCounter &)
MultipleResetsLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
MultipleResetsLeg & withCouponSpreads(Spread spread)
std::vector< Natural > fixingDays_
MultipleResetsLeg & withGearings(Real gearing)
std::vector< Spread > rateSpreads_
MultipleResetsLeg & withFixingDays(Natural fixingDays)
MultipleResetsLeg & withRateSpreads(Spread spread)
MultipleResetsLeg & withPaymentAdjustment(BusinessDayConvention)
ext::shared_ptr< IborIndex > index_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
void initialize(const FloatingRateCoupon &coupon) override
const MultipleResetsCoupon * coupon_
Real floorletPrice(Rate effectiveFloor) const override
Rate capletRate(Rate effectiveCap) const override
Payment schedule.
Definition: schedule.hpp:40
std::vector< Spread > couponSpreads_
std::vector< Real > notionals_
std::vector< Natural > fixingDays_
std::vector< Spread > rateSpreads_
ext::shared_ptr< IborIndex > index_
Coupon pricers.
Integer paymentLag_
Coupon paying a variable index-based rate.
BusinessDayConvention
Business Day conventions.
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
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:37
AveragingMultipleResetsPricer AveragingRatePricer
CompoundingMultipleResetsPricer CompoundingRatePricer
MultipleResetsPricer SubPeriodsPricer
MultipleResetsCoupon SubPeriodsCoupon
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
rate-averaging method
date schedule