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

#include <qle/pricingengines/commodityapoengine.hpp>

+ Inheritance diagram for CommodityAveragePriceOptionBaseEngine:
+ Collaboration diagram for CommodityAveragePriceOptionBaseEngine:

Public Member Functions

 CommodityAveragePriceOptionBaseEngine (const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve, const QuantLib::Handle< QuantExt::BlackScholesModelWrapper > &model, QuantLib::Real beta=0.0)
 
 CommodityAveragePriceOptionBaseEngine (const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve, const QuantLib::Handle< QuantLib::BlackVolTermStructure > &vol, QuantLib::Real beta=0.0)
 

Protected Member Functions

QuantLib::Real rho (const QuantLib::Date &ed_1, const QuantLib::Date &ed_2) const
 Return the correlation between two future expiry dates ed_1 and ed_2. More...
 
bool isModelDependent () const
 
bool barrierTriggered (const Real price, const bool logPrice) const
 
bool alive (const bool barrierTriggered) const
 

Protected Attributes

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

Detailed Description

Commodity APO Engine base class Correlation is parametrized as \(\rho(s, t) = \exp(-\beta * \abs(s - t))\) where \(s\) and \(t\) are times to futures expiry.

Definition at line 75 of file commodityapoengine.hpp.

Constructor & Destructor Documentation

◆ CommodityAveragePriceOptionBaseEngine() [1/2]

CommodityAveragePriceOptionBaseEngine ( const QuantLib::Handle< QuantLib::YieldTermStructure > &  discountCurve,
const QuantLib::Handle< QuantExt::BlackScholesModelWrapper > &  model,
QuantLib::Real  beta = 0.0 
)

◆ CommodityAveragePriceOptionBaseEngine() [2/2]

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

Definition at line 152 of file commodityapoengine.cpp.

155 : discountCurve_(discountCurve), volStructure_(vol), beta_(beta) {
156 QL_REQUIRE(beta_ >= 0.0, "beta >= 0 required, found " << beta_);
157 registerWith(discountCurve_);
158 registerWith(volStructure_);
159}
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
QuantLib::Handle< QuantLib::BlackVolTermStructure > volStructure_

Member Function Documentation

◆ 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 161 of file commodityapoengine.cpp.

161 {
162 if (beta_ == 0.0 || ed_1 == ed_2) {
163 return 1.0;
164 } else {
165 Time t_1 = volStructure_->timeFromReference(ed_1);
166 Time t_2 = volStructure_->timeFromReference(ed_2);
167 return exp(-beta_ * fabs(t_2 - t_1));
168 }
169}
CompiledFormula exp(CompiledFormula x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isModelDependent()

bool isModelDependent ( ) const
protected

In certain cases, the APO value is not model dependent. This method returns true if the APO value is model dependent. If the APO value is not model dependent, this method returns false and populates the results with the model independent value.

Definition at line 171 of file commodityapoengine.cpp.

171 {
172
173 // Discount factor to the APO payment date
174 Real discount = discountCurve_->discount(arguments_.flow->date());
175
176 // Valuation date
177 Date today = Settings::instance().evaluationDate();
178
179 // If all pricing dates are on or before today. This can happen when the APO payment date is a positive number
180 // of days after the final APO pricing date and today is in between.
181 if (today >= arguments_.flow->indices().rbegin()->first) {
182
183 // Put call indicator
184 Real omega = arguments_.type == Option::Call ? 1.0 : -1.0;
185
186 // Populate the result value
187 Real payoff = arguments_.flow->gearing() * max(omega * (arguments_.accrued - arguments_.effectiveStrike), 0.0);
188 results_.value = arguments_.quantity * payoff * discount;
189
190 return false;
191 }
192
193 // If a portion of the average price has already accrued, the effective strike of the APO will
194 // have changed by the accrued amount. The strike could be non-positive.
195 Real effectiveStrike = arguments_.effectiveStrike - arguments_.accrued;
196 if (effectiveStrike <= 0.0) {
197
198 // If the effective strike is <= 0, put payoff is 0.0 and call payoff is [A - K]
199 if (arguments_.type == Option::Call) {
200 results_.value = (arguments_.flow->amount() - arguments_.quantity * arguments_.strikePrice) * discount;
201 } else {
202 results_.value = 0.0;
203 }
204
205 return false;
206 }
207
208 // If we get to here, value is model dependent except the option was knocked out
209
210 bool barrierTriggered = false;
211 Real lastFixing = 0.0;
212
213 for (const auto& kv : arguments_.flow->indices()) {
214 // Break on the first pricing date that is greater than today
215 if (today < kv.first) {
216 break;
217 }
218 // Update accrued where pricing date is on or before today
219 Real fxRate{1.};
220 if(arguments_.fxIndex)
221 fxRate=arguments_.fxIndex->fixing(kv.first);
222 lastFixing = fxRate*kv.second->fixing(kv.first);
223 if (arguments_.barrierStyle == Exercise::American)
224 barrierTriggered = barrierTriggered || this->barrierTriggered(lastFixing, false);
225 }
226
227 if (arguments_.barrierStyle == Exercise::European)
228 barrierTriggered = this->barrierTriggered(lastFixing, false);
229
230 if(barrierTriggered && (arguments_.barrierType == Barrier::DownOut || arguments_.barrierType == Barrier::UpOut)) {
231 results_.value = 0.0;
232 return false;
233 }
234
235 return true;
236}
const Instrument::results * results_
Definition: cdsoption.cpp:81
bool barrierTriggered(const Real price, const bool logPrice) const
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)
Swap::arguments * arguments_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ barrierTriggered()

bool barrierTriggered ( const Real  price,
const bool  logPrice 
) const
protected

Check barriers on given (log-)price

Definition at line 238 of file commodityapoengine.cpp.

238 {
239 if (arguments_.barrierLevel == Null<Real>())
240 return false;
241 Real tmp = logPrice ? logBarrier_ : arguments_.barrierLevel;
242 if (arguments_.barrierType == Barrier::DownIn || arguments_.barrierType == Barrier::DownOut)
243 return price <= tmp;
244 else if (arguments_.barrierType == Barrier::UpIn || arguments_.barrierType == Barrier::UpOut)
245 return price >= tmp;
246 return false;
247}
+ Here is the caller graph for this function:

◆ alive()

bool alive ( const bool  barrierTriggered) const
protected

Check whether option is alive depending on whether barrier was triggered

Definition at line 249 of file commodityapoengine.cpp.

249 {
250 if (arguments_.barrierLevel == Null<Real>())
251 return true;
252 return ((arguments_.barrierType == Barrier::DownIn || arguments_.barrierType == Barrier::UpIn) &&
254 ((arguments_.barrierType == Barrier::DownOut || arguments_.barrierType == Barrier::UpOut) &&
256}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ discountCurve_

QuantLib::Handle<QuantLib::YieldTermStructure> discountCurve_
protected

Definition at line 102 of file commodityapoengine.hpp.

◆ volStructure_

QuantLib::Handle<QuantLib::BlackVolTermStructure> volStructure_
protected

Definition at line 103 of file commodityapoengine.hpp.

◆ beta_

QuantLib::Real beta_
protected

Definition at line 104 of file commodityapoengine.hpp.

◆ logBarrier_

QuantLib::Real logBarrier_
mutableprotected

Definition at line 106 of file commodityapoengine.hpp.