21#include <ql/pricingengines/blackformula.hpp>
22#include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp>
27 const ext::shared_ptr<QuantLib::YoYInflationIndex>& index,
28 const Handle<QuantLib::YoYOptionletVolatilitySurface>& volatility,
const Handle<YieldTermStructure>& discountCurve)
29 : index_(index), volatility_(volatility), discountCurve_(discountCurve) {
47 Real value = 0.0, vega = 0.0;
48 Size optionlets =
arguments_.startDates.size();
49 std::vector<Real> values(optionlets, 0.0);
50 std::vector<Real> stdDevs(optionlets, 0.0);
51 std::vector<Real> forwards(optionlets, 0.0);
52 YoYInflationCapFloor::Type type =
arguments_.type;
54 Handle<YoYInflationTermStructure> yoyTS =
index()->yoyInflationTermStructure();
56 QL_REQUIRE(!discountTS.empty(),
"YoYInflationCapFloorEngine: No discount curve given.");
57 Date settlement = discountTS->referenceDate();
59 for (Size i = 0; i < optionlets; ++i) {
61 if (paymentDate > settlement) {
62 DiscountFactor d =
arguments_.nominals[i] *
arguments_.gearings[i] * discountTS->discount(paymentDate) *
72 forwards[i] = yoyTS->yoyRate(
arguments_.fixingDates[i], Period(0, Days));
73 Rate forward = forwards[i];
78 sqrtTime = std::sqrt(
volatility_->timeFromBase(fixingDate));
81 if (type == YoYInflationCapFloor::Cap || type == YoYInflationCapFloor::Collar) {
84 stdDevs[i] = std::sqrt(
volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
88 values[i] =
optionletImpl(Option::Call, strike, forward, stdDevs[i], d);
89 vega +=
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
91 if (type == YoYInflationCapFloor::Floor || type == YoYInflationCapFloor::Collar) {
94 stdDevs[i] = std::sqrt(
volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
96 Real floorlet =
optionletImpl(Option::Put, strike, forward, stdDevs[i], d);
97 Real floorletVega =
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
98 if (type == YoYInflationCapFloor::Floor) {
100 vega -= floorletVega;
103 values[i] -= floorlet;
104 vega -=
optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
112 results_.additionalResults[
"vega"] = vega;
113 results_.additionalResults[
"optionletsPrice"] = values;
114 results_.additionalResults[
"optionletsAtmForward"] = forwards;
115 if (type != YoYInflationCapFloor::Collar)
116 results_.additionalResults[
"optionletsStdDev"] = stdDevs;
123 const ext::shared_ptr<QuantLib::YoYInflationIndex>& index,
124 const Handle<QuantLib::YoYOptionletVolatilitySurface>& volatility,
const Handle<YieldTermStructure>& discountCurve)
129 return blackFormula(type, strike, forward, stdDev, d);
133 Real sqrtTime, Real d)
const {
134 return blackFormulaStdDevDerivative(type, strike, forward, stdDev, d) * sqrtTime;
137YoYInflationUnitDisplacedBlackCapFloorEngine ::YoYInflationUnitDisplacedBlackCapFloorEngine(
138 const ext::shared_ptr<QuantLib::YoYInflationIndex>& index,
139 const Handle<QuantLib::YoYOptionletVolatilitySurface>& volatility,
const Handle<YieldTermStructure>& discountCurve)
143 Real stdDev, Real d)
const {
145 return blackFormula(type, strike + 1.0, forward + 1.0, stdDev, d);
149 Real stdDev, Real sqrtTime, Real d)
const {
150 return blackFormulaStdDevDerivative(type, strike + 1.0, forward + 1.0, stdDev, d) * sqrtTime;
154 const ext::shared_ptr<QuantLib::YoYInflationIndex>& index,
155 const Handle<QuantLib::YoYOptionletVolatilitySurface>& volatility,
const Handle<YieldTermStructure>& discountCurve)
160 return bachelierBlackFormula(type, strike, forward, stdDev, d);
164 Real sqrtTime, Real d)
const {
165 return bachelierBlackFormulaStdDevDerivative(strike, forward, stdDev, d) * sqrtTime;
const Instrument::results * results_
virtual Real optionletImpl(Option::Type, Real strike, Real forward, Real stdDev, Real d) const override
YoYInflationBachelierCapFloorEngine(const ext::shared_ptr< QuantLib::YoYInflationIndex > &, const Handle< QuantLib::YoYOptionletVolatilitySurface > &, const Handle< YieldTermStructure > &discountCurve)
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const override
virtual Real optionletImpl(Option::Type, Real strike, Real forward, Real stdDev, Real d) const override
YoYInflationBlackCapFloorEngine(const ext::shared_ptr< QuantLib::YoYInflationIndex > &, const Handle< QuantLib::YoYOptionletVolatilitySurface > &, const Handle< YieldTermStructure > &discountCurve)
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const override
Base YoY inflation cap/floor engine.
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const =0
YoYInflationCapFloorEngine(const ext::shared_ptr< QuantLib::YoYInflationIndex > &, const Handle< QuantLib::YoYOptionletVolatilitySurface > &vol, const Handle< YieldTermStructure > &discountCurve)
Handle< YieldTermStructure > discountCurve_
void calculate() const override
virtual Real optionletImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real d) const =0
descendents only need to implement this
void setVolatility(const Handle< QuantLib::YoYOptionletVolatilitySurface > &vol)
ext::shared_ptr< QuantLib::YoYInflationIndex > index() const
ext::shared_ptr< QuantLib::YoYInflationIndex > index_
Handle< QuantLib::YoYOptionletVolatilitySurface > volatility_
virtual Real optionletImpl(Option::Type, Real strike, Real forward, Real stdDev, Real d) const override
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const override
Inflation cap/floor engines from QuantLib, with optional external discount curve.
Swap::arguments * arguments_