23#ifndef quantext_piecewise_optionlet_curve_hpp
24#define quantext_piecewise_optionlet_curve_hpp
26#include <ql/patterns/lazyobject.hpp>
27#include <ql/termstructures/localbootstrap.hpp>
28#include <ql/termstructures/yield/bootstraptraits.hpp>
39 typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure>
helper;
42 static QuantLib::Date
initialDate(
const QuantLib::OptionletVolatilityStructure* ovts) {
43 return ovts->referenceDate();
47 static QuantLib::Real
initialValue(
const QuantLib::OptionletVolatilityStructure* ovts) {
return 0.0; }
50 template <
class C>
static QuantLib::Real
guess(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size) {
59 if (c->volatilityType() == QuantLib::Normal) {
67 return c->data()[i - 1];
72 static QuantLib::Real
minValueAfter(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size) {
74 if (c->volatilityType() == QuantLib::Normal) {
83 static QuantLib::Real
maxValueAfter(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size) {
86 if (c->volatilityType() == QuantLib::Normal) {
94 static void updateGuess(std::vector<QuantLib::Real>& data, QuantLib::Real vol, QuantLib::Size i) { data[i] = vol; }
105 typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure>
helper;
114 const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
115 const QuantLib::Calendar& calendar, QuantLib::BusinessDayConvention bdc,
116 const QuantLib::DayCounter& dayCounter,
118 QuantLib::Real
displacement = 0.0,
bool flatFirstPeriod =
true,
119 const Interpolator& i = Interpolator(),
123 const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
124 const QuantLib::Calendar& calendar, QuantLib::BusinessDayConvention bdc,
125 const QuantLib::DayCounter& dayCounter,
127 QuantLib::Real
displacement = 0.0,
bool flatFirstPeriod =
true,
128 const Interpolator& i = Interpolator(),
134 QuantLib::Date
maxDate()
const override;
139 const std::vector<QuantLib::Time>&
times()
const;
140 const std::vector<QuantLib::Date>&
dates()
const;
141 const std::vector<QuantLib::Real>&
volatilities()
const;
142 std::vector<std::pair<QuantLib::Date, QuantLib::Real> >
nodes()
const;
160 QuantLib::Real
volatilityImpl(QuantLib::Time optionTime, QuantLib::Rate strike)
const override;
177template <
class Interpolator,
template <
class>
class Bootstrap>
179 const QuantLib::Date& referenceDate,
const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
180 const QuantLib::Calendar& calendar, QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dayCounter,
181 QuantLib::VolatilityType volatilityType, QuantLib::Real displacement,
bool flatFirstPeriod,
const Interpolator& i,
182 const Bootstrap<this_curve>& bootstrap)
183 :
base_curve(referenceDate, calendar, bdc, dayCounter, volatilityType, displacement, flatFirstPeriod, i),
184 instruments_(instruments), accuracy_(1e-12), bootstrap_(bootstrap) {
188template <
class Interpolator,
template <
class>
class Bootstrap>
190 QuantLib::Natural settlementDays,
const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
191 const QuantLib::Calendar& calendar, QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dayCounter,
192 QuantLib::VolatilityType volatilityType, QuantLib::Real displacement,
bool flatFirstPeriod,
const Interpolator& i,
193 const Bootstrap<this_curve>& bootstrap)
194 :
base_curve(settlementDays, calendar, bdc, dayCounter, volatilityType, displacement, flatFirstPeriod, i),
195 instruments_(instruments), accuracy_(1e-12), bootstrap_(bootstrap) {
199template <
class Interpolator,
template <
class>
class Bootstrap>
202 return base_curve::maxDate();
205template <
class Interpolator,
template <
class>
class Bootstrap>
208 return base_curve::times();
211template <
class Interpolator,
template <
class>
class Bootstrap>
214 return base_curve::dates();
217template <
class Interpolator,
template <
class>
class Bootstrap>
220 return base_curve::volatilities();
223template <
class Interpolator,
template <
class>
class Bootstrap>
224inline std::vector<std::pair<QuantLib::Date, QuantLib::Real> >
227 return base_curve::nodes();
230template <
class Interpolator,
template <
class>
class Bootstrap>
238 LazyObject::update();
246 this->updated_ =
false;
249template <
class Interpolator,
template <
class>
class Bootstrap>
251 QuantLib::Rate strike)
const {
253 return base_curve::volatilityImpl(optionTime, strike);
256template <
class Interpolator,
template <
class>
class Bootstrap>
259 bootstrap_.calculate();
Helper for bootstrapping optionlet volatilities from cap floor volatilities.
QuantLib::Real displacement() const override
QuantLib::VolatilityType volatilityType() const override
QuantLib::Real volatilityImpl(QuantLib::Time optionTime, QuantLib::Rate strike) const override
void performCalculations() const override
Bootstrap< this_curve > bootstrap_
const std::vector< QuantLib::Time > & times() const
Interpolator interpolator_type
InterpolatedOptionletCurve< Interpolator > base_curve
QuantLib::Date maxDate() const override
const std::vector< QuantLib::Real > & volatilities() const
QuantLib::Real accuracy_
Accuracy of the match.
PiecewiseOptionletCurve(const QuantLib::Date &referenceDate, const std::vector< QuantLib::ext::shared_ptr< helper > > &instruments, const QuantLib::Calendar &calendar, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dayCounter, QuantLib::VolatilityType volatilityType=QuantLib::Normal, QuantLib::Real displacement=0.0, bool flatFirstPeriod=true, const Interpolator &i=Interpolator(), const Bootstrap< this_curve > &bootstrap=Bootstrap< this_curve >())
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
const std::vector< QuantLib::Date > & dates() const
std::vector< QuantLib::ext::shared_ptr< helper > > instruments_
Vector of helper instruments to be matched.
std::vector< std::pair< QuantLib::Date, QuantLib::Real > > nodes() const
PiecewiseOptionletCurve< Interpolator, Bootstrap > this_curve
friend class Bootstrap< this_curve >
OptionletTraits traits_type
Bootstrap needs these typedefs.
Straight copy of ql/termstructures/iterativebootstrap.hpp with minor changes.
Interpolated one-dimensional curve of optionlet volatilities.
Traits class that is needed for Bootstrap classes to work
static void updateGuess(std::vector< QuantLib::Real > &data, QuantLib::Real vol, QuantLib::Size i)
Root finding update.
static QuantLib::Size maxIterations()
Maximum number of iterations to perform in search for root.
static QuantLib::Date initialDate(const QuantLib::OptionletVolatilityStructure *ovts)
Start date of the optionlet volatility term structure.
static QuantLib::Real minValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
Minimum value after a given iteration. Lower bound for optionlet volatility is 0.
static QuantLib::Real guess(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
Guesses.
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
Helper type.
static QuantLib::Real initialValue(const QuantLib::OptionletVolatilityStructure *ovts)
The value at the reference date of the term structure.
static QuantLib::Real maxValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
Maximum value after a given iteration.