24#include <ql/cashflows/cashflows.hpp>
25#include <ql/quotes/derivedquote.hpp>
26#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
27#include <ql/utilities/null_deleter.hpp>
29#include <boost/bind/bind.hpp>
30#include <ql/functional.hpp>
38 const Period& rateComputationPeriod, QuantLib::Rate strike,
39 const Handle<Quote>& quote,
40 const QuantLib::ext::shared_ptr<QuantLib::OvernightIndex>& index,
41 const Handle<YieldTermStructure>& discountingCurve,
bool moving,
43 QuantLib::VolatilityType quoteVolatilityType, QuantLib::Real quoteDisplacement)
44 : RelativeDateBootstrapHelper<OptionletVolatilityStructure>(
45 Handle<Quote>(
QuantLib::ext::make_shared<DerivedQuote<
QuantLib::ext::function<Real(Real)>>>(
47 type_(type), tenor_(tenor), rateComputationPeriod_(rateComputationPeriod), strike_(strike), index_(index),
48 discountHandle_(discountingCurve), moving_(moving), effectiveDate_(effectiveDate), quoteType_(quoteType),
49 quoteVolatilityType_(quoteVolatilityType), quoteDisplacement_(quoteDisplacement), rawQuote_(quote),
54 "Cannot have CapFloorHelper type 'Automatic' with quote type of Premium");
58 "A fixed effective date does not make sense for a moving helper");
71 Date today = Settings::instance().evaluationDate();
85 QL_REQUIRE(!
capFloor_.empty(),
"OISCapFloorHelper: got empty leg.");
87 maturityDate_ = CashFlows::maturityDate(
capFloor_);
90 auto cfon = QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCoupon>(
capFloor_.front());
91 QL_REQUIRE(cfon,
"OISCapFloorHelper: Expected the first cashflow on the ois cap floor instrument to be a "
92 "CappedFlooredOvernightIndexedCoupon");
93 earliestDate_ = std::max(today, cfon->underlying()->fixingDates().front());
96 auto cfon2 = QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCoupon>(
capFloor_.back());
97 QL_REQUIRE(cfon2,
"OISCapFloorHelper: Expected the final cashflow on the cap floor instrument to be a "
98 "CappedFlooredOvernightIndexedCoupon");
99 pillarDate_ = latestDate_ = latestRelevantDate_ = cfon2->underlying()->fixingDates().back();
118 CapFloor::Type capFloorType = atm >
strike_ ? CapFloor::Floor : CapFloor::Cap;
126 auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c);
130 QuantLib::ext::shared_ptr<OptionletVolatilityStructure> temp(ovts, null_deleter());
132 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::setTermStructure(ovts);
134 auto pricer = QuantLib::ext::make_shared<BlackOvernightIndexedCouponPricer>(
ovtsHandle_);
136 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
138 f->setPricer(pricer);
145 Handle<OptionletVolatilityStructure> constOvts;
147 constOvts = Handle<OptionletVolatilityStructure>(QuantLib::ext::make_shared<ConstantOptionletVolatility>(
150 constOvts = Handle<OptionletVolatilityStructure>(QuantLib::ext::make_shared<ConstantOptionletVolatility>(
151 0, NullCalendar(), Unadjusted,
rawQuote_, Actual365Fixed(), Normal));
153 auto pricer = QuantLib::ext::make_shared<BlackOvernightIndexedCouponPricer>(constOvts,
true);
155 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
157 f->setPricer(pricer);
164 QL_REQUIRE(termStructure_ != 0,
"CapFloorHelper's optionlet volatility term structure has not been set");
166 auto f = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c);
175 if (Visitor<OISCapFloorHelper>* v1 =
dynamic_cast<Visitor<OISCapFloorHelper>*
>(&v))
178 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::accept(v);
black coupon pricer for capped / floored ON indexed coupons
QuoteType
Enum to indicate the type of the quote provided with the CapFloorHelper.
MakeOISCapFloor & withEffectiveDate(const Date &effectiveDate)
MakeOISCapFloor & withTelescopicValueDates(bool telescopicValueDates)
QuantLib::Handle< QuantLib::Quote > rawQuote_
QuantLib::Period rateComputationPeriod_
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_
QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > index_
QuantLib::Real quoteDisplacement_
void initializeDates() override
void setTermStructure(QuantLib::OptionletVolatilityStructure *ovts) override
CapFloorHelper::QuoteType quoteType_
OISCapFloorHelper(CapFloorHelper::Type type, const QuantLib::Period &tenor, const QuantLib::Period &rateComputationPeriod, QuantLib::Rate strike, const QuantLib::Handle< QuantLib::Quote > "e, const QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > &index, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve, bool moving=true, const QuantLib::Date &effectiveDate=QuantLib::Date(), CapFloorHelper::QuoteType quoteType=CapFloorHelper::Premium, QuantLib::VolatilityType quoteVolatilityType=QuantLib::Normal, QuantLib::Real quoteDisplacement=0.0)
OISCapFloorHelper, similar to CapFloorHelper.
QuantLib::Real impliedQuote() const override
QuantLib::VolatilityType quoteVolatilityType_
CapFloorHelper::Type type_
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
helper class to instantiate standard market OIS cap / floors
Leg getOisCapFloorUnderlying(const Leg &oisCapFloor)
get the underlying ON coupons from an OIS cf
Helper for bootstrapping optionlet volatilties from ois cap floor volatilities.
coupon paying the compounded daily overnight rate, copy of QL class, added includeSpread flag