QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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_));
152
153 if (engine_ == nullptr) {
155 overnightIndex_->forwardingTermStructure();
156 bool includeSettlementDateFlows = false;
157 ext::shared_ptr<PricingEngine> engine(new
158 DiscountingSwapEngine(disc, includeSettlementDateFlows));
159 ois->setPricingEngine(engine);
160 } else
161 ois->setPricingEngine(engine_);
162
163 return ois;
164 }
165
167 type_ = flag ? Swap::Receiver : Swap::Payer ;
168 return *this;
169 }
170
172 type_ = type;
173 return *this;
174 }
175
177 nominal_ = n;
178 return *this;
179 }
180
182 settlementDays_ = settlementDays;
184 return *this;
185 }
186
187 MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
188 effectiveDate_ = effectiveDate;
189 return *this;
190 }
191
192 MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
193 terminationDate_ = terminationDate;
194 swapTenor_ = Period();
195 return *this;
196 }
197
200 }
201
204 return *this;
205 }
206
209 return *this;
210 }
211
213 paymentAdjustment_ = convention;
214 return *this;
215 }
216
218 paymentLag_ = lag;
219 return *this;
220 }
221
223 paymentCalendar_ = cal;
224 return *this;
225 }
226
229 }
230
232 fixedCalendar_ = cal;
233 return *this;
234 }
235
237 overnightCalendar_ = cal;
238 return *this;
239 }
240
243 }
244
246 fixedRule_ = r;
247 return *this;
248 }
249
252 return *this;
253 }
254
257 bool includeSettlementDateFlows = false;
258 engine_ = ext::shared_ptr<PricingEngine>(new
259 DiscountingSwapEngine(d, includeSettlementDateFlows));
260 return *this;
261 }
262
264 const ext::shared_ptr<PricingEngine>& engine) {
265 engine_ = engine;
266 return *this;
267 }
268
270 fixedDayCount_ = dc;
271 return *this;
272 }
273
276 }
277
279 fixedConvention_ = bdc;
280 return *this;
281 }
282
285 return *this;
286 }
287
291 }
292
295 return *this;
296 }
297
300 return *this;
301 }
302
305 }
306
308 fixedEndOfMonth_ = flag;
309 isDefaultEOM_ = false;
310 return *this;
311 }
312
315 isDefaultEOM_ = false;
316 return *this;
317 }
318
320 overnightSpread_ = sp;
321 return *this;
322 }
323
324 MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
325 telescopicValueDates_ = telescopicValueDates;
326 return *this;
327 }
328
330 averagingMethod_ = averagingMethod;
331 return *this;
332 }
333
334}
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:191
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:94
BusinessDayConvention paymentAdjustment_
Definition: makeois.hpp:106
BusinessDayConvention fixedConvention_
Definition: makeois.hpp:109
MakeOIS & withFixedLegRule(DateGeneration::Rule r)
Definition: makeois.cpp:245
bool telescopicValueDates_
Definition: makeois.hpp:125
MakeOIS & withPaymentAdjustment(BusinessDayConvention convention)
Definition: makeois.cpp:212
MakeOIS & withTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:288
MakeOIS & withPaymentLag(Integer lag)
Definition: makeois.cpp:217
MakeOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
Definition: makeois.cpp:255
MakeOIS & withType(Swap::Type type)
Definition: makeois.cpp:171
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:181
Calendar paymentCalendar_
Definition: makeois.hpp:105
DateGeneration::Rule overnightRule_
Definition: makeois.hpp:114
DayCounter fixedDayCount_
Definition: makeois.hpp:121
MakeOIS & receiveFixed(bool flag=true)
Definition: makeois.cpp:166
MakeOIS & withPaymentFrequency(Frequency f)
Definition: makeois.cpp:198
bool overnightEndOfMonth_
Definition: makeois.hpp:115
MakeOIS & withFixedLegDayCount(const DayCounter &dc)
Definition: makeois.cpp:269
Integer paymentLag_
Definition: makeois.hpp:107
MakeOIS & withRule(DateGeneration::Rule r)
Definition: makeois.cpp:241
MakeOIS & withCalendar(const Calendar &cal)
Definition: makeois.cpp:227
MakeOIS & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
Definition: makeois.cpp:263
MakeOIS & withFixedLegEndOfMonth(bool flag=true)
Definition: makeois.cpp:307
MakeOIS & withOvernightLegRule(DateGeneration::Rule r)
Definition: makeois.cpp:250
MakeOIS & withFixedLegConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:278
BusinessDayConvention overnightConvention_
Definition: makeois.hpp:111
Frequency fixedPaymentFrequency_
Definition: makeois.hpp:103
MakeOIS & withOvernightLegTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:298
MakeOIS & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:293
Frequency overnightPaymentFrequency_
Definition: makeois.hpp:104
Natural settlementDays_
Definition: makeois.hpp:99
RateAveraging::Type averagingMethod_
Definition: makeois.hpp:126
BusinessDayConvention overnightTerminationDateConvention_
Definition: makeois.hpp:112
MakeOIS & withFixedLegCalendar(const Calendar &cal)
Definition: makeois.cpp:231
MakeOIS & withPaymentCalendar(const Calendar &cal)
Definition: makeois.cpp:222
DateGeneration::Rule fixedRule_
Definition: makeois.hpp:113
MakeOIS & withTerminationDate(const Date &)
Definition: makeois.cpp:192
MakeOIS & withEffectiveDate(const Date &)
Definition: makeois.cpp:187
MakeOIS & withOvernightLegSpread(Spread sp)
Definition: makeois.cpp:319
ext::shared_ptr< PricingEngine > engine_
Definition: makeois.hpp:123
Calendar overnightCalendar_
Definition: makeois.hpp:101
Swap::Type type_
Definition: makeois.hpp:117
MakeOIS & withEndOfMonth(bool flag=true)
Definition: makeois.cpp:303
MakeOIS & withOvernightLegPaymentFrequency(Frequency f)
Definition: makeois.cpp:207
MakeOIS & withFixedLegPaymentFrequency(Frequency f)
Definition: makeois.cpp:202
BusinessDayConvention fixedTerminationDateConvention_
Definition: makeois.hpp:110
MakeOIS & withNominal(Real n)
Definition: makeois.cpp:176
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:329
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:324
MakeOIS & withConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:274
MakeOIS & withOvernightLegConvention(BusinessDayConvention bdc)
Definition: makeois.cpp:283
Spread overnightSpread_
Definition: makeois.hpp:120
Calendar fixedCalendar_
Definition: makeois.hpp:101
MakeOIS & withOvernightLegCalendar(const Calendar &cal)
Definition: makeois.cpp:236
MakeOIS & withOvernightLegEndOfMonth(bool flag=true)
Definition: makeois.cpp:313
template class providing a null value for a given type.
Definition: null.hpp:76
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
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:35
ext::shared_ptr< YieldTermStructure > r
date schedule