Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
StrippedCPIVolatilitySurface< Interpolator2D > Class Template Reference

Stripped zero inflation volatility structure. More...

#include <qle/termstructures/strippedcpivolatilitystructure.hpp>

+ Inheritance diagram for StrippedCPIVolatilitySurface< Interpolator2D >:
+ Collaboration diagram for StrippedCPIVolatilitySurface< Interpolator2D >:

Classes

class  ObjectiveFunction
 

Public Member Functions

QL_DEPRECATED StrippedCPIVolatilitySurface (PriceQuotePreference type, const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &priceSurface, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &zeroIndex, const QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > &engine, const QuantLib::Date &capFloorStartDate=Date(), const QuantLib::Real &upperVolBound=StrippedCPIVolSurfaceDefaultValues::upperVolBound, const QuantLib::Real &lowerVolBound=StrippedCPIVolSurfaceDefaultValues::lowerVolBound, const QuantLib::Real &solverTolerance=StrippedCPIVolSurfaceDefaultValues::solverTolerance, const Interpolator2D &interpolator2d=Interpolator2D(), const QuantLib::VolatilityType &volType=QuantLib::ShiftedLognormal, const double displacement=0.0)
 
 StrippedCPIVolatilitySurface (PriceQuotePreference type, const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &priceSurface, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &zeroIndex, const bool quotedPricesUseInterpolatedCPIFixings, const QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > &engine, const QuantLib::Date &capFloorStartDate=Date(), const QuantLib::Real &upperVolBound=StrippedCPIVolSurfaceDefaultValues::upperVolBound, const QuantLib::Real &lowerVolBound=StrippedCPIVolSurfaceDefaultValues::lowerVolBound, const QuantLib::Real &solverTolerance=StrippedCPIVolSurfaceDefaultValues::solverTolerance, const Interpolator2D &interpolator2d=Interpolator2D(), const QuantLib::VolatilityType &volType=QuantLib::ShiftedLognormal, const double displacement=0.0)
 
LazyObject interface
void performCalculations () const
 
Limits
QuantLib::Real minStrike () const override
 the minimum strike for which the term structure can return vols More...
 
QuantLib::Real maxStrike () const override
 the maximum strike for which the term structure can return vols More...
 
QuantLib::Date maxDate () const override
 maximum date for which the term structure can return vols More...
 
- Public Member Functions inherited from CPIVolatilitySurface
 CPIVolatilitySurface (QuantLib::Natural settlementDays, const QuantLib::Calendar &, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const QuantLib::Period &observationLag, QuantLib::Frequency frequency, bool indexIsInterpolated, const QuantLib::Date &capFloorStartDate=QuantLib::Date(), QuantLib::VolatilityType volType=QuantLib::ShiftedLognormal, double displacement=0.0)
 
QuantLib::Date optionDateFromTenor (const QuantLib::Period &tenor) const override
 Computes the expiry date from the capFloorStartDate() More...
 
QuantLib::Date baseDate () const override
 base date will be in the past More...
 
QuantLib::VolatilityType volatilityType () const
 Returns the volatility type. More...
 
double displacement () const
 Returns the displacement for lognormal volatilities. More...
 
bool isLogNormal () const
 
QuantLib::Volatility volatility (const QuantLib::Date &maturityDate, QuantLib::Rate strike, const QuantLib::Period &obsLag=QuantLib::Period(-1, QuantLib::Days), bool extrapolate=false) const override
 
virtual QuantLib::Real atmStrike (const QuantLib::Date &maturity, const QuantLib::Period &obsLag=QuantLib::Period(-1, QuantLib::Days)) const =0
 
QuantLib::Date capFloorStartDate () const
 

Inspectors

PriceQuotePreference preference_
 
QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > priceSurface_
 
QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > index_
 
QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngineengine_
 
QuantLib::Real upperVolBound_
 
QuantLib::Real lowerVolBound_
 
QuantLib::Real solverTolerance_
 
std::vector< QuantLib::Rate > strikes_
 
std::vector< QuantLib::Period > maturities_
 
std::vector< QuantLib::Time > maturityTimes_
 
QuantLib::Matrix volData_
 
Interpolator2D interpolator2d_
 
