Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
averageonindexedcoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 averageonindexedcoupon.hpp
20 \brief coupon paying the weighted average of the daily overnight rate
21
22 \ingroup cashflows
23*/
24
25#pragma once
26
27#include <ql/cashflows/couponpricer.hpp>
28#include <ql/cashflows/floatingratecoupon.hpp>
29#include <ql/indexes/iborindex.hpp>
30#include <ql/time/schedule.hpp>
31
32namespace QuantExt {
33using namespace QuantLib;
34
35//! average overnight coupon pricer
36/*! \ingroup cashflows
37 */
38class AverageONIndexedCouponPricer;
39
40//! average overnight coupon
41/*! %Coupon paying the interest due to the weighted average of daily
42 overnight fixings. The rateCutoff counts the number of fixing
43 dates starting at the end date whose fixings are not taken into
44 account, but rather replaced by the last known fixing before.
45
46 \ingroup cashflows
47*/
49public:
50 AverageONIndexedCoupon(const Date& paymentDate, Real nominal, const Date& startDate, const Date& endDate,
51 const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex, Real gearing = 1.0,
52 Spread spread = 0.0, Natural rateCutoff = 0, const DayCounter& dayCounter = DayCounter(),
53 const Period& lookback = 0 * Days, const Size fixingDays = Null<Size>(),
54 const Date& rateComputationStartDate = Null<Date>(),
55 const Date& rateComputationEndDate = Null<Date>(), const bool telescopicValueDates = false);
56 //! \name Inspectors
57 //@{
58 //! fixing dates for the rates to be averaged
59 const std::vector<Date>& fixingDates() const { return fixingDates_; }
60 //! accrual periods for the averaging
61 const std::vector<Time>& dt() const { return dt_; }
62 //! fixings to be averaged
63 const std::vector<Rate>& indexFixings() const;
64 //! value dates for the rates to be averaged
65 const std::vector<Date>& valueDates() const { return valueDates_; }
66 //! rate cutoff associated with the coupon
67 Natural rateCutoff() const { return rateCutoff_; }
68 //! lookback period
69 const Period& lookback() const { return lookback_; }
70 //! rate computation start date
72 //! rate computation end date
73 const Date& rateComputationEndDate() const { return rateComputationEndDate_; }
74 //! the underlying index
75 const ext::shared_ptr<OvernightIndex>& overnightIndex() const { return overnightIndex_; }
76 //@}
77 //! \name FloatingRateCoupon interface
78 //@{
79 //! the date when the coupon is fully determined
80 Date fixingDate() const override;
81 //@}
82 //! \name Visitability
83 //@{
84 void accept(AcyclicVisitor&) override;
85 //@}
86private:
87 QuantLib::ext::shared_ptr<OvernightIndex> overnightIndex_;
88 std::vector<Date> valueDates_, fixingDates_;
89 mutable std::vector<Rate> fixings_;
91 std::vector<Time> dt_;
92 Natural rateCutoff_;
93 Period lookback_;
95};
96
97//! capped floored overnight indexed coupon
99public:
100 /*! capped / floored averaged, backward-looking on coupon, local means that the daily rates are capped / floored
101 while a global cap / floor is applied to the effective period rate */
102 CappedFlooredAverageONIndexedCoupon(const ext::shared_ptr<AverageONIndexedCoupon>& underlying,
103 Real cap = Null<Real>(), Real floor = Null<Real>(), bool nakedOption = false,
104 bool localCapFloor = false, bool includeSpread = false);
105
106 //! \name Observer interface
107 //@{
108 void deepUpdate() override;
109 //@}
110 //! \name LazyObject interface
111 //@{
112 void performCalculations() const override;
113 void alwaysForwardNotifications() override;
114 //@}
115 //! \name Coupon interface
116 //@{
117 Rate rate() const override;
118 Rate convexityAdjustment() const override;
119 //@}
120 //! \name FloatingRateCoupon interface
121 //@{
122 Date fixingDate() const override { return underlying_->fixingDate(); }
123 //@}
124 //! cap
125 Rate cap() const;
126 //! floor
127 Rate floor() const;
128 //! effective cap of fixing
129 Rate effectiveCap() const;
130 //! effective floor of fixing
131 Rate effectiveFloor() const;
132 //! effective caplet volatility
133 Real effectiveCapletVolatility() const;
134 //! effective floorlet volatility
135 Real effectiveFloorletVolatility() const;
136 //@}
137 //! \name Visitability
138 //@{
139 virtual void accept(AcyclicVisitor&) override;
140
141 bool isCapped() const { return cap_ != Null<Real>(); }
142 bool isFloored() const { return floor_ != Null<Real>(); }
143
144 ext::shared_ptr<AverageONIndexedCoupon> underlying() const { return underlying_; }
145 bool nakedOption() const { return nakedOption_; }
146 bool localCapFloor() const { return localCapFloor_; }
147 bool includeSpread() const { return includeSpread_; }
148
149protected:
150 ext::shared_ptr<AverageONIndexedCoupon> underlying_;
157};
158
159//! capped floored averaged indexed coupon pricer base class
160class CapFlooredAverageONIndexedCouponPricer : public FloatingRateCouponPricer {
161public:
162 CapFlooredAverageONIndexedCouponPricer(const Handle<OptionletVolatilityStructure>& v,
163 const bool effectiveVolatilityInput = false);
164 Handle<OptionletVolatilityStructure> capletVolatility() const;
165 bool effectiveVolatilityInput() const;
166 Real effectiveCapletVolatility() const; // only available after capletRate() was called
167 Real effectiveFloorletVolatility() const; // only available after floorletRate() was called
168
169protected:
170 Handle<OptionletVolatilityStructure> capletVol_;
172 mutable Real effectiveCapletVolatility_ = Null<Real>();
173 mutable Real effectiveFloorletVolatility_ = Null<Real>();
174};
175
176//! helper class building a sequence of overnight coupons
177/*! \ingroup cashflows
178 */
180public:
181 AverageONLeg(const Schedule& schedule, const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex);
182 AverageONLeg& withNotional(Real notional);
183 AverageONLeg& withNotionals(const std::vector<Real>& notionals);
184 AverageONLeg& withPaymentDayCounter(const DayCounter& dayCounter);
185 AverageONLeg& withPaymentAdjustment(BusinessDayConvention convention);
186 AverageONLeg& withGearing(Real gearing);
187 AverageONLeg& withGearings(const std::vector<Real>& gearings);
188 AverageONLeg& withSpread(Spread spread);
189 AverageONLeg& withSpreads(const std::vector<Spread>& spreads);
190 AverageONLeg& withTelescopicValueDates(bool telescopicValueDates);
191 AverageONLeg& withRateCutoff(Natural rateCutoff);
192 AverageONLeg& withPaymentCalendar(const Calendar& calendar);
193 AverageONLeg& withPaymentLag(Natural lag);
194 AverageONLeg& withLookback(const Period& lookback);
195 AverageONLeg& withFixingDays(const Size fixingDays);
196 AverageONLeg& withCaps(Rate cap);
197 AverageONLeg& withCaps(const std::vector<Rate>& caps);
198 AverageONLeg& withFloors(Rate floor);
199 AverageONLeg& withFloors(const std::vector<Rate>& floors);
200 AverageONLeg& includeSpreadInCapFloors(bool includeSpread);
201 AverageONLeg& withNakedOption(const bool nakedOption);
202 AverageONLeg& withLocalCapFloor(const bool localCapFloor);
203 AverageONLeg& withInArrears(const bool inArrears);
204 AverageONLeg& withLastRecentPeriod(const boost::optional<Period>& lastRecentPeriod);
205 AverageONLeg& withLastRecentPeriodCalendar(const Calendar& lastRecentPeriodCalendar);
206 AverageONLeg& withPaymentDates(const std::vector<QuantLib::Date>& paymentDates);
207 AverageONLeg& withAverageONIndexedCouponPricer(const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer>& couponPricer);
209 const QuantLib::ext::shared_ptr<CapFlooredAverageONIndexedCouponPricer>& couponPricer);
210 operator Leg() const;
211
212private:
213 Schedule schedule_;
214 QuantLib::ext::shared_ptr<OvernightIndex> overnightIndex_;
215 std::vector<Real> notionals_;
217 BusinessDayConvention paymentAdjustment_;
218 Natural paymentLag_;
219 std::vector<Real> gearings_;
220 std::vector<Spread> spreads_;
223 Natural rateCutoff_;
224 Period lookback_;
225 Natural fixingDays_;
226 std::vector<Rate> caps_, floors_;
231 boost::optional<Period> lastRecentPeriod_;
233 std::vector<QuantLib::Date> paymentDates_;
234 QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer> couponPricer_;
235 QuantLib::ext::shared_ptr<CapFlooredAverageONIndexedCouponPricer> capFlooredCouponPricer_;
236};
237
238} // namespace QuantExt
Natural rateCutoff() const
rate cutoff associated with the coupon
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
const ext::shared_ptr< OvernightIndex > & overnightIndex() const
the underlying index
const std::vector< Date > & valueDates() const
value dates for the rates to be averaged
const Date & rateComputationStartDate() const
rate computation start date
const Date & rateComputationEndDate() const
rate computation end date
void accept(AcyclicVisitor &) override
const Period & lookback() const
lookback period
const std::vector< Time > & dt() const
accrual periods for the averaging
const std::vector< Rate > & indexFixings() const
fixings to be averaged
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be averaged
Date fixingDate() const override
the date when the coupon is fully determined
helper class building a sequence of overnight coupons
AverageONLeg & withGearing(Real gearing)
AverageONLeg & withLastRecentPeriod(const boost::optional< Period > &lastRecentPeriod)
AverageONLeg & withPaymentDates(const std::vector< QuantLib::Date > &paymentDates)
BusinessDayConvention paymentAdjustment_
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
AverageONLeg & withSpread(Spread spread)
AverageONLeg & withPaymentDayCounter(const DayCounter &dayCounter)
AverageONLeg & includeSpreadInCapFloors(bool includeSpread)
AverageONLeg & withPaymentLag(Natural lag)
AverageONLeg & withNotional(Real notional)
AverageONLeg & withLookback(const Period &lookback)
AverageONLeg & withRateCutoff(Natural rateCutoff)
boost::optional< Period > lastRecentPeriod_
std::vector< QuantLib::Date > paymentDates_
AverageONLeg & withLastRecentPeriodCalendar(const Calendar &lastRecentPeriodCalendar)
AverageONLeg & withPaymentCalendar(const Calendar &calendar)
AverageONLeg & withNakedOption(const bool nakedOption)
QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricer > capFlooredCouponPricer_
std::vector< Spread > spreads_
AverageONLeg & withLocalCapFloor(const bool localCapFloor)
AverageONLeg & withTelescopicValueDates(bool telescopicValueDates)
AverageONLeg & withPaymentAdjustment(BusinessDayConvention convention)
AverageONLeg & withNotionals(const std::vector< Real > &notionals)
AverageONLeg & withSpreads(const std::vector< Spread > &spreads)
AverageONLeg & withInArrears(const bool inArrears)
AverageONLeg & withCaps(Rate cap)
AverageONLeg & withFloors(Rate floor)
AverageONLeg & withCapFlooredAverageONIndexedCouponPricer(const QuantLib::ext::shared_ptr< CapFlooredAverageONIndexedCouponPricer > &couponPricer)
QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > couponPricer_
AverageONLeg & withAverageONIndexedCouponPricer(const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &couponPricer)
AverageONLeg & withFixingDays(const Size fixingDays)
AverageONLeg & withGearings(const std::vector< Real > &gearings)
capped floored averaged indexed coupon pricer base class
Handle< OptionletVolatilityStructure > capletVolatility() const
Handle< OptionletVolatilityStructure > capletVol_
capped floored overnight indexed coupon
Real effectiveCapletVolatility() const
effective caplet volatility
ext::shared_ptr< AverageONIndexedCoupon > underlying() const
virtual void accept(AcyclicVisitor &) override
Real effectiveFloorletVolatility() const
effective floorlet volatility
Rate effectiveCap() const
effective cap of fixing
Rate effectiveFloor() const
effective floor of fixing
ext::shared_ptr< AverageONIndexedCoupon > underlying_