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
CommoditySwaptionBaseEngine Class Reference

Commodity Swaption Engine base class. More...

#include <qle/pricingengines/commodityswaptionengine.hpp>

+ Inheritance diagram for CommoditySwaptionBaseEngine:
+ Collaboration diagram for CommoditySwaptionBaseEngine:

Public Member Functions

 CommoditySwaptionBaseEngine (const Handle< YieldTermStructure > &discountCurve, const Handle< QuantLib::BlackVolTermStructure > &vol, Real beta=0.0)
 

Protected Member Functions

QuantLib::Size fixedLegIndex () const
 
QuantLib::Real fixedLegValue (QuantLib::Size fixedLegIndex) const
 Give back the fixed leg price at the swaption expiry time. More...
 
QuantLib::Real strike (QuantLib::Size fixedLegIndex) const
 
QuantLib::Real rho (const QuantLib::Date &ed_1, const QuantLib::Date &ed_2) const
 
bool averaging (QuantLib::Size floatLegIndex) const
 

Protected Attributes

Handle< YieldTermStructure > discountCurve_
 
Handle< QuantLib::BlackVolTermStructure > volStructure_
 
Real beta_
 

Detailed Description

Commodity Swaption Engine base class.

Correlation is parametrized as rho(s, t) = exp(-beta * abs(s - t)) where s and t are times to futures expiry. This is described in detail in the ORE+ Product Catalogue.

Definition at line 39 of file commodityswaptionengine.hpp.

Constructor & Destructor Documentation

◆ CommoditySwaptionBaseEngine()

CommoditySwaptionBaseEngine ( const Handle< YieldTermStructure > &  discountCurve,
const Handle< QuantLib::BlackVolTermStructure > &  vol,
Real  beta = 0.0 
)

Definition at line 77 of file commodityswaptionengine.cpp.

79 : discountCurve_(discountCurve), volStructure_(vol), beta_(beta) {
80 QL_REQUIRE(beta_ >= 0.0, "beta >= 0 required, found " << beta_);
81 registerWith(discountCurve_);
82 registerWith(volStructure_);
83}
Handle< QuantLib::BlackVolTermStructure > volStructure_

Member Function Documentation

◆ fixedLegIndex()

Size fixedLegIndex ( ) const
protected

Performs checks on the underlying swap to ensure that:

  • it has two legs with a commodity fixed leg against a commodity floating leg
  • every cashflow on the commodity floating leg is either averaging or non-averaging Returns the index of the commodity fixed leg. Based on the checks, the commodity floating leg is the other leg.

Definition at line 85 of file commodityswaptionengine.cpp.

85 {
86
87 Size fixedLegIndex = Null<Size>();
88 bool haveFloatingLeg = false;
89
90 QL_REQUIRE(arguments_.legs.size() == 2, "Two legs expected but found " << arguments_.legs.size());
91
92 // Check both legs and populate the index of the fixed leg.
93 for (Size i = 0; i < 2; i++) {
94 QuantLib::ext::shared_ptr<CashFlow> cf = arguments_.legs[i].front();
95 if (QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow> flow =
96 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(cf)) {
97 haveFloatingLeg = true;
98 checkCashflows<CommodityIndexedAverageCashFlow>(arguments_.legs[i]);
99 } else if (QuantLib::ext::shared_ptr<CommodityIndexedCashFlow> flow =
100 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(cf)) {
101 haveFloatingLeg = true;
102 checkCashflows<CommodityIndexedCashFlow>(arguments_.legs[i]);
103 } else {
104 fixedLegIndex = i;
105 }
106 }
107
108 QL_REQUIRE(haveFloatingLeg, "CommoditySwaptionBaseEngine: expected the swap to have a commodity floating leg");
109 QL_REQUIRE(fixedLegIndex != Null<Size>(), "CommoditySwaptionBaseEngine: expected the swap to have a fixed leg");
110
111 return fixedLegIndex;
112}
Swap::arguments * arguments_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixedLegValue()

Real fixedLegValue ( QuantLib::Size  fixedLegIndex) const
protected

Give back the fixed leg price at the swaption expiry time.

Definition at line 114 of file commodityswaptionengine.cpp.

114 {
115
116 // Return the commodity fixed leg value at the swaption expiry time.
117 // This is the quantity K^{*} in the ORE+ Product Catalogue.
118 Real value = 0.0;
119
120 for (const QuantLib::ext::shared_ptr<CashFlow>& cf : arguments_.legs[fixedLegIndex]) {
121 value += cf->amount() * discountCurve_->discount(cf->date());
122 }
123
124 Date exercise = arguments_.exercise->dateAt(0);
125 Real discountExercise = discountCurve_->discount(exercise);
126 value /= discountExercise;
127
128 return value;
129}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strike()

Real strike ( QuantLib::Size  fixedLegIndex) const
protected

Need a strike price when querying the volatility surface in certain calculations. We take this as the first fixed leg period amount divided by the first floating leg quantity.

Definition at line 131 of file commodityswaptionengine.cpp.

131 {
132
133 // First calculation period fixed leg amount
134 Real amount = arguments_.legs[fixedLegIndex].front()->amount();
135
136 // Divide by first calculation period floating leg (full calculation period) quantity
137 Size idxFloat = fixedLegIndex == 0 ? 1 : 0;
138 QuantLib::ext::shared_ptr<CashFlow> cf = arguments_.legs[idxFloat].front();
139 if (QuantLib::ext::shared_ptr<CommodityIndexedCashFlow> ccf = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(cf)) {
140 return amount / ccf->periodQuantity();
141 } else if (QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow> ccf =
142 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(cf)) {
143 return amount / ccf->periodQuantity();
144 } else {
145 QL_FAIL("Expected a CommodityIndexedCashFlow or CommodityIndexedAverageCashFlow");
146 }
147}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rho()

Real rho ( const QuantLib::Date &  ed_1,
const QuantLib::Date &  ed_2 
) const
protected

Return the correlation between two future expiry dates ed_1 and ed_2

Definition at line 149 of file commodityswaptionengine.cpp.

149 {
150
151 if (beta_ == 0.0 || ed_1 == ed_2) {
152 return 1.0;
153 } else {
154 Time t_1 = volStructure_->timeFromReference(ed_1);
155 Time t_2 = volStructure_->timeFromReference(ed_2);
156 return exp(-beta_ * fabs(t_2 - t_1));
157 }
158}
CompiledFormula exp(CompiledFormula x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ averaging()

bool averaging ( QuantLib::Size  floatLegIndex) const
protected

Return true if floating leg is averaging, otherwise false.

Definition at line 160 of file commodityswaptionengine.cpp.

160 {
161
162 // All cashflows in the floating leg have been checked for same type so just use first one here
163 return static_cast<bool>(
164 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(arguments_.legs[floatLegIndex].front()));
165}
+ Here is the caller graph for this function:

Member Data Documentation

◆ discountCurve_

Handle<YieldTermStructure> discountCurve_
protected

Definition at line 69 of file commodityswaptionengine.hpp.

◆ volStructure_

Handle<QuantLib::BlackVolTermStructure> volStructure_
protected

Definition at line 70 of file commodityswaptionengine.hpp.

◆ beta_

Real beta_
protected

Definition at line 71 of file commodityswaptionengine.hpp.