QuantLib::Interpolation2D vols_
 
bool computeTimeToExpiryFromLastAvailableFixingDate_
 
const std::vector< QuantLib::Real > & strikes ()
 
const std::vector< QuantLib::Period > & maturities ()
 
const QuantLib::Matrix & volData ()
 
QuantLib::Real atmStrike (const QuantLib::Date &maturity, const QuantLib::Period &obsLag=QuantLib::Period(-1, QuantLib::Days)) const override
 
QuantLib::Volatility volatilityImpl (QuantLib::Time length, QuantLib::Rate strike) const override
 
bool chooseFloor (QuantLib::Real strike, QuantLib::Real atmRate) const
 

Additional Inherited Members

- Protected Member Functions inherited from CPIVolatilitySurface
virtual double fixingTime (const QuantLib::Date &maturityDate) const
 Computes the expiry time from the capFloorStartDate() More...
 
- Protected Attributes inherited from CPIVolatilitySurface
QuantLib::VolatilityType volType_
 
double displacement_
 

Detailed Description

template<class Interpolator2D>
class QuantExt::StrippedCPIVolatilitySurface< Interpolator2D >

Stripped zero inflation volatility structure.

The surface provides implied CPI Black volatilities for the union of strikes that occur in the underlying cap and floor price surface.

The type argument determines which kind of price quotes are used with priority when there is an overlap, i.e. strikes for which we have both cap and floor quotes: If type is Cap: Use cap quotes where available, floor quotes otherwise If type is Floor: Use floor quotes where available, cap quotes otherwise If type is CapFloor: In case of overlap, use floor quotes up to the ATM strike, cap quotes for strikes beyond ATM

Definition at line 60 of file strippedcpivolatilitystructure.hpp.

Constructor & Destructor Documentation

◆ StrippedCPIVolatilitySurface() [1/2]

QL_DEPRECATED_DISABLE_WARNING StrippedCPIVolatilitySurface ( PriceQuotePreference  type,
const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &  priceSurface,
const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &  zeroIndex,
const QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > &  engine,
const QuantLib::Date &  capFloorStartDate = Date(),
const QuantLib::Real &  upperVolBound = StrippedCPIVolSurfaceDefaultValues::upperVolBound,
const QuantLib::Real &  lowerVolBound = StrippedCPIVolSurfaceDefaultValues::lowerVolBound,
const QuantLib::Real &  solverTolerance = StrippedCPIVolSurfaceDefaultValues::solverTolerance,
const Interpolator2D &  interpolator2d = Interpolator2D(),
const QuantLib::VolatilityType &  volType = QuantLib::ShiftedLognormal,
const double  displacement = 0.0 
)

Definition at line 182 of file strippedcpivolatilitystructure.hpp.

190 type, priceSurface, index, index->interpolated(), engine, capFloorStartDate, upperVolBound, lowerVolBound,
191 solverTolerance, interpolator2d, volType, displacement) {}
double displacement() const
Returns the displacement for lognormal volatilities.
QuantLib::Date capFloorStartDate() const
QL_DEPRECATED StrippedCPIVolatilitySurface(PriceQuotePreference type, const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &priceSurface, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &zeroIndex, const QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > &engine, const QuantLib::Date &capFloorStartDate=Date(), const QuantLib::Real &upperVolBound=StrippedCPIVolSurfaceDefaultValues::upperVolBound, const QuantLib::Real &lowerVolBound=StrippedCPIVolSurfaceDefaultValues::lowerVolBound, const QuantLib::Real &solverTolerance=StrippedCPIVolSurfaceDefaultValues::solverTolerance, const Interpolator2D &interpolator2d=Interpolator2D(), const QuantLib::VolatilityType &volType=QuantLib::ShiftedLognormal, const double displacement=0.0)

◆ StrippedCPIVolatilitySurface() [2/2]

