/src/quantlib/ql/instruments/zerocouponinflationswap.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2007, 2009 Chris Kenyon |
5 | | Copyright (C) 2009 StatPro Italia srl |
6 | | Copyright (C) 2021 Ralf Konrad Eckel |
7 | | |
8 | | This file is part of QuantLib, a free-software/open-source library |
9 | | for financial quantitative analysts and developers - http://quantlib.org/ |
10 | | |
11 | | QuantLib is free software: you can redistribute it and/or modify it |
12 | | under the terms of the QuantLib license. You should have received a |
13 | | copy of the license along with this program; if not, please email |
14 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
15 | | <http://quantlib.org/license.shtml>. |
16 | | |
17 | | This program is distributed in the hope that it will be useful, but WITHOUT |
18 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
20 | | */ |
21 | | |
22 | | /*! \file zerocouponinflationswap.hpp |
23 | | \brief Zero-coupon inflation-indexed swap |
24 | | */ |
25 | | |
26 | | #ifndef quantlib_xxxzciis_hpp |
27 | | #define quantlib_xxxzciis_hpp |
28 | | |
29 | | #include <ql/indexes/inflationindex.hpp> |
30 | | #include <ql/instruments/swap.hpp> |
31 | | #include <ql/time/calendar.hpp> |
32 | | #include <ql/time/daycounter.hpp> |
33 | | |
34 | | |
35 | | namespace QuantLib { |
36 | | //! Zero-coupon inflation-indexed swap |
37 | | /*! Quoted as a fixed rate \f$ K \f$. At start: |
38 | | \f[ |
39 | | P_n(0,T) N [(1+K)^{T}-1] = |
40 | | P_n(0,T) N \left[ \frac{I(T)}{I(0)} -1 \right] |
41 | | \f] |
42 | | where \f$ T \f$ is the maturity time, \f$ P_n(0,t) \f$ is the |
43 | | nominal discount factor at time \f$ t \f$, \f$ N \f$ is the |
44 | | notional, and \f$ I(t) \f$ is the inflation index value at |
45 | | time \f$ t \f$. |
46 | | |
47 | | This inherits from swap and has two very simple legs: a fixed |
48 | | leg, from the quote (K); and an indexed leg. At maturity the |
49 | | two single cashflows are swapped. These are the notional |
50 | | versus the inflation-indexed notional Because the coupons are |
51 | | zero there are no accruals (and no coupons). |
52 | | |
53 | | In this swap, the passed type (Payer or Receiver) refers to |
54 | | the inflation leg. |
55 | | |
56 | | Inflation is generally available on every day, including |
57 | | holidays and weekends. Hence there is a variable to state |
58 | | whether the observe/fix dates for inflation are adjusted or |
59 | | not. The default is not to adjust. |
60 | | |
61 | | A zero inflation swap is a simple enough instrument that the |
62 | | standard discounting pricing engine that works for a vanilla |
63 | | swap also works. |
64 | | |
65 | | \note we do not need Schedules on the legs because they use |
66 | | one or two dates only per leg. |
67 | | */ |
68 | | class ZeroCouponInflationSwap : public Swap { |
69 | | public: |
70 | | class arguments; |
71 | | class engine; |
72 | | |
73 | | ZeroCouponInflationSwap(Type type, |
74 | | Real nominal, |
75 | | const Date& startDate, // start date of contract (only) |
76 | | const Date& maturity, // this is pre-adjustment! |
77 | | Calendar fixCalendar, |
78 | | BusinessDayConvention fixConvention, |
79 | | DayCounter dayCounter, |
80 | | Rate fixedRate, |
81 | | const ext::shared_ptr<ZeroInflationIndex>& infIndex, |
82 | | const Period& observationLag, |
83 | | CPI::InterpolationType observationInterpolation, |
84 | | bool adjustInfObsDates = false, |
85 | | Calendar infCalendar = Calendar(), |
86 | | BusinessDayConvention infConvention = BusinessDayConvention()); |
87 | | |
88 | | //! \name Inspectors |
89 | | //@{ |
90 | | //! "Payer" or "Receiver" refers to the inflation leg |
91 | 0 | Type type() const { return type_; } |
92 | 0 | Real nominal() const { return nominal_; } |
93 | 0 | Date startDate() const override { return startDate_; } |
94 | 0 | Date maturityDate() const override { return maturityDate_; } |
95 | 0 | Calendar fixedCalendar() const { return fixCalendar_; } |
96 | 0 | BusinessDayConvention fixedConvention() const { |
97 | 0 | return fixConvention_; |
98 | 0 | } |
99 | 0 | DayCounter dayCounter() const { return dayCounter_; } |
100 | | //! \f$ K \f$ in the above formula. |
101 | 0 | Rate fixedRate() const { return fixedRate_; } |
102 | 0 | ext::shared_ptr<ZeroInflationIndex> inflationIndex() const { |
103 | 0 | return infIndex_; |
104 | 0 | } |
105 | 0 | Period observationLag() const { return observationLag_; } |
106 | 0 | CPI::InterpolationType observationInterpolation() const { |
107 | 0 | return observationInterpolation_; |
108 | 0 | } |
109 | 0 | bool adjustObservationDates() const { return adjustInfObsDates_; } |
110 | 0 | Calendar inflationCalendar() const { return infCalendar_; } |
111 | 0 | BusinessDayConvention inflationConvention() const { |
112 | 0 | return infConvention_; |
113 | 0 | } |
114 | | //! just one cashflow (that is not a coupon) in each leg |
115 | | const Leg& fixedLeg() const; |
116 | | //! just one cashflow (that is not a coupon) in each leg |
117 | | const Leg& inflationLeg() const; |
118 | | //@} |
119 | | |
120 | | //! \name Results |
121 | | //@{ |
122 | | Real fixedLegNPV() const; |
123 | | Real inflationLegNPV() const; |
124 | | Real fairRate() const; |
125 | | //@} |
126 | | |
127 | | protected: |
128 | | Type type_; |
129 | | Real nominal_; |
130 | | Date startDate_, maturityDate_; |
131 | | Calendar fixCalendar_; |
132 | | BusinessDayConvention fixConvention_; |
133 | | Rate fixedRate_; |
134 | | ext::shared_ptr<ZeroInflationIndex> infIndex_; |
135 | | Period observationLag_; |
136 | | CPI::InterpolationType observationInterpolation_; |
137 | | bool adjustInfObsDates_; |
138 | | Calendar infCalendar_; |
139 | | BusinessDayConvention infConvention_; |
140 | | DayCounter dayCounter_; |
141 | | Date baseDate_, obsDate_; |
142 | | }; |
143 | | |
144 | | |
145 | | class ZeroCouponInflationSwap::arguments : public Swap::arguments { |
146 | | public: |
147 | | Rate fixedRate; |
148 | | }; |
149 | | |
150 | | |
151 | | class ZeroCouponInflationSwap::engine |
152 | | : public GenericEngine<ZeroCouponInflationSwap::arguments, |
153 | | ZeroCouponInflationSwap::results> {}; |
154 | | |
155 | | } |
156 | | |
157 | | |
158 | | #endif |