Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equitymargincoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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/equitymargincoupon.hpp
20 \brief coupon paying the return on an equity
21 \ingroup cashflows
22*/
23
24#ifndef quantext_equity_margin_coupon_hpp
25#define quantext_equity_margin_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 margin coupon pricer
40/*! \ingroup cashflows
41 */
42class EquityMarginCouponPricer;
43
44//! equity coupon
45/*!
46 \ingroup cashflows
47*/
48class EquityMarginCoupon : public Coupon, public Observer {
49public:
50 EquityMarginCoupon(const Date& paymentDate, Real nominal, Rate rate, Real marginFactor, const Date& startDate, const Date& endDate, Natural fixingDays,
51 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve, const DayCounter& dayCounter,
52 bool isTotalReturn = false, Real dividendFactor = 1.0, bool notionalReset = false,
53 Real initialPrice = Null<Real>(), Real quantity = Null<Real>(), const Date& fixingStartDate = Date(),
54 const Date& fixingEndDate = Date(), const Date& refPeriodStart = Date(),
55 const Date& refPeriodEnd = Date(), const Date& exCouponDate = Date(), Real multiplier = Null<Real>(),
56 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex = nullptr, const bool initialPriceIsInTargetCcy = false);
57
58 //! \name CashFlow interface
59 //@{
60 //@}
61
62 //! \name Coupon interface
63 //@{
64 DayCounter dayCounter() const override { return dayCounter_; }
65 Real accruedAmount(const Date&) const override;
66 Real amount() const override;
67 // calculates the rate for the period, not yearly i.e. (S(t+1)-S(t))/S(t)
68 Rate rate() const override;
69 // nominal changes if notional is resettable
70 Real nominal() const override;
71 //@}
72
73 //! \name Inspectors
74 //@{
75 //! equity reference rate curve
76 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve() const { return equityCurve_; }
77 //! fx index curve
78 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex() const { return fxIndex_; }
79 //! total return or price return?
80 bool isTotalReturn() const { return isTotalReturn_; }
81 //! are dividends scaled (e.g. to account for tax)
82 Real dividendFactor() const { return dividendFactor_; }
83 //! The date at which the starting equity price is fixed
84 Date fixingStartDate() const { return fixingStartDate_; }
85 //! The date at which performance is measured
86 Date fixingEndDate() const { return fixingEndDate_; }
87 //! return both fixing dates
88 std::vector<Date> fixingDates() const;
89 //! initial price
90 Real initialPrice() const;
91 //! initial price is in target ccy (if applicable, i.e. if fxIndex != null, otherwise ignored)
92 bool initialPriceIsInTargetCcy() const;
93 //! Number of equity shares held
94 Real quantity() const { return quantity_; }
95 //! FX conversion rate (or 1.0 if not applicable)
96 Real fxRate() const;
97 //! This function is called for other coupon types
98 Date fixingDate() const {
99 QL_FAIL("Equity Coupons have 2 fixings, not 1.");
100 return Date();
101 }
102 Real marginFactor() const { return marginFactor_; }
103 InterestRate fixedRate() const { return fixedRate_; }
104 Real multiplier() const { return multiplier_; }
105 //@}
106
107 //! \name Observer interface
108 //@{
109 void update() override { notifyObservers(); }
110 //@}
111
112 //! \name Visitability
113 //@{
114 virtual void accept(AcyclicVisitor&) override;
115 //@}
116
117 void setPricer(const QuantLib::ext::shared_ptr<EquityMarginCouponPricer>&);
118 QuantLib::ext::shared_ptr<EquityMarginCouponPricer> pricer() const;
119
120protected:
121 QuantLib::ext::shared_ptr<EquityMarginCouponPricer> pricer_;
122 Natural fixingDays_;
123 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equityCurve_;
124 DayCounter dayCounter_;
133 Natural paymentLag_;
134 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
136 InterestRate fixedRate_;
138};
139
140// inline definitions
141
142inline void EquityMarginCoupon::accept(AcyclicVisitor& v) {
143 Visitor<EquityMarginCoupon>* v1 = dynamic_cast<Visitor<EquityMarginCoupon>*>(&v);
144 if (v1 != 0)
145 v1->visit(*this);
146 else
147 Coupon::accept(v);
148}
149
150//! helper class building a sequence of equity margin coupons
151/*! \ingroup cashflows
152 */
154public:
155 EquityMarginLeg(const Schedule& schedule, const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equityCurve,
156 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex = nullptr);
157
159 const DayCounter& paymentDayCounter,
160 Compounding comp = Simple,
161 Frequency freq = Annual);
162 EquityMarginLeg& withCouponRates(const std::vector<Rate>&,
163 const DayCounter& paymentDayCounter,
164 Compounding comp = Simple,
165 Frequency freq = Annual);
166 EquityMarginLeg& withCouponRates(const InterestRate&);
167 EquityMarginLeg& withCouponRates(const std::vector<InterestRate>&);
168
169 EquityMarginLeg& withInitialMarginFactor(const Real& marginFactor);
170
171 EquityMarginLeg& withNotional(Real notional);
172 EquityMarginLeg& withNotionals(const std::vector<Real>& notionals);
173 EquityMarginLeg& withPaymentDayCounter(const DayCounter& dayCounter);
174 EquityMarginLeg& withPaymentAdjustment(BusinessDayConvention convention);
175 EquityMarginLeg& withPaymentLag(Natural paymentLag);
176 EquityMarginLeg& withPaymentCalendar(const Calendar& calendar);
182 EquityMarginLeg& withValuationSchedule(const Schedule& valuationSchedule);
186
187 operator Leg() const;
188
189private:
190
191 std::vector<InterestRate> couponRates_;
193 Schedule schedule_;
194 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equityCurve_;
195 QuantLib::ext::shared_ptr<FxIndex> fxIndex_;
196 std::vector<Real> notionals_;
198 Natural paymentLag_;
199 BusinessDayConvention paymentAdjustment_;
205 Natural fixingDays_;
210};
211
212} // namespace QuantExt
213
214#endif
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
Date fixingDate() const
This function is called for other coupon types.
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
void setPricer(const QuantLib::ext::shared_ptr< EquityMarginCouponPricer > &)
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
fx index curve
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)
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)
DayCounter dayCounter() const override
bool isTotalReturn() const
total return or price return?
Real accruedAmount(const Date &) const override
QuantLib::ext::shared_ptr< EquityMarginCouponPricer > pricer_
Real quantity() const
Number of equity shares held.
QuantLib::ext::shared_ptr< EquityMarginCouponPricer > pricer() const
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 margin coupons
EquityMarginLeg & withPaymentCalendar(const Calendar &calendar)
EquityMarginLeg & withPaymentLag(Natural paymentLag)
EquityMarginLeg & withQuantity(Real)
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equityCurve_
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
EquityMarginLeg & withNotionalReset(bool)
EquityMarginLeg & withNotionals(const std::vector< Real > &notionals)
EquityMarginLeg & withFixingDays(Natural)
EquityMarginLeg & withCouponRates(const std::vector< Rate > &, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
std::vector< InterestRate > couponRates_
EquityMarginLeg & withDividendFactor(Real)
EquityMarginLeg & withInitialPrice(Real)
std::vector< Real > notionals_
EquityMarginLeg & withNotional(Real notional)
EquityMarginLeg & withInitialPriceIsInTargetCcy(bool)
EquityMarginLeg & withPaymentAdjustment(BusinessDayConvention convention)
EquityMarginLeg & withTotalReturn(bool)
EquityMarginLeg & withPaymentDayCounter(const DayCounter &dayCounter)
EquityMarginLeg & withMultiplier(Real)
EquityMarginLeg & withValuationSchedule(const Schedule &valuationSchedule)
EquityMarginLeg & withInitialMarginFactor(const Real &marginFactor)
EquityMarginLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
equity index class for holding equity fixing histories and forwarding.
FX index class.