/src/quantlib/ql/termstructures/volatility/inflation/cpivolatilitystructure.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009, 2011 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 cpivolatilitystructure.hpp |
21 | | \brief zero inflation (i.e. CPI/RPI/HICP/etc.) volatility structures |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_cpi_volatility_structure_hpp |
25 | | #define quantlib_cpi_volatility_structure_hpp |
26 | | |
27 | | #include <ql/termstructures/voltermstructure.hpp> |
28 | | |
29 | | namespace QuantLib { |
30 | | |
31 | | //! zero inflation (i.e. CPI/RPI/HICP/etc.) volatility structures |
32 | | /*! Abstract interface. CPI volatility is always with respect to |
33 | | some base date. Also deal with lagged observations of an index |
34 | | with a (usually different) availability lag. |
35 | | */ |
36 | | class CPIVolatilitySurface : public VolatilityTermStructure { |
37 | | public: |
38 | | /*! calculates the reference date based on the global |
39 | | evaluation date. |
40 | | */ |
41 | | CPIVolatilitySurface(Natural settlementDays, |
42 | | const Calendar&, |
43 | | BusinessDayConvention bdc, |
44 | | const DayCounter& dc, |
45 | | const Period& observationLag, |
46 | | Frequency frequency, |
47 | | bool indexIsInterpolated); |
48 | | |
49 | | //! \name Volatility |
50 | | /*! by default, inflation is observed with the lag |
51 | | of the term structure. |
52 | | |
53 | | Because inflation is highly linked to dates (for |
54 | | interpolation, periods, etc) time-based overload of the |
55 | | methods are not provided. |
56 | | */ |
57 | | //@{ |
58 | | //! Returns the volatility for a given maturity date and strike rate. |
59 | | Volatility volatility(const Date& maturityDate, |
60 | | Rate strike, |
61 | | const Period &obsLag = Period(-1,Days), |
62 | | bool extrapolate = false) const; |
63 | | //! returns the volatility for a given option tenor and strike rate |
64 | | Volatility volatility(const Period& optionTenor, |
65 | | Rate strike, |
66 | | const Period &obsLag = Period(-1,Days), |
67 | | bool extrapolate = false) const; |
68 | | /*! Returns the volatility for a given time and strike rate. No adjustments |
69 | | due to lags and interpolation are applied to the input time. */ |
70 | | Volatility volatility(Time time, Rate strike) const; |
71 | | |
72 | | //! Returns the total integrated variance for a given exercise |
73 | | //! date and strike rate. |
74 | | /*! Total integrated variance is useful because it scales out |
75 | | t for the optionlet pricing formulae. Note that it is |
76 | | called "total" because the surface does not know whether |
77 | | it represents Black, Bachelier or Displaced Diffusion |
78 | | variance. These are virtual so alternate connections |
79 | | between const vol and total var are possible. |
80 | | */ |
81 | | virtual Volatility totalVariance(const Date& exerciseDate, |
82 | | Rate strike, |
83 | | const Period &obsLag = Period(-1,Days), |
84 | | bool extrapolate = false) const; |
85 | | //! returns the total integrated variance for a given option |
86 | | //! tenor and strike rate. |
87 | | virtual Volatility totalVariance(const Period& optionTenor, |
88 | | Rate strike, |
89 | | const Period &obsLag = Period(-1,Days), |
90 | | bool extrapolate = false) const; |
91 | | //@} |
92 | | |
93 | | //! \name Inspectors |
94 | | //@{ |
95 | | /*! The term structure observes with a lag that is usually |
96 | | different from the availability lag of the index. An |
97 | | inflation rate is given, by default, for the maturity |
98 | | requested assuming this lag. |
99 | | */ |
100 | 0 | virtual Period observationLag() const { return observationLag_; } |
101 | 0 | virtual Frequency frequency() const { return frequency_; } |
102 | 0 | virtual bool indexIsInterpolated() const { |
103 | 0 | return indexIsInterpolated_; |
104 | 0 | } |
105 | | virtual Date baseDate() const; |
106 | | //! base date will be in the past because of observation lag |
107 | | virtual Time timeFromBase(const Date &date, |
108 | | const Period& obsLag = Period(-1,Days)) const; |
109 | | // acts as zero time value for boostrapping |
110 | 0 | virtual Volatility baseLevel() const { |
111 | 0 | QL_REQUIRE(baseLevel_ != Null<Volatility>(), |
112 | 0 | "Base volatility, for baseDate(), not set."); |
113 | 0 | return baseLevel_; |
114 | 0 | } |
115 | | //@} |
116 | | |
117 | | //! \name Limits |
118 | | //@{ |
119 | | //! the minimum strike for which the term structure can return vols |
120 | | Real minStrike() const override = 0; |
121 | | //! the maximum strike for which the term structure can return vols |
122 | | Real maxStrike() const override = 0; |
123 | | //@} |
124 | | protected: |
125 | | virtual void checkRange(const Date&, Rate strike, bool extrapolate) const; |
126 | | virtual void checkRange(Time, Rate strike, bool extrapolate) const; |
127 | | |
128 | | /*! Implements the actual volatility surface calculation in |
129 | | derived classes e.g. bilinear interpolation. N.B. does |
130 | | not derive the surface. |
131 | | */ |
132 | | virtual Volatility volatilityImpl(Time length, |
133 | | Rate strike) const = 0; |
134 | | |
135 | | mutable Volatility baseLevel_; |
136 | | // so you do not need an index |
137 | | Period observationLag_; |
138 | | Frequency frequency_; |
139 | | bool indexIsInterpolated_; |
140 | | }; |
141 | | |
142 | | } |
143 | | |
144 | | #endif |
145 | | |