QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cpicoupon.hpp
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
25#ifndef quantlib_cpicoupon_hpp
26#define quantlib_cpicoupon_hpp
27
28#include <ql/cashflows/inflationcoupon.hpp>
29#include <ql/cashflows/indexedcashflow.hpp>
30#include <ql/indexes/inflationindex.hpp>
31#include <ql/time/schedule.hpp>
32
33namespace QuantLib {
34
35
36 class CPICouponPricer;
37
39
55 class CPICoupon : public InflationCoupon {
56 public:
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
105 QL_DEPRECATED
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
124 QL_DEPRECATED
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
143 QL_DEPRECATED
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());
160
161 QL_DEPRECATED_DISABLE_WARNING
162 ~CPICoupon() override = default;
163 QL_DEPRECATED_ENABLE_WARNING
164
166
167
168 Real fixedRate() const;
169
173 [[deprecated("Do not use this method. A spread doesn't make sense for this coupon.")]]
174 Spread spread() const;
175
177
181 Rate baseCPI() const;
182
184 Date baseDate() const;
185
188
190 ext::shared_ptr<ZeroInflationIndex> cpiIndex() const;
192
194
195 Real accruedAmount(const Date&) const override;
196
198 Rate indexFixing() const override;
199
201
202 Rate indexRatio(Date d) const;
203
205
208
210
211 void accept(AcyclicVisitor&) override;
213 protected:
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
229
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
243
244 Real baseFixing() const override;
246 Date baseDate() const override;
247
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
272
277 class CPILeg {
278 public:
279 CPILeg(const 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);
295 [[deprecated("Do not use this method. A spread doesn't make sense for these coupons.")]]
296 CPILeg& withSpreads(Spread spread);
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 {
343 QL_DEPRECATED_DISABLE_WARNING
344 return spread_;
345 QL_DEPRECATED_ENABLE_WARNING
346 }
347
349 QL_DEPRECATED_DISABLE_WARNING
350 return (rate()-spread())/fixedRate();
351 QL_DEPRECATED_ENABLE_WARNING
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:285
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:305
BusinessDayConvention exCouponAdjustment_
Definition: cpicoupon.hpp:330
CPILeg & withSubtractInflationNominal(bool)
Definition: cpicoupon.cpp:295
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:357
CPILeg & withFixedRates(Real fixedRate)
Definition: cpicoupon.cpp:275
CPILeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
Definition: cpicoupon.cpp:345
std::vector< Real > notionals_
Definition: cpicoupon.hpp:319
std::vector< Spread > spreads_
Definition: cpicoupon.hpp:326
CPILeg & withCaps(Rate cap)
Definition: cpicoupon.cpp:325
CPILeg & withPaymentDayCounter(const DayCounter &)
Definition: cpicoupon.cpp:300
CPILeg & withPaymentCalendar(const Calendar &)
Definition: cpicoupon.cpp:310
CPILeg & withSpreads(Spread spread)
Definition: cpicoupon.cpp:315
CPILeg & withFloors(Rate floor)
Definition: cpicoupon.cpp:335
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:269
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
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
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
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