19#include <ql/instruments/makecapfloor.hpp>
20#include <ql/option.hpp>
21#include <ql/pricingengines/blackformula.hpp>
22#include <ql/pricingengines/capfloor/bacheliercapfloorengine.hpp>
23#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
24#include <ql/utilities/dataformatters.hpp>
27#include <boost/make_shared.hpp>
29using QuantLib::ext::shared_ptr;
34 const shared_ptr<IborIndex>& index, Rate switchStrike, Real accuracy,
35 Natural maxIter,
const Handle<YieldTermStructure>& discount,
36 const VolatilityType type,
const Real displacement,
37 const optional<VolatilityType> targetVolatilityType,
38 const optional<Real> targetDisplacement)
39 :
OptionletStripper(termVolSurface, index, discount, targetVolatilityType ? *targetVolatilityType : type,
40 targetDisplacement ? *targetDisplacement : displacement),
41 volQuotes_(nOptionletTenors_, std::vector<shared_ptr<SimpleQuote> >(nStrikes_)),
42 floatingSwitchStrike_(switchStrike == Null<Rate>() ? true : false), capFlooMatrixNotInitialized_(true),
43 switchStrike_(switchStrike), accuracy_(accuracy), maxIter_(maxIter), inputVolatilityType_(type),
44 inputDisplacement_(displacement) {
51 Real firstGuess = 0.14;
64 Rate averageAtmOptionletRate = 0.0;
85 volQuotes_[i][j] = shared_ptr<SimpleQuote>(
new SimpleQuote());
107 Real previousCapFloorPrice = 0.0;
125 capFloorType = capFloorType == CapFloor::Cap ? CapFloor::Floor : CapFloor::Cap;
127 QL_REQUIRE(ok,
"Failed to strip Caplet vols");
138 const Handle<YieldTermStructure>& discountCurve, Real firstGuess)
const {
143 Option::Type optionletType = capFloorType == CapFloor::Floor ? Option::Put : Option::Call;
145 Real previousCapFloorPrice = 0.0;
151 Real capFloorPrice = capFloor.NPV();
152 Real optionletPrice = std::max(0.0, capFloorPrice - previousCapFloorPrice);
153 previousCapFloorPrice = capFloorPrice;
159 out[i] = blackFormulaImpliedStdDev(optionletType, strike,
atmOptionletRate_[i], optionletPrice,
168 }
catch (std::exception& ) {
CapFloorMatrix capFloors_
const Matrix & capletVols() const
void performCalculations() const override
bool floatingSwitchStrike_
const Real inputDisplacement_
Rate switchStrike() const
std::vector< std::vector< QuantLib::ext::shared_ptr< SimpleQuote > > > volQuotes_
std::vector< std::vector< QuantLib::ext::shared_ptr< PricingEngine > > > capFloorEngines_
const Matrix & optionletPrices() const
bool capFlooMatrixNotInitialized_
OptionletStripper1(const QuantLib::ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &, const QuantLib::ext::shared_ptr< IborIndex > &index, Rate switchStrikes=Null< Rate >(), Real accuracy=1.0e-6, Natural maxIter=100, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0, const optional< VolatilityType > targetVolatilityType=boost::none, const optional< Real > targetDisplacement=boost::none)
bool stripOptionlets(std::vector< Real > &, CapFloor::Type, Size, const Handle< YieldTermStructure > &, Real) const
const Matrix & capFloorPrices() const
const Handle< YieldTermStructure > & discountCurve() const
const VolatilityType inputVolatilityType_
const Matrix & capFloorVolatilities() const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
std::vector< Period > capFloorLengths_
Handle< YieldTermStructure > discount_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
std::vector< Time > optionletTimes_
const VolatilityType volatilityType_
virtual void populateDates() const
Method to populate the dates, times and accruals that can be overridden in derived classes.
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
ext::shared_ptr< IborIndex > index_
std::vector< std::vector< QuantLib::ext::shared_ptr< QuantLib::CapFloor > > > CapFloorMatrix
Optionlet (caplet/floorlet) volatility strippers.