19#include <boost/bind/bind.hpp>
20#include <ql/functional.hpp>
21#include <ql/instruments/makecapfloor.hpp>
22#include <ql/pricingengines/capfloor/bacheliercapfloorengine.hpp>
23#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
24#include <ql/quotes/derivedquote.hpp>
25#include <ql/utilities/null_deleter.hpp>
40 const QuantLib::ext::shared_ptr<IborIndex>& iborIndex,
41 const Handle<YieldTermStructure>& discountingCurve,
bool moving,
42 const QuantLib::Date& effectiveDate,
QuoteType quoteType,
43 QuantLib::VolatilityType quoteVolatilityType, QuantLib::Real quoteDisplacement,
44 bool endOfMonth,
bool firstCapletExcluded)
45 : RelativeDateBootstrapHelper<OptionletVolatilityStructure>(
46 Handle<Quote>(
QuantLib::ext::make_shared<DerivedQuote<
QuantLib::ext::function<Real(Real)> > >(
48 type_(type), tenor_(tenor), strike_(strike), iborIndex_(iborIndex), discountHandle_(discountingCurve),
49 moving_(moving), effectiveDate_(effectiveDate), quoteType_(quoteType), quoteVolatilityType_(quoteVolatilityType),
50 quoteDisplacement_(quoteDisplacement), endOfMonth_(endOfMonth), firstCapletExcluded_(firstCapletExcluded),
51 rawQuote_(quote), initialised_(false) {
54 QL_REQUIRE(
type_ !=
Automatic,
"Cannot have CapFloorHelper type 'Automatic' with quote type of Premium");
58 "A fixed effective date does not make sense for a moving helper");
70 CapFloor::Type capFloorType = CapFloor::Cap;
72 capFloorType = CapFloor::Floor;
86 maturityDate_ =
capFloor_->maturityDate();
89 const Leg& leg =
capFloor_->floatingLeg();
92 QuantLib::ext::shared_ptr<CashFlow> cf = leg.front();
93 QuantLib::ext::shared_ptr<FloatingRateCoupon> frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(cf);
94 QL_REQUIRE(frc,
"Expected the first cashflow on the cap floor instrument to be a FloatingRateCoupon");
95 earliestDate_ = frc->fixingDate();
99 frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(cf);
100 QL_REQUIRE(frc,
"Expected the final cashflow on the cap floor instrument to be a FloatingRateCoupon");
101 pillarDate_ = latestDate_ = latestRelevantDate_ = frc->fixingDate();
120 CapFloor::Type capFloorType = atm >
strike_ ? CapFloor::Floor : CapFloor::Cap;
132 QuantLib::ext::shared_ptr<OptionletVolatilityStructure> temp(ovts, null_deleter());
136 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::setTermStructure(ovts);
139 if (ovts->volatilityType() == ShiftedLognormal) {
149 capFloorCopy_->setPricingEngine(QuantLib::ext::make_shared<BlackCapFloorEngine>(
159 QL_REQUIRE(termStructure_ != 0,
"CapFloorHelper's optionlet volatility term structure has not been set");
165 if (Visitor<CapFloorHelper>* v1 =
dynamic_cast<Visitor<CapFloorHelper>*
>(&v))
168 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::accept(v);
185 return out <<
"Floor";
187 return out <<
"Automatic";
189 QL_FAIL(
"Unknown CapFloorHelper::Type (" << Integer(type) <<
")");
196 return out <<
"Volatility";
198 return out <<
"Premium";
200 QL_FAIL(
"Unknown CapFloorHelper::QuoteType (" << Integer(type) <<
")");
Helper for bootstrapping optionlet volatilities from cap floor volatilities.
QuantLib::Handle< QuantLib::Quote > rawQuote_
QuantLib::Real npv(QuantLib::Real quote)
A method to calculate the cap floor premium from a flat cap floor volatility value.
void accept(QuantLib::AcyclicVisitor &) override
QuantLib::Date effectiveDate_
bool firstCapletExcluded_
QuantLib::ext::shared_ptr< QuantLib::IborIndex > iborIndex_
CapFloorHelper(Type type, const QuantLib::Period &tenor, QuantLib::Rate strike, const QuantLib::Handle< QuantLib::Quote > "e, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &iborIndex, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve, bool moving=true, const QuantLib::Date &effectiveDate=QuantLib::Date(), QuoteType quoteType=Premium, QuantLib::VolatilityType quoteVolatilityType=QuantLib::Normal, QuantLib::Real quoteDisplacement=0.0, bool endOfMonth=false, bool firstCapletExcluded=true)
QuantLib::Real quoteDisplacement_
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloorCopy_
A copy of the underlying instrument that is used in the npv method.
void initializeDates() override
RelativeDateBootstrapHelper interface.
void setTermStructure(QuantLib::OptionletVolatilityStructure *ovts) override
Sets the helper's OptionletVolatilityStructure to ovts and sets up the pricing engine for capFloor_.
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor_
The underlying instrument.
QuoteType
Enum to indicate the type of the quote provided with the CapFloorHelper.
QuantLib::Real impliedQuote() const override
Returns the capFloor_ instrument's premium.
QuantLib::VolatilityType quoteVolatilityType_
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
The OptionletVolatilityStructure Handle that we link to the capFloor_ instrument.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)