22#include <ql/instruments/makecapfloor.hpp>
23#include <ql/math/solvers1d/brent.hpp>
24#include <ql/pricingengines/capfloor/bacheliercapfloorengine.hpp>
25#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
26#include <ql/termstructures/volatility/optionlet/strippedoptionletadapter.hpp>
28#include <boost/make_shared.hpp>
33 const Handle<QuantLib::CapFloorTermVolCurve>& atmCapFloorTermVolCurve,
34 const Handle<YieldTermStructure>& discount,
const VolatilityType type,
35 const Real displacement)
36 :
OptionletStripper(optionletStripper->termVolSurface(), optionletStripper->index(), discount,
37 optionletStripper->volatilityType(), optionletStripper->displacement()),
38 stripper_(optionletStripper), atmCapFloorTermVolCurve_(atmCapFloorTermVolCurve),
39 dc_(stripper_->termVolSurface()->dayCounter()), nOptionExpiries_(atmCapFloorTermVolCurve->optionTenors().size()),
40 atmCapFloorStrikes_(nOptionExpiries_), atmCapFloorPrices_(nOptionExpiries_), spreadsVolImplied_(nOptionExpiries_),
41 caps_(nOptionExpiries_), maxEvaluations_(10000), accuracy_(1.e-6), inputVolatilityType_(type),
42 inputDisplacement_(displacement) {
47 QL_REQUIRE(
dc_ == atmCapFloorTermVolCurve->dayCounter(),
"different day counters provided");
68 const Handle<YieldTermStructure>& discountCurve =
77 QuantLib::ext::shared_ptr<PricingEngine> engine;
79 engine = QuantLib::ext::make_shared<BlackCapFloorEngine>(discountCurve, atmOptionVol,
dc_,
inputDisplacement_);
81 engine = QuantLib::ext::make_shared<BachelierCapFloorEngine>(discountCurve, atmOptionVol,
dc_);
89 QuantLib::ext::shared_ptr<PricingEngine> tempEngine = QuantLib::ext::make_shared<BlackCapFloorEngine>(discountCurve, 0.01);
90 caps_[j] = MakeCapFloor(CapFloor::Cap, optionExpiriesTenors[j],
index_, Null<Rate>(), 0 * Days)
91 .withPricingEngine(tempEngine);
94 caps_[j]->setPricingEngine(engine);
102 adapter.enableExtrapolation();
104 Volatility unadjustedVol, adjustedVol;
107 if (i <=
caps_[j]->floatingLeg().size()) {
112 vector<Rate>::const_iterator previous =
127 Volatility guess = 0.0001, minSpread = -0.1, maxSpread = 0.1;
131 Volatility root = solver.solve(f,
accuracy_, guess, minSpread, maxSpread);
154 const QuantLib::ext::shared_ptr<QuantExt::OptionletStripper>& optionletStripper,
const QuantLib::ext::shared_ptr<CapFloor>& cap,
155 Real targetValue,
const Handle<YieldTermStructure>& discount)
156 : cap_(cap),
targetValue_(targetValue), discount_(discount) {
158 adapter->enableExtrapolation();
162 spreadQuote_ = QuantLib::ext::shared_ptr<SimpleQuote>(
new SimpleQuote(-1.0));
164 QuantLib::ext::shared_ptr<OptionletVolatilityStructure> spreadedAdapter(
169 QuantLib::ext::shared_ptr<PricingEngine> engine;
170 if (optionletStripper->volatilityType() == ShiftedLognormal) {
171 engine = QuantLib::ext::make_shared<BlackCapFloorEngine>(
172 discount_, Handle<OptionletVolatilityStructure>(spreadedAdapter), optionletStripper->displacement());
173 }
else if (optionletStripper->volatilityType() == Normal) {
174 engine = QuantLib::ext::make_shared<BachelierCapFloorEngine>(
discount_,
175 Handle<OptionletVolatilityStructure>(spreadedAdapter));
177 QL_FAIL(
"Unknown volatility type: " << optionletStripper->volatilityType());
180 cap_->setPricingEngine(engine);
184 if (s != spreadQuote_->value())
185 spreadQuote_->setValue(s);
Real operator()(Volatility spreadVol) const
ObjectiveFunction(const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > &, const QuantLib::ext::shared_ptr< QuantLib::CapFloor > &, Real targetValue, const Handle< YieldTermStructure > &discount)
const Handle< YieldTermStructure > discount_
QuantLib::ext::shared_ptr< SimpleQuote > spreadQuote_
QuantLib::ext::shared_ptr< QuantLib::CapFloor > cap_
void performCalculations() const override
const Real inputDisplacement_
OptionletStripper2(const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > &optionletStripper, const Handle< QuantLib::CapFloorTermVolCurve > &atmCapFloorTermVolCurve, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0)
vector< Real > atmCapFloorPrices() const
const Handle< QuantLib::CapFloorTermVolCurve > atmCapFloorTermVolCurve_
vector< Volatility > spreadsVolImplied(const Handle< YieldTermStructure > &discount) const
vector< Rate > atmCapFloorStrikes_
const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > stripper_
vector< Rate > atmCapFloorStrikes() const
vector< Volatility > spreadsVolImplied_
vector< QuantLib::ext::shared_ptr< QuantLib::CapFloor > > caps_
const VolatilityType inputVolatilityType_
vector< Real > atmCapFloorPrices_
vector< Volatility > spreadsVol() const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
Handle< YieldTermStructure > discount_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
const VolatilityType volatilityType_
std::vector< std::vector< Rate > > optionletStrikes_
ext::shared_ptr< IborIndex > index_
ATM optionlet (caplet/floorlet) volatility stripper.
Adds floor to QuantLib::SpreadedOptionletVolatility.