23#ifndef quantext_piecewiseoptionletstripper_hpp
24#define quantext_piecewiseoptionletstripper_hpp
43 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>&
index,
44 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
45 bool flatFirstPeriod =
true,
46 const QuantLib::VolatilityType
capFloorVolType = QuantLib::ShiftedLognormal,
48 const boost::optional<VolatilityType> optionletVolType = boost::none,
49 const boost::optional<QuantLib::Real> optionletVolDisplacement = boost::none,
50 bool interpOnOptionlets =
true,
const Interpolator& i = Interpolator(),
51 const Bootstrap<optionlet_curve>& bootstrap = Bootstrap<optionlet_curve>(),
87 mutable std::vector<QuantLib::ext::shared_ptr<optionlet_curve> >
strikeCurves_;
90 typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure>
helper;
91 std::vector<std::vector<QuantLib::ext::shared_ptr<helper> > >
helpers_;
94 std::vector<std::vector<QuantLib::ext::shared_ptr<QuantLib::SimpleQuote> > >
quotes_;
97template <
class Interpolator,
template <
class>
class Bootstrap>
99 const QuantLib::ext::shared_ptr<QuantExt::CapFloorTermVolSurface>& capFloorSurface,
100 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
101 bool flatFirstPeriod,
const QuantLib::VolatilityType capFloorVolType,
const QuantLib::Real capFloorVolDisplacement,
102 const boost::optional<VolatilityType> optionletVolType,
103 const boost::optional<QuantLib::Real> optionletVolDisplacement,
bool interpOnOptionlets,
const Interpolator& i,
104 const Bootstrap<optionlet_curve>& bootstrap,
const Period& rateComputationPeriod,
const Size onCapSettlementDays)
105 :
OptionletStripper(capFloorSurface, index, discount, optionletVolType ? *optionletVolType : capFloorVolType,
106 optionletVolDisplacement ? *optionletVolDisplacement : 0.0, rateComputationPeriod,
107 onCapSettlementDays),
108 flatFirstPeriod_(flatFirstPeriod), capFloorVolType_(capFloorVolType),
109 capFloorVolDisplacement_(capFloorVolDisplacement), interpOnOptionlets_(interpOnOptionlets), interpolator_(i),
110 bootstrap_(bootstrap), strikeCurves_(nStrikes_), helpers_(nStrikes_) {
114 using QuantLib::Handle;
115 using QuantLib::Period;
116 using QuantLib::Quote;
117 using QuantLib::SimpleQuote;
118 using QuantLib::Size;
123 bool isOis = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(
index) !=
nullptr;
131 for (Size j = 0; j <
strikes.size(); j++) {
132 for (Size i = 0; i < tenors.size(); i++) {
135 Date effDate =
index_->fixingCalendar().advance(
137 helpers_[j].push_back(QuantLib::ext::make_shared<OISCapFloorHelper>(
142 helpers_[j].push_back(QuantLib::ext::make_shared<CapFloorHelper>(
150template <
class Interpolator,
template <
class>
class Bootstrap>
154 using QuantLib::Period;
155 using QuantLib::Rate;
156 using QuantLib::Size;
163 vector<Rate>
strikes = termVolSurface_->strikes();
164 vector<Period> tenors = interpOnOptionlets_ ? termVolSurface_->optionTenors() : capFloorLengths_;
167 for (Size i = 0; i < tenors.size(); i++) {
168 for (Size j = 0; j <
strikes.size(); j++) {
169 quotes_[i][j]->setValue(termVolSurface_->volatility(tenors[i],
strikes[j]));
174 for (Size j = 0; j <
strikes.size(); j++) {
175 strikeCurves_[j] = QuantLib::ext::make_shared<optionlet_curve>(
176 termVolSurface_->referenceDate(), helpers_[j], termVolSurface_->calendar(),
177 termVolSurface_->businessDayConvention(), termVolSurface_->dayCounter(), volatilityType_, displacement_,
178 flatFirstPeriod_, interpolator_, bootstrap_);
182 for (Size j = 0; j <
strikes.size(); j++) {
183 for (Size i = 0; i < nOptionletTenors_; ++i) {
184 optionletVolatilities_[i][j] = strikeCurves_[j]->volatility(optionletDates_[i],
strikes[j]);
const Size onCapSettlementDays_
const Period & rateComputationPeriod() const
const Period rateComputationPeriod_
std::vector< Period > capFloorLengths_
Handle< YieldTermStructure > discount_
ext::shared_ptr< IborIndex > index() const
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
ext::shared_ptr< IborIndex > index_
void performCalculations() const override
Interpolator interpolator_
The interpolator.
PiecewiseOptionletCurve< Interpolator, Bootstrap >::this_curve optionlet_curve
std::vector< QuantLib::ext::shared_ptr< optionlet_curve > > strikeCurves_
A one-dimensional optionlet curve for each strike in the underlying cap floor matrix.
PiecewiseOptionletStripper(const QuantLib::ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &capFloorSurface, 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< 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 >(), const Period &rateComputationPeriod=0 *Days, const Size onCapSettlementDays=0)
QuantLib::VolatilityType capFloorVolType() const
Volatility type for the underlying cap floor matrix.
std::vector< std::vector< QuantLib::ext::shared_ptr< helper > > > helpers_
QuantLib::VolatilityType capFloorVolType_
Volatility type for the underlying cap floor matrix.
QuantLib::Real capFloorVolDisplacement_
The applicable shift if the underlying cap floor matrix has shifted lognormal volatility.
Bootstrap< optionlet_curve > bootstrap_
The bootstrapper.
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
Store the vector of helpers for each strike column. The first dimension is strike and second is optio...
bool interpOnOptionlets_
True to interpolate on optionlet volatilities, false to interpolate on cap floor term volatilities.
std::vector< std::vector< QuantLib::ext::shared_ptr< QuantLib::SimpleQuote > > > quotes_
Store the cap floor surface quotes. The first dimension is option tenor and second is strike.
QuantLib::Real capFloorVolDisplacement() const
The applicable shift if the underlying cap floor matrix has shifted lognormal volatility.
bool flatFirstPeriod_
Flat optionlet volatility before first optionlet fixing date.
Straight copy of ql/termstructures/iterativebootstrap.hpp with minor changes.
Helper for bootstrapping optionlet volatilties from ois cap floor volatilities.
optionlet (caplet/floorlet) volatility stripper
One-dimensional curve of bootstrapped optionlet volatilities.