Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cmbcoupon.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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#include <ql/cashflows/capflooredcoupon.hpp>
20#include <ql/cashflows/cashflowvectors.hpp>
22#include <utility>
23
24namespace QuantExt {
25
26CmbCoupon::CmbCoupon(const Date& paymentDate,
27 Real nominal,
28 const Date& startDate,
29 const Date& endDate,
30 Natural fixingDays,
31 const ext::shared_ptr<ConstantMaturityBondIndex>& bondIndex,
32 Real gearing,
33 Spread spread,
34 const Date& refPeriodStart,
35 const Date& refPeriodEnd,
36 const DayCounter& dayCounter,
37 bool isInArrears,
38 const Date& exCouponDate)
39 : FloatingRateCoupon(paymentDate, nominal, startDate, endDate,
40 fixingDays, bondIndex, gearing, spread,
41 refPeriodStart, refPeriodEnd,
42 dayCounter, isInArrears, exCouponDate),
43 bondIndex_(bondIndex) {
44 registerWith(bondIndex_);
45}
46
47void CmbCoupon::accept(AcyclicVisitor& v) {
48 auto* v1 = dynamic_cast<Visitor<CmbCoupon>*>(&v);
49 if (v1 != nullptr)
50 v1->visit(*this);
51 else
52 FloatingRateCoupon::accept(v);
53}
54
56 coupon_ = dynamic_cast<const CmbCoupon *>(&coupon);
57 QL_REQUIRE(coupon_, "CmbCouponPricer: expected CmbCoupon");
59 gearing_ = coupon_->gearing();
60 spread_ = coupon_->spread();
61 fixingDate_ = coupon_->fixingDate();
62}
63
65 return 0.0;
66}
67
69 return gearing_ * (index_->fixing(fixingDate_) + spread_);
70}
71
72Real CmbCouponPricer::capletPrice(Rate effectiveCap) const {
73 return 0.0;
74};
75
76Rate CmbCouponPricer::capletRate(Rate effectiveCap) const {
77 return 0.0;
78};
79
80Real CmbCouponPricer::floorletPrice(Rate effectiveFloor) const {
81 return 0.0;
82};
83
84Rate CmbCouponPricer::floorletRate(Rate effectiveFloor) const {
85 return 0.0;
86};
87
88void CmbCoupon::setPricer(const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
89 FloatingRateCoupon::setPricer(pricer);
90}
91
92CmbLeg::CmbLeg(Schedule schedule, std::vector<ext::shared_ptr<ConstantMaturityBondIndex>> bondIndices)
93 : schedule_(std::move(schedule)), bondIndices_(bondIndices),
94 paymentAdjustment_(Following), inArrears_(false), zeroPayments_(false) {
95 QL_REQUIRE(bondIndices_.size() == schedule_.size() - 1, "vector size mismatch between schedule ("
96 << schedule_.size() << ") and bond indices ("
97 << bondIndices_.size() << ")");
98}
99
101 notionals_ = std::vector<Real>(1, notional);
102 return *this;
103}
104
105CmbLeg& CmbLeg::withNotionals(const std::vector<Real>& notionals) {
106 notionals_ = notionals;
107 return *this;
108}
109
110CmbLeg& CmbLeg::withPaymentDayCounter(const DayCounter& dayCounter) {
111 paymentDayCounter_ = dayCounter;
112 return *this;
113}
114
115CmbLeg& CmbLeg::withPaymentAdjustment(BusinessDayConvention convention) {
116 paymentAdjustment_ = convention;
117 return *this;
118}
119
120CmbLeg& CmbLeg::withFixingDays(Natural fixingDays) {
121 fixingDays_ = std::vector<Natural>(1, fixingDays);
122 return *this;
123}
124
125CmbLeg& CmbLeg::withFixingDays(const std::vector<Natural>& fixingDays) {
126 fixingDays_ = fixingDays;
127 return *this;
128}
129
131 gearings_ = std::vector<Real>(1, gearing);
132 return *this;
133}
134
135CmbLeg& CmbLeg::withGearings(const std::vector<Real>& gearings) {
136 gearings_ = gearings;
137 return *this;
138}
139
141 spreads_ = std::vector<Spread>(1, spread);
142 return *this;
143}
144
145CmbLeg& CmbLeg::withSpreads(const std::vector<Spread>& spreads) {
146 spreads_ = spreads;
147 return *this;
148}
149
151 caps_ = std::vector<Rate>(1, cap);
152 return *this;
153}
154
155CmbLeg& CmbLeg::withCaps(const std::vector<Rate>& caps) {
156 caps_ = caps;
157 return *this;
158}
159
161 floors_ = std::vector<Rate>(1, floor);
162 return *this;
163}
164
165CmbLeg& CmbLeg::withFloors(const std::vector<Rate>& floors) {
166 floors_ = floors;
167 return *this;
168}
169
171 inArrears_ = flag;
172 return *this;
173}
174
176 zeroPayments_ = flag;
177 return *this;
178}
179
180CmbLeg& CmbLeg::withPaymentCalendar(const Calendar& cal) {
181 paymentCalendar_ = cal;
182 return *this;
183}
184
185CmbLeg& CmbLeg::withExCouponPeriod(const Period& period,
186 const Calendar& cal,
187 BusinessDayConvention convention,
188 bool endOfMonth) {
189 exCouponPeriod_ = period;
190 exCouponCalendar_ = cal;
191 exCouponAdjustment_ = convention;
192 exCouponEndOfMonth_ = endOfMonth;
193 return *this;
194}
195
196CmbLeg::operator Leg() const {
197 Leg leg;
198 for (Size i = 0; i < schedule_.size() - 1; i++) {
199 Date paymentDate = paymentCalendar_.adjust(schedule_[i + 1], paymentAdjustment_);
200 QuantLib::ext::shared_ptr<CmbCoupon> coupon
201 = QuantLib::ext::make_shared<CmbCoupon>(paymentDate, notionals_[i], schedule_[i], schedule_[i + 1],
202 fixingDays_[i], bondIndices_[i], gearings_[i], spreads_[i], Date(), Date(),
203 paymentDayCounter_, inArrears_);
204 auto pricer = QuantLib::ext::make_shared<CmbCouponPricer>();
205 coupon->setPricer(pricer);
206 leg.push_back(coupon);
207 }
208 return leg;
209}
210
211}
CMB coupon class.
Definition: cmbcoupon.hpp:33
const ext::shared_ptr< ConstantMaturityBondIndex > & bondIndex() const
Definition: cmbcoupon.hpp:55
CmbCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< ConstantMaturityBondIndex > &index, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const DayCounter &dayCounter=DayCounter(), bool isInArrears=false, const Date &exCouponDate=Date())
Definition: cmbcoupon.cpp:26
void accept(AcyclicVisitor &) override
Definition: cmbcoupon.cpp:47
ext::shared_ptr< ConstantMaturityBondIndex > bondIndex_
Definition: cmbcoupon.hpp:61
void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &pricer) override
Definition: cmbcoupon.cpp:88
Real capletPrice(Rate effectiveCap) const override
Definition: cmbcoupon.cpp:72
Rate floorletRate(Rate effectiveFloor) const override
Definition: cmbcoupon.cpp:84
ext::shared_ptr< ConstantMaturityBondIndex > index_
Definition: cmbcoupon.hpp:80
void initialize(const FloatingRateCoupon &coupon) override
Definition: cmbcoupon.cpp:55
const CmbCoupon * coupon_
Definition: cmbcoupon.hpp:79
Rate swapletRate() const override
Definition: cmbcoupon.cpp:68
Real floorletPrice(Rate effectiveFloor) const override
Definition: cmbcoupon.cpp:80
Real swapletPrice() const override
Definition: cmbcoupon.cpp:64
Rate capletRate(Rate effectiveCap) const override
Definition: cmbcoupon.cpp:76
helper class building a sequence of capped/floored cmb coupons
Definition: cmbcoupon.hpp:87
Schedule schedule_
Definition: cmbcoupon.hpp:113
BusinessDayConvention paymentAdjustment_
Definition: cmbcoupon.hpp:117
std::vector< Rate > caps_
Definition: cmbcoupon.hpp:122
std::vector< ext::shared_ptr< ConstantMaturityBondIndex > > bondIndices_
Definition: cmbcoupon.hpp:114
BusinessDayConvention exCouponAdjustment_
Definition: cmbcoupon.hpp:126
CmbLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth)
Definition: cmbcoupon.cpp:185
Calendar paymentCalendar_
Definition: cmbcoupon.hpp:118
CmbLeg & withNotionals(Real notional)
Definition: cmbcoupon.cpp:100
CmbLeg & withGearings(Real gearing)
Definition: cmbcoupon.cpp:130
CmbLeg(Schedule schedule, std::vector< ext::shared_ptr< ConstantMaturityBondIndex > > bondIndices)
Definition: cmbcoupon.cpp:92
CmbLeg & withFixingDays(Natural fixingDays)
Definition: cmbcoupon.cpp:120
std::vector< Real > notionals_
Definition: cmbcoupon.hpp:115
std::vector< Spread > spreads_
Definition: cmbcoupon.hpp:121
CmbLeg & withFloors(Rate floor)
Definition: cmbcoupon.cpp:160
CmbLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: cmbcoupon.cpp:115
bool exCouponEndOfMonth_
Definition: cmbcoupon.hpp:127
std::vector< Natural > fixingDays_
Definition: cmbcoupon.hpp:119
Period exCouponPeriod_
Definition: cmbcoupon.hpp:124
Calendar exCouponCalendar_
Definition: cmbcoupon.hpp:125
std::vector< Rate > floors_
Definition: cmbcoupon.hpp:122
CmbLeg & withZeroPayments(bool flag=true)
Definition: cmbcoupon.cpp:175
CmbLeg & withSpreads(Spread spread)
Definition: cmbcoupon.cpp:140
CmbLeg & withPaymentCalendar(const Calendar &cal)
Definition: cmbcoupon.cpp:180
CmbLeg & inArrears(bool flag=true)
Definition: cmbcoupon.cpp:170
CmbLeg & withPaymentDayCounter(const DayCounter &)
Definition: cmbcoupon.cpp:110
CmbLeg & withCaps(Rate cap)
Definition: cmbcoupon.cpp:150
std::vector< Real > gearings_
Definition: cmbcoupon.hpp:120
DayCounter paymentDayCounter_
Definition: cmbcoupon.hpp:116
Constant Maturity Bond yield coupon.