QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cpiswap.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, 2009, 2011 Chris Kenyon
5 Copyright (C) 2009 StatPro Italia srl
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 cpiswap.hpp
22 \brief zero-inflation-indexed-ratio-with-base swap
23 */
24
25#ifndef quantlib_zeroinflationswap_hpp
26#define quantlib_zeroinflationswap_hpp
27
29#include <ql/time/calendar.hpp>
31#include <ql/time/schedule.hpp>
34
35namespace QuantLib {
36
37 class ZeroInflationIndex;
38
39 //! zero-inflation-indexed swap,
40 /*! fixed x zero-inflation, i.e. fixed x CPI(i'th fixing)/CPI(base)
41 versus floating + spread
42
43 Note that this does ony the inflation-vs-floating-leg.
44 Extension to inflation-vs-fixed-leg. is simple - just replace
45 the floating leg with a fixed leg.
46
47 Typically there are notional exchanges at the end: either
48 inflated-notional vs notional; or just (inflated-notional -
49 notional) vs zero. The latter is perhaphs more typical.
50 \warning Setting subtractInflationNominal to true means that
51 the original inflation nominal is subtracted from both
52 nominals before they are exchanged, even if they are
53 different.
54
55 This swap can mimic a ZCIIS where [(1+q)^n - 1] is exchanged
56 against (cpi ratio - 1), by using differnt nominals on each
57 leg and setting subtractInflationNominal to true. ALSO -
58 there must be just one date in each schedule.
59
60 The two legs can have different schedules, fixing (days vs
61 lag), settlement, and roll conventions. N.B. accrual
62 adjustment periods are already in the schedules. Trade date
63 and swap settlement date are outside the scope of the
64 instrument.
65 */
66 class CPISwap : public Swap {
67 public:
68 class arguments;
69 class results;
70 class engine;
71
72 /*! In this swap, the type (Payer or Receiver) refers to the floating leg. */
76 // float+spread leg
80 const BusinessDayConvention& floatRoll,
82 ext::shared_ptr<IborIndex> floatIndex,
83 // fixed x inflation leg
88 const BusinessDayConvention& fixedRoll,
90 ext::shared_ptr<ZeroInflationIndex> fixedIndex,
93
94 // results
95 // float+spread
96 virtual Real floatLegNPV() const;
97 virtual Spread fairSpread() const;
98 // fixed rate x inflation
99 virtual Real fixedLegNPV() const;
100 virtual Rate fairRate() const;
101
102 // inspectors
103 virtual Type type() const;
104 virtual Real nominal() const;
105 virtual bool subtractInflationNominal() const;
106
107 // float+spread
108 virtual Spread spread() const;
109 virtual const DayCounter& floatDayCount() const;
110 virtual const Schedule& floatSchedule() const;
111 virtual const BusinessDayConvention& floatPaymentRoll() const;
112 virtual Natural fixingDays() const;
113 virtual const ext::shared_ptr<IborIndex>& floatIndex() const;
114
115 // fixed rate x inflation
116 virtual Rate fixedRate() const;
117 virtual Real baseCPI() const;
118 virtual const DayCounter& fixedDayCount() const;
119 virtual const Schedule& fixedSchedule() const;
120 virtual const BusinessDayConvention& fixedPaymentRoll() const;
121 virtual Period observationLag() const;
122 virtual const ext::shared_ptr<ZeroInflationIndex>& fixedIndex() const;
124 virtual Real inflationNominal() const;
125
126 // legs
127 virtual const Leg& cpiLeg() const;
128 virtual const Leg& floatLeg() const;
129
130 // other
131 void setupArguments(PricingEngine::arguments* args) const override;
132 void fetchResults(const PricingEngine::results*) const override;
133
134 private:
135 void setupExpired() const override;
136
140
141 // float+spread leg
147 ext::shared_ptr<IborIndex> floatIndex_;
148
149 // fixed x inflation leg
155 ext::shared_ptr<ZeroInflationIndex> fixedIndex_;
159 // results
162
163 };
164
165
166 //! %Arguments for swap calculation
168 public:
172
173 void validate() const override;
174 };
175
176 //! %Results from swap calculation
178 public:
181 void reset() override;
182 };
183
184 class CPISwap::engine : public GenericEngine<CPISwap::arguments,
185 CPISwap::results> {};
186
187
188 // inline definitions
189
190 // inspectors
191 inline Swap::Type CPISwap::type() const { return type_; }
192 inline Real CPISwap::nominal() const { return nominal_; }
194
195 // float+spread
196 inline Spread CPISwap::spread() const { return spread_; }
197 inline const DayCounter& CPISwap::floatDayCount() const { return floatDayCount_; }
198 inline const Schedule& CPISwap::floatSchedule() const { return floatSchedule_; }
200 inline Natural CPISwap::fixingDays() const { return fixingDays_; }
201 inline const ext::shared_ptr<IborIndex>& CPISwap::floatIndex() const { return floatIndex_; }
202
203 // fixed rate x inflation
204 inline Rate CPISwap::fixedRate() const { return fixedRate_; }
205 inline Real CPISwap::baseCPI() const { return baseCPI_; }
206 inline const DayCounter& CPISwap::fixedDayCount() const { return fixedDayCount_; }
207 inline const Schedule& CPISwap::fixedSchedule() const { return fixedSchedule_; }
210 inline const ext::shared_ptr<ZeroInflationIndex>& CPISwap::fixedIndex() const { return fixedIndex_; }
213
214 inline const Leg& CPISwap::cpiLeg() const {//inflation indexed
215 return legs_[0];
216 }
217
218 inline const Leg& CPISwap::floatLeg() const {
219 return legs_[1];
220 }
221
222}
223
224#endif
225
calendar class
Arguments for swap calculation
Definition: cpiswap.hpp:167
void validate() const override
Definition: cpiswap.cpp:208
Results from swap calculation
Definition: cpiswap.hpp:177
void reset() override
Definition: cpiswap.cpp:212
zero-inflation-indexed swap,
Definition: cpiswap.hpp:66
ext::shared_ptr< IborIndex > floatIndex_
Definition: cpiswap.hpp:147
virtual Rate fixedRate() const
Definition: cpiswap.hpp:204
Real inflationNominal_
Definition: cpiswap.hpp:158
BusinessDayConvention fixedPaymentRoll_
Definition: cpiswap.hpp:154
virtual const DayCounter & fixedDayCount() const
Definition: cpiswap.hpp:206
Period observationLag_
Definition: cpiswap.hpp:156
virtual Rate fairRate() const
Definition: cpiswap.cpp:145
virtual const BusinessDayConvention & floatPaymentRoll() const
Definition: cpiswap.hpp:199
BusinessDayConvention floatPaymentRoll_
Definition: cpiswap.hpp:145
virtual Natural fixingDays() const
Definition: cpiswap.hpp:200
virtual const Leg & floatLeg() const
Definition: cpiswap.hpp:218
ext::shared_ptr< ZeroInflationIndex > fixedIndex_
Definition: cpiswap.hpp:155
virtual const Schedule & fixedSchedule() const
Definition: cpiswap.hpp:207
DayCounter fixedDayCount_
Definition: cpiswap.hpp:152
virtual const Schedule & floatSchedule() const
Definition: cpiswap.hpp:198
Spread fairSpread_
Definition: cpiswap.hpp:160
virtual CPI::InterpolationType observationInterpolation() const
Definition: cpiswap.hpp:211
DayCounter floatDayCount_
Definition: cpiswap.hpp:143
virtual Spread fairSpread() const
Definition: cpiswap.cpp:151
virtual const ext::shared_ptr< IborIndex > & floatIndex() const
Definition: cpiswap.hpp:201
virtual Real floatLegNPV() const
Definition: cpiswap.cpp:164
virtual Real inflationNominal() const
Definition: cpiswap.hpp:212
Natural fixingDays_
Definition: cpiswap.hpp:146
Schedule fixedSchedule_
Definition: cpiswap.hpp:153
virtual Type type() const
Definition: cpiswap.hpp:191
virtual Period observationLag() const
Definition: cpiswap.hpp:209
virtual const BusinessDayConvention & fixedPaymentRoll() const
Definition: cpiswap.hpp:208
virtual Real nominal() const
Definition: cpiswap.hpp:192
virtual const Leg & cpiLeg() const
Definition: cpiswap.hpp:214
void setupArguments(PricingEngine::arguments *args) const override
for simple case sufficient to copy base class
Definition: cpiswap.cpp:134
CPI::InterpolationType observationInterpolation_
Definition: cpiswap.hpp:157
virtual const ext::shared_ptr< ZeroInflationIndex > & fixedIndex() const
Definition: cpiswap.hpp:210
void setupExpired() const override
Definition: cpiswap.cpp:170
void fetchResults(const PricingEngine::results *) const override
Definition: cpiswap.cpp:177
virtual bool subtractInflationNominal() const
Definition: cpiswap.hpp:193
Schedule floatSchedule_
Definition: cpiswap.hpp:144
virtual const DayCounter & floatDayCount() const
Definition: cpiswap.hpp:197
bool subtractInflationNominal_
Definition: cpiswap.hpp:139
virtual Real baseCPI() const
Definition: cpiswap.hpp:205
virtual Real fixedLegNPV() const
Definition: cpiswap.cpp:158
virtual Spread spread() const
Definition: cpiswap.hpp:196
day counter class
Definition: daycounter.hpp:44
template base class for option pricing engines
template class providing a null value for a given type.
Definition: null.hpp:76
Payment schedule.
Definition: schedule.hpp:40
Interest rate swap.
Definition: swap.hpp:41
std::vector< Leg > legs_
Definition: swap.hpp:133
Coupon paying a zero-inflation index.
day counter class
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
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:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
date schedule
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ AsIndex
same interpolation as index
Interest rate swap.