/src/quantlib/ql/cashflows/inflationcouponpricer.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009 Chris Kenyon |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | /*! \file inflationcouponpricer.hpp |
21 | | \brief inflation-coupon pricers |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_inflation_coupon_pricer_hpp |
25 | | #define quantlib_inflation_coupon_pricer_hpp |
26 | | |
27 | | #include <ql/cashflow.hpp> |
28 | | #include <ql/option.hpp> |
29 | | #include <ql/cashflows/yoyinflationcoupon.hpp> |
30 | | #include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | //! Base inflation-coupon pricer. |
35 | | /*! The main reason we can't use FloatingRateCouponPricer as the |
36 | | base is that it takes a FloatingRateCoupon which takes an |
37 | | InterestRateIndex and we need an inflation index (these are |
38 | | lagged). |
39 | | |
40 | | The basic inflation-specific thing that the pricer has to do |
41 | | is deal with different lags in the index and the option |
42 | | e.g. the option could look 3 months back and the index 2. |
43 | | |
44 | | We add the requirement that pricers do inverseCap/Floor-lets. |
45 | | These are cap/floor-lets as usually defined, i.e. pay out if |
46 | | underlying is above/below a strike. The non-inverse (usual) |
47 | | versions are from a coupon point of view (a capped coupon has |
48 | | a maximum at the strike). |
49 | | |
50 | | We add the inverse prices so that conventional caps can be |
51 | | priced simply. |
52 | | */ |
53 | | class InflationCouponPricer: public virtual Observer, |
54 | | public virtual Observable { |
55 | | public: |
56 | | QL_DEPRECATED_DISABLE_WARNING |
57 | 0 | InflationCouponPricer() = default; |
58 | 0 | ~InflationCouponPricer() override = default; |
59 | | QL_DEPRECATED_ENABLE_WARNING |
60 | | //! \name Interface |
61 | | //@{ |
62 | | virtual Real swapletPrice() const = 0; |
63 | | virtual Rate swapletRate() const = 0; |
64 | | virtual Real capletPrice(Rate effectiveCap) const = 0; |
65 | | virtual Rate capletRate(Rate effectiveCap) const = 0; |
66 | | virtual Real floorletPrice(Rate effectiveFloor) const = 0; |
67 | | virtual Rate floorletRate(Rate effectiveFloor) const = 0; |
68 | | virtual void initialize(const InflationCoupon&) = 0; |
69 | | //@} |
70 | | |
71 | | //! \name Observer interface |
72 | | //@{ |
73 | 0 | void update() override { notifyObservers(); } |
74 | | //@} |
75 | | protected: |
76 | | Date paymentDate_; |
77 | | }; |
78 | | |
79 | | |
80 | | void setCouponPricer(const Leg& leg, |
81 | | const ext::shared_ptr<InflationCouponPricer>&); |
82 | | |
83 | | |
84 | | //! base pricer for capped/floored YoY inflation coupons |
85 | | /*! \note this pricer can already do swaplets but to get |
86 | | volatility-dependent coupons you need the descendents. |
87 | | */ |
88 | | class YoYInflationCouponPricer : public InflationCouponPricer { |
89 | | public: |
90 | 0 | YoYInflationCouponPricer() = default; |
91 | | |
92 | | explicit YoYInflationCouponPricer(Handle<YieldTermStructure> nominalTermStructure); |
93 | | |
94 | | YoYInflationCouponPricer(Handle<YoYOptionletVolatilitySurface> capletVol, |
95 | | Handle<YieldTermStructure> nominalTermStructure); |
96 | | |
97 | 0 | virtual Handle<YoYOptionletVolatilitySurface> capletVolatility() const{ |
98 | 0 | return capletVol_; |
99 | 0 | } |
100 | | |
101 | 0 | virtual Handle<YieldTermStructure> nominalTermStructure() const{ |
102 | 0 | return nominalTermStructure_; |
103 | 0 | } |
104 | | |
105 | | virtual void setCapletVolatility( |
106 | | const Handle<YoYOptionletVolatilitySurface>& capletVol); |
107 | | |
108 | | //! \name InflationCouponPricer interface |
109 | | //@{ |
110 | | Real swapletPrice() const override; |
111 | | Rate swapletRate() const override; |
112 | | Real capletPrice(Rate effectiveCap) const override; |
113 | | Rate capletRate(Rate effectiveCap) const override; |
114 | | Real floorletPrice(Rate effectiveFloor) const override; |
115 | | Rate floorletRate(Rate effectiveFloor) const override; |
116 | | void initialize(const InflationCoupon&) override; |
117 | | //@} |
118 | | |
119 | | protected: |
120 | | virtual Real optionletPrice(Option::Type optionType, |
121 | | Real effStrike) const; |
122 | | virtual Real optionletRate(Option::Type optionType, |
123 | | Real effStrike) const; |
124 | | |
125 | | /*! Derived classes usually only need to implement this. |
126 | | |
127 | | The name of the method is misleading. This actually |
128 | | returns the rate of the optionlet (so not discounted and |
129 | | not accrued). |
130 | | */ |
131 | | virtual Real optionletPriceImp(Option::Type, Real strike, |
132 | | Real forward, Real stdDev) const; |
133 | | virtual Rate adjustedFixing(Rate fixing = Null<Rate>()) const; |
134 | | |
135 | | //! data |
136 | | Handle<YoYOptionletVolatilitySurface> capletVol_; |
137 | | Handle<YieldTermStructure> nominalTermStructure_; |
138 | | const YoYInflationCoupon* coupon_; |
139 | | Real gearing_; |
140 | | Spread spread_; |
141 | | Real discount_; |
142 | | }; |
143 | | |
144 | | |
145 | | //! Black-formula pricer for capped/floored yoy inflation coupons |
146 | | class BlackYoYInflationCouponPricer : public YoYInflationCouponPricer { |
147 | | public: |
148 | | BlackYoYInflationCouponPricer() |
149 | | : YoYInflationCouponPricer(Handle<YoYOptionletVolatilitySurface>(), |
150 | 0 | Handle<YieldTermStructure>()) {} |
151 | | |
152 | | explicit BlackYoYInflationCouponPricer( |
153 | | const Handle<YieldTermStructure>& nominalTermStructure) |
154 | 0 | : YoYInflationCouponPricer(nominalTermStructure) {} |
155 | | |
156 | | BlackYoYInflationCouponPricer( |
157 | | const Handle<YoYOptionletVolatilitySurface>& capletVol, |
158 | | const Handle<YieldTermStructure>& nominalTermStructure) |
159 | 0 | : YoYInflationCouponPricer(capletVol, nominalTermStructure) {} |
160 | | protected: |
161 | | Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override; |
162 | | }; |
163 | | |
164 | | |
165 | | //! Unit-Displaced-Black-formula pricer for capped/floored yoy inflation coupons |
166 | | class UnitDisplacedBlackYoYInflationCouponPricer : public YoYInflationCouponPricer { |
167 | | public: |
168 | | UnitDisplacedBlackYoYInflationCouponPricer() |
169 | | : YoYInflationCouponPricer(Handle<YoYOptionletVolatilitySurface>(), |
170 | 0 | Handle<YieldTermStructure>()) {} |
171 | | |
172 | | explicit UnitDisplacedBlackYoYInflationCouponPricer( |
173 | | const Handle<YieldTermStructure>& nominalTermStructure) |
174 | 0 | : YoYInflationCouponPricer(nominalTermStructure) {} |
175 | | |
176 | | UnitDisplacedBlackYoYInflationCouponPricer( |
177 | | const Handle<YoYOptionletVolatilitySurface>& capletVol, |
178 | | const Handle<YieldTermStructure>& nominalTermStructure) |
179 | 0 | : YoYInflationCouponPricer(capletVol, nominalTermStructure) {} |
180 | | protected: |
181 | | Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override; |
182 | | }; |
183 | | |
184 | | |
185 | | //! Bachelier-formula pricer for capped/floored yoy inflation coupons |
186 | | class BachelierYoYInflationCouponPricer : public YoYInflationCouponPricer { |
187 | | public: |
188 | | BachelierYoYInflationCouponPricer() |
189 | | : YoYInflationCouponPricer(Handle<YoYOptionletVolatilitySurface>(), |
190 | 0 | Handle<YieldTermStructure>()) {} |
191 | | |
192 | | explicit BachelierYoYInflationCouponPricer( |
193 | | const Handle<YieldTermStructure>& nominalTermStructure) |
194 | 0 | : YoYInflationCouponPricer(nominalTermStructure) {} |
195 | | |
196 | | BachelierYoYInflationCouponPricer( |
197 | | const Handle<YoYOptionletVolatilitySurface>& capletVol, |
198 | | const Handle<YieldTermStructure>& nominalTermStructure) |
199 | 0 | : YoYInflationCouponPricer(capletVol, nominalTermStructure) {} |
200 | | protected: |
201 | | Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override; |
202 | | }; |
203 | | |
204 | | } |
205 | | |
206 | | |
207 | | #endif |
208 | | |
209 | | |