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

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

#include <qle/cashflows/equitymargincoupon.hpp>

+ Collaboration diagram for EquityMarginLeg:

Public Member Functions

 EquityMarginLeg (const Schedule &schedule, const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > &equityCurve, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
 
EquityMarginLegwithCouponRates (Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
 
EquityMarginLegwithCouponRates (const std::vector< Rate > &, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
 
EquityMarginLegwithCouponRates (const InterestRate &)
 
EquityMarginLegwithCouponRates (const std::vector< InterestRate > &)
 
EquityMarginLegwithInitialMarginFactor (const Real &marginFactor)
 
EquityMarginLegwithNotional (Real notional)
 
EquityMarginLegwithNotionals (const std::vector< Real > &notionals)
 
EquityMarginLegwithPaymentDayCounter (const DayCounter &dayCounter)
 
EquityMarginLegwithPaymentAdjustment (BusinessDayConvention convention)
 
EquityMarginLegwithPaymentLag (Natural paymentLag)
 
EquityMarginLegwithPaymentCalendar (const Calendar &calendar)
 
EquityMarginLegwithTotalReturn (bool)
 
EquityMarginLegwithDividendFactor (Real)
 
EquityMarginLegwithInitialPrice (Real)
 
EquityMarginLegwithInitialPriceIsInTargetCcy (bool)
 
EquityMarginLegwithFixingDays (Natural)
 
EquityMarginLegwithValuationSchedule (const Schedule &valuationSchedule)
 
EquityMarginLegwithNotionalReset (bool)
 
EquityMarginLegwithQuantity (Real)
 
EquityMarginLegwithMultiplier (Real)
 
 operator Leg () const
 

Private Attributes

std::vector< InterestRate > couponRates_
 
Real marginFactor_
 
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_
 
bool isTotalReturn_
 
Real initialPrice_
 
bool initialPriceIsInTargetCcy_
 
Real dividendFactor_
 
Natural fixingDays_
 
Schedule valuationSchedule_
 
bool notionalReset_
 
Real quantity_
 
Real multiplier_
 

Detailed Description

helper class building a sequence of equity margin coupons

Definition at line 153 of file equitymargincoupon.hpp.

Constructor & Destructor Documentation

◆ EquityMarginLeg()

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

Definition at line 126 of file equitymargincoupon.cpp.

128 : schedule_(schedule), equityCurve_(equityCurve), fxIndex_(fxIndex) {}
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_

Member Function Documentation

◆ withCouponRates() [1/4]

EquityMarginLeg & withCouponRates ( Rate  ,
const DayCounter &  paymentDayCounter,
Compounding  comp = Simple,
Frequency  freq = Annual 
)

◆ withCouponRates() [2/4]

EquityMarginLeg & withCouponRates ( const std::vector< Rate > &  ,
const DayCounter &  paymentDayCounter,
Compounding  comp = Simple,
Frequency  freq = Annual 
)

◆ withCouponRates() [3/4]

EquityMarginLeg & withCouponRates ( const InterestRate &  i)

Definition at line 139 of file equitymargincoupon.cpp.

139 {
140 couponRates_.resize(1);
141 couponRates_[0] = i;
142 return *this;
143}
std::vector< InterestRate > couponRates_

◆ withCouponRates() [4/4]

EquityMarginLeg & withCouponRates ( const std::vector< InterestRate > &  interestRates)

Definition at line 155 of file equitymargincoupon.cpp.

156 {
157 couponRates_ = interestRates;
158 return *this;
159}

◆ withInitialMarginFactor()

EquityMarginLeg & withInitialMarginFactor ( const Real &  marginFactor)

Definition at line 161 of file equitymargincoupon.cpp.

161 {
162 marginFactor_ = i;
163 return *this;
164}

◆ withNotional()

EquityMarginLeg & withNotional ( Real  notional)

Definition at line 166 of file equitymargincoupon.cpp.

166 {
167 notionals_ = std::vector<Real>(1, notional);
168 return *this;
169}
std::vector< Real > notionals_

◆ withNotionals()

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

Definition at line 171 of file equitymargincoupon.cpp.

171 {
172 notionals_ = notionals;
173 return *this;
174}

◆ withPaymentDayCounter()

EquityMarginLeg & withPaymentDayCounter ( const DayCounter &  dayCounter)

Definition at line 176 of file equitymargincoupon.cpp.

176 {
177 paymentDayCounter_ = dayCounter;
178 return *this;
179}

◆ withPaymentAdjustment()

EquityMarginLeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 181 of file equitymargincoupon.cpp.

181 {
182 paymentAdjustment_ = convention;
183 return *this;
184}
BusinessDayConvention paymentAdjustment_

◆ withPaymentLag()

EquityMarginLeg & withPaymentLag ( Natural  paymentLag)

Definition at line 186 of file equitymargincoupon.cpp.

186 {
187 paymentLag_ = paymentLag;
188 return *this;
189}

◆ withPaymentCalendar()

EquityMarginLeg & withPaymentCalendar ( const Calendar &  calendar)

Definition at line 191 of file equitymargincoupon.cpp.

191 {
192 paymentCalendar_ = calendar;
193 return *this;
194}

◆ withTotalReturn()

EquityMarginLeg & withTotalReturn ( bool  totalReturn)

Definition at line 196 of file equitymargincoupon.cpp.

196 {
197 isTotalReturn_ = totalReturn;
198 return *this;
199}

◆ withDividendFactor()

EquityMarginLeg & withDividendFactor ( Real  dividendFactor)

Definition at line 201 of file equitymargincoupon.cpp.

201 {
202 dividendFactor_ = dividendFactor;
203 return *this;
204}

◆ withInitialPrice()

EquityMarginLeg & withInitialPrice ( Real  initialPrice)

Definition at line 206 of file equitymargincoupon.cpp.

206 {
207 initialPrice_ = initialPrice;
208 return *this;
209}

◆ withInitialPriceIsInTargetCcy()

EquityMarginLeg & withInitialPriceIsInTargetCcy ( bool  initialPriceIsInTargetCcy)

Definition at line 216 of file equitymargincoupon.cpp.

216 {
217 initialPriceIsInTargetCcy_ = initialPriceIsInTargetCcy;
218 return *this;
219}

◆ withFixingDays()

EquityMarginLeg & withFixingDays ( Natural  fixingDays)

Definition at line 221 of file equitymargincoupon.cpp.

221 {
222 fixingDays_ = fixingDays;
223 return *this;
224}

◆ withValuationSchedule()

EquityMarginLeg & withValuationSchedule ( const Schedule &  valuationSchedule)

Definition at line 226 of file equitymargincoupon.cpp.

226 {
227 valuationSchedule_ = valuationSchedule;
228 return *this;
229}

◆ withNotionalReset()

EquityMarginLeg & withNotionalReset ( bool  notionalReset)

Definition at line 231 of file equitymargincoupon.cpp.

231 {
232 notionalReset_ = notionalReset;
233 return *this;
234}

◆ withQuantity()

EquityMarginLeg & withQuantity ( Real  quantity)

Definition at line 236 of file equitymargincoupon.cpp.

236 {
237 quantity_ = quantity;
238 return *this;
239}

◆ withMultiplier()

EquityMarginLeg & withMultiplier ( Real  multiplier)

Definition at line 211 of file equitymargincoupon.cpp.

211 {
212 multiplier_ = multiplier;
213 return *this;
214}

◆ operator Leg()

operator Leg ( ) const

Definition at line 241 of file equitymargincoupon.cpp.

241 {
242
243 Leg cashflows;
244 Date startDate;
245 Date endDate;
246 Date paymentDate;
247 InterestRate rate = couponRates_[0];
248
249 Calendar calendar;
250 if (!paymentCalendar_.empty()) {
251 calendar = paymentCalendar_;
252 } else {
253 calendar = schedule_.calendar();
254 }
255
256 Size numPeriods = schedule_.size() - 1;
257
258 if (valuationSchedule_.size() > 0) {
259 QL_REQUIRE(valuationSchedule_.size() == schedule_.size(),
260 "mismatch in valuationSchedule (" << valuationSchedule_.size() << ") and scheduleData (" << schedule_.size() << ") sizes");
261 }
262
263 for (Size i = 0; i < numPeriods; ++i) {
264 startDate = schedule_.date(i);
265 endDate = schedule_.date(i + 1);
266 paymentDate = calendar.advance(endDate, paymentLag_, Days, paymentAdjustment_);
267
268 Date fixingStartDate = Date();
269 Date fixingEndDate = Date();
270 if (valuationSchedule_.size() > 0) {
271 fixingStartDate = valuationSchedule_.date(i);
272 fixingEndDate = valuationSchedule_.date(i + 1);
273 }
274
275 InterestRate rate;
276 if ((i-1) < couponRates_.size())
277 rate = couponRates_[i-1];
278 else
279 rate = couponRates_.back();
280
281 Real initialPrice = (i == 0) ? initialPrice_ : Null<Real>();
282 bool initialPriceIsInTargetCcy = initialPrice != Null<Real>() ? initialPriceIsInTargetCcy_ : false;
283 Real quantity = Null<Real>(), notional = Null<Real>();
284 if (notionalReset_) {
285 if (quantity_ != Null<Real>()) {
286 quantity = quantity_;
287 QL_REQUIRE(notionals_.empty(), "EquityMarginLeg: notional and quantity are given at the same time");
288 } else {
289 QL_REQUIRE(fxIndex_ == nullptr,
290 "EquityMarginLeg: can not compute quantity from nominal when fx conversion is required");
291 QL_REQUIRE(!notionals_.empty(), "EquityMarginLeg: can not compute qunantity, since no notional is given");
292 quantity = notionals_.front() ;
293 }
294 } else {
295 if (!notionals_.empty()) {
296 notional = detail::get(notionals_, i, 0.0);
297 QL_REQUIRE(quantity_ == Null<Real>(), "EquityMarginLeg: notional and quantity are given at the same time");
298 } else {
299 QL_REQUIRE(fxIndex_ == nullptr,
300 "EquityMarginLeg: can not compute notional from quantity when fx conversion is required");
301 QL_REQUIRE(quantity_ != Null<Real>(),
302 "EquityMarginLeg: can not compute notional, since no quantity is given");
303 notional = quantity_;
304 }
305 }
306
307 QuantLib::ext::shared_ptr<EquityMarginCoupon> cashflow(
308 new EquityMarginCoupon(paymentDate, notional, rate, marginFactor_, startDate, endDate, fixingDays_, equityCurve_, paymentDayCounter_,
309 isTotalReturn_, dividendFactor_, notionalReset_, initialPrice, quantity, fixingStartDate,
310 fixingEndDate, Date(), Date(), Date(), multiplier_, fxIndex_, initialPriceIsInTargetCcy));
311
312 QuantLib::ext::shared_ptr<EquityMarginCouponPricer> pricer(new EquityMarginCouponPricer);
313 cashflow->setPricer(pricer);
314
315 cashflows.push_back(cashflow);
316 }
317 return cashflows;
318}

Member Data Documentation

◆ couponRates_

std::vector<InterestRate> couponRates_
private

Definition at line 191 of file equitymargincoupon.hpp.

◆ marginFactor_

Real marginFactor_
private

Definition at line 192 of file equitymargincoupon.hpp.

◆ schedule_

Schedule schedule_
private

Definition at line 193 of file equitymargincoupon.hpp.

◆ equityCurve_

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

Definition at line 194 of file equitymargincoupon.hpp.

◆ fxIndex_

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

Definition at line 195 of file equitymargincoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 196 of file equitymargincoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 197 of file equitymargincoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 198 of file equitymargincoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 199 of file equitymargincoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 200 of file equitymargincoupon.hpp.

◆ isTotalReturn_

bool isTotalReturn_
private

Definition at line 201 of file equitymargincoupon.hpp.

◆ initialPrice_

Real initialPrice_
private

Definition at line 202 of file equitymargincoupon.hpp.

◆ initialPriceIsInTargetCcy_

bool initialPriceIsInTargetCcy_
private

Definition at line 203 of file equitymargincoupon.hpp.

◆ dividendFactor_

Real dividendFactor_
private

Definition at line 204 of file equitymargincoupon.hpp.

◆ fixingDays_

Natural fixingDays_
private

Definition at line 205 of file equitymargincoupon.hpp.

◆ valuationSchedule_

Schedule valuationSchedule_
private

Definition at line 206 of file equitymargincoupon.hpp.

◆ notionalReset_

bool notionalReset_
private

Definition at line 207 of file equitymargincoupon.hpp.

◆ quantity_

Real quantity_
private

Definition at line 208 of file equitymargincoupon.hpp.

◆ multiplier_

Real multiplier_
private

Definition at line 209 of file equitymargincoupon.hpp.