Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.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 yoyinflationoptionletvolatilitystructure.hpp
21
    \brief yoy inflation volatility structures
22
 */
23
24
#ifndef quantlib_yoy_optionlet_volatility_structures_hpp
25
#define quantlib_yoy_optionlet_volatility_structures_hpp
26
27
#include <ql/termstructures/voltermstructure.hpp>
28
#include <ql/termstructures/volatility/volatilitytype.hpp>
29
#include <ql/math/interpolation.hpp>
30
#include <ql/time/calendars/target.hpp>
31
#include <ql/quote.hpp>
32
33
namespace QuantLib {
34
35
    /*! Abstract interface ... no data, only results.
36
37
        Basically used to change the BlackVariance() methods to
38
        totalVariance.  Also deal with lagged observations of an index
39
        with a (usually different) availability lag.
40
    */
41
    class YoYOptionletVolatilitySurface : public VolatilityTermStructure {
42
    public:
43
        //! \name Constructor
44
        //! calculate the reference date based on the global evaluation date
45
        YoYOptionletVolatilitySurface(Natural settlementDays,
46
                                      const Calendar&,
47
                                      BusinessDayConvention bdc,
48
                                      const DayCounter& dc,
49
                                      const Period& observationLag,
50
                                      Frequency frequency,
51
                                      bool indexIsInterpolated,
52
                                      VolatilityType volType = ShiftedLognormal,
53
                                      Real displacement = 0.0);
54
55
0
        ~YoYOptionletVolatilitySurface() override = default;
56
57
        //! \name Volatility (only)
58
        //@{
59
        //! Returns the volatility for a given maturity date and strike rate
60
        //! that observes inflation, by default, with the observation lag
61
        //! of the term structure.
62
        //! Because inflation is highly linked to dates (for interpolation, periods, etc)
63
        //! we do NOT provide a time version.
64
        Volatility volatility(const Date& maturityDate,
65
                              Rate strike,
66
                              const Period &obsLag = Period(-1,Days),
67
                              bool extrapolate = false) const;
68
        //! returns the volatility for a given option tenor and strike rate
69
        Volatility volatility(const Period& optionTenor,
70
                              Rate strike,
71
                              const Period &obsLag = Period(-1,Days),
72
                              bool extrapolate = false) const;
73
        /*! Returns the volatility for a given time and strike rate. No adjustments
74
          due to lags and interpolation are applied to the input time. */
75
        Volatility volatility(Time time, Rate strike) const;
76
77
        //! Returns the volatility type
78
0
        virtual VolatilityType volatilityType() const { return volType_; }
79
        //! Returns the displacement for lognormal volatilities
80
0
        virtual Real displacement() const { return displacement_; }
81
82
        //! Returns the total integrated variance for a given exercise date and strike rate.
83
        /*! Total integrated variance is useful because it scales out
84
         t for the optionlet pricing formulae.  Note that it is
85
         called "total" because the surface does not know whether
86
         it represents Black, Bachelier or Displaced Diffusion
87
         variance.  These are virtual so alternate connections
88
         between const vol and total var are possible.
89
90
         Because inflation is highly linked to dates (for interpolation, periods, etc)
91
         we do NOT provide a time version
92
         */
93
        virtual Volatility totalVariance(const Date& exerciseDate,
94
                                         Rate strike,
95
                                         const Period &obsLag = Period(-1,Days),
96
                                         bool extrapolate = false) const;
97
        //! returns the total integrated variance for a given option tenor and strike rate
98
        virtual Volatility totalVariance(const Period& optionTenor,
99
                                         Rate strike,
100
                                         const Period &obsLag = Period(-1,Days),
101
                                         bool extrapolate = false) const;
102
103
        //! The TS observes with a lag that is usually different from the
104
        //! availability lag of the index.  An inflation rate is given,
105
        //! by default, for the maturity requested assuming this lag.
106
0
        virtual Period observationLag() const { return observationLag_; }
107
0
        virtual Frequency frequency() const { return frequency_; }
108
0
        virtual bool indexIsInterpolated() const { return indexIsInterpolated_; }
109
        virtual Date baseDate() const;
110
        //! base date will be in the past because of observation lag
111
        virtual Time timeFromBase(const Date &date,
112
                                  const Period& obsLag = Period(-1,Days)) const;
113
        //@}
114
115
        //! \name Limits
116
        //@{
117
        //! the minimum strike for which the term structure can return vols
118
        Real minStrike() const override = 0;
119
        //! the maximum strike for which the term structure can return vols
120
        Real maxStrike() const override = 0;
121
        //@}
122
123
        // acts as zero time value for boostrapping
124
0
        virtual Volatility baseLevel() const {
125
0
            QL_REQUIRE(baseLevel_ != Null<Volatility>(),
126
0
                       "Base volatility, for baseDate(), not set.");
127
0
            return baseLevel_;
128
0
        }
129
130
    protected:
131
        virtual void checkRange(const Date &, Rate strike, bool extrapolate) const;
132
        virtual void checkRange(Time, Rate strike, bool extrapolate) const;
133
134
        //! Implements the actual volatility surface calculation in
135
        //! derived classes e.g. bilinear interpolation.  N.B. does
136
        //! not derive the surface.
137
        virtual Volatility volatilityImpl(Time length,
138
                                          Rate strike) const = 0;
139
140
        // acts as zero time value for boostrapping
141
0
        virtual void setBaseLevel(Volatility v) { baseLevel_ = v; }
142
        mutable Volatility baseLevel_;
143
144
        // so you do not need an index
145
        Period observationLag_;
146
        Frequency frequency_;
147
        bool indexIsInterpolated_;
148
        VolatilityType volType_;
149
        Real displacement_;
150
    };
151
152
153
    //! Constant surface, no K or T dependence.
154
    class ConstantYoYOptionletVolatility
155
    : public YoYOptionletVolatilitySurface {
156
    public:
157
        //! \name Constructors
158
        //@{
159
        //! calculate the reference date based on the global evaluation date
160
        ConstantYoYOptionletVolatility(Volatility v,
161
                                       Natural settlementDays,
162
                                       const Calendar&,
163
                                       BusinessDayConvention bdc,
164
                                       const DayCounter& dc,
165
                                       const Period& observationLag,
166
                                       Frequency frequency,
167
                                       bool indexIsInterpolated,
168
                                       Rate minStrike = -1.0,   // -100%
169
                                       Rate maxStrike = 100.0, // +10,000%
170
                                       VolatilityType volType = ShiftedLognormal,
171
                                       Real displacement = 0.0);
172
173
        // costructor taking a quote
174
        ConstantYoYOptionletVolatility(Handle<Quote> v,
175
                                       Natural settlementDays,
176
                                       const Calendar&,
177
                                       BusinessDayConvention bdc,
178
                                       const DayCounter& dc,
179
                                       const Period& observationLag,
180
                                       Frequency frequency,
181
                                       bool indexIsInterpolated,
182
                                       Rate minStrike = -1.0,  // -100%
183
                                       Rate maxStrike = 100.0, // +10,000%
184
                                       VolatilityType volType = ShiftedLognormal,
185
                                       Real displacement = 0.0);
186
        //@}
187
188
        //! \name Limits
189
        //@{
190
0
        Date maxDate() const override { return Date::maxDate(); }
191
        //! the minimum strike for which the term structure can return vols
192
0
        Real minStrike() const override { return minStrike_; }
193
        //! the maximum strike for which the term structure can return vols
194
0
        Real maxStrike() const override { return maxStrike_; }
195
        //@}
196
    protected:
197
        //! implements the actual volatility calculation in derived classes
198
      Volatility volatilityImpl(Time length, Rate strike) const override;
199
200
      Handle<Quote> volatility_;
201
      Rate minStrike_, maxStrike_;
202
    };
203
204
205
206
} // namespace QuantLib
207
208
#endif
209