23#ifndef quantext_interpolated_cpi_volatility_structure_hpp
24#define quantext_interpolated_cpi_volatility_structure_hpp
26#include <ql/indexes/inflationindex.hpp>
27#include <ql/math/interpolations/interpolation2d.hpp>
28#include <ql/math/matrix.hpp>
29#include <ql/quote.hpp>
30#include <ql/termstructures/volatility/inflation/constantcpivolatility.hpp>
43template <
class Interpolator2D>
47 const std::vector<std::vector<Handle<Quote>>>
quotes,
48 const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index,
49 const bool quotedInstrumentsAreInterpolated,
50 const Natural settlementDays,
const Calendar& cal, BusinessDayConvention bdc,
51 const DayCounter& dc,
const Period& observationLag,
53 const Interpolator2D& interpolator2d = Interpolator2D(),
54 const QuantLib::VolatilityType volType = QuantLib::ShiftedLognormal,
60 const std::vector<std::vector<Handle<Quote>>>
quotes,
61 const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index,
62 const Natural settlementDays,
const Calendar& cal, BusinessDayConvention bdc,
63 const DayCounter& dc,
const Period& observationLag,
65 const Interpolator2D& interpolator2d = Interpolator2D(),
66 const QuantLib::VolatilityType volType = QuantLib::ShiftedLognormal,
74 CPIVolatilitySurface::update();
81 QuantLib::Real
minStrike()
const override;
83 QuantLib::Real
maxStrike()
const override;
85 QuantLib::Date
maxDate()
const override;
92 const std::vector<std::vector<Handle<Quote> > >&
quotes() {
return quotes_; }
96 QuantLib::Volatility
volatilityImpl(QuantLib::Time length, QuantLib::Rate strike)
const override;
98 QuantLib::Real
atmStrike(
const QuantLib::Date& maturity,
99 const QuantLib::Period& obsLag = QuantLib::Period(-1, QuantLib::Days))
const override;
106 mutable std::vector<std::vector<Handle<Quote> > >
quotes_;
107 QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>
index_;
109 mutable QuantLib::Interpolation2D
vols_;
114template <
class Interpolator2D>
116 const std::vector<Period>& optionTenors,
const std::vector<Real>&
strikes,
117 const std::vector<std::vector<Handle<Quote>>> quotes,
const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index,
118 const bool quotedInstrumentsOberserveInterpolated,
const Natural settlementDays,
const Calendar& cal, BusinessDayConvention bdc,
const DayCounter& dc,
119 const Period& observationLag,
const Date& capFloorStartDate,
const Interpolator2D& interpolator2d,
120 const QuantLib::VolatilityType volType,
const double displacement)
122 quotedInstrumentsOberserveInterpolated,
123 capFloorStartDate, volType, displacement),
124 optionTenors_(optionTenors), strikes_(
strikes), quotes_(quotes), index_(index), interpolator2d_(interpolator2d) {
126 QL_REQUIRE(
quotes_[i].size() ==
strikes_.size(),
"quotes row " << i <<
" length does not match strikes size");
127 for (Size j = 0; j <
strikes_.size(); ++j)
133QL_DEPRECATED_DISABLE_WARNING
134template <
class Interpolator2D>
136 const std::vector<Period>& optionTenors,
const std::vector<Real>&
strikes,
137 const std::vector<std::vector<Handle<Quote>>> quotes,
const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index,
138 const Natural settlementDays,
const Calendar& cal, BusinessDayConvention bdc,
const DayCounter& dc,
139 const Period& observationLag,
const Date& capFloorStartDate,
const Interpolator2D& interpolator2d,
140 const QuantLib::VolatilityType volType,
const double displacement)
141 :
CPIVolatilitySurface(settlementDays, cal, bdc, dc, observationLag, index->frequency(), index->interpolated(),
142 capFloorStartDate, volType, displacement),
143 optionTenors_(optionTenors), strikes_(
strikes), quotes_(quotes), index_(index), interpolator2d_(interpolator2d) {
145 QL_REQUIRE(
quotes_[i].size() ==
strikes_.size(),
"quotes row " << i <<
" length does not match strikes size");
146 for (Size j = 0; j <
strikes_.size(); ++j)
150QL_DEPRECATED_ENABLE_WARNING
153 volData_ = QuantLib::Matrix(strikes_.size(), optionTenors_.size(), QuantLib::Null<QuantLib::Real>());
154 QL_REQUIRE(quotes_.size() == optionTenors_.size(),
"quotes rows does not match option tenors size");
155 optionTimes_.clear();
156 for (Size i = 0; i < optionTenors_.size(); ++i) {
157 QuantLib::Date d = optionDateFromTenor(optionTenors_[i]);
159 optionTimes_.push_back(fixingTime(d));
160 for (QuantLib::Size j = 0; j < strikes_.size(); j++)
161 volData_[j][i] = quotes_[i][j]->value();
164 vols_ = interpolator2d_.interpolate(optionTimes_.begin(), optionTimes_.end(), strikes_.begin(), strikes_.end(),
167 vols_.enableExtrapolation();
172 return strikes_.front() - QL_EPSILON;
176 return strikes_.back() + QL_EPSILON;
180 QuantLib::Date today = QuantLib::Settings::instance().evaluationDate();
181 return today + optionTenors_.back();
184template <
class Interpolator2D>
186 QuantLib::Rate strike)
const {
188 return vols_(length, strike);
191template <
class Interpolator2D>
193 const QuantLib::Period& obsLag)
const {
194 QuantLib::Period lag = obsLag == -1 * QuantLib::Days ? observationLag() : obsLag;
198 index_, capFloorStartDate(), observationLag(), indexIsInterpolated());
199 double atm = forwardCPI / baseCPI;
201 QuantLib::inflationYearFraction(frequency(), indexIsInterpolated(), dayCounter(), baseDate(), fixingDate);
202 return std::pow(atm, 1.0 / ttm) - 1.0;
double displacement() const
Returns the displacement for lognormal volatilities.
QuantLib::Date capFloorStartDate() const
Interpolated zero inflation volatility structure.
Interpolator2D interpolator2d_
void performCalculations() const override
InterpolatedCPIVolatilitySurface(const std::vector< Period > &optionTenors, const std::vector< Real > &strikes, const std::vector< std::vector< Handle< Quote > > > quotes, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index, const bool quotedInstrumentsAreInterpolated, const Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const DayCounter &dc, const Period &observationLag, const Date &capFloorStartDate=Date(), const Interpolator2D &interpolator2d=Interpolator2D(), const QuantLib::VolatilityType volType=QuantLib::ShiftedLognormal, const double displacement=0.0)
const std::vector< QuantLib::Real > & strikes()
QuantLib::Interpolation2D vols_
std::vector< QuantLib::Time > optionTimes_
QuantLib::Real minStrike() const override
the minimum strike for which the term structure can return vols
const QuantLib::Matrix & volData()
const std::vector< std::vector< Handle< Quote > > > & quotes()
std::vector< QuantLib::Rate > strikes_
QuantLib::Real maxStrike() const override
the maximum strike for which the term structure can return vols
QuantLib::Date maxDate() const override
maximum date for which the term structure can return vols
QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > index_
std::vector< std::vector< Handle< Quote > > > quotes_
const std::vector< QuantLib::Period > & optionTenors()
std::vector< QuantLib::Period > optionTenors_
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
interpolated correlation term structure
some inflation related utilities.
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
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.