QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
ratehelpers.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 StatPro Italia srl
6 Copyright (C) 2007, 2008, 2009, 2015 Ferdinando Ametrano
7 Copyright (C) 2007, 2009 Roland Lichters
8 Copyright (C) 2015 Maddalena Zanzi
9 Copyright (C) 2015 Paolo Mazzocchi
10 Copyright (C) 2018 Matthias Lungwitz
11
12 This file is part of QuantLib, a free-software/open-source library
13 for financial quantitative analysts and developers - http://quantlib.org/
14
15 QuantLib is free software: you can redistribute it and/or modify it
16 under the terms of the QuantLib license. You should have received a
17 copy of the license along with this program; if not, please email
18 <quantlib-dev@lists.sf.net>. The license is also available online at
19 <http://quantlib.org/license.shtml>.
20
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the license for more details.
24*/
25
30#ifndef quantlib_ratehelpers_hpp
31#define quantlib_ratehelpers_hpp
32
33#include <ql/termstructures/bootstraphelper.hpp>
34#include <ql/instruments/vanillaswap.hpp>
35#include <ql/instruments/bmaswap.hpp>
36#include <ql/instruments/futures.hpp>
37#include <ql/time/calendar.hpp>
38#include <ql/time/daycounter.hpp>
39#include <ql/time/calendars/unitedstates.hpp>
40#include <ql/optional.hpp>
41
42namespace QuantLib {
43
44 class SwapIndex;
45 class Quote;
46
50
53 public:
55 const Date& iborStartDate,
56 Natural lengthInMonths,
57 const Calendar& calendar,
58 BusinessDayConvention convention,
59 bool endOfMonth,
60 const DayCounter& dayCounter,
64 const Date& iborStartDate,
65 Natural lengthInMonths,
66 const Calendar& calendar,
67 BusinessDayConvention convention,
68 bool endOfMonth,
69 const DayCounter& dayCounter,
73 const Date& iborStartDate,
74 const Date& iborEndDate,
75 const DayCounter& dayCounter,
79 const Date& iborStartDate,
80 const Date& endDate,
81 const DayCounter& dayCounter,
85 const Date& iborStartDate,
86 const ext::shared_ptr<IborIndex>& iborIndex,
90 const Date& iborStartDate,
91 const ext::shared_ptr<IborIndex>& iborIndex,
95
96 Real impliedQuote() const override;
98
102
104 void accept(AcyclicVisitor&) override;
106 private:
109 };
110
111
114 public:
116 const Period& tenor,
117 Natural fixingDays,
118 const Calendar& calendar,
119 BusinessDayConvention convention,
120 bool endOfMonth,
121 const DayCounter& dayCounter);
123 const Period& tenor,
124 Natural fixingDays,
125 const Calendar& calendar,
126 BusinessDayConvention convention,
127 bool endOfMonth,
128 const DayCounter& dayCounter);
130 const ext::shared_ptr<IborIndex>& iborIndex);
132 const ext::shared_ptr<IborIndex>& iborIndex);
134
135 Real impliedQuote() const override;
136 void setTermStructure(YieldTermStructure*) override;
138
140 void accept(AcyclicVisitor&) override;
142 private:
143 void initializeDates() override;
145 ext::shared_ptr<IborIndex> iborIndex_;
147 };
148
149
152 public:
153 FraRateHelper(const Handle<Quote>& rate,
154 Natural monthsToStart,
155 Natural monthsToEnd,
156 Natural fixingDays,
157 const Calendar& calendar,
158 BusinessDayConvention convention,
159 bool endOfMonth,
160 const DayCounter& dayCounter,
162 Date customPillarDate = Date(),
163 bool useIndexedCoupon = true);
164 FraRateHelper(Rate rate,
165 Natural monthsToStart,
166 Natural monthsToEnd,
167 Natural fixingDays,
168 const Calendar& calendar,
169 BusinessDayConvention convention,
170 bool endOfMonth,
171 const DayCounter& dayCounter,
173 Date customPillarDate = Date(),
174 bool useIndexedCoupon = true);
175 FraRateHelper(const Handle<Quote>& rate,
176 Natural monthsToStart,
177 const ext::shared_ptr<IborIndex>& iborIndex,
179 Date customPillarDate = Date(),
180 bool useIndexedCoupon = true);
181 FraRateHelper(Rate rate,
182 Natural monthsToStart,
183 const ext::shared_ptr<IborIndex>& iborIndex,
185 Date customPillarDate = Date(),
186 bool useIndexedCoupon = true);
187 FraRateHelper(const Handle<Quote>& rate,
188 Period periodToStart,
189 Natural lengthInMonths,
190 Natural fixingDays,
191 const Calendar& calendar,
192 BusinessDayConvention convention,
193 bool endOfMonth,
194 const DayCounter& dayCounter,
196 Date customPillarDate = Date(),
197 bool useIndexedCoupon = true);
198 FraRateHelper(Rate rate,
199 Period periodToStart,
200 Natural lengthInMonths,
201 Natural fixingDays,
202 const Calendar& calendar,
203 BusinessDayConvention convention,
204 bool endOfMonth,
205 const DayCounter& dayCounter,
207 Date customPillarDate = Date(),
208 bool useIndexedCoupon = true);
209 FraRateHelper(const Handle<Quote>& rate,
210 Period periodToStart,
211 const ext::shared_ptr<IborIndex>& iborIndex,
213 Date customPillarDate = Date(),
214 bool useIndexedCoupon = true);
215 FraRateHelper(Rate rate,
216 Period periodToStart,
217 const ext::shared_ptr<IborIndex>& iborIndex,
219 Date customPillarDate = Date(),
220 bool useIndexedCoupon = true);
221 FraRateHelper(const Handle<Quote>& rate,
222 Natural immOffsetStart,
223 Natural immOffsetEnd,
224 const ext::shared_ptr<IborIndex>& iborIndex,
226 Date customPillarDate = Date(),
227 bool useIndexedCoupon = true);
228 FraRateHelper(Rate rate,
229 Natural immOffsetStart,
230 Natural immOffsetEnd,
231 const ext::shared_ptr<IborIndex>& iborIndex,
233 Date customPillarDate = Date(),
234 bool useIndexedCoupon = true);
236
237 Real impliedQuote() const override;
238 void setTermStructure(YieldTermStructure*) override;
240
242 void accept(AcyclicVisitor&) override;
244 private:
245 void initializeDates() override;
247 ext::optional<Period> periodToStart_;
248 ext::optional<Natural> immOffsetStart_, immOffsetEnd_;
250 ext::shared_ptr<IborIndex> iborIndex_;
254 };
255
256
258
260 public:
261 SwapRateHelper(const Handle<Quote>& rate,
262 const ext::shared_ptr<SwapIndex>& swapIndex,
264 const Period& fwdStart = 0 * Days,
265 // exogenous discounting curve
266 Handle<YieldTermStructure> discountingCurve = {},
268 Date customPillarDate = Date(),
269 bool endOfMonth = false,
270 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
271 SwapRateHelper(const Handle<Quote>& rate,
272 const Period& tenor,
273 Calendar calendar,
274 // fixed leg
275 Frequency fixedFrequency,
276 BusinessDayConvention fixedConvention,
277 DayCounter fixedDayCount,
278 // floating leg
279 const ext::shared_ptr<IborIndex>& iborIndex,
281 const Period& fwdStart = 0 * Days,
282 // exogenous discounting curve
283 Handle<YieldTermStructure> discountingCurve = {},
284 Natural settlementDays = Null<Natural>(),
286 Date customPillarDate = Date(),
287 bool endOfMonth = false,
288 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
289 SwapRateHelper(Rate rate,
290 const ext::shared_ptr<SwapIndex>& swapIndex,
292 const Period& fwdStart = 0 * Days,
293 // exogenous discounting curve
294 Handle<YieldTermStructure> discountingCurve = {},
296 Date customPillarDate = Date(),
297 bool endOfMonth = false,
298 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
299 SwapRateHelper(Rate rate,
300 const Period& tenor,
301 Calendar calendar,
302 // fixed leg
303 Frequency fixedFrequency,
304 BusinessDayConvention fixedConvention,
305 DayCounter fixedDayCount,
306 // floating leg
307 const ext::shared_ptr<IborIndex>& iborIndex,
309 const Period& fwdStart = 0 * Days,
310 // exogenous discounting curve
311 Handle<YieldTermStructure> discountingCurve = {},
312 Natural settlementDays = Null<Natural>(),
314 Date customPillarDate = Date(),
315 bool endOfMonth = false,
316 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
318
319 Real impliedQuote() const override;
320 void setTermStructure(YieldTermStructure*) override;
322
324 Spread spread() const;
325 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
326 ext::shared_ptr<VanillaSwap> swap() const;
327 const Period& forwardStart() const;
329
331 void accept(AcyclicVisitor&) override;
333 protected:
334 void initializeDates() override;
342 ext::shared_ptr<IborIndex> iborIndex_;
343 ext::shared_ptr<VanillaSwap> swap_;
350 ext::optional<bool> useIndexedCoupons_;
351 };
352
353
356 public:
357 BMASwapRateHelper(const Handle<Quote>& liborFraction,
358 const Period& tenor, // swap maturity
359 Natural settlementDays,
360 Calendar calendar,
361 // bma leg
362 const Period& bmaPeriod,
363 BusinessDayConvention bmaConvention,
364 DayCounter bmaDayCount,
365 ext::shared_ptr<BMAIndex> bmaIndex,
366 // ibor leg
367 ext::shared_ptr<IborIndex> index);
369
370 Real impliedQuote() const override;
371 void setTermStructure(YieldTermStructure*) override;
373
375 void accept(AcyclicVisitor&) override;
377 protected:
378 void initializeDates() override;
385 ext::shared_ptr<BMAIndex> bmaIndex_;
386 ext::shared_ptr<IborIndex> iborIndex_;
387
388 ext::shared_ptr<BMASwap> swap_;
390 };
391
392
394
428 public:
429 FxSwapRateHelper(const Handle<Quote>& fwdPoint,
430 Handle<Quote> spotFx,
431 const Period& tenor,
434 BusinessDayConvention convention,
435 bool endOfMonth,
437 Handle<YieldTermStructure> collateralCurve,
440
441 Real impliedQuote() const override;
442 void setTermStructure(YieldTermStructure*) override;
444
446 Real spot() const { return spot_->value(); }
447 Period tenor() const { return tenor_; }
448 Natural fixingDays() const { return fixingDays_; }
449 Calendar calendar() const { return cal_; }
451 bool endOfMonth() const { return eom_; }
457
459 void accept(AcyclicVisitor&) override;
461 private:
462 void initializeDates() override;
468 bool eom_;
470
472
475
478 };
479
480 // inline
481
483 return spread_.empty() ? 0.0 : spread_->value();
484 }
485
486 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
487 inline ext::shared_ptr<VanillaSwap> SwapRateHelper::swap() const {
488 return swap_;
489 }
490
491 inline const Period& SwapRateHelper::forwardStart() const {
492 return fwdStart_;
493 }
494
495}
496
497#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Rate helper for bootstrapping over BMA swap rates.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< IborIndex > iborIndex_
void accept(AcyclicVisitor &) override
void initializeDates() override
ext::shared_ptr< BMAIndex > bmaIndex_
Real impliedQuote() const override
BusinessDayConvention bmaConvention_
ext::shared_ptr< BMASwap > swap_
Base helper class for bootstrapping.
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Rate helper for bootstrapping over deposit rates.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< IborIndex > iborIndex_
void accept(AcyclicVisitor &) override
void initializeDates() override
Real impliedQuote() const override
Rate helper for bootstrapping over FRA rates.
ext::optional< Natural > immOffsetEnd_
void setTermStructure(YieldTermStructure *) override
ext::optional< Natural > immOffsetStart_
RelinkableHandle< YieldTermStructure > termStructureHandle_
Pillar::Choice pillarChoice_
ext::shared_ptr< IborIndex > iborIndex_
ext::optional< Period > periodToStart_
void accept(AcyclicVisitor &) override
void initializeDates() override
Real impliedQuote() const override
Rate helper for bootstrapping over IborIndex futures prices.
Definition: ratehelpers.hpp:52
void accept(AcyclicVisitor &) override
Real impliedQuote() const override
Rate helper for bootstrapping over Fx Swap rates.
Calendar tradingCalendar() const
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Natural fixingDays() const
Calendar calendar() const
void accept(AcyclicVisitor &) override
RelinkableHandle< YieldTermStructure > collRelinkableHandle_
Handle< YieldTermStructure > collHandle_
void initializeDates() override
BusinessDayConvention conv_
bool isFxBaseCurrencyCollateralCurrency() const
Real impliedQuote() const override
Calendar adjustmentCalendar() const
BusinessDayConvention businessDayConvention() const
Shared handle to an observable.
Definition: handle.hpp:41
template class providing a null value for a given type.
Definition: null.hpp:76
Bootstrap helper with date schedule relative to global evaluation date.
Relinkable handle to an observable.
Definition: handle.hpp:112
Rate helper for bootstrapping over swap rates.
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
BusinessDayConvention fixedConvention_
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< VanillaSwap > swap_
Pillar::Choice pillarChoice_
const Period & forwardStart() const
Handle< YieldTermStructure > discountHandle_
Handle< Quote > spread_
ext::shared_ptr< IborIndex > iborIndex_
ext::optional< bool > useIndexedCoupons_
ext::shared_ptr< VanillaSwap > swap() const
void accept(AcyclicVisitor &) override
void initializeDates() override
Real impliedQuote() const override
Interest-rate term structure.
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
BootstrapHelper< YieldTermStructure > RateHelper
Definition: ratehelpers.hpp:47
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper
Definition: ratehelpers.hpp:49
Type
Futures type enumeration.
Definition: futures.hpp:36
Choice
Enumeration for pillar determination alternatives.
@ LastRelevantDate
instruments maturity date