Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
YoYInflationCapFloorEngine Class Referenceabstract

Base YoY inflation cap/floor engine. More...

#include <qle/pricingengines/inflationcapfloorengines.hpp>

+ Inheritance diagram for YoYInflationCapFloorEngine:
+ Collaboration diagram for YoYInflationCapFloorEngine:

Public Member Functions

 YoYInflationCapFloorEngine (const ext::shared_ptr< QuantLib::YoYInflationIndex > &, const Handle< QuantLib::YoYOptionletVolatilitySurface > &vol, const Handle< YieldTermStructure > &discountCurve)
 
ext::shared_ptr< QuantLib::YoYInflationIndex > index () const
 
Handle< QuantLib::YoYOptionletVolatilitySurface > volatility () const
 
void setVolatility (const Handle< QuantLib::YoYOptionletVolatilitySurface > &vol)
 
void calculate () const override
 

Protected Member Functions

virtual Real optionletImpl (Option::Type type, Rate strike, Rate forward, Real stdDev, Real d) const =0
 descendents only need to implement this More...
 
virtual Real optionletVegaImpl (Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const =0
 

Protected Attributes

ext::shared_ptr< QuantLib::YoYInflationIndex > index_
 
Handle< QuantLib::YoYOptionletVolatilitySurface > volatility_
 
Handle< YieldTermStructure > discountCurve_
 

Detailed Description

Base YoY inflation cap/floor engine.

This class doesn't know yet what sort of vol it is. The inflation index must be linked to a yoy inflation term structure. This provides the curves, hence the call uses a shared_ptr<> not a handle<> to the index.

Definition at line 47 of file inflationcapfloorengines.hpp.

Constructor & Destructor Documentation

◆ YoYInflationCapFloorEngine()

YoYInflationCapFloorEngine ( const ext::shared_ptr< QuantLib::YoYInflationIndex > &  index,
const Handle< QuantLib::YoYOptionletVolatilitySurface > &  vol,
const Handle< YieldTermStructure > &  discountCurve 
)

Definition at line 26 of file inflationcapfloorengines.cpp.

29 : index_(index), volatility_(volatility), discountCurve_(discountCurve) {
30 registerWith(index_);
31 registerWith(volatility_);
32 registerWith(discountCurve_);
33}
Handle< QuantLib::YoYOptionletVolatilitySurface > volatility() const
ext::shared_ptr< QuantLib::YoYInflationIndex > index() const
ext::shared_ptr< QuantLib::YoYInflationIndex > index_
Handle< QuantLib::YoYOptionletVolatilitySurface > volatility_

Member Function Documentation

◆ index()

ext::shared_ptr< QuantLib::YoYInflationIndex > index ( ) const

Definition at line 53 of file inflationcapfloorengines.hpp.

53{ return index_; }
+ Here is the caller graph for this function:

◆ volatility()

Handle< QuantLib::YoYOptionletVolatilitySurface > volatility ( ) const

Definition at line 54 of file inflationcapfloorengines.hpp.

54{ return volatility_; }

◆ setVolatility()

void setVolatility ( const Handle< QuantLib::YoYOptionletVolatilitySurface > &  vol)

Definition at line 35 of file inflationcapfloorengines.cpp.

35 {
36 if (!volatility_.empty())
37 unregisterWith(volatility_);
38 volatility_ = v;
39 registerWith(volatility_);
40 update();
41}

◆ calculate()

void calculate ( ) const
override

Definition at line 43 of file inflationcapfloorengines.cpp.

43 {
44
45 // copy black version then adapt to others
46
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;
53
54 Handle<YoYInflationTermStructure> yoyTS = index()->yoyInflationTermStructure();
55 Handle<YieldTermStructure> discountTS = discountCurve_;
56 QL_REQUIRE(!discountTS.empty(), "YoYInflationCapFloorEngine: No discount curve given.");
57 Date settlement = discountTS->referenceDate();
58
59 for (Size i = 0; i < optionlets; ++i) {
60 Date paymentDate = arguments_.payDates[i];
61 if (paymentDate > settlement) { // discard expired caplets
62 DiscountFactor d = arguments_.nominals[i] * arguments_.gearings[i] * discountTS->discount(paymentDate) *
63 arguments_.accrualTimes[i];
64
65 // We explicitly have the index and assume that
66 // the fixing is natural, i.e. no convexity adjustment.
67 // If that was required then we would also need
68 // nominal vols in the pricing engine, i.e. a different engine.
69 // This also means that we do not need the coupon to have
70 // a pricing engine to return the swaplet rate and then
71 // the adjusted fixing in the instrument.
72 forwards[i] = yoyTS->yoyRate(arguments_.fixingDates[i], Period(0, Days));
73 Rate forward = forwards[i];
74
75 Date fixingDate = arguments_.fixingDates[i];
76 Time sqrtTime = 0.0;
77 if (fixingDate > volatility_->baseDate()) {
78 sqrtTime = std::sqrt(volatility_->timeFromBase(fixingDate));
79 }
80
81 if (type == YoYInflationCapFloor::Cap || type == YoYInflationCapFloor::Collar) {
82 Rate strike = arguments_.capRates[i];
83 if (sqrtTime > 0.0) {
84 stdDevs[i] = std::sqrt(volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
85 }
86
87 // sttDev=0 for already-fixed dates so everything on forward
88 values[i] = optionletImpl(Option::Call, strike, forward, stdDevs[i], d);
89 vega += optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
90 }
91 if (type == YoYInflationCapFloor::Floor || type == YoYInflationCapFloor::Collar) {
92 Rate strike = arguments_.floorRates[i];
93 if (sqrtTime > 0.0) {
94 stdDevs[i] = std::sqrt(volatility_->totalVariance(fixingDate, strike, Period(0, Days)));
95 }
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) {
99 values[i] = floorlet;
100 vega -= floorletVega;
101 } else {
102 // a collar is long a cap and short a floor
103 values[i] -= floorlet;
104 vega -= optionletVegaImpl(Option::Call, strike, forward, stdDevs[i], sqrtTime, d);
105 }
106 }
107 value += values[i];
108 }
109 }
110 results_.value = value;
111
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;
117}
const Instrument::results * results_
Definition: cdsoption.cpp:81
virtual Real optionletVegaImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real sqrtTime, Real d) const =0
virtual Real optionletImpl(Option::Type type, Rate strike, Rate forward, Real stdDev, Real d) const =0
descendents only need to implement this
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Definition: inflation.cpp:183
Swap::arguments * arguments_
+ Here is the call graph for this function:

◆ optionletImpl()

virtual Real optionletImpl ( Option::Type  type,
Rate  strike,
Rate  forward,
Real  stdDev,
Real  d 
) const
protectedpure virtual

descendents only need to implement this

+ Here is the caller graph for this function:

◆ optionletVegaImpl()

virtual Real optionletVegaImpl ( Option::Type  type,
Rate  strike,
Rate  forward,
Real  stdDev,
Real  sqrtTime,
Real  d 
) const
protectedpure virtual

Member Data Documentation

◆ index_

ext::shared_ptr<QuantLib::YoYInflationIndex> index_
protected

Definition at line 66 of file inflationcapfloorengines.hpp.

◆ volatility_

Handle<QuantLib::YoYOptionletVolatilitySurface> volatility_
protected

Definition at line 67 of file inflationcapfloorengines.hpp.

◆ discountCurve_

Handle<YieldTermStructure> discountCurve_
protected

Definition at line 68 of file inflationcapfloorengines.hpp.