QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
makeois.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, 2014, 2015 Ferdinando Ametrano
5 Copyright (C) 2015 Paolo Mazzocchi
6 Copyright (C) 2017 Joseph Jeisman
7 Copyright (C) 2017 Fabrice Lecuyer
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
26#include <ql/time/schedule.hpp>
27
28namespace QuantLib {
29
30 MakeOIS::MakeOIS(const Period& swapTenor,
31 const ext::shared_ptr<OvernightIndex>& overnightIndex,
32 Rate fixedRate,
33 const Period& forwardStart)
34 : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate),
35 forwardStart_(forwardStart),
36 fixedCalendar_(overnightIndex->fixingCalendar()),
37 overnightCalendar_(overnightIndex->fixingCalendar()),
38 fixedDayCount_(overnightIndex->dayCounter()) {}
39
40 MakeOIS::operator OvernightIndexedSwap() const {
41 ext::shared_ptr<OvernightIndexedSwap> ois = *this;
42 return *ois;
43 }
44
45 MakeOIS::operator ext::shared_ptr<OvernightIndexedSwap>() const {
46
47 Date startDate;
48 if (effectiveDate_ != Date())
49 startDate = effectiveDate_;
50 else {
52 // if the evaluation date is not a business day
53 // then move to the next business day
54 refDate = overnightCalendar_.adjust(refDate);
55 Date spotDate = overnightCalendar_.advance(refDate,
56 settlementDays_*Days);
57 startDate = spotDate+forwardStart_;
58 if (forwardStart_.length()<0)
59 startDate = overnightCalendar_.adjust(startDate, Preceding);
60 else
61 startDate = overnightCalendar_.adjust(startDate, Following);
62 }
63
64 // OIS end of month default
65 bool fixedEndOfMonth, overnightEndOfMonth;
66 if (isDefaultEOM_)
67 fixedEndOfMonth = overnightEndOfMonth = overnightCalendar_.isEndOfMonth(startDate);
68 else {
69 fixedEndOfMonth = fixedEndOfMonth_;
70 overnightEndOfMonth = overnightEndOfMonth_;
71 }
72
73 Date endDate = terminationDate_;
74 if (endDate == Date()) {
75 if (overnightEndOfMonth)
76 endDate = overnightCalendar_.advance(startDate,
77 swapTenor_,
79 overnightEndOfMonth);
80 else
81 endDate = startDate + swapTenor_;
82 }
83
84 Frequency fixedPaymentFrequency, overnightPaymentFrequency;
85 DateGeneration::Rule fixedRule, overnightRule;
86 if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) {
87 fixedPaymentFrequency = Once;
88 fixedRule = DateGeneration::Zero;
89 } else {
90 fixedPaymentFrequency = fixedPaymentFrequency_;
91 fixedRule = fixedRule_;
92 }
93 if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) {
94 overnightPaymentFrequency = Once;
95 overnightRule = DateGeneration::Zero;
96 } else {
97 overnightPaymentFrequency = overnightPaymentFrequency_;
98 overnightRule = overnightRule_;
99 }
100
101 Schedule fixedSchedule(startDate, endDate,
102 Period(fixedPaymentFrequency),
103 fixedCalendar_,
104 fixedConvention_,
105 fixedTerminationDateConvention_,
106 fixedRule,
107 fixedEndOfMonth);
108
109 Schedule overnightSchedule(startDate, endDate,
110 Period(overnightPaymentFrequency),
111 overnightCalendar_,
112 overnightConvention_,
113 overnightTerminationDateConvention_,
114 overnightRule,
115 overnightEndOfMonth);
116
117 Rate usedFixedRate = fixedRate_;
118 if (fixedRate_ == Null<Rate>()) {
119 OvernightIndexedSwap temp(type_, nominal_,
120 fixedSchedule,
121 0.0, // fixed rate
122 fixedDayCount_,
123 overnightSchedule,
124 overnightIndex_, overnightSpread_,
125 paymentLag_, paymentAdjustment_,
126 paymentCalendar_, telescopicValueDates_);
127 if (engine_ == nullptr) {
129 overnightIndex_->forwardingTermStructure();
130 QL_REQUIRE(!disc.empty(),
131 "null term structure set to this instance of " <<
132 overnightIndex_->name());
133 bool includeSettlementDateFlows = false;
134 ext::shared_ptr<PricingEngine> engine(new
135 DiscountingSwapEngine(disc, includeSettlementDateFlows));
136 temp.setPricingEngine(engine);
137 } else
139
140 usedFixedRate = temp.fairRate();
141 }
142
143 ext::shared_ptr<OvernightIndexedSwap> ois(new
144 OvernightIndexedSwap(type_, nominal_,
145 fixedSchedule,
146 usedFixedRate, fixedDayCount_,
147 overnightSchedule,
148 overnightIndex_, overnightSpread_,
149 paymentLag_, paymentAdjustment_,
150 paymentCalendar_, telescopicValueDates_,
151 averagingMethod_, lookbackDays_,
152 lockoutDays_, applyObservationShift_));
153
154 if (engine_ == nullptr) {
156 overnightIndex_->forwardingTermStructure();
157 bool includeSettlementDateFlows = false;
158 ext::shared_ptr<PricingEngine> engine(new
159 DiscountingSwapEngine(disc, includeSettlementDateFlows));
160 ois->setPricingEngine(engine);
161 } else
162 ois->setPricingEngine(engine_);
163
164 return ois;
165 }
166
168 type_ = flag ? Swap::Receiver : Swap::Payer ;
169 return *this;
170 }
171
173 type_ = type;
174 return *this;
175 }
176
178 nominal_ = n;
179 return *this;
180 }
181
183 settlementDays_ = settlementDays;
185 return *this;
186 }
187
188 MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
189 effectiveDate_ = effectiveDate;
190 return *this;
191 }
192
193 MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
194 terminationDate_ = terminationDate;
195 if (terminationDate != Date())
196 swapTenor_ = Period();
197 return *this;
198 }
199
202 }
203
206 return *this;
207 }
208
211 return *this;
212 }
213
215 paymentAdjustment_ = convention;
216 return *this;
217 }
218
220 paymentLag_ = lag;
221 return *this;
222 }
223
225 paymentCalendar_ = cal;
226 return *this;
227 }
228
231 }
232
234 fixedCalendar_ = cal;
235 return *this;
236 }
237
239 overnightCalendar_ = cal;
240 return *this;
241 }
242
245 }
246
248 fixedRule_ = r;
249 return *this;
250 }
251
254 return *this;
255 }
256
259 bool includeSettlementDateFlows = false;
260 engine_ = ext::shared_ptr<PricingEngine>(new
261 DiscountingSwapEngine(d, includeSettlementDateFlows));
262 return *this;
263 }
264
266 const ext::shared_ptr<PricingEngine>& engine) {
267 engine_ = engine;
268 return *this;
269 }
270
272 fixedDayCount_ = dc;
273 return *this;
274 }
275
278 }
279
281 fixedConvention_ = bdc;
282 return *this;
283 }
284
287 return *this;
288 }
289
293 }
294
297 return *this;
298 }
299
302 return *this;
303 }
304
307 }
308
310 fixedEndOfMonth_ = flag;
311 isDefaultEOM_ = false;
312 return *this;
313 }
314
317 isDefaultEOM_ = false;
318 return *this;
319 }
320
322 overnightSpread_ = sp;
323 return *this;
324 }
325
326 MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
327 telescopicValueDates_ = telescopicValueDates;
328 return *this;
329 }
330
332 averagingMethod_ = averagingMethod;
333 return *this;
334 }
335
337 lookbackDays_ = lookbackDays;
338 return *this;
339 }
340
342 lockoutDays_ = lockoutDays;
343 return *this;
344 }
345
346 MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
347 applyObservationShift_ = applyObservationShift;
348 return *this;
349 }
350
351}
ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:60
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
static Date advance(const Date &d, Integer units, TimeUnit)
Definition: date.cpp:139
day counter class
Definition: daycounter.hpp:44
Discounting engine for swaps.
Shared handle to an observable.
Definition: handle.hpp:41
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:188
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
Definition: instrument.cpp:35
helper class
Definition: makeois.hpp:39
Period swapTenor_
Definition: makeois.hpp:98
BusinessDayConvention paymentAdjustment_
Definition: makeois.hpp:110
BusinessDayConvention fixedConvention_
Definition: makeois.hpp:113
MakeOIS & withFixedLegRule(DateGeneration::Rule r)
Definition: makeois.cpp:247
bool telescopicValueDates_
Definition: makeois.hpp:129
MakeOIS & withPaymentAdjustment(BusinessDayConvention convention)
Definition: makeois.cpp:214
MakeOIS & withTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:290
MakeOIS & withPaymentLag(Integer lag)
Definition: makeois.cpp:219
MakeOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
Definition: makeois.cpp:257
Natural lookbackDays_
Definition: makeois.hpp:131
MakeOIS & withLockoutDays(Natural lockoutDays)
Definition: makeois.cpp:341
MakeOIS & withType(Swap::Type type)
Definition: makeois.cpp:172
MakeOIS(const Period &swapTenor, const ext::shared_ptr< OvernightIndex > &overnightIndex, Rate fixedRate=Null< Rate >(), const Period &fwdStart=0 *Days)
Definition: makeois.cpp:30
MakeOIS & withSettlementDays(Natural settlementDays)
Definition: makeois.cpp:182
Calendar paymentCalendar_
Definition: makeois.hpp:109
DateGeneration::Rule overnightRule_
Definition: makeois.hpp:118
DayCounter fixedDayCount_
Definition: makeois.hpp:125
MakeOIS & receiveFixed(bool flag=true)
Definition: makeois.cpp:167
MakeOIS & withPaymentFrequency(Frequency f)
Definition: makeois.cpp:200
bool overnightEndOfMonth_
Definition: makeois.hpp:119
MakeOIS & withFixedLegDayCount(const DayCounter &dc)
Definition: makeois.cpp:271
Integer paymentLag_
Definition: makeois.hpp:111
MakeOIS & withRule(DateGeneration::Rule r)
Definition: makeois.cpp:243
MakeOIS & withCalendar(const Calendar &cal)
Definition: makeois.cpp:229
MakeOIS & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
Definition: makeois.cpp:265
MakeOIS & withFixedLegEndOfMonth(bool flag=true)
Definition: makeois.cpp:309
MakeOIS & withLookbackDays(Natural lookbackDays)
Definition: makeois.cpp:336
MakeOIS & withOvernightLegRule(DateGeneration::Rule r)
Definition: makeois.cpp:252
MakeOIS & withFixedLegConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:280
BusinessDayConvention overnightConvention_
Definition: makeois.hpp:115
bool applyObservationShift_
Definition: makeois.hpp:133
Frequency fixedPaymentFrequency_
Definition: makeois.hpp:107
MakeOIS & withOvernightLegTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:300
MakeOIS & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:295
Frequency overnightPaymentFrequency_
Definition: makeois.hpp:108
Natural settlementDays_
Definition: makeois.hpp:103
RateAveraging::Type averagingMethod_
Definition: makeois.hpp:130
BusinessDayConvention overnightTerminationDateConvention_
Definition: makeois.hpp:116
MakeOIS & withFixedLegCalendar(const Calendar &cal)
Definition: makeois.cpp:233
MakeOIS & withPaymentCalendar(const Calendar &cal)
Definition: makeois.cpp:224
DateGeneration::Rule fixedRule_
Definition: makeois.hpp:117
MakeOIS & withTerminationDate(const Date &)
Definition: makeois.cpp:193
MakeOIS & withEffectiveDate(const Date &)
Definition: makeois.cpp:188
MakeOIS & withOvernightLegSpread(Spread sp)
Definition: makeois.cpp:321
ext::shared_ptr< PricingEngine > engine_
Definition: makeois.hpp:127
Calendar overnightCalendar_
Definition: makeois.hpp:105
Swap::Type type_
Definition: makeois.hpp:121
MakeOIS & withEndOfMonth(bool flag=true)
Definition: makeois.cpp:305
MakeOIS & withOvernightLegPaymentFrequency(Frequency f)
Definition: makeois.cpp:209
MakeOIS & withFixedLegPaymentFrequency(Frequency f)
Definition: makeois.cpp:204
BusinessDayConvention fixedTerminationDateConvention_
Definition: makeois.hpp:114
MakeOIS & withNominal(Real n)
Definition: makeois.cpp:177
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:331
Natural lockoutDays_
Definition: makeois.hpp:132
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:326
MakeOIS & withConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:276
MakeOIS & withOvernightLegConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:285
Spread overnightSpread_
Definition: makeois.hpp:124
Calendar fixedCalendar_
Definition: makeois.hpp:105
MakeOIS & withObservationShift(bool applyObservationShift=true)
Definition: makeois.cpp:346
MakeOIS & withOvernightLegCalendar(const Calendar &cal)
Definition: makeois.cpp:238
MakeOIS & withOvernightLegEndOfMonth(bool flag=true)
Definition: makeois.cpp:315
template class providing a null value for a given type.
Definition: null.hpp:59
Overnight indexed swap: fix vs compounded overnight rate.
Payment schedule.
Definition: schedule.hpp:40
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Calendar paymentCalendar_
Integer paymentLag_
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
@ Once
only once, e.g., a zero-coupon
Definition: frequency.hpp:38
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
Real Rate
interest rates
Definition: types.hpp:70
base class for Inter-Bank-Offered-Rate indexes
Helper class to instantiate overnight indexed swaps.
Definition: any.hpp:37
ext::shared_ptr< YieldTermStructure > r
date schedule