QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cpicoupon.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) 2011 Chris Kenyon
5 Copyright (C) 2022 Quaternion Risk Management Ltd
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 cpicoupon.hpp
22 \brief Coupon paying a zero-inflation index
23*/
24
25#ifndef quantlib_cpicoupon_hpp
26#define quantlib_cpicoupon_hpp
27
31#include <ql/time/schedule.hpp>
32
33namespace QuantLib {
34
35
36 class CPICouponPricer;
37
38 //! %Coupon paying the performance of a CPI (zero inflation) index
39 /*! The performance is relative to the index value on the base date.
40
41 The other inflation value is taken from the refPeriodEnd date
42 with observation lag, so any roll/calendar etc. will be built
43 in by the caller. By default this is done in the
44 InflationCoupon which uses ModifiedPreceding with fixing days
45 assumed positive meaning earlier, i.e. always stay in same
46 month (relative to referencePeriodEnd).
47
48 This is more sophisticated than an %IndexedCashFlow because it
49 does date calculations itself.
50
51 \todo we do not do any convexity adjustment for lags different
52 to the natural ZCIIS lag that was used to create the
53 forward inflation curve.
54 */
55 class CPICoupon : public InflationCoupon {
56 public:
57 //! \name Constructors
58 //@{
60 const Date& paymentDate,
62 const Date& startDate,
63 const Date& endDate,
64 const ext::shared_ptr<ZeroInflationIndex>& index,
69 const Date& refPeriodStart = Date(),
70 const Date& refPeriodEnd = Date(),
71 const Date& exCouponDate = Date());
72
73 CPICoupon(const Date& baseDate, // user provided, could be arbitrary
74 const Date& paymentDate,
76 const Date& startDate,
77 const Date& endDate,
78 const ext::shared_ptr<ZeroInflationIndex>& index,
83 const Date& refPeriodStart = Date(),
84 const Date& refPeriodEnd = Date(),
85 const Date& exCouponDate = Date());
86
87 CPICoupon(Real baseCPI, // user provided, could be arbitrary
88 const Date& baseDate,
89 const Date& paymentDate,
91 const Date& startDate,
92 const Date& endDate,
93 const ext::shared_ptr<ZeroInflationIndex>& index,
98 const Date& refPeriodStart = Date(),
99 const Date& refPeriodEnd = Date(),
100 const Date& exCouponDate = Date());
101
102 /*! \deprecated Use one of the constructors without spread.
103 Deprecated in version 1.31.
104 */
106 CPICoupon(Real baseCPI, // user provided, could be arbitrary
107 const Date& paymentDate,
109 const Date& startDate,
110 const Date& endDate,
111 const ext::shared_ptr<ZeroInflationIndex>& index,
112 const Period& observationLag,
114 const DayCounter& dayCounter,
117 const Date& refPeriodStart = Date(),
118 const Date& refPeriodEnd = Date(),
119 const Date& exCouponDate = Date());
120
121 /*! \deprecated Use one of the constructors without spread.
122 Deprecated in version 1.31.
123 */
125 CPICoupon(const Date& baseDate, // user provided, could be arbitrary
126 const Date& paymentDate,
128 const Date& startDate,
129 const Date& endDate,
130 const ext::shared_ptr<ZeroInflationIndex>& index,
131 const Period& observationLag,
133 const DayCounter& dayCounter,
136 const Date& refPeriodStart = Date(),
137 const Date& refPeriodEnd = Date(),
138 const Date& exCouponDate = Date());
139
140 /*! \deprecated Use one of the constructors without spread.
141 Deprecated in version 1.31.
142 */
144 CPICoupon(Real baseCPI, // user provided, could be arbitrary
145 const Date& baseDate,
146 const Date& paymentDate,
148 const Date& startDate,
149 const Date& endDate,
150 const ext::shared_ptr<ZeroInflationIndex>& index,
151 const Period& observationLag,
153 const DayCounter& dayCounter,
156 const Date& refPeriodStart = Date(),
157 const Date& refPeriodEnd = Date(),
158 const Date& exCouponDate = Date());
159 //@}
160
162 ~CPICoupon() override = default;
164
165 //! \name Inspectors
166 //@{
167 //! fixed rate that will be inflated by the index ratio
168 Real fixedRate() const;
169
170 /*! \deprecated Do not use this method. A spread doesn't make sense for this coupon.
171 Deprecated in version 1.31.
172 */
173 [[deprecated("Do not use this method. A spread doesn't make sense for this coupon.")]]
174 Spread spread() const;
175
176 //! base value for the CPI index
177 /*! \warning make sure that the interpolation used to create
178 this is what you are using for the fixing,
179 i.e. the observationInterpolation.
180 */
181 Rate baseCPI() const;
182
183 //! base date for the base fixing of the CPI index
184 Date baseDate() const;
185
186 //! how do you observe the index? as-is, flat, linear?
188
189 //! index used
190 ext::shared_ptr<ZeroInflationIndex> cpiIndex() const;
191 //@}
192
193 //! \name Calculations
194 //@{
195 Real accruedAmount(const Date&) const override;
196
197 //! the index value observed (with a lag) at the end date
198 Rate indexFixing() const override;
199
200 //! the ratio between the index fixing at the passed date and the base CPI
201 /*! No adjustments are applied */
202 Rate indexRatio(Date d) const;
203
204 //! the ratio between the end index fixing and the base CPI
205 /*! This might include adjustments calculated by the pricer */
207 //@}
208
209 //! \name Visitability
210 //@{
211 void accept(AcyclicVisitor&) override;
212 //@}
213 protected:
216 /*! \deprecated Don't use this data member. A spread doesn't make sense for this coupon.
217 Deprecated in version 1.31.
218 */
219 [[deprecated("Do not use this data member. A spread doesn't make sense for this coupon.")]]
223
224 bool checkPricerImpl(const ext::shared_ptr<InflationCouponPricer>&) const override;
225 };
226
227
228 //! Cash flow paying the performance of a CPI (zero inflation) index
229 /*! It is NOT a coupon, i.e. no accruals. */
231 public:
233 const ext::shared_ptr<ZeroInflationIndex>& index,
234 const Date& baseDate,
236 const Date& observationDate,
237 const Period& observationLag,
239 const Date& paymentDate,
240 bool growthOnly = false);
241
242 //! value used on base date
243 /*! This does not have to agree with index on that date. */
244 Real baseFixing() const override;
245 //! you may not have a valid date
246 Date baseDate() const override;
247
250 //! do you want linear/constant/as-index interpolation of future data?
252 return interpolation_;
253 }
254 virtual Frequency frequency() const { return frequency_; }
255
256 ext::shared_ptr<ZeroInflationIndex> cpiIndex() const;
257
258 Real indexFixing() const override;
259
260 Real amount() const override;
261
262 protected:
268 };
269
270
271 //! Helper class building a sequence of capped/floored CPI coupons.
272 /*! Also allowing for the inflated notional at the end...
273 especially if there is only one date in the schedule.
274 If the fixed rate is zero you get a FixedRateCoupon, otherwise
275 you get a ZeroInflationCoupon.
276 */
277 class CPILeg {
278 public:
279 CPILeg(Schedule schedule,
280 ext::shared_ptr<ZeroInflationIndex> index,
281 Real baseCPI,
282 const Period& observationLag);
283 CPILeg& withNotionals(Real notional);
284 CPILeg& withNotionals(const std::vector<Real>& notionals);
285 CPILeg& withFixedRates(Real fixedRate);
286 CPILeg& withFixedRates(const std::vector<Real>& fixedRates);
292 /*! \deprecated Do not use this method. A spread doesn't make sense for these coupons.
293 Deprecated in version 1.31.
294 */
295 [[deprecated("Do not use this method. A spread doesn't make sense for these coupons.")]]
296 CPILeg& withSpreads(Spread spread);
297 /*! \deprecated Do not use this method. A spread doesn't make sense for these coupons.
298 Deprecated in version 1.31.
299 */
300 [[deprecated("Do not use this method. A spread doesn't make sense for these coupons.")]]
301 CPILeg& withSpreads(const std::vector<Spread>& spreads);
302 CPILeg& withCaps(Rate cap);
303 CPILeg& withCaps(const std::vector<Rate>& caps);
304 CPILeg& withFloors(Rate floor);
305 CPILeg& withFloors(const std::vector<Rate>& floors);
307 const Calendar&,
309 bool endOfMonth = false);
310 CPILeg& withBaseDate(const Date& baseDate);
311
312 operator Leg() const;
313
314 private:
316 ext::shared_ptr<ZeroInflationIndex> index_;
319 std::vector<Real> notionals_;
320 std::vector<Real> fixedRates_;
326 std::vector<Spread> spreads_;
327 std::vector<Rate> caps_, floors_;
333 };
334
335
336 // inline definitions
337
338 inline Real CPICoupon::fixedRate() const {
339 return fixedRate_;
340 }
341
342 inline Real CPICoupon::spread() const {
344 return spread_;
346 }
347
350 return (rate()-spread())/fixedRate();
352 }
353
356 }
357
358 inline Rate CPICoupon::baseCPI() const {
359 return baseCPI_;
360 }
361
362 inline Date CPICoupon::baseDate() const {
363 return baseDate_;
364 }
365
368 }
369
370 inline ext::shared_ptr<ZeroInflationIndex> CPICoupon::cpiIndex() const {
371 return ext::dynamic_pointer_cast<ZeroInflationIndex>(index());
372 }
373
374
375 inline ext::shared_ptr<ZeroInflationIndex> CPICashFlow::cpiIndex() const {
376 return ext::dynamic_pointer_cast<ZeroInflationIndex>(index());
377 }
378
379}
380
381#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Cash flow paying the performance of a CPI (zero inflation) index.
Definition: cpicoupon.hpp:230
Date observationDate() const
Definition: cpicoupon.hpp:248
ext::shared_ptr< ZeroInflationIndex > cpiIndex() const
Definition: cpicoupon.hpp:375
CPI::InterpolationType interpolation_
Definition: cpicoupon.hpp:266
Date baseDate() const override
you may not have a valid date
Definition: cpicoupon.cpp:219
Real amount() const override
returns the amount of the cash flow
Definition: cpicoupon.cpp:242
Real baseFixing() const override
value used on base date
Definition: cpicoupon.cpp:228
Period observationLag() const
Definition: cpicoupon.hpp:249
virtual Frequency frequency() const
Definition: cpicoupon.hpp:254
Real indexFixing() const override
Definition: cpicoupon.cpp:232
virtual CPI::InterpolationType interpolation() const
do you want linear/constant/as-index interpolation of future data?
Definition: cpicoupon.hpp:251
Coupon paying the performance of a CPI (zero inflation) index
Definition: cpicoupon.hpp:55
bool checkPricerImpl(const ext::shared_ptr< InflationCouponPricer > &) const override
makes sure you were given the correct type of pricer
Definition: cpicoupon.cpp:191
void accept(AcyclicVisitor &) override
Definition: cpicoupon.cpp:153
Rate baseCPI() const
base value for the CPI index
Definition: cpicoupon.hpp:358
Rate indexFixing() const override
the index value observed (with a lag) at the end date
Definition: cpicoupon.hpp:354
ext::shared_ptr< ZeroInflationIndex > cpiIndex() const
index used
Definition: cpicoupon.hpp:370
CPI::InterpolationType observationInterpolation() const
how do you observe the index? as-is, flat, linear?
Definition: cpicoupon.hpp:366
QL_DEPRECATED_DISABLE_WARNING ~CPICoupon() override=default
Rate indexRatio(Date d) const
the ratio between the index fixing at the passed date and the base CPI
Definition: cpicoupon.cpp:172
Date baseDate() const
base date for the base fixing of the CPI index
Definition: cpicoupon.hpp:362
Real accruedAmount(const Date &) const override
accrued amount at the given date
Definition: cpicoupon.cpp:161
Spread spread() const
Definition: cpicoupon.hpp:342
CPI::InterpolationType observationInterpolation_
Definition: cpicoupon.hpp:221
Real fixedRate() const
fixed rate that will be inflated by the index ratio
Definition: cpicoupon.hpp:338
Rate adjustedIndexGrowth() const
the ratio between the end index fixing and the base CPI
Definition: cpicoupon.hpp:348
Helper class building a sequence of capped/floored CPI coupons.
Definition: cpicoupon.hpp:277
CPILeg & withNotionals(Real notional)
Definition: cpicoupon.cpp:284
Schedule schedule_
Definition: cpicoupon.hpp:315
BusinessDayConvention paymentAdjustment_
Definition: cpicoupon.hpp:322
std::vector< Rate > caps_
Definition: cpicoupon.hpp:327
CPILeg & withPaymentAdjustment(BusinessDayConvention)
Definition: cpicoupon.cpp:304
BusinessDayConvention exCouponAdjustment_
Definition: cpicoupon.hpp:330
CPILeg & withSubtractInflationNominal(bool)
Definition: cpicoupon.cpp:294
Period observationLag_
Definition: cpicoupon.hpp:318
Calendar paymentCalendar_
Definition: cpicoupon.hpp:323
ext::shared_ptr< ZeroInflationIndex > index_
Definition: cpicoupon.hpp:316
CPILeg & withBaseDate(const Date &baseDate)
Definition: cpicoupon.cpp:356
CPILeg & withFixedRates(Real fixedRate)
Definition: cpicoupon.cpp:274
CPILeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
Definition: cpicoupon.cpp:344
std::vector< Real > notionals_
Definition: cpicoupon.hpp:319
std::vector< Spread > spreads_
Definition: cpicoupon.hpp:326
CPILeg & withCaps(Rate cap)
Definition: cpicoupon.cpp:324
CPILeg & withPaymentDayCounter(const DayCounter &)
Definition: cpicoupon.cpp:299
CPILeg & withPaymentCalendar(const Calendar &)
Definition: cpicoupon.cpp:309
CPILeg & withSpreads(Spread spread)
Definition: cpicoupon.cpp:314
CPILeg & withFloors(Rate floor)
Definition: cpicoupon.cpp:334
bool exCouponEndOfMonth_
Definition: cpicoupon.hpp:331
std::vector< Real > fixedRates_
Definition: cpicoupon.hpp:320
CPI::InterpolationType observationInterpolation_
Definition: cpicoupon.hpp:324
Period exCouponPeriod_
Definition: cpicoupon.hpp:328
Calendar exCouponCalendar_
Definition: cpicoupon.hpp:329
std::vector< Rate > floors_
Definition: cpicoupon.hpp:327
bool subtractInflationNominal_
Definition: cpicoupon.hpp:325
CPILeg & withObservationInterpolation(CPI::InterpolationType)
Definition: cpicoupon.cpp:268
DayCounter paymentDayCounter_
Definition: cpicoupon.hpp:321
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
const Date & accrualEndDate() const
end of the accrual period
Definition: coupon.hpp:108
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Cash flow dependent on an index ratio.
virtual Real notional() const
virtual bool growthOnly() const
virtual ext::shared_ptr< Index > index() const
Base inflation-coupon class.
Rate rate() const override
accrued rate
Period observationLag() const
how the coupon observes the index
DayCounter dayCounter() const override
day counter for accrual calculation
const ext::shared_ptr< InflationIndex > & index() const
yoy inflation index
template class providing a null value for a given type.
Definition: null.hpp:76
Payment schedule.
Definition: schedule.hpp:40
Date d
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
Cash flow dependent on an index ratio (NOT a coupon, i.e. no accruals)
Coupon paying a variable index-based rate.
base classes for inflation indexes
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
#define QL_DEPRECATED
Definition: qldefines.hpp:215
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
date schedule
static Real laggedFixing(const ext::shared_ptr< ZeroInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated inflation fixing
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ AsIndex
same interpolation as index