24#ifndef quantlib_interpolated_yoy_optionlet_stripper_hpp
25#define quantlib_interpolated_yoy_optionlet_stripper_hpp
43 template <
class Interpolator1D>
49 void initialize(
const ext::shared_ptr<YoYCapFloorTermPriceSurface>&,
50 const ext::shared_ptr<YoYInflationCapFloorEngine>&,
51 Real slope)
const override;
54 std::vector<Rate>
strikes()
const override {
57 std::pair<std::vector<Rate>, std::vector<Volatility> >
slice(
const Date&
d)
const override;
61 mutable std::vector<ext::shared_ptr<YoYOptionletVolatilitySurface> >
73 const ext::shared_ptr<YoYInflationIndex>& anIndex,
74 const ext::shared_ptr<YoYCapFloorTermPriceSurface>&,
75 ext::shared_ptr<YoYInflationCapFloorEngine> p,
85 mutable std::vector<Volatility>
vvec_;
88 ext::shared_ptr<YoYCapFloorTermPriceSurface>
surf_;
90 ext::shared_ptr<YoYInflationCapFloorEngine>
p_;
97 template <
class Interpolator1D>
104 const ext::shared_ptr<YoYInflationIndex>& anIndex,
105 const ext::shared_ptr<YoYCapFloorTermPriceSurface>& surf,
106 ext::shared_ptr<YoYInflationCapFloorEngine> p,
108 : slope_(slope), K_(K), frequency_(anIndex->frequency()),
109 indexIsInterpolated_(anIndex->interpolated()), tvec_(
std::vector<
Time>(2)),
111 surf_(surf),
p_(
std::move(p)) {
116 (
Size)std::floor(0.5+surf->timeFromReference(surf->minMaturity())),
117 surf->calendar(), lag)
130 Size n = (
Size)std::floor(0.5 + surf->timeFromReference(
surf_->minMaturity()));
132 "first maturity in price surface not > 0: "
140 template <
class Interpolator1D>
145 vvec_[0] = guess - slope_ * (tvec_[1] - tvec_[0]) * guess;
147 ext::shared_ptr<InterpolatedYoYOptionletVolatilityCurve<Linear> >
156 p_->setVolatility(hCurve);
158 return priceToMatch_ - capfloor_->NPV();
162 template <
class Interpolator1D>
164 initialize(
const ext::shared_ptr<YoYCapFloorTermPriceSurface> &
s,
165 const ext::shared_ptr<YoYInflationCapFloorEngine> &p,
166 const Real slope)
const {
187 ext::shared_ptr<YoYInflationIndex> anIndex(
199 Real solverTolerance_ = 1e-7;
201 Real lo = 0.00001, hi = 0.08;
202 Real guess = (hi+lo)/2.0;
210 found = solver.
solve(
214 solverTolerance_, guess, lo, hi );
215 }
catch( std::exception &e) {
216 QL_FAIL(
"failed to find solution here because: " << e.what());
220 Real notional = 10000;
221 std::vector<ext::shared_ptr<BootstrapHelper<YoYOptionletVolatilitySurface> > > helperInstruments;
222 std::vector<ext::shared_ptr<YoYOptionletHelper> > helpers;
235 Size nT = (
Size)floor(
s->timeFromReference(
s->yoyOptionDateFromTenor(Tp))+0.5);
236 helpers.push_back(ext::shared_ptr<YoYOptionletHelper>(
241 anIndex, K, nT,
p_)));
243 ext::shared_ptr<ConstantYoYOptionletVolatility> yoyVolBLACK(
251 helpers[j]->setTermStructure(
255 helperInstruments.push_back(helpers[j]);
259 Real Tmin =
s->timeFromReference(
s->yoyOptionDateFromTenor(TPmin));
260 Volatility baseYoYVolatility = found - slope * Tmin * found;
261 Rate eps = std::max(K, 0.02) / 1000.0;
267 settlementDays, cal, bdc, dc,
lag_,
271 helperInstruments) );
272 testPW->recalculate();
278 template <
class Interpolator1D>
279 std::pair<std::vector<Rate>, std::vector<Volatility> >
281 const Date &
d)
const {
283 const std::vector<Real>& Ks =
strikes();
285 const Size nK = Ks.size();
287 std::pair<std::vector<Rate>, std::vector<Volatility> > result =
288 std::make_pair(std::vector<Rate>(nK), std::vector<Volatility>(nK));
290 for (
Size i = 0; i < nK; i++) {
294 result.second[i] =
v;
Actual/365 (Fixed) day count convention.
Constant surface, no K or T dependence.
Shared handle to an observable.
Real operator()(Volatility guess) const
std::vector< Volatility > vvec_
std::vector< Time > tvec_
bool indexIsInterpolated_
ext::shared_ptr< YoYInflationCapFloor > capfloor_
ext::shared_ptr< YoYCapFloorTermPriceSurface > surf_
std::vector< Date > dvec_
ext::shared_ptr< YoYInflationCapFloorEngine > p_
ObjectiveFunction(YoYInflationCapFloor::Type type, Real slope, Rate K, Period &lag, Natural fixingDays, const ext::shared_ptr< YoYInflationIndex > &anIndex, const ext::shared_ptr< YoYCapFloorTermPriceSurface > &, ext::shared_ptr< YoYInflationCapFloorEngine > p, Real priceToMatch)
Rate maxStrike() const override
Rate minStrike() const override
void initialize(const ext::shared_ptr< YoYCapFloorTermPriceSurface > &, const ext::shared_ptr< YoYInflationCapFloorEngine > &, Real slope) const override
YoYOptionletStripper interface.
std::vector< ext::shared_ptr< YoYOptionletVolatilitySurface > > volCurves_
std::vector< Rate > strikes() const override
std::pair< std::vector< Rate >, std::vector< Volatility > > slice(const Date &d) const override
Interpolated flat smile surface.
MakeYoYInflationCapFloor & withStrike(Rate strike)
MakeYoYInflationCapFloor & withNominal(Real n)
Piecewise year-on-year inflation volatility term structure.
Relinkable handle to an observable.
market element returning a stored value
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Quoted year-on-year Generic CPI (i.e. not a ratio)
Year-on-year inflation-volatility bootstrap helper.
Interface for inflation cap stripping, i.e. from price surfaces.
bool indexIsInterpolated_
ext::shared_ptr< YoYCapFloorTermPriceSurface > YoYCapFloorTermPriceSurface_
ext::shared_ptr< YoYInflationCapFloorEngine > p_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Generic inflation indexes.
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
Real Volatility
volatility
std::size_t Size
size of a container
Helper class to instantiate standard yoy inflation cap/floor.
ext::shared_ptr< BlackVolTermStructure > v
piecewise yoy inflation volatility term structure
helpers for YoY inflation-volatility bootstrap
yoy inflation-cap stripping