QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
oisratehelper.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009, 2012 Roland Lichters
5 Copyright (C) 2009, 2012 Ferdinando Ametrano
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
26#include <utility>
27
28namespace QuantLib {
29
31 const Period& tenor, // swap maturity
32 const Handle<Quote>& fixedRate,
33 const ext::shared_ptr<OvernightIndex>& overnightIndex,
35 bool telescopicValueDates,
36 Integer paymentLag,
37 BusinessDayConvention paymentConvention,
38 Frequency paymentFrequency,
39 Calendar paymentCalendar,
40 const Period& forwardStart,
41 const Spread overnightSpread,
42 Pillar::Choice pillar,
43 Date customPillarDate,
44 RateAveraging::Type averagingMethod,
45 ext::optional<bool> endOfMonth,
46 ext::optional<Frequency> fixedPaymentFrequency,
47 Calendar fixedCalendar)
48 : RelativeDateRateHelper(fixedRate), pillarChoice_(pillar), settlementDays_(settlementDays), tenor_(tenor),
49 discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates),
50 paymentLag_(paymentLag), paymentConvention_(paymentConvention),
51 paymentFrequency_(paymentFrequency), paymentCalendar_(std::move(paymentCalendar)),
52 forwardStart_(forwardStart), overnightSpread_(overnightSpread),
53 averagingMethod_(averagingMethod), endOfMonth_(endOfMonth),
54 fixedPaymentFrequency_(fixedPaymentFrequency), fixedCalendar_(std::move(fixedCalendar)) {
55
57 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
58 // We want to be notified of changes of fixings, but we don't
59 // want notifications from termStructureHandle_ (they would
60 // interfere with bootstrapping.)
62
65
66 pillarDate_ = customPillarDate;
68 }
69
71
72 // input discount curve Handle might be empty now but it could
73 // be assigned a curve later; use a RelinkableHandle here
84 if (endOfMonth_) {
86 }
89 }
90 if (!fixedCalendar_.empty()) {
92 }
93 swap_ = tmp;
94
96
97 earliestDate_ = swap_->startDate();
98 maturityDate_ = swap_->maturityDate();
99
100 Date lastPaymentDate = std::max(swap_->overnightLeg().back()->date(),
101 swap_->fixedLeg().back()->date());
102 latestRelevantDate_ = std::max(maturityDate_, lastPaymentDate);
103
104 switch (pillarChoice_) {
107 break;
110 break;
112 // pillarDate_ already assigned at construction time
114 "pillar date (" << pillarDate_ << ") must be later "
115 "than or equal to the instrument's earliest date (" <<
116 earliestDate_ << ")");
118 "pillar date (" << pillarDate_ << ") must be before "
119 "or equal to the instrument's latest relevant date (" <<
120 latestRelevantDate_ << ")");
121 break;
122 default:
123 QL_FAIL("unknown Pillar::Choice(" << Integer(pillarChoice_) << ")");
124 }
125
126 latestDate_ = std::max(swap_->maturityDate(), lastPaymentDate);
127 }
128
130 // do not set the relinkable handle as an observer -
131 // force recalculation when needed
132 bool observer = false;
133
134 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
135 termStructureHandle_.linkTo(temp, observer);
136
137 if (discountHandle_.empty())
138 discountRelinkableHandle_.linkTo(temp, observer);
139 else
141
143 }
144
146 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
147 // we didn't register as observers - force calculation
148 swap_->deepUpdate();
149 return swap_->fairRate();
150 }
151
153 auto* v1 = dynamic_cast<Visitor<OISRateHelper>*>(&v);
154 if (v1 != nullptr)
155 v1->visit(*this);
156 else
158 }
159
161 const Date& endDate,
162 const Handle<Quote>& fixedRate,
163 const ext::shared_ptr<OvernightIndex>& overnightIndex,
165 bool telescopicValueDates,
166 RateAveraging::Type averagingMethod,
167 Integer paymentLag,
168 BusinessDayConvention paymentConvention,
169 Frequency paymentFrequency,
170 const Calendar& paymentCalendar,
171 Spread overnightSpread,
172 ext::optional<bool> endOfMonth,
173 ext::optional<Frequency> fixedPaymentFrequency,
174 const Calendar& fixedCalendar)
175 : RateHelper(fixedRate), discountHandle_(std::move(discount)),
176 telescopicValueDates_(telescopicValueDates), averagingMethod_(averagingMethod) {
177
178 auto clonedOvernightIndex =
179 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
180 // We want to be notified of changes of fixings, but we don't
181 // want notifications from termStructureHandle_ (they would
182 // interfere with bootstrapping.)
183 clonedOvernightIndex->unregisterWith(termStructureHandle_);
184
185 registerWith(clonedOvernightIndex);
187
188 // input discount curve Handle might be empty now but it could
189 // be assigned a curve later; use a RelinkableHandle here
190 auto tmp = MakeOIS(Period(), clonedOvernightIndex, 0.0)
192 .withEffectiveDate(startDate)
193 .withTerminationDate(endDate)
195 .withPaymentLag(paymentLag)
196 .withPaymentAdjustment(paymentConvention)
197 .withPaymentFrequency(paymentFrequency)
198 .withPaymentCalendar(paymentCalendar)
199 .withOvernightLegSpread(overnightSpread)
201 if (endOfMonth) {
202 tmp.withEndOfMonth(*endOfMonth);
203 }
204 if (fixedPaymentFrequency) {
205 tmp.withFixedLegPaymentFrequency(*fixedPaymentFrequency);
206 }
207 if (!fixedCalendar.empty()) {
208 tmp.withFixedLegCalendar(fixedCalendar);
209 }
210 swap_ = tmp;
211
212 earliestDate_ = swap_->startDate();
213 Date lastPaymentDate = std::max(swap_->overnightLeg().back()->date(),
214 swap_->fixedLeg().back()->date());
215 latestDate_ = std::max(swap_->maturityDate(), lastPaymentDate);
216 }
217
219 const Date& endDate,
220 const Handle<Quote>& fixedRate,
221 const ext::shared_ptr<OvernightIndex>& overnightIndex,
223 bool telescopicValueDates,
224 RateAveraging::Type averagingMethod,
225 Integer paymentLag,
226 BusinessDayConvention paymentConvention,
227 Frequency paymentFrequency,
228 const Calendar& paymentCalendar,
229 const Period&,
230 Spread overnightSpread,
231 ext::optional<bool> endOfMonth,
232 ext::optional<Frequency> fixedPaymentFrequency,
233 const Calendar& fixedCalendar)
234 : DatedOISRateHelper(startDate, endDate, fixedRate, overnightIndex, std::move(discount), telescopicValueDates,
235 averagingMethod, paymentLag, paymentConvention, paymentFrequency, paymentCalendar,
236 overnightSpread, endOfMonth, fixedPaymentFrequency, fixedCalendar) {}
237
239 // do not set the relinkable handle as an observer -
240 // force recalculation when needed
241 bool observer = false;
242
243 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
244 termStructureHandle_.linkTo(temp, observer);
245
246 if (discountHandle_.empty())
247 discountRelinkableHandle_.linkTo(temp, observer);
248 else
250
252 }
253
255 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
256 // we didn't register as observers - force calculation
257 swap_->deepUpdate();
258 return swap_->fairRate();
259 }
260
262 auto* v1 = dynamic_cast<Visitor<DatedOISRateHelper>*>(&v);
263 if (v1 != nullptr)
264 v1->visit(*this);
265 else
267 }
268
269}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Base helper class for bootstrapping.
virtual void accept(AcyclicVisitor &)
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
calendar class
Definition: calendar.hpp:61
bool empty() const
Returns whether or not the calendar is initialized.
Definition: calendar.hpp:202
Concrete date class.
Definition: date.hpp:125
Rate helper for bootstrapping over Overnight Indexed Swap rates.
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
RateAveraging::Type averagingMethod_
ext::shared_ptr< OvernightIndexedSwap > swap_
Real impliedQuote() const override
DatedOISRateHelper(const Date &startDate, const Date &endDate, const Handle< Quote > &fixedRate, const ext::shared_ptr< OvernightIndex > &overnightIndex, Handle< YieldTermStructure > discountingCurve={}, bool telescopicValueDates=false, RateAveraging::Type averagingMethod=RateAveraging::Compound, Integer paymentLag=0, BusinessDayConvention paymentConvention=Following, Frequency paymentFrequency=Annual, const Calendar &paymentCalendar=Calendar(), Spread overnightSpread=0.0, ext::optional< bool > endOfMonth=ext::nullopt, ext::optional< Frequency > fixedPaymentFrequency=ext::nullopt, const Calendar &fixedCalendar=Calendar())
Shared handle to an observable.
Definition: handle.hpp:41
helper class
Definition: makeois.hpp:39
MakeOIS & withPaymentAdjustment(BusinessDayConvention convention)
Definition: makeois.cpp:212
MakeOIS & withPaymentLag(Integer lag)
Definition: makeois.cpp:217
MakeOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
Definition: makeois.cpp:255
MakeOIS & withSettlementDays(Natural settlementDays)
Definition: makeois.cpp:181
MakeOIS & withPaymentFrequency(Frequency f)
Definition: makeois.cpp:198
MakeOIS & withFixedLegCalendar(const Calendar &cal)
Definition: makeois.cpp:231
MakeOIS & withPaymentCalendar(const Calendar &cal)
Definition: makeois.cpp:222
MakeOIS & withTerminationDate(const Date &)
Definition: makeois.cpp:192
MakeOIS & withEffectiveDate(const Date &)
Definition: makeois.cpp:187
MakeOIS & withOvernightLegSpread(Spread sp)
Definition: makeois.cpp:319
MakeOIS & withEndOfMonth(bool flag=true)
Definition: makeois.cpp:303
MakeOIS & withFixedLegPaymentFrequency(Frequency f)
Definition: makeois.cpp:202
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:329
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:324
ext::shared_ptr< OvernightIndex > overnightIndex_
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Pillar::Choice pillarChoice_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
ext::optional< bool > endOfMonth_
RateAveraging::Type averagingMethod_
void initializeDates() override
ext::shared_ptr< OvernightIndexedSwap > swap_
BusinessDayConvention paymentConvention_
Real impliedQuote() const override
OISRateHelper(Natural settlementDays, const Period &tenor, const Handle< Quote > &fixedRate, const ext::shared_ptr< OvernightIndex > &overnightIndex, Handle< YieldTermStructure > discountingCurve={}, bool telescopicValueDates=false, Integer paymentLag=0, BusinessDayConvention paymentConvention=Following, Frequency paymentFrequency=Annual, Calendar paymentCalendar=Calendar(), const Period &forwardStart=0 *Days, Spread overnightSpread=0.0, Pillar::Choice pillar=Pillar::LastRelevantDate, Date customPillarDate=Date(), RateAveraging::Type averagingMethod=RateAveraging::Compound, ext::optional< bool > endOfMonth=ext::nullopt, ext::optional< Frequency > fixedPaymentFrequency=ext::nullopt, Calendar fixedCalendar=Calendar())
ext::optional< Frequency > fixedPaymentFrequency_
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Bootstrap helper with date schedule relative to global evaluation date.
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Interest-rate term structure.
const DefaultType & t
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Spread
spreads on interest rates
Definition: types.hpp:74
Helper class to instantiate overnight indexed swaps.
Definition: any.hpp:35
void simplifyNotificationGraph(Instrument &instrument, const Leg &leg, bool unregisterCoupons)
Utility function to optimize the observability graph of an instrument.
STL namespace.
empty deleter for shared_ptr
Overnight Indexed Swap (aka OIS) rate helpers.
ext::shared_ptr< BlackVolTermStructure > v
utility functions to reduce number of notifications sent by observables
Choice
Enumeration for pillar determination alternatives.
@ CustomDate
last date relevant for instrument pricing
@ LastRelevantDate
instruments maturity date