Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
EquityLeg Class Reference

helper class building a sequence of equity coupons More...

#include <qle/cashflows/equitycoupon.hpp>

+ Collaboration diagram for EquityLeg:

Public Member Functions

 EquityLeg (const Schedule &schedule, const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > &equityCurve, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
 
EquityLegwithNotional (Real notional)
 
EquityLegwithNotionals (const std::vector< Real > &notionals)
 
EquityLegwithPaymentDayCounter (const DayCounter &dayCounter)
 
EquityLegwithPaymentAdjustment (BusinessDayConvention convention)
 
EquityLegwithPaymentLag (Natural paymentLag)
 
EquityLegwithPaymentCalendar (const Calendar &calendar)
 
EquityLegwithReturnType (EquityReturnType)
 
EquityLegwithDividendFactor (Real)
 
EquityLegwithInitialPrice (Real)
 
EquityLegwithInitialPriceIsInTargetCcy (bool)
 
EquityLegwithFixingDays (Natural)
 
EquityLegwithValuationSchedule (const Schedule &valuationSchedule)
 
EquityLegwithNotionalReset (bool)
 
EquityLegwithQuantity (Real)
 
 operator Leg () const
 

Private Attributes

Schedule schedule_
 
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2equityCurve_
 
QuantLib::ext::shared_ptr< FxIndexfxIndex_
 
std::vector< Real > notionals_
 
DayCounter paymentDayCounter_
 
Natural paymentLag_
 
BusinessDayConvention paymentAdjustment_
 
Calendar paymentCalendar_
 
EquityReturnType returnType_
 
Real initialPrice_
 
bool initialPriceIsInTargetCcy_
 
Real dividendFactor_
 
Natural fixingDays_
 
Schedule valuationSchedule_
 
bool notionalReset_
 
Real quantity_
 

Detailed Description

helper class building a sequence of equity coupons

Definition at line 161 of file equitycoupon.hpp.

Constructor & Destructor Documentation

◆ EquityLeg()

EquityLeg ( const Schedule &  schedule,
const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > &  equityCurve,
const QuantLib::ext::shared_ptr< FxIndex > &  fxIndex = nullptr 
)

Definition at line 179 of file equitycoupon.cpp.

181 : schedule_(schedule), equityCurve_(equityCurve), fxIndex_(fxIndex), paymentLag_(0), paymentAdjustment_(Following),
184 quantity_(Null<Real>()) {}
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
EquityReturnType returnType_

Member Function Documentation

◆ withNotional()

EquityLeg & withNotional ( Real  notional)

Definition at line 186 of file equitycoupon.cpp.

186 {
187 notionals_ = std::vector<Real>(1, notional);
188 return *this;
189}
std::vector< Real > notionals_

◆ withNotionals()

EquityLeg & withNotionals ( const std::vector< Real > &  notionals)

Definition at line 191 of file equitycoupon.cpp.

191 {
192 notionals_ = notionals;
193 return *this;
194}

◆ withPaymentDayCounter()

EquityLeg & withPaymentDayCounter ( const DayCounter &  dayCounter)

Definition at line 196 of file equitycoupon.cpp.

196 {
197 paymentDayCounter_ = dayCounter;
198 return *this;
199}
DayCounter paymentDayCounter_

◆ withPaymentAdjustment()

EquityLeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 201 of file equitycoupon.cpp.

201 {
202 paymentAdjustment_ = convention;
203 return *this;
204}

◆ withPaymentLag()

EquityLeg & withPaymentLag ( Natural  paymentLag)

Definition at line 206 of file equitycoupon.cpp.

206 {
207 paymentLag_ = paymentLag;
208 return *this;
209}

◆ withPaymentCalendar()

EquityLeg & withPaymentCalendar ( const Calendar &  calendar)

Definition at line 211 of file equitycoupon.cpp.

211 {
212 paymentCalendar_ = calendar;
213 return *this;
214}

◆ withReturnType()

EquityLeg & withReturnType ( EquityReturnType  returnType)

Definition at line 216 of file equitycoupon.cpp.

216 {
217 returnType_ = returnType;
218 return *this;
219}

◆ withDividendFactor()

EquityLeg & withDividendFactor ( Real  dividendFactor)

Definition at line 221 of file equitycoupon.cpp.

221 {
222 dividendFactor_ = dividendFactor;
223 return *this;
224}

◆ withInitialPrice()

EquityLeg & withInitialPrice ( Real  initialPrice)

Definition at line 226 of file equitycoupon.cpp.

226 {
227 initialPrice_ = initialPrice;
228 return *this;
229}

◆ withInitialPriceIsInTargetCcy()

EquityLeg & withInitialPriceIsInTargetCcy ( bool  initialPriceIsInTargetCcy)

Definition at line 231 of file equitycoupon.cpp.

231 {
232 initialPriceIsInTargetCcy_ = initialPriceIsInTargetCcy;
233 return *this;
234}

◆ withFixingDays()

EquityLeg & withFixingDays ( Natural  fixingDays)

Definition at line 236 of file equitycoupon.cpp.

236 {
237 fixingDays_ = fixingDays;
238 return *this;
239}

◆ withValuationSchedule()

EquityLeg & withValuationSchedule ( const Schedule &  valuationSchedule)

Definition at line 241 of file equitycoupon.cpp.

241 {
242 valuationSchedule_ = valuationSchedule;
243 return *this;
244}

◆ withNotionalReset()

EquityLeg & withNotionalReset ( bool  notionalReset)

Definition at line 246 of file equitycoupon.cpp.

246 {
247 notionalReset_ = notionalReset;
248 return *this;
249}

◆ withQuantity()

EquityLeg & withQuantity ( Real  quantity)

Definition at line 251 of file equitycoupon.cpp.

251 {
252 quantity_ = quantity;
253 return *this;
254}

◆ operator Leg()

operator Leg ( ) const

Definition at line 256 of file equitycoupon.cpp.

256 {
257
258 Leg cashflows;
259 Date startDate;
260 Date endDate;
261 Date paymentDate;
262
263 Calendar calendar;
264 if (!paymentCalendar_.empty()) {
265 calendar = paymentCalendar_;
266 } else {
267 calendar = schedule_.calendar();
268 }
269
270 Size numPeriods = schedule_.size() - 1;
271
272 if (valuationSchedule_.size() > 0) {
273 QL_REQUIRE(valuationSchedule_.size() == schedule_.size(),
274 "mismatch in valuationSchedule (" << valuationSchedule_.size() << ") and scheduleData ("
275 << schedule_.size() << ") sizes");
276 }
277
278 Date legFixingDate = Date();
279 if (valuationSchedule_.size() > 0)
280 legFixingDate = valuationSchedule_.dates().front();
281 else if (schedule_.size() > 0)
282 legFixingDate = equityCurve_->fixingCalendar().advance(schedule_.dates().front(),
283 -static_cast<Integer>(fixingDays_), Days, Preceding);
284 else
285 QL_FAIL("Cannot build equity leg, neither schedule nor valuation schedule are defined");
286
287 Real quantity = Null<Real>(), notional = Null<Real>(), legInitialNotional = Null<Real>();
288 if (notionalReset_) {
289 // We need a quantity in each coupon in this case
290 if (quantity_ != Null<Real>()) {
291 quantity = quantity_;
292 QL_REQUIRE(notionals_.empty(), "EquityLeg: notional and quantity are given at the same time");
293 } else {
294 // If we have a notional, but no quantity is given:
295 // a) Compute quantity from notional and initial price
296 // b) If initial price is missing, leave quantity undefined here:
297 // The coupon will compute it from legInitialNotional=notional and legFixingDate
298 QL_REQUIRE(!notionals_.empty(), "EquityLeg: can not compute qunantity, since no notional is given");
299 QL_REQUIRE(fxIndex_ == nullptr || initialPriceIsInTargetCcy_,
300 "EquityLeg: can not compute quantity from nominal when fx conversion is required");
301 notional = notionals_.front();
302 legInitialNotional = notional;
303 if (initialPrice_ != Null<Real>())
304 quantity = (initialPrice_ == 0) ? notional : notional / initialPrice_;
305 }
306 } else {
307 if (!notionals_.empty()) {
308 QL_REQUIRE(quantity_ == Null<Real>(), "EquityLeg: notional and quantity are given at the same time");
309 // notional is determined below in the loop over the periods
310 legInitialNotional = notionals_.front();
311 } else {
312 QL_REQUIRE(initialPrice_ != Null<Real>(), "EquityLeg: can not compute notional, since no intialPrice is given");
313 QL_REQUIRE(quantity_ != Null<Real>(), "EquityLeg: can not compute notional, since no quantity is given");
314 QL_REQUIRE(fxIndex_ == nullptr || initialPriceIsInTargetCcy_,
315 "EquityLeg: can not compute notional from quantity when fx conversion is required");
316 notional = (initialPrice_ == 0) ? quantity_ : quantity_ * initialPrice_;
317 }
318 }
319
320 for (Size i = 0; i < numPeriods; ++i) {
321 startDate = schedule_.date(i);
322 endDate = schedule_.date(i + 1);
323 paymentDate = calendar.advance(endDate, paymentLag_, Days, paymentAdjustment_);
324
325 Date fixingStartDate = Date();
326 Date fixingEndDate = Date();
327 if (valuationSchedule_.size() > 0) {
328 fixingStartDate = valuationSchedule_.date(i);
329 fixingEndDate = valuationSchedule_.date(i + 1);
330 }
331
332 Real initialPrice = (i == 0) ? initialPrice_ : Null<Real>();
333 bool initialPriceIsInTargetCcy = initialPrice != Null<Real>() ? initialPriceIsInTargetCcy_ : false;
334 if (!notionalReset_ && !notionals_.empty()) {
335 notional = detail::get(notionals_, i, 0.0);
336 }
337
338 QuantLib::ext::shared_ptr<EquityCoupon> cashflow(new EquityCoupon(
339 paymentDate, notional, startDate, endDate, fixingDays_, equityCurve_, paymentDayCounter_, returnType_,
340 dividendFactor_, notionalReset_, initialPrice, quantity, fixingStartDate, fixingEndDate, Date(), Date(),
341 Date(), fxIndex_, initialPriceIsInTargetCcy, legInitialNotional, legFixingDate));
342
343 QuantLib::ext::shared_ptr<EquityCouponPricer> pricer(new EquityCouponPricer);
344 cashflow->setPricer(pricer);
345
346 cashflows.push_back(cashflow);
347 }
348 return cashflows;
349}

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 182 of file equitycoupon.hpp.

◆ equityCurve_

QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equityCurve_
private

Definition at line 183 of file equitycoupon.hpp.

◆ fxIndex_

QuantLib::ext::shared_ptr<FxIndex> fxIndex_
private

Definition at line 184 of file equitycoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 185 of file equitycoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 186 of file equitycoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 187 of file equitycoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 188 of file equitycoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 189 of file equitycoupon.hpp.

◆ returnType_

EquityReturnType returnType_
private

Definition at line 190 of file equitycoupon.hpp.

◆ initialPrice_

Real initialPrice_
private

Definition at line 191 of file equitycoupon.hpp.

◆ initialPriceIsInTargetCcy_

bool initialPriceIsInTargetCcy_
private

Definition at line 192 of file equitycoupon.hpp.

◆ dividendFactor_

Real dividendFactor_
private

Definition at line 193 of file equitycoupon.hpp.

◆ fixingDays_

Natural fixingDays_
private

Definition at line 194 of file equitycoupon.hpp.

◆ valuationSchedule_

Schedule valuationSchedule_
private

Definition at line 195 of file equitycoupon.hpp.

◆ notionalReset_

bool notionalReset_
private

Definition at line 196 of file equitycoupon.hpp.

◆ quantity_

Real quantity_
private

Definition at line 197 of file equitycoupon.hpp.