QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
makeois.cpp
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
23#include <ql/instruments/makeois.hpp>
24#include <ql/pricingengines/swap/discountingswapengine.hpp>
25#include <ql/indexes/iborindex.hpp>
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
37 calendar_(overnightIndex->fixingCalendar()),
38
39 fixedDayCount_(overnightIndex->dayCounter()) {}
40
41 MakeOIS::operator OvernightIndexedSwap() const {
42 ext::shared_ptr<OvernightIndexedSwap> ois = *this;
43 return *ois;
44 }
45
46 MakeOIS::operator ext::shared_ptr<OvernightIndexedSwap>() const {
47
48 Date startDate;
49 if (effectiveDate_ != Date())
50 startDate = effectiveDate_;
51 else {
53 // if the evaluation date is not a business day
54 // then move to the next business day
55 refDate = calendar_.adjust(refDate);
56 Date spotDate = calendar_.advance(refDate,
57 settlementDays_*Days);
58 startDate = spotDate+forwardStart_;
59 if (forwardStart_.length()<0)
60 startDate = calendar_.adjust(startDate, Preceding);
61 else
62 startDate = calendar_.adjust(startDate, Following);
63 }
64
65 // OIS end of month default
66 bool usedEndOfMonth =
67 isDefaultEOM_ ? calendar_.isEndOfMonth(startDate) : endOfMonth_;
68
69 Date endDate = terminationDate_;
70 if (endDate == Date()) {
71 if (usedEndOfMonth)
72 endDate = calendar_.advance(startDate,
73 swapTenor_,
75 usedEndOfMonth);
76 else
77 endDate = startDate + swapTenor_;
78 }
79
80 Schedule schedule(startDate, endDate,
81 Period(paymentFrequency_),
82 calendar_,
85 rule_,
86 usedEndOfMonth);
87
88 Rate usedFixedRate = fixedRate_;
89 if (fixedRate_ == Null<Rate>()) {
90 OvernightIndexedSwap temp(type_, nominal_,
91 schedule,
92 0.0, // fixed rate
93 fixedDayCount_,
94 overnightIndex_, overnightSpread_,
95 paymentLag_, paymentAdjustment_,
96 paymentCalendar_, telescopicValueDates_);
97 if (engine_ == nullptr) {
99 overnightIndex_->forwardingTermStructure();
100 QL_REQUIRE(!disc.empty(),
101 "null term structure set to this instance of " <<
102 overnightIndex_->name());
103 bool includeSettlementDateFlows = false;
104 ext::shared_ptr<PricingEngine> engine(new
105 DiscountingSwapEngine(disc, includeSettlementDateFlows));
106 temp.setPricingEngine(engine);
107 } else
108 temp.setPricingEngine(engine_);
109
110 usedFixedRate = temp.fairRate();
111 }
112
113 ext::shared_ptr<OvernightIndexedSwap> ois(new
114 OvernightIndexedSwap(type_, nominal_,
115 schedule,
116 usedFixedRate, fixedDayCount_,
117 overnightIndex_, overnightSpread_,
118 paymentLag_, paymentAdjustment_,
119 paymentCalendar_, telescopicValueDates_,
120 averagingMethod_));
121
122 if (engine_ == nullptr) {
124 overnightIndex_->forwardingTermStructure();
125 bool includeSettlementDateFlows = false;
126 ext::shared_ptr<PricingEngine> engine(new
127 DiscountingSwapEngine(disc, includeSettlementDateFlows));
128 ois->setPricingEngine(engine);
129 } else
130 ois->setPricingEngine(engine_);
131
132 return ois;
133 }
134
136 type_ = flag ? Swap::Receiver : Swap::Payer ;
137 return *this;
138 }
139
141 type_ = type;
142 return *this;
143 }
144
146 nominal_ = n;
147 return *this;
148 }
149
151 settlementDays_ = settlementDays;
153 return *this;
154 }
155
156 MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
157 effectiveDate_ = effectiveDate;
158 return *this;
159 }
160
161 MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
162 terminationDate_ = terminationDate;
163 swapTenor_ = Period();
164 return *this;
165 }
166
171 return *this;
172 }
173
175 paymentAdjustment_ = convention;
176 return *this;
177 }
178
180 paymentLag_ = lag;
181 return *this;
182 }
183
185 paymentCalendar_ = cal;
186 return *this;
187 }
188
190 rule_ = r;
193 return *this;
194 }
195
198 bool includeSettlementDateFlows = false;
199 engine_ = ext::shared_ptr<PricingEngine>(new
200 DiscountingSwapEngine(d, includeSettlementDateFlows));
201 return *this;
202 }
203
205 const ext::shared_ptr<PricingEngine>& engine) {
206 engine_ = engine;
207 return *this;
208 }
209
211 fixedDayCount_ = dc;
212 return *this;
213 }
214
216 endOfMonth_ = flag;
217 isDefaultEOM_ = false;
218 return *this;
219 }
220
222 overnightSpread_ = sp;
223 return *this;
224 }
225
226 MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
227 telescopicValueDates_ = telescopicValueDates;
228 return *this;
229 }
230
232 averagingMethod_ = averagingMethod;
233 return *this;
234 }
235
236}
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
static bool isEndOfMonth(const Date &d)
whether a date is the last day of its month
Definition: date.hpp:434
static Date advance(const Date &d, Integer units, TimeUnit)
Definition: date.cpp:139
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:166
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:79
BusinessDayConvention paymentAdjustment_
Definition: makeois.hpp:90
bool telescopicValueDates_
Definition: makeois.hpp:104
MakeOIS & withPaymentAdjustment(BusinessDayConvention convention)
Definition: makeois.cpp:174
MakeOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
Definition: makeois.cpp:196
MakeOIS & withType(Swap::Type type)
Definition: makeois.cpp:140
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:150
Calendar paymentCalendar_
Definition: makeois.hpp:89
DayCounter fixedDayCount_
Definition: makeois.hpp:100
MakeOIS & receiveFixed(bool flag=true)
Definition: makeois.cpp:135
MakeOIS & withPaymentFrequency(Frequency f)
Definition: makeois.cpp:167
Date terminationDate_
Definition: makeois.hpp:85
Natural paymentLag_
Definition: makeois.hpp:91
MakeOIS & withFixedLegDayCount(const DayCounter &dc)
Definition: makeois.cpp:210
MakeOIS & withRule(DateGeneration::Rule r)
Definition: makeois.cpp:189
MakeOIS & withPaymentLag(Natural lag)
Definition: makeois.cpp:179
MakeOIS & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
Definition: makeois.cpp:204
DateGeneration::Rule rule_
Definition: makeois.hpp:93
Natural settlementDays_
Definition: makeois.hpp:84
RateAveraging::Type averagingMethod_
Definition: makeois.hpp:105
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
ext::shared_ptr< PricingEngine > engine_
Definition: makeois.hpp:102
Swap::Type type_
Definition: makeois.hpp:96
MakeOIS & withEndOfMonth(bool flag=true)
Definition: makeois.cpp:215
MakeOIS & withNominal(Real n)
Definition: makeois.cpp:145
MakeOIS & withAveragingMethod(RateAveraging::Type averagingMethod)
Definition: makeois.cpp:231
MakeOIS & withTelescopicValueDates(bool telescopicValueDates)
Definition: makeois.cpp:226
Frequency paymentFrequency_
Definition: makeois.hpp:88
Spread overnightSpread_
Definition: makeois.hpp:99
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
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
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35