Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equitymargincouponpricer.cpp
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
20
21namespace QuantExt {
22
24
25 Calendar calendar = equityCurve_->fixingCalendar();
26
27 Date startDate = coupon_->fixingStartDate();
28 // the final date in the period is treated differently
29 Date endDate = equityCurve_->fixingCalendar().advance(coupon_->fixingEndDate(), -1 * Days);
30
31 Real equityPrice = equityCurve_->fixing(endDate, false, false);
32 Real dividends = 0.0;
33 Real fx = fxIndex_ ? fxIndex_->fixing(coupon_->fixingEndDate()) : 1.0;
34 // Dividends that are already fixed dividends + yield accrued over remaining period.
35 // yield accrued = Forward without dividend yield - Forward with dividend yield
36 if (isTotalReturn_) {
37 // projected dividends from today until the fixing end date
38 dividends = equityCurve_->fixing(endDate, false, true) -
39 equityCurve_->fixing(endDate, false, false);
40 // subtract projected dividends from today until the fixing start date
41 if (coupon_->fixingStartDate() > Settings::instance().evaluationDate()) {
42 dividends -= (equityCurve_->fixing(startDate, false, true) -
43 equityCurve_->fixing(startDate, false, false));
44 }
45 // add historical dividends
46 dividends += equityCurve_->dividendsBetweenDates(startDate, endDate);
47 }
48
49 Real rate = (equityPrice + dividends * dividendFactor_) * fx * fixedRate_.dayCounter().yearFraction(startDate, endDate) * marginFactor_;
50
51 // on the valuation date we return the initialPrice
52 startDate = endDate;
53 endDate = coupon_->fixingEndDate();
54 fx = fxIndex_ ? fxIndex_->fixing(coupon_->fixingEndDate()) : 1.0;
55 rate += initialPrice_ * fx * fixedRate_.dayCounter().yearFraction(startDate, endDate) * marginFactor_;
56
57 return rate * fixedRate_;
58}
59
61
62 coupon_ = &coupon;
63
64 marginFactor_ = coupon.marginFactor();
65 fixedRate_ = coupon.fixedRate();
66 equityCurve_ = QuantLib::ext::dynamic_pointer_cast<EquityIndex2>(coupon.equityCurve());
67 fxIndex_ = QuantLib::ext::dynamic_pointer_cast<FxIndex>(coupon.fxIndex());
70 initialPrice_ = coupon.initialPrice();
71}
72
73} // namespace QuantExt
const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > & equityCurve() const
equity reference rate curve
const QuantLib::ext::shared_ptr< FxIndex > & fxIndex() const
fx index curve
Real dividendFactor() const
are dividends scaled (e.g. to account for tax)
Date fixingEndDate() const
The date at which performance is measured.
bool isTotalReturn() const
total return or price return?
Date fixingStartDate() const
The date at which the starting equity price is fixed.
Real initialPrice() const
initial price
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
virtual void initialize(const EquityMarginCoupon &coupon)
QuantLib::ext::shared_ptr< EquityIndex2 > equityCurve_
Pricer for equity margin coupons.