23#ifndef quantext_piecewiseatmoptionletcurve_hpp
24#define quantext_piecewiseatmoptionletcurve_hpp
42 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
43 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
44 bool flatFirstPeriod =
true,
45 const QuantLib::VolatilityType
capFloorVolType = QuantLib::ShiftedLognormal,
47 const boost::optional<QuantLib::VolatilityType> optionletVolType = boost::none,
48 const boost::optional<QuantLib::Real> optionletVolDisplacement = boost::none,
49 bool interpOnOptionlets =
true,
const Interpolator& i = Interpolator(),
50 const Bootstrap<optionlet_curve>& bootstrap = Bootstrap<optionlet_curve>());
53 const QuantLib::ext::shared_ptr<CapFloorTermVolCurve>& cftvc,
54 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
55 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
56 bool flatFirstPeriod =
true,
57 const QuantLib::VolatilityType
capFloorVolType = QuantLib::ShiftedLognormal,
59 const boost::optional<QuantLib::VolatilityType> optionletVolType = boost::none,
60 const boost::optional<QuantLib::Real> optionletVolDisplacement = boost::none,
61 bool interpOnOptionlets =
true,
const Interpolator& i = Interpolator(),
62 const Bootstrap<optionlet_curve>& bootstrap = Bootstrap<optionlet_curve>());
84 QuantLib::Date
maxDate()
const override;
89 QuantLib::Rate
minStrike()
const override;
90 QuantLib::Rate
maxStrike()
const override;
100 QuantLib::ext::shared_ptr<optionlet_curve>
curve()
const;
105 QuantLib::ext::shared_ptr<QuantLib::SmileSection>
smileSectionImpl(QuantLib::Time optionTime)
const override;
106 QuantLib::Volatility
volatilityImpl(QuantLib::Time optionTime, QuantLib::Rate strike)
const override;
111 QuantLib::ext::shared_ptr<CapFloorTermVolCurve>
cftvc_;
138 QuantLib::ext::shared_ptr<optionlet_curve>
curve_;
144 typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure>
helper;
145 std::vector<QuantLib::ext::shared_ptr<helper> >
helpers_;
148 std::vector<QuantLib::ext::shared_ptr<QuantLib::SimpleQuote> >
quotes_;
151 void initialise(
const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
152 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount);
155template <
class Interpolator,
template <
class>
class Bootstrap>
157 QuantLib::Natural settlementDays,
const QuantLib::ext::shared_ptr<CapFloorTermVolCurve>& cftvc,
158 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
159 bool flatFirstPeriod,
const QuantLib::VolatilityType capFloorVolType,
const QuantLib::Real capFloorVolDisplacement,
160 const boost::optional<QuantLib::VolatilityType> optionletVolType,
161 const boost::optional<QuantLib::Real> optionletVolDisplacement,
bool interpOnOptionlets,
const Interpolator& i,
162 const Bootstrap<optionlet_curve>& bootstrap)
163 :
QuantLib::OptionletVolatilityStructure(settlementDays, cftvc->calendar(), cftvc->businessDayConvention(),
164 cftvc->dayCounter()),
165 cftvc_(cftvc), flatFirstPeriod_(flatFirstPeriod), capFloorVolType_(capFloorVolType),
166 capFloorVolDisplacement_(capFloorVolDisplacement),
167 volatilityType_(optionletVolType ? *optionletVolType : capFloorVolType),
168 displacement_(optionletVolDisplacement ? *optionletVolDisplacement : 0.0),
169 interpOnOptionlets_(interpOnOptionlets), interpolator_(i), bootstrap_(bootstrap), tenors_(cftvc_->optionTenors()),
170 helpers_(tenors_.size()), quotes_(tenors_.size()) {
174 curve_ = QuantLib::ext::make_shared<optionlet_curve>(settlementDays,
helpers_,
cftvc_->calendar(),
179template <
class Interpolator,
template <
class>
class Bootstrap>
181 const QuantLib::Date& referenceDate,
const QuantLib::ext::shared_ptr<CapFloorTermVolCurve>& cftvc,
182 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
183 bool flatFirstPeriod,
const QuantLib::VolatilityType capFloorVolType,
const QuantLib::Real capFloorVolDisplacement,
184 const boost::optional<QuantLib::VolatilityType> optionletVolType,
185 const boost::optional<QuantLib::Real> optionletVolDisplacement,
bool interpOnOptionlets,
const Interpolator& i,
186 const Bootstrap<optionlet_curve>& bootstrap)
187 :
QuantLib::OptionletVolatilityStructure(referenceDate, cftvc->calendar(), cftvc->businessDayConvention(),
188 cftvc->dayCounter()),
189 cftvc_(cftvc), flatFirstPeriod_(flatFirstPeriod), capFloorVolType_(capFloorVolType),
190 capFloorVolDisplacement_(capFloorVolDisplacement),
191 volatilityType_(optionletVolType ? *optionletVolType : capFloorVolType),
192 displacement_(optionletVolDisplacement ? *optionletVolDisplacement : 0.0),
193 interpOnOptionlets_(interpOnOptionlets), interpolator_(i), bootstrap_(bootstrap), tenors_(cftvc_->optionTenors()),
194 helpers_(tenors_.size()), quotes_(tenors_.size()) {
198 curve_ = QuantLib::ext::make_shared<optionlet_curve>(referenceDate,
helpers_,
cftvc_->calendar(),
203template <
class Interpolator,
template <
class>
class Bootstrap>
206 LazyObject::update();
209 this->updated_ =
false;
212template <
class Interpolator,
template <
class>
class Bootstrap>
216 for (QuantLib::Size i = 0; i < tenors_.size(); i++) {
217 quotes_[i]->setValue(cftvc_->volatility(tenors_[i], 0.01));
221template <
class Interpolator,
template <
class>
class Bootstrap>
224 return curve_->maxDate();
227template <
class Interpolator,
template <
class>
class Bootstrap>
230 return curve_->minStrike();
233template <
class Interpolator,
template <
class>
class Bootstrap>
236 return curve_->maxStrike();
239template <
class Interpolator,
template <
class>
class Bootstrap>
241 return volatilityType_;
244template <
class Interpolator,
template <
class>
class Bootstrap>
246 return displacement_;
249template <
class Interpolator,
template <
class>
class Bootstrap>
250QuantLib::ext::shared_ptr<typename PiecewiseAtmOptionletCurve<Interpolator, Bootstrap>::optionlet_curve>
256template <
class Interpolator,
template <
class>
class Bootstrap>
257QuantLib::ext::shared_ptr<QuantLib::SmileSection>
260 return curve_->smileSection(optionTime,
true);
263template <
class Interpolator,
template <
class>
class Bootstrap>
265 QuantLib::Rate strike)
const {
267 return curve_->volatility(optionTime, 0.01,
true);
270template <
class Interpolator,
template <
class>
class Bootstrap>
272 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
273 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount) {
276 using QuantLib::Handle;
277 using QuantLib::Null;
278 using QuantLib::Period;
279 using QuantLib::Quote;
280 using QuantLib::Rate;
281 using QuantLib::Real;
282 using QuantLib::SimpleQuote;
283 using QuantLib::Size;
287 registerWith(cftvc_);
292 if (!this->moving_) {
293 Calendar cal = index->fixingCalendar();
294 Date ref = referenceDate();
295 ref = cal.adjust(ref);
296 effectiveDate = cal.advance(ref, index->fixingDays() * Days);
301 if (!interpOnOptionlets_) {
304 Period indexTenor = index->tenor();
305 Period maxCapFloorTenor = tenors_.back();
309 tenors_.push_back(indexTenor + indexTenor);
310 QL_REQUIRE(maxCapFloorTenor >= tenors_.back(),
311 "First cap floor tenor, " << tenors_.back()
312 <<
", is greater than cap floor term vol surface's max tenor, "
313 << maxCapFloorTenor);
316 Period nextTenor = tenors_.back() + indexTenor;
317 while (nextTenor <= maxCapFloorTenor) {
318 tenors_.push_back(nextTenor);
319 nextTenor += indexTenor;
323 quotes_.resize(tenors_.size());
324 helpers_.resize(tenors_.size());
328 for (Size i = 0; i < tenors_.size(); i++) {
329 quotes_[i] = QuantLib::ext::make_shared<SimpleQuote>(cftvc_->volatility(tenors_[i], 0.01));
330 helpers_[i] = QuantLib::ext::make_shared<CapFloorHelper>(
331 CapFloorHelper::Cap, tenors_[i], Null<Real>(), Handle<Quote>(quotes_[i]), index, discount, this->moving_,
Cap floor at-the-money term volatility curve.
std::vector< QuantLib::ext::shared_ptr< QuantLib::SimpleQuote > > quotes_
Store the ATM cap floor curve quotes.
void performCalculations() const override
QuantLib::Real displacement() const override
std::vector< QuantLib::ext::shared_ptr< helper > > helpers_
QuantLib::ext::shared_ptr< optionlet_curve > curve_
The stripped optionlet curve.
Interpolator interpolator_
The interpolator.
PiecewiseOptionletCurve< Interpolator, Bootstrap >::this_curve optionlet_curve
QuantLib::VolatilityType capFloorVolType() const
Volatility type for the underlying ATM cap floor curve.
QuantLib::Volatility volatilityImpl(QuantLib::Time optionTime, QuantLib::Rate strike) const override
std::vector< QuantLib::Period > tenors_
Store the helper tenors.
QuantLib::VolatilityType volatilityType() const override
QuantLib::VolatilityType capFloorVolType_
Volatility type for the underlying ATM cap floor volatility curve.
QuantLib::Real capFloorVolDisplacement_
The applicable shift if the underlying ATM cap floor volatility curve has shifted lognormal volatilit...
QuantLib::VolatilityType volatilityType_
This optionlet structure's volatility type.
QuantLib::ext::shared_ptr< optionlet_curve > curve() const
The underlying optionlet curve.
QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl(QuantLib::Time optionTime) const override
Bootstrap< optionlet_curve > bootstrap_
The bootstrapper.
QuantLib::Date maxDate() const override
QuantLib::ext::shared_ptr< CapFloorTermVolCurve > cftvc_
The underlying ATM cap floor term volatility curve.
PiecewiseAtmOptionletCurve(QuantLib::Natural settlementDays, const QuantLib::ext::shared_ptr< CapFloorTermVolCurve > &cftvc, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &index, const QuantLib::Handle< QuantLib::YieldTermStructure > &discount, bool flatFirstPeriod=true, const QuantLib::VolatilityType capFloorVolType=QuantLib::ShiftedLognormal, const QuantLib::Real capFloorVolDisplacement=0.0, const boost::optional< QuantLib::VolatilityType > optionletVolType=boost::none, const boost::optional< QuantLib::Real > optionletVolDisplacement=boost::none, bool interpOnOptionlets=true, const Interpolator &i=Interpolator(), const Bootstrap< optionlet_curve > &bootstrap=Bootstrap< optionlet_curve >())
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
Store the vector of ATM cap floor helpers that are used in the bootstrap.
QuantLib::Rate minStrike() const override
bool interpOnOptionlets_
True to interpolate on optionlet volatilities, false to interpolate on cap floor term volatilities.
QuantLib::Rate maxStrike() const override
QuantLib::Real displacement_
This optionlet structure's shift if its volatility type is shifted lognormal.
QuantLib::Real capFloorVolDisplacement() const
The applicable shift if the underlying ATM cap floor curve has shifted lognormal volatility.
void initialise(const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &index, const QuantLib::Handle< QuantLib::YieldTermStructure > &discount)
Shared initialisation.
bool flatFirstPeriod_
Flat optionlet volatility before first optionlet fixing date.
Straight copy of ql/termstructures/iterativebootstrap.hpp with minor changes.
One-dimensional curve of bootstrapped optionlet volatilities.