21#include <ql/indexes/iborindex.hpp>
22#include <ql/instruments/makecapfloor.hpp>
23#include <ql/math/solvers1d/brent.hpp>
24#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/volatility/capfloor/capfloortermvolcurve.hpp>
27#include <ql/termstructures/volatility/optionlet/optionletstripper1.hpp>
28#include <ql/termstructures/volatility/optionlet/optionletstripper2.hpp>
29#include <ql/termstructures/volatility/optionlet/spreadedoptionletvol.hpp>
30#include <ql/termstructures/volatility/optionlet/strippedoptionletadapter.hpp>
37 const ext::shared_ptr<OptionletStripper1>& optionletStripper1,
40 optionletStripper1->iborIndex(),
42 optionletStripper1->volatilityType(),
43 optionletStripper1->displacement()),
44 stripper1_(optionletStripper1), atmCapFloorTermVolCurve_(atmCapFloorTermVolCurve),
45 dc_(stripper1_->termVolSurface()->dayCounter()),
46 nOptionExpiries_(atmCapFloorTermVolCurve->optionTenors().size()),
47 atmCapFloorStrikes_(nOptionExpiries_), atmCapFloorPrices_(nOptionExpiries_),
48 spreadsVolImplied_(nOptionExpiries_), caps_(nOptionExpiries_) {
52 QL_REQUIRE(
dc_ == atmCapFloorTermVolCurve->dayCounter(),
53 "different day counters provided");
70 const std::vector<Period>& optionExpiriesTenors =
72 const std::vector<Time>& optionExpiriesTimes =
77 optionExpiriesTimes[j], 33.3333);
78 ext::shared_ptr<BlackCapFloorEngine> engine(
new
82 optionExpiriesTenors[j],
99 if (i<=
caps_[j]->floatingLeg().size()) {
105 std::vector<Rate>::const_iterator previous =
126 Volatility guess = 0.0001, minSpread = -0.1, maxSpread = 0.1;
131 minSpread, maxSpread);
157 const ext::shared_ptr<OptionletStripper1>& optionletStripper1,
158 ext::shared_ptr<CapFloor> cap,
160 : cap_(
std::move(cap)), targetValue_(targetValue) {
161 ext::shared_ptr<OptionletVolatilityStructure> adapter(
new
163 adapter->enableExtrapolation();
169 ext::shared_ptr<OptionletVolatilityStructure> spreadedAdapter(
new
173 ext::shared_ptr<BlackCapFloorEngine> engine(
new
175 optionletStripper1->iborIndex()->forwardingTermStructure(),
178 cap_->setPricingEngine(engine);
183 if (s!=spreadQuote_->value())
184 spreadQuote_->setValue(s);
185 return cap_->NPV()-targetValue_;
Black-formula cap/floor engine.
Shared handle to an observable.
virtual void calculate() const
MakeCapFloor & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
ext::shared_ptr< CapFloor > cap_
ObjectiveFunction(const ext::shared_ptr< OptionletStripper1 > &, ext::shared_ptr< CapFloor >, Real targetValue)
Real operator()(Volatility spreadVol) const
ext::shared_ptr< SimpleQuote > spreadQuote_
void performCalculations() const override
std::vector< Volatility > spreadsVolImplied_
const ext::shared_ptr< OptionletStripper1 > stripper1_
std::vector< Rate > atmCapFloorStrikes_
std::vector< Real > atmCapFloorPrices_
std::vector< ext::shared_ptr< CapFloor > > caps_
std::vector< Volatility > spreadsVolImplied() const
std::vector< Rate > atmCapFloorStrikes() const
std::vector< Volatility > spreadsVol() const
OptionletStripper2(const ext::shared_ptr< OptionletStripper1 > &optionletStripper1, const Handle< CapFloorTermVolCurve > &atmCapFloorTermVolCurve)
const Handle< CapFloorTermVolCurve > atmCapFloorTermVolCurve_
std::vector< Real > atmCapFloorPrices() const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
ext::shared_ptr< IborIndex > iborIndex_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
std::vector< std::vector< Rate > > optionletStrikes_
Volatility volatility(const Period &optionTenor, Rate strike, bool extrapolate=false) const
returns the volatility for a given option tenor and strike rate
void setMaxEvaluations(Size evaluations)
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Interest-rate term structure.
Real Volatility
volatility
std::size_t Size
size of a container