Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equitycoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/cashflows/equitycoupon.hpp
20 \brief coupon paying the return on an equity
21 \ingroup cashflows
22*/
23
24#ifndef quantext_equity_coupon_hpp
25#define quantext_equity_coupon_hpp
26
27#include <ql/cashflows/coupon.hpp>
28#include <ql/handle.hpp>
29#include <ql/patterns/visitor.hpp>
30#include <ql/termstructures/yieldtermstructure.hpp>
31#include <ql/time/daycounter.hpp>
32#include <ql/time/schedule.hpp>
35
36namespace QuantExt {
37using namespace QuantLib;
38
39//! equity coupon pricer
40/*! \ingroup cashflows
41 */
42class EquityCouponPricer;
43
45
46EquityReturnType parseEquityReturnType(const std::string& str);
47std::ostream& operator<<(std::ostream& out, EquityReturnType t);
48
49//! equity coupon
50/*!
51 \ingroup cashflows
52*/
53class EquityCoupon : public Coupon, public Observer {
54public:
55 EquityCoupon(const Date& paymentDate, Real nominal, const Date& startDate, const Date& endDate, Natural fixingDays,
56 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve, const DayCounter& dayCounter,
57 EquityReturnType returnType, Real dividendFactor = 1.0, bool notionalReset = false,
58 Real initialPrice = Null<Real>(), Real quantity = Null<Real>(), const Date& fixingStartDate = Date(),
59 const Date& fixingEndDate = Date(), const Date& refPeriodStart = Date(),
60 const Date& refPeriodEnd = Date(), const Date& exCouponDate = Date(),
61 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex = nullptr, const bool initialPriceIsInTargetCcy = false,
62 Real legInitialNotional = Null<Real>(), const Date& legFixingDate = Date());
63
64 //! \name CashFlow interface
65 //@{
66 Real amount() const override { return rate() * nominal(); }
67 //@}
68
69 //! \name Coupon interface
70 //@{
71 // Real price(const Handle<YieldTermStructure>& discountingCurve) const;
72 DayCounter dayCounter() const override { return dayCounter_; }
73 Real accruedAmount(const Date&) const override;
74 // calculates the rate for the period, not yearly i.e. (S(t+1)-S(t))/S(t)
75 Rate rate() const override;
76 // nominal changes if notional is resettable
77 Real nominal() const override;
78 //@}
79
80 //! \name Inspectors
81 //@{
82 //! equity reference rate curve
83 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve() const { return equityCurve_; }
84 //! fx index curve
85 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex() const { return fxIndex_; }
86 //! the return type of the coupon
88 //! are dividends scaled (e.g. to account for tax)
89 Real dividendFactor() const { return dividendFactor_; }
90 //! The date at which the starting equity price is fixed
91 Date fixingStartDate() const { return fixingStartDate_; }
92 //! The date at which performance is measured
93 Date fixingEndDate() const { return fixingEndDate_; }
94 //! return both fixing dates
95 std::vector<Date> fixingDates() const;
96 //! initial price
97 Real initialPrice() const;
98 //! initial price is in target ccy (if applicable, i.e. if fxIndex != null, otherwise ignored)
99 bool initialPriceIsInTargetCcy() const;
100 //! Number of equity shares held
101 Real quantity() const;
102 //! FX conversion rate (or 1.0 if not applicable)
103 Real fxRate() const;
104 //! This function is called for other coupon types
105 Date fixingDate() const {
106 QL_FAIL("Equity Coupons have 2 fixings, not 1.");
107 return Date();
108 }
109 //! Initial notional of the equity leg, to compute quantity if not provided in the resetting case
111 //! Fixing date of the first equity coupon, to compute quantity if not provided in the resetting case
112 Date legFixingDate() const { return legFixingDate_; }
113 //@}
114
115 //! \name Observer interface
116 //@{
117 void update() override { notifyObservers(); }
118 //@}
119
120 //! \name Visitability
121 //@{
122 virtual void accept(AcyclicVisitor&) override;
123 //@}
124 void setPricer(const QuantLib::ext::shared_ptr<EquityCouponPricer>&);
125 QuantLib::ext::shared_ptr<EquityCouponPricer> pricer() const;
126
127protected:
128 QuantLib::ext::shared_ptr<EquityCouponPricer> pricer_;
129 Natural fixingDays_;
130 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equityCurve_;
131 DayCounter dayCounter_;
137 mutable Real quantity_;
140 Natural paymentLag_;
141 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
144};
145
146// inline definitions
147
148inline void EquityCoupon::accept(AcyclicVisitor& v) {
149 Visitor<EquityCoupon>* v1 = dynamic_cast<Visitor<EquityCoupon>*>(&v);
150 if (v1 != 0)
151 v1->visit(*this);
152 else
153 Coupon::accept(v);
154}
155
156inline QuantLib::ext::shared_ptr<EquityCouponPricer> EquityCoupon::pricer() const { return pricer_; }
157
158//! helper class building a sequence of equity coupons
159/*! \ingroup cashflows
160 */
162public:
163 EquityLeg(const Schedule& schedule, const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve,
164 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex = nullptr);
165 EquityLeg& withNotional(Real notional);
166 EquityLeg& withNotionals(const std::vector<Real>& notionals);
167 EquityLeg& withPaymentDayCounter(const DayCounter& dayCounter);
168 EquityLeg& withPaymentAdjustment(BusinessDayConvention convention);
169 EquityLeg& withPaymentLag(Natural paymentLag);
170 EquityLeg& withPaymentCalendar(const Calendar& calendar);
175 EquityLeg& withFixingDays(Natural);
176 EquityLeg& withValuationSchedule(const Schedule& valuationSchedule);
178 EquityLeg& withQuantity(Real);
179 operator Leg() const;
180
181private:
182 Schedule schedule_;
183 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equityCurve_;
184 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
185 std::vector<Real> notionals_;
187 Natural paymentLag_;
188 BusinessDayConvention paymentAdjustment_;
194 Natural fixingDays_;
198};
199
200} // namespace QuantExt
201
202#endif
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
Date fixingDate() const
This function is called for other coupon types.
void setPricer(const QuantLib::ext::shared_ptr< EquityCouponPricer > &)
EquityReturnType returnType() const
the return type of the coupon
QuantLib::ext::shared_ptr< EquityCouponPricer > pricer() const
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > & equityCurve() const
equity reference rate curve
std::vector< Date > fixingDates() const
return both fixing dates
Date legFixingDate() const
Fixing date of the first equity coupon, to compute quantity if not provided in the resetting case.
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
fx index curve
void update() override
Real dividendFactor() const
are dividends scaled (e.g. to account for tax)
bool initialPriceIsInTargetCcy() const
initial price is in target ccy (if applicable, i.e. if fxIndex != null, otherwise ignored)
Rate rate() const override
Real amount() const override
virtual void accept(AcyclicVisitor &) override
Date fixingEndDate() const
The date at which performance is measured.
Real fxRate() const
FX conversion rate (or 1.0 if not applicable)
Real nominal() const override
EquityReturnType returnType_
Real legInitialNotional() const
Initial notional of the equity leg, to compute quantity if not provided in the resetting case.
DayCounter dayCounter() const override
Real accruedAmount(const Date &) const override
QuantLib::ext::shared_ptr< EquityCouponPricer > pricer_
Real quantity() const
Number of equity shares held.
Date fixingStartDate() const
The date at which the starting equity price is fixed.
Real initialPrice() const
initial price
helper class building a sequence of equity coupons
EquityLeg & withInitialPriceIsInTargetCcy(bool)
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
BusinessDayConvention paymentAdjustment_
EquityLeg & withDividendFactor(Real)
EquityLeg & withPaymentCalendar(const Calendar &calendar)
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
EquityLeg & withNotional(Real notional)
EquityLeg & withFixingDays(Natural)
std::vector< Real > notionals_
EquityReturnType returnType_
EquityLeg & withNotionalReset(bool)
EquityLeg & withQuantity(Real)
EquityLeg & withNotionals(const std::vector< Real > &notionals)
EquityLeg & withInitialPrice(Real)
EquityLeg & withPaymentDayCounter(const DayCounter &dayCounter)
EquityLeg & withValuationSchedule(const Schedule &valuationSchedule)
EquityLeg & withPaymentAdjustment(BusinessDayConvention convention)
EquityLeg & withPaymentLag(Natural paymentLag)
EquityLeg & withReturnType(EquityReturnType)
DayCounter paymentDayCounter_
equity index class for holding equity fixing histories and forwarding.
FX index class.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
EquityReturnType parseEquityReturnType(const std::string &str)