QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
oisratehelper.cpp
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
21#include <ql/instruments/makeois.hpp>
22#include <ql/instruments/simplifynotificationgraph.hpp>
23#include <ql/pricingengines/swap/discountingswapengine.hpp>
24#include <ql/termstructures/yield/oisratehelper.hpp>
25#include <ql/utilities/null_deleter.hpp>
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 Natural 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 : RelativeDateRateHelper(fixedRate), pillarChoice_(pillar), settlementDays_(settlementDays), tenor_(tenor),
47 discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates),
48 paymentLag_(paymentLag), paymentConvention_(paymentConvention),
49 paymentFrequency_(paymentFrequency), paymentCalendar_(std::move(paymentCalendar)),
50 forwardStart_(forwardStart), overnightSpread_(overnightSpread),
51 averagingMethod_(averagingMethod), endOfMonth_(endOfMonth) {
52
54 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
55 // We want to be notified of changes of fixings, but we don't
56 // want notifications from termStructureHandle_ (they would
57 // interfere with bootstrapping.)
59
62
63 pillarDate_ = customPillarDate;
65 }
66
68
69 // input discount curve Handle might be empty now but it could
70 // be assigned a curve later; use a RelinkableHandle here
81 if (endOfMonth_) {
83 } else {
84 swap_ = tmp;
85 }
86
88
89 earliestDate_ = swap_->startDate();
90 maturityDate_ = swap_->maturityDate();
91
92 Date lastPaymentDate = std::max(swap_->overnightLeg().back()->date(),
93 swap_->fixedLeg().back()->date());
94 latestRelevantDate_ = std::max(maturityDate_, lastPaymentDate);
95
96 switch (pillarChoice_) {
99 break;
102 break;
104 // pillarDate_ already assigned at construction time
105 QL_REQUIRE(pillarDate_ >= earliestDate_,
106 "pillar date (" << pillarDate_ << ") must be later "
107 "than or equal to the instrument's earliest date (" <<
108 earliestDate_ << ")");
109 QL_REQUIRE(pillarDate_ <= latestRelevantDate_,
110 "pillar date (" << pillarDate_ << ") must be before "
111 "or equal to the instrument's latest relevant date (" <<
112 latestRelevantDate_ << ")");
113 break;
114 default:
115 QL_FAIL("unknown Pillar::Choice(" << Integer(pillarChoice_) << ")");
116 }
117
118 latestDate_ = std::max(swap_->maturityDate(), lastPaymentDate);
119 }
120
122 // do not set the relinkable handle as an observer -
123 // force recalculation when needed
124 bool observer = false;
125
126 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
127 termStructureHandle_.linkTo(temp, observer);
128
129 if (discountHandle_.empty())
130 discountRelinkableHandle_.linkTo(temp, observer);
131 else
133
135 }
136
138 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
139 // we didn't register as observers - force calculation
140 swap_->deepUpdate();
141 return swap_->fairRate();
142 }
143
145 auto* v1 = dynamic_cast<Visitor<OISRateHelper>*>(&v);
146 if (v1 != nullptr)
147 v1->visit(*this);
148 else
150 }
151
153 const Date& endDate,
154 const Handle<Quote>& fixedRate,
155 const ext::shared_ptr<OvernightIndex>& overnightIndex,
157 bool telescopicValueDates,
158 RateAveraging::Type averagingMethod,
159 Natural paymentLag,
160 BusinessDayConvention paymentConvention,
161 Frequency paymentFrequency,
162 const Calendar& paymentCalendar,
163 const Period& forwardStart,
164 Spread overnightSpread,
165 ext::optional<bool> endOfMonth)
166 : RateHelper(fixedRate), discountHandle_(std::move(discount)),
167 telescopicValueDates_(telescopicValueDates), averagingMethod_(averagingMethod) {
168
169 auto clonedOvernightIndex =
170 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
171 // We want to be notified of changes of fixings, but we don't
172 // want notifications from termStructureHandle_ (they would
173 // interfere with bootstrapping.)
174 clonedOvernightIndex->unregisterWith(termStructureHandle_);
175
176 registerWith(clonedOvernightIndex);
178
179 // input discount curve Handle might be empty now but it could
180 // be assigned a curve later; use a RelinkableHandle here
181 auto tmp = MakeOIS(Period(), clonedOvernightIndex, 0.0, forwardStart)
183 .withEffectiveDate(startDate)
184 .withTerminationDate(endDate)
186 .withPaymentLag(paymentLag)
187 .withPaymentAdjustment(paymentConvention)
188 .withPaymentFrequency(paymentFrequency)
189 .withPaymentCalendar(paymentCalendar)
190 .withOvernightLegSpread(overnightSpread)
192 if (endOfMonth) {
193 swap_ = tmp.withEndOfMonth(*endOfMonth);
194 } else {
195 swap_ = tmp;
196 }
197
198 earliestDate_ = swap_->startDate();
199 Date lastPaymentDate = std::max(swap_->overnightLeg().back()->date(),
200 swap_->fixedLeg().back()->date());
201 latestDate_ = std::max(swap_->maturityDate(), lastPaymentDate);
202 }
203
205 // do not set the relinkable handle as an observer -
206 // force recalculation when needed
207 bool observer = false;
208
209 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
210 termStructureHandle_.linkTo(temp, observer);
211
212 if (discountHandle_.empty())
213 discountRelinkableHandle_.linkTo(temp, observer);
214 else
216
218 }
219
221 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
222 // we didn't register as observers - force calculation
223 swap_->deepUpdate();
224 return swap_->fairRate();
225 }
226
228 auto* v1 = dynamic_cast<Visitor<DatedOISRateHelper>*>(&v);
229 if (v1 != nullptr)
230 v1->visit(*this);
231 else
233 }
234
235}
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
Concrete date class.
Definition: date.hpp:125
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
RateAveraging::Type averagingMethod_
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, Natural paymentLag=0, BusinessDayConvention paymentConvention=Following, Frequency paymentFrequency=Annual, const Calendar &paymentCalendar=Calendar(), const Period &forwardStart=0 *Days, Spread overnightSpread=0.0, ext::optional< bool > endOfMonth=ext::nullopt)
ext::shared_ptr< OvernightIndexedSwap > swap_
Real impliedQuote() const override
Shared handle to an observable.
Definition: handle.hpp:41
helper class
Definition: makeois.hpp:39
MakeOIS & withPaymentAdjustment(BusinessDayConvention convention)
Definition: makeois.cpp:174
MakeOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
Definition: makeois.cpp:196
MakeOIS & withSettlementDays(Natural settlementDays)
Definition: makeois.cpp:150
MakeOIS & withPaymentFrequency(Frequency f)
Definition: makeois.cpp:167
MakeOIS & withPaymentLag(Natural lag)
Definition: makeois.cpp:179
MakeOIS & withPaymentCalendar(const Calendar &cal)
Definition: makeois.cpp:184
MakeOIS & withTerminationDate(const Date &)
Definition: makeois.cpp:161
MakeOIS & withEffectiveDate(const Date &)
Definition: makeois.cpp:156
MakeOIS & withOvernightLegSpread(Spread sp)
Definition: makeois.cpp:221
MakeOIS & withEndOfMonth(bool flag=true)
Definition: makeois.cpp:215
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:231
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:226
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, Natural 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)
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.
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
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.
Choice
Enumeration for pillar determination alternatives.
@ CustomDate
last date relevant for instrument pricing
@ LastRelevantDate
instruments maturity date