StrippedCPIVolatilitySurface ( PriceQuotePreference  type,
const QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > &  priceSurface,
const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &  zeroIndex,
const bool  quotedPricesUseInterpolatedCPIFixings,
const QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > &  engine,
const QuantLib::Date &  capFloorStartDate = Date(),
const QuantLib::Real &  upperVolBound = StrippedCPIVolSurfaceDefaultValues::upperVolBound,
const QuantLib::Real &  lowerVolBound = StrippedCPIVolSurfaceDefaultValues::lowerVolBound,
const QuantLib::Real &  solverTolerance = StrippedCPIVolSurfaceDefaultValues::solverTolerance,
const Interpolator2D &  interpolator2d = Interpolator2D(),
const QuantLib::VolatilityType &  volType = QuantLib::ShiftedLognormal,
const double  displacement = 0.0 
)

Definition at line 161 of file strippedcpivolatilitystructure.hpp.

169 : QuantExt::CPIVolatilitySurface(priceSurface->settlementDays(), priceSurface->calendar(),
170 priceSurface->businessDayConvention(), priceSurface->dayCounter(),
171 priceSurface->observationLag(), index->frequency(),
172 quotedPriceUseInterpolatedCPIFixing,
174 preference_(type), priceSurface_(priceSurface), index_(index), engine_(engine), upperVolBound_(upperVolBound),
175 lowerVolBound_(lowerVolBound), solverTolerance_(solverTolerance), interpolator2d_(interpolator2d) {
176
178}
QuantLib::Handle< QuantLib::CPICapFloorTermPriceSurface > priceSurface_
QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > index_
QuantLib::ext::shared_ptr< QuantExt::CPICapFloorEngine > engine_
+ Here is the call graph for this function:

Member Function Documentation

◆ performCalculations()

QL_DEPRECATED_ENABLE_WARNING void performCalculations

Definition at line 194 of file strippedcpivolatilitystructure.hpp.

194 {
195 strikes_ = priceSurface_->strikes();
196 maturities_ = priceSurface_->maturities();
197 volData_ = QuantLib::Matrix(strikes_.size(), maturities_.size(), QuantLib::Null<QuantLib::Real>());
198 QuantLib::Brent solver;
199 QuantLib::Real guess = (upperVolBound_ + lowerVolBound_) / 2.0;
200 QuantLib::Date startDate = capFloorStartDate();
201 QuantLib::Date underlyingBaseDate =
202 ZeroInflation::fixingDate(startDate, observationLag(), frequency(), indexIsInterpolated());
203 double baseCPI = ZeroInflation::cpiFixing(index_, startDate, observationLag(), indexIsInterpolated());
204 for (QuantLib::Size i = 0; i < strikes_.size(); i++) {
205 for (QuantLib::Size j = 0; j < maturities_.size(); j++) {
206
207 QuantLib::Date maturityDate = optionDateFromTenor(maturities_[j]);
208 QuantLib::Date fixDate =
209 ZeroInflation::fixingDate(maturityDate, observationLag(), frequency(), indexIsInterpolated());
210 Rate I1 = ZeroInflation::cpiFixing(index_, maturityDate, observationLag(), indexIsInterpolated());
211
212 Time timeToMaturity = dayCounter().yearFraction(underlyingBaseDate, fixDate);
213 QuantLib::Real atmRate = std::pow(I1 / baseCPI, 1 / timeToMaturity) - 1.0;
214
215 bool useFloor = chooseFloor(strikes_[i], atmRate);
216
217 // FIXME: Do we need an effective maturity here ?
218 QuantLib::Real priceToMatch = useFloor ? priceSurface_->floorPrice(maturities_[j], strikes_[i])
219 : priceSurface_->capPrice(maturities_[j], strikes_[i]);
220 try {
221 auto interpolationType =
222 indexIsInterpolated() ? CPI::InterpolationType::Linear : CPI::InterpolationType::Flat;
223 ObjectiveFunction func(priceToMatch, useFloor, strikes_[i], startDate, maturityDate, baseCPI,
224 priceSurface_, index_, engine_, interpolationType);
225 QuantLib::Real found = solver.solve(func, solverTolerance_, guess, lowerVolBound_, upperVolBound_);
226 volData_[i][j] = found;
227 } catch (std::exception& e) {
228 QL_FAIL("failed to find implied vol for "
229 << (useFloor ? "Floor" : "Cap") << " with strike " << strikes_[i] << " and maturity "
230 << maturities_[j] << ", because: " << e.what() << " "
231 << QuantLib::io::iso_date(startDate + maturities_[j]) << " " << maturityDate);
232 }
233 }
234 }
235
236 maturityTimes_.clear();
237 for (QuantLib::Size i = 0; i < maturities_.size(); i++) {
238 QuantLib::Date d = optionDateFromTenor(maturities_[i]);
239 maturityTimes_.push_back(fixingTime(d));
240 }
241
242 vols_ = interpolator2d_.interpolate(maturityTimes_.begin(), maturityTimes_.end(), strikes_.begin(), strikes_.end(),
243 volData_);
244 vols_.enableExtrapolation();
245}
virtual double fixingTime(const QuantLib::Date &maturityDate) const
Computes the expiry time from the capFloorStartDate()
QuantLib::Date optionDateFromTenor(const QuantLib::Period &tenor) const override
Computes the expiry date from the capFloorStartDate()
bool chooseFloor(QuantLib::Real strike, QuantLib::Real atmRate) const
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Definition: inflation.cpp:183
QuantLib::Rate cpiFixing(const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index, const QuantLib::Date &maturity, const QuantLib::Period &obsLag, bool interpolated)
Computes a CPI fixing giving an zeroIndex, with interpolation if needed.
Definition: inflation.cpp:166
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minStrike()

QuantLib::Real minStrike
override

the minimum strike for which the term structure can return vols

Definition at line 295 of file strippedcpivolatilitystructure.hpp.

295 {
296 return strikes_.front() - QL_EPSILON;
297}

◆ maxStrike()

QuantLib::Real maxStrike
override

the maximum strike for which the term structure can return vols

Definition at line 299 of file strippedcpivolatilitystructure.hpp.

299 {
300 return strikes_.back() + QL_EPSILON;
301}

◆ maxDate()

QuantLib::Date maxDate
override

maximum date for which the term structure can return vols

Definition at line 303 of file strippedcpivolatilitystructure.hpp.

303 {
304 QuantLib::Date today = QuantLib::Settings::instance().evaluationDate();
305 return today + maturities_.back();
306}

◆ strikes()

const std::vector< QuantLib::Real > & strikes ( )

Definition at line 104 of file strippedcpivolatilitystructure.hpp.

104{ return strikes_; }

◆ maturities()

const std::vector< QuantLib::Period > & maturities ( )

Definition at line 105 of file strippedcpivolatilitystructure.hpp.

105{ return maturities_; }

◆ volData()

const QuantLib::Matrix & volData ( )

Definition at line 106 of file strippedcpivolatilitystructure.hpp.

106{ return volData_; }

◆ atmStrike()

QuantLib::Real atmStrike ( const QuantLib::Date &  maturity,
const QuantLib::Period &  obsLag = QuantLib::Period(-1, QuantLib::Days) 
) const
overridevirtual

Implements CPIVolatilitySurface.

Definition at line 357 of file strippedcpivolatilitystructure.hpp.

358 {
359 QuantLib::Period lag = obsLag == -1 * QuantLib::Days ? observationLag() : obsLag;
360 QuantLib::Date fixingDate = ZeroInflation::fixingDate(maturity, lag, frequency(), indexIsInterpolated());
361 double forwardCPI = ZeroInflation::cpiFixing(index_, maturity, lag, indexIsInterpolated());
362 double baseCPI = ZeroInflation::cpiFixing(index_, capFloorStartDate(), observationLag(), indexIsInterpolated());
363 double atm = forwardCPI / baseCPI;
364 double ttm =
365 QuantLib::inflationYearFraction(frequency(), indexIsInterpolated(), dayCounter(), baseDate(), fixingDate);
366 return std::pow(atm, 1.0 / ttm) - 1.0;
367}
QuantLib::Date baseDate() const override
base date will be in the past
+ Here is the call graph for this function:

◆ volatilityImpl()

QuantLib::Volatility volatilityImpl ( QuantLib::Time  length,
QuantLib::Rate  strike 
) const
overrideprivate

Definition at line 309 of file strippedcpivolatilitystructure.hpp.

310 {
311 return vols_(length, strike);
312}

◆ chooseFloor()

bool chooseFloor ( QuantLib::Real  strike,
QuantLib::Real  atmRate 
) const
private

Definition at line 248 of file strippedcpivolatilitystructure.hpp.

248 {
249 if (preference_ == Floor) {
250 if (strike <= priceSurface_->floorStrikes().back())
251 return true;
252 else
253 return false;
254 }
255
256 if (preference_ == Cap) {
257 if (strike < priceSurface_->capStrikes().front())
258 return true;
259 else
260 return false;
261 }
262
263 // else: Use floors where we have floor quotes only, caps where we have cap quotes only,
264 // and decide based on ATM where we have both cap and floor quotes
265
266 // 1) strike < maxFloorStrike < minCapStrike: Floor!
267 if (strike <= priceSurface_->floorStrikes().back() && strike < priceSurface_->capStrikes().front())
268 return true;
269 // 2) strike > maxFloorStrike and strike >= minCapStrike: Cap!
270 else if (strike > priceSurface_->floorStrikes().back() && strike >= priceSurface_->capStrikes().front())
271 return false;
272 // 3) Overlap, maxFloorStrike > minCapStrike and strike in between: Depends on atmRate which surface we pick
273 else if (strike <= priceSurface_->floorStrikes().back() && strike >= priceSurface_->capStrikes().front()) {
274 // we have overlapping strikes, decide depending on atm level
275 if (strike < atmRate)
276 return true;
277 else
278 return false;
279 // 4) Gap, maxFloorStrike < minCapStrike and strike in the gap: Depends on atmRate which surface we
280 // extrapolate
281 } else if (strike > priceSurface_->floorStrikes().back() && strike < priceSurface_->capStrikes().front()) {
282 // there is a gap between floor end and caps begin, decide again depending on strike level
283 if (strike < atmRate)
284 return true;
285 else
286 return false;
287 } else {
288 QL_FAIL("case not covered in StrippedCPIVolatilitySurface: strike="
289 << strike << " maxFloorStrike=" << priceSurface_->floorStrikes().back()
290 << " minCapStrike=" << priceSurface_->capStrikes().front() << " atm=" << atmRate);
291 return false;
292 }
293}

Member Data Documentation

◆ preference_

PriceQuotePreference preference_
private

Definition at line 143 of file strippedcpivolatilitystructure.hpp.

◆ priceSurface_

QuantLib::Handle<QuantLib::CPICapFloorTermPriceSurface> priceSurface_
private

Definition at line 144 of file strippedcpivolatilitystructure.hpp.

◆ index_

QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex> index_
private

Definition at line 145 of file strippedcpivolatilitystructure.hpp.

◆ engine_

QuantLib::ext::shared_ptr<QuantExt::CPICapFloorEngine> engine_
private

Definition at line 146 of file strippedcpivolatilitystructure.hpp.

◆ upperVolBound_

QuantLib::Real upperVolBound_
private

Definition at line 147 of file strippedcpivolatilitystructure.hpp.

◆ lowerVolBound_

QuantLib::Real lowerVolBound_
private

Definition at line 148 of file strippedcpivolatilitystructure.hpp.

◆ solverTolerance_

QuantLib::Real solverTolerance_
private

Definition at line 149 of file strippedcpivolatilitystructure.hpp.

◆ strikes_

std::vector<QuantLib::Rate> strikes_
mutableprivate

Definition at line 151 of file strippedcpivolatilitystructure.hpp.

◆ maturities_

std::vector<QuantLib::Period> maturities_
mutableprivate

Definition at line 152 of file strippedcpivolatilitystructure.hpp.

◆ maturityTimes_

std::vector<QuantLib::Time> maturityTimes_
mutableprivate

Definition at line 153 of file strippedcpivolatilitystructure.hpp.

◆ volData_

QuantLib::Matrix volData_
mutableprivate

Definition at line 154 of file strippedcpivolatilitystructure.hpp.

◆ interpolator2d_

Interpolator2D interpolator2d_
private

Definition at line 155 of file strippedcpivolatilitystructure.hpp.

◆ vols_

QuantLib::Interpolation2D vols_
mutableprivate

Definition at line 156 of file strippedcpivolatilitystructure.hpp.

◆ computeTimeToExpiryFromLastAvailableFixingDate_

bool computeTimeToExpiryFromLastAvailableFixingDate_
private

Definition at line 157 of file strippedcpivolatilitystructure.hpp.