Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
overnightindexedcoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/*
20 Copyright (C) 2009 Roland Lichters
21 Copyright (C) 2009 Ferdinando Ametrano
22 Copyright (C) 2014 Peter Caspers
23 Copyright (C) 2017 Joseph Jeisman
24 Copyright (C) 2017 Fabrice Lecuyer
25
26 This file is part of QuantLib, a free-software/open-source library
27 for financial quantitative analysts and developers - http://quantlib.org/
28
29 QuantLib is free software: you can redistribute it and/or modify it
30 under the terms of the QuantLib license. You should have received a
31 copy of the license along with this program; if not, please email
32 <quantlib-dev@lists.sf.net>. The license is also available online at
33 <http://quantlib.org/license.shtml>.
34
35 This program is distributed in the hope that it will be useful, but WITHOUT
36 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
37 FOR A PARTICULAR PURPOSE. See the license for more details.
38*/
39
40/*! \file overnightindexedcoupon.hpp
41 \brief coupon paying the compounded daily overnight rate,
42 copy of QL class, added includeSpread flag
43*/
44
45#pragma once
46
47#include <ql/cashflows/couponpricer.hpp>
48#include <ql/cashflows/floatingratecoupon.hpp>
49#include <ql/indexes/iborindex.hpp>
50#include <ql/time/schedule.hpp>
51
52namespace QuantLib {
53class OptionletVolatilityStructure;
54}
55
56namespace QuantExt {
57using namespace QuantLib;
58
59//! overnight coupon
60/*! %Coupon paying the compounded interest due to daily overnight fixings.
61
62 \warning telescopicValueDates optimizes the schedule for calculation speed,
63 but might fail to produce correct results if the coupon ages by more than
64 a grace period of 7 days. It is therefore recommended not to set this flag
65 to true unless you know exactly what you are doing. The intended use is
66 rather by the OISRateHelper which is safe, since it reinitialises the
67 instrument each time the evaluation date changes.
68
69 if includeSpread = true, the spread is included in the daily compounding,
70 otherwise it is added to the effective coupon rate after the compounding
71*/
73public:
74 OvernightIndexedCoupon(const Date& paymentDate, Real nominal, const Date& startDate, const Date& endDate,
75 const ext::shared_ptr<OvernightIndex>& overnightIndex, Real gearing = 1.0,
76 Spread spread = 0.0, const Date& refPeriodStart = Date(), const Date& refPeriodEnd = Date(),
77 const DayCounter& dayCounter = DayCounter(), bool telescopicValueDates = false,
78 bool includeSpread = false, const Period& lookback = 0 * Days, const Natural rateCutoff = 0,
79 const Natural fixingDays = Null<Size>(), const Date& rateComputationStartDate = Null<Date>(),
80 const Date& rateComputationEndDate = Null<Date>());
81 //! \name Inspectors
82 //@{
83 //! fixing dates for the rates to be compounded
84 const std::vector<Date>& fixingDates() const { return fixingDates_; }
85 //! accrual (compounding) periods
86 const std::vector<Time>& dt() const { return dt_; }
87 //! fixings to be compounded
88 const std::vector<Rate>& indexFixings() const;
89 //! value dates for the rates to be compounded
90 const std::vector<Date>& valueDates() const { return valueDates_; }
91 //! include spread in compounding?
92 bool includeSpread() const { return includeSpread_; }
93 /*! effectiveSpread and effectiveIndexFixing are set such that
94 coupon amount = notional * accrualPeriod * ( gearing * effectiveIndexFixing + effectiveSpread )
95 notice that
96 - gearing = 1 is required if includeSpread = true
97 - effectiveSpread = spread() if includeSpread = false */
98 Real effectiveSpread() const;
99 Real effectiveIndexFixing() const;
100 //! lookback period
101 const Period& lookback() const { return lookback_; }
102 //! rate cutoff
103 Natural rateCutoff() const { return rateCutoff_; }
104 //! rate computation start date
106 //! rate computation end date
107 const Date& rateComputationEndDate() const { return rateComputationEndDate_; }
108 //! the underlying index
109 const ext::shared_ptr<OvernightIndex>& overnightIndex() const { return overnightIndex_; }
110 //@}
111 //! \name FloatingRateCoupon interface
112 //@{
113 //! the date when the coupon is fully determined
114 Date fixingDate() const override { return fixingDates_[fixingDates_.size() - 1 - rateCutoff_]; }
115 //@}
116 //! \name Visitability
117 //@{
118 void accept(AcyclicVisitor&) override;
119 //@}
120private:
121 QuantLib::ext::shared_ptr<OvernightIndex> overnightIndex_;
122 std::vector<Date> valueDates_, fixingDates_;
123 mutable std::vector<Rate> fixings_;
124 Size n_;
125 std::vector<Time> dt_;
127 Period lookback_;
128 Natural rateCutoff_;
130};
131
132//! OvernightIndexedCoupon pricer
133class OvernightIndexedCouponPricer : public FloatingRateCouponPricer {
134public:
135 void initialize(const FloatingRateCoupon& coupon) override;
136 void compute() const;
137 Rate swapletRate() const override;
138 Rate effectiveSpread() const;
139 Rate effectiveIndexFixing() const;
140 Real swapletPrice() const override { QL_FAIL("swapletPrice not available"); }
141 Real capletPrice(Rate) const override { QL_FAIL("capletPrice not available"); }
142 Rate capletRate(Rate) const override { QL_FAIL("capletRate not available"); }
143 Real floorletPrice(Rate) const override { QL_FAIL("floorletPrice not available"); }
144 Rate floorletRate(Rate) const override { QL_FAIL("floorletRate not available"); }
145
146protected:
149};
150
151//! capped floored overnight indexed coupon
153public:
154 /*! capped / floored compounded, backward-looking on coupon, local means that the daily rates are capped / floored
155 while a global cap / floor is applied to the effective period rate */
156 CappedFlooredOvernightIndexedCoupon(const ext::shared_ptr<OvernightIndexedCoupon>& underlying,
157 Real cap = Null<Real>(), Real floor = Null<Real>(), bool nakedOption = false,
158 bool localCapFloor = false);
159
160 //! \name Observer interface
161 //@{
162 void deepUpdate() override;
163 //@}
164 //! \name LazyObject interface
165 //@{
166 void performCalculations() const override;
167 void alwaysForwardNotifications() override;
168 //@}
169 //! \name Coupon interface
170 //@{
171 Rate rate() const override;
172 Rate convexityAdjustment() const override;
173 //@}
174 //! \name FloatingRateCoupon interface
175 //@{
176 Date fixingDate() const override { return underlying_->fixingDate(); }
177 //@}
178 //! cap
179 Rate cap() const;
180 //! floor
181 Rate floor() const;
182 //! effective cap of fixing
183 Rate effectiveCap() const;
184 //! effective floor of fixing
185 Rate effectiveFloor() const;
186 //! effective caplet volatility
187 Real effectiveCapletVolatility() const;
188 //! effective floorlet volatility
189 Real effectiveFloorletVolatility() const;
190 //@}
191 //! \name Visitability
192 //@{
193 virtual void accept(AcyclicVisitor&) override;
194
195 bool isCapped() const { return cap_ != Null<Real>(); }
196 bool isFloored() const { return floor_ != Null<Real>(); }
197
198 ext::shared_ptr<OvernightIndexedCoupon> underlying() const { return underlying_; }
199 bool nakedOption() const { return nakedOption_; }
200 bool localCapFloor() const { return localCapFloor_; }
201
202protected:
203 ext::shared_ptr<OvernightIndexedCoupon> underlying_;
209};
210
211//! capped floored overnight indexed coupon pricer base class
212class CappedFlooredOvernightIndexedCouponPricer : public FloatingRateCouponPricer {
213public:
214 CappedFlooredOvernightIndexedCouponPricer(const Handle<OptionletVolatilityStructure>& v,
215 const bool effectiveVolatilityInput = false);
216 Handle<OptionletVolatilityStructure> capletVolatility() const;
217 bool effectiveVolatilityInput() const;
218 Real effectiveCapletVolatility() const; // only available after capletRate() was called
219 Real effectiveFloorletVolatility() const; // only available after floorletRate() was called
220
221protected:
222 Handle<OptionletVolatilityStructure> capletVol_;
224 mutable Real effectiveCapletVolatility_ = Null<Real>();
225 mutable Real effectiveFloorletVolatility_ = Null<Real>();
226};
227
228//! helper class building a sequence of overnight coupons
230public:
231 OvernightLeg(const Schedule& schedule, const ext::shared_ptr<OvernightIndex>& overnightIndex);
232 OvernightLeg& withNotionals(Real notional);
233 OvernightLeg& withNotionals(const std::vector<Real>& notionals);
234 OvernightLeg& withPaymentDayCounter(const DayCounter&);
235 OvernightLeg& withPaymentAdjustment(BusinessDayConvention);
236 OvernightLeg& withPaymentCalendar(const Calendar&);
237 OvernightLeg& withPaymentLag(Natural lag);
238 OvernightLeg& withGearings(Real gearing);
239 OvernightLeg& withGearings(const std::vector<Real>& gearings);
240 OvernightLeg& withSpreads(Spread spread);
241 OvernightLeg& withSpreads(const std::vector<Spread>& spreads);
242 OvernightLeg& withTelescopicValueDates(bool telescopicValueDates);
244 OvernightLeg& withLookback(const Period& lookback);
245 OvernightLeg& withRateCutoff(const Natural rateCutoff);
246 OvernightLeg& withFixingDays(const Natural fixingDays);
247 OvernightLeg& withCaps(Rate cap);
248 OvernightLeg& withCaps(const std::vector<Rate>& caps);
249 OvernightLeg& withFloors(Rate floor);
250 OvernightLeg& withFloors(const std::vector<Rate>& floors);
251 OvernightLeg& withNakedOption(const bool nakedOption);
252 OvernightLeg& withLocalCapFloor(const bool localCapFloor);
253 OvernightLeg& withInArrears(const bool inArrears);
254 OvernightLeg& withLastRecentPeriod(const boost::optional<Period>& lastRecentPeriod);
255 OvernightLeg& withLastRecentPeriodCalendar(const Calendar& lastRecentPeriodCalendar);
256 OvernightLeg& withOvernightIndexedCouponPricer(const QuantLib::ext::shared_ptr<OvernightIndexedCouponPricer>& couponPricer);
257 OvernightLeg& withPaymentDates(const std::vector<Date>& paymentDates);
259 const QuantLib::ext::shared_ptr<CappedFlooredOvernightIndexedCouponPricer>& couponPricer);
260 operator Leg() const;
261
262private:
263 Schedule schedule_;
264 ext::shared_ptr<OvernightIndex> overnightIndex_;
265 std::vector<Real> notionals_;
268 BusinessDayConvention paymentAdjustment_;
269 Natural paymentLag_;
270 std::vector<Real> gearings_;
271 std::vector<Spread> spreads_;
274 Period lookback_;
275 Natural rateCutoff_;
276 Natural fixingDays_;
277 std::vector<Rate> caps_, floors_;
281 boost::optional<Period> lastRecentPeriod_;
283 std::vector<QuantLib::Date> paymentDates_;
284 QuantLib::ext::shared_ptr<OvernightIndexedCouponPricer> couponPricer_;
285 QuantLib::ext::shared_ptr<CappedFlooredOvernightIndexedCouponPricer> capFlooredCouponPricer_;
286};
287
288} // namespace QuantExt
capped floored overnight indexed coupon
Real effectiveCapletVolatility() const
effective caplet volatility
ext::shared_ptr< OvernightIndexedCoupon > underlying() const
virtual void accept(AcyclicVisitor &) override
Real effectiveFloorletVolatility() const
effective floorlet volatility
Rate effectiveCap() const
effective cap of fixing
ext::shared_ptr< OvernightIndexedCoupon > underlying_
Rate effectiveFloor() const
effective floor of fixing
capped floored overnight indexed coupon pricer base class
Handle< OptionletVolatilityStructure > capletVolatility() const
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
bool includeSpread() const
include spread in compounding?
const ext::shared_ptr< OvernightIndex > & overnightIndex() const
the underlying index
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
const Date & rateComputationStartDate() const
rate computation start date
const Date & rateComputationEndDate() const
rate computation end date
const std::vector< Rate > & indexFixings() const
fixings to be compounded
void accept(AcyclicVisitor &) override
const Period & lookback() const
lookback period
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
Date fixingDate() const override
the date when the coupon is fully determined
void initialize(const FloatingRateCoupon &coupon) override
helper class building a sequence of overnight coupons
ext::shared_ptr< OvernightIndex > overnightIndex_
OvernightLeg & withLookback(const Period &lookback)
BusinessDayConvention paymentAdjustment_
OvernightLeg & withGearings(Real gearing)
QuantLib::ext::shared_ptr< CappedFlooredOvernightIndexedCouponPricer > capFlooredCouponPricer_
OvernightLeg & withOvernightIndexedCouponPricer(const QuantLib::ext::shared_ptr< OvernightIndexedCouponPricer > &couponPricer)
OvernightLeg & withCapFlooredOvernightIndexedCouponPricer(const QuantLib::ext::shared_ptr< CappedFlooredOvernightIndexedCouponPricer > &couponPricer)
OvernightLeg & withPaymentCalendar(const Calendar &)
OvernightLeg & withLastRecentPeriod(const boost::optional< Period > &lastRecentPeriod)
OvernightLeg & withFloors(Rate floor)
OvernightLeg & withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg & withPaymentAdjustment(BusinessDayConvention)
boost::optional< Period > lastRecentPeriod_
std::vector< QuantLib::Date > paymentDates_
OvernightLeg & withNakedOption(const bool nakedOption)
std::vector< Spread > spreads_
OvernightLeg & withFixingDays(const Natural fixingDays)
OvernightLeg & withNotionals(Real notional)
OvernightLeg & withRateCutoff(const Natural rateCutoff)
OvernightLeg & withCaps(Rate cap)
OvernightLeg & withPaymentDayCounter(const DayCounter &)
OvernightLeg & withInArrears(const bool inArrears)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg & withPaymentDates(const std::vector< Date > &paymentDates)
OvernightLeg & withLocalCapFloor(const bool localCapFloor)
OvernightLeg & includeSpread(bool includeSpread)
OvernightLeg & withPaymentLag(Natural lag)
QuantLib::ext::shared_ptr< OvernightIndexedCouponPricer > couponPricer_
OvernightLeg & withLastRecentPeriodCalendar(const Calendar &lastRecentPeriodCalendar)