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 <http://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/math/interpolation.hpp> 29 #include <ql/time/calendars/target.hpp> 30 31 namespace QuantLib { 32 33 /*! Abstract interface ... no data, only results. 34 35 Basically used to change the BlackVariance() methods to 36 totalVariance. Also deal with lagged observations of an index 37 with a (usually different) availability lag. 38 */ 39 class YoYOptionletVolatilitySurface : public VolatilityTermStructure { 40 public: 41 //! \name Constructor 42 //! calculate the reference date based on the global evaluation date 43 YoYOptionletVolatilitySurface(Natural settlementDays, 44 const Calendar&, 45 BusinessDayConvention bdc, 46 const DayCounter& dc, 47 const Period& observationLag, 48 Frequency frequency, 49 bool indexIsInterpolated); 50 ~YoYOptionletVolatilitySurface()51 virtual ~YoYOptionletVolatilitySurface() {} 52 53 //! \name Volatility (only) 54 //@{ 55 //! Returns the volatility for a given maturity date and strike rate 56 //! that observes inflation, by default, with the observation lag 57 //! of the term structure. 58 //! Because inflation is highly linked to dates (for interpolation, periods, etc) 59 //! we do NOT provide a time version. 60 Volatility volatility(const Date& maturityDate, 61 Rate strike, 62 const Period &obsLag = Period(-1,Days), 63 bool extrapolate = false) const; 64 //! returns the volatility for a given option tenor and strike rate 65 Volatility volatility(const Period& optionTenor, 66 Rate strike, 67 const Period &obsLag = Period(-1,Days), 68 bool extrapolate = false) const; 69 70 //! Returns the total integrated variance for a given exercise date and strike rate. 71 /*! Total integrated variance is useful because it scales out 72 t for the optionlet pricing formulae. Note that it is 73 called "total" because the surface does not know whether 74 it represents Black, Bachelier or Displaced Diffusion 75 variance. These are virtual so alternate connections 76 between const vol and total var are possible. 77 78 Because inflation is highly linked to dates (for interpolation, periods, etc) 79 we do NOT provide a time version 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 tenor and strike rate 86 virtual Volatility totalVariance(const Period& optionTenor, 87 Rate strike, 88 const Period &obsLag = Period(-1,Days), 89 bool extrapolate = false) const; 90 91 //! The TS observes with a lag that is usually different from the 92 //! availability lag of the index. An inflation rate is given, 93 //! by default, for the maturity requested assuming this lag. observationLag() const94 virtual Period observationLag() const { return observationLag_; } frequency() const95 virtual Frequency frequency() const { return frequency_; } indexIsInterpolated() const96 virtual bool indexIsInterpolated() const { return indexIsInterpolated_; } 97 virtual Date baseDate() const; 98 //! base date will be in the past because of observation lag 99 virtual Time timeFromBase(const Date &date, 100 const Period& obsLag = Period(-1,Days)) const; 101 //@} 102 103 //! \name Limits 104 //@{ 105 //! the minimum strike for which the term structure can return vols 106 virtual Real minStrike() const = 0; 107 //! the maximum strike for which the term structure can return vols 108 virtual Real maxStrike() const = 0; 109 //@} 110 111 // acts as zero time value for boostrapping baseLevel() const112 virtual Volatility baseLevel() const { 113 QL_REQUIRE(baseLevel_ != Null<Volatility>(), 114 "Base volatility, for baseDate(), not set."); 115 return baseLevel_; 116 } 117 118 protected: 119 virtual void checkRange(const Date &, Rate strike, bool extrapolate) const; 120 virtual void checkRange(Time, Rate strike, bool extrapolate) const; 121 122 //! Implements the actual volatility surface calculation in 123 //! derived classes e.g. bilinear interpolation. N.B. does 124 //! not derive the surface. 125 virtual Volatility volatilityImpl(Time length, 126 Rate strike) const = 0; 127 128 // acts as zero time value for boostrapping setBaseLevel(Volatility v)129 virtual void setBaseLevel(Volatility v) { baseLevel_ = v; } 130 mutable Volatility baseLevel_; 131 132 // so you do not need an index 133 Period observationLag_; 134 Frequency frequency_; 135 bool indexIsInterpolated_; 136 }; 137 138 139 //! Constant surface, no K or T dependence. 140 class ConstantYoYOptionletVolatility 141 : public YoYOptionletVolatilitySurface { 142 public: 143 //! \name Constructor 144 //@{ 145 //! calculate the reference date based on the global evaluation date 146 ConstantYoYOptionletVolatility(Volatility v, 147 Natural settlementDays, 148 const Calendar&, 149 BusinessDayConvention bdc, 150 const DayCounter& dc, 151 const Period& observationLag, 152 Frequency frequency, 153 bool indexIsInterpolated, 154 Rate minStrike = -1.0, // -100% 155 Rate maxStrike = 100.0); // +10,000% 156 //@} ~ConstantYoYOptionletVolatility()157 virtual ~ConstantYoYOptionletVolatility() {} 158 159 //! \name Limits 160 //@{ maxDate() const161 virtual Date maxDate() const { return Date::maxDate(); } 162 //! the minimum strike for which the term structure can return vols minStrike() const163 virtual Real minStrike() const { return minStrike_; } 164 //! the maximum strike for which the term structure can return vols maxStrike() const165 virtual Real maxStrike() const { return maxStrike_; } 166 //@} 167 168 protected: 169 //! implements the actual volatility calculation in derived classes 170 virtual Volatility volatilityImpl(Time length, Rate strike) const; 171 172 Volatility volatility_; 173 Rate minStrike_, maxStrike_; 174 }; 175 176 177 178 } // namespace QuantLib 179 180 #endif 181 182