QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
ratehelpers.hpp
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) 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
26/*! \file ratehelpers.hpp
27 \brief deposit, FRA, futures, and various swap rate helpers
28*/
29
30#ifndef quantlib_ratehelpers_hpp
31#define quantlib_ratehelpers_hpp
32
37#include <ql/time/calendar.hpp>
39#include <ql/optional.hpp>
40
41namespace QuantLib {
42
43 class SwapIndex;
44 class Quote;
45
49
50 //! Rate helper for bootstrapping over IborIndex futures prices
52 public:
54 const Date& iborStartDate,
55 Natural lengthInMonths,
56 const Calendar& calendar,
57 BusinessDayConvention convention,
58 bool endOfMonth,
59 const DayCounter& dayCounter,
63 const Date& iborStartDate,
64 Natural lengthInMonths,
65 const Calendar& calendar,
66 BusinessDayConvention convention,
67 bool endOfMonth,
68 const DayCounter& dayCounter,
72 const Date& iborStartDate,
73 const Date& iborEndDate,
74 const DayCounter& dayCounter,
78 const Date& iborStartDate,
79 const Date& endDate,
80 const DayCounter& dayCounter,
84 const Date& iborStartDate,
85 const ext::shared_ptr<IborIndex>& iborIndex,
89 const Date& iborStartDate,
90 const ext::shared_ptr<IborIndex>& iborIndex,
93 //! \name RateHelper interface
94 //@{
95 Real impliedQuote() const override;
96 //@}
97 //! \name FuturesRateHelper inspectors
98 //@{
100 //@}
101 //! \name Visitability
102 //@{
103 void accept(AcyclicVisitor&) override;
104 //@}
105 private:
108 };
109
110
111 //! Rate helper for bootstrapping over deposit rates
113 public:
115 const Period& tenor,
116 Natural fixingDays,
117 const Calendar& calendar,
118 BusinessDayConvention convention,
119 bool endOfMonth,
120 const DayCounter& dayCounter);
122 const Period& tenor,
123 Natural fixingDays,
124 const Calendar& calendar,
125 BusinessDayConvention convention,
126 bool endOfMonth,
127 const DayCounter& dayCounter);
129 const ext::shared_ptr<IborIndex>& iborIndex);
131 const ext::shared_ptr<IborIndex>& iborIndex);
132 //! \name RateHelper interface
133 //@{
134 Real impliedQuote() const override;
135 void setTermStructure(YieldTermStructure*) override;
136 //@}
137 //! \name Visitability
138 //@{
139 void accept(AcyclicVisitor&) override;
140 //@}
141 private:
142 void initializeDates() override;
144 ext::shared_ptr<IborIndex> iborIndex_;
146 };
147
148
149 //! Rate helper for bootstrapping over %FRA rates
151 public:
152 FraRateHelper(const Handle<Quote>& rate,
153 Natural monthsToStart,
154 Natural monthsToEnd,
155 Natural fixingDays,
156 const Calendar& calendar,
157 BusinessDayConvention convention,
158 bool endOfMonth,
159 const DayCounter& dayCounter,
161 Date customPillarDate = Date(),
162 bool useIndexedCoupon = true);
163 FraRateHelper(Rate rate,
164 Natural monthsToStart,
165 Natural monthsToEnd,
166 Natural fixingDays,
167 const Calendar& calendar,
168 BusinessDayConvention convention,
169 bool endOfMonth,
170 const DayCounter& dayCounter,
172 Date customPillarDate = Date(),
173 bool useIndexedCoupon = true);
174 FraRateHelper(const Handle<Quote>& rate,
175 Natural monthsToStart,
176 const ext::shared_ptr<IborIndex>& iborIndex,
178 Date customPillarDate = Date(),
179 bool useIndexedCoupon = true);
180 FraRateHelper(Rate rate,
181 Natural monthsToStart,
182 const ext::shared_ptr<IborIndex>& iborIndex,
184 Date customPillarDate = Date(),
185 bool useIndexedCoupon = true);
186 FraRateHelper(const Handle<Quote>& rate,
187 Period periodToStart,
188 Natural lengthInMonths,
189 Natural fixingDays,
190 const Calendar& calendar,
191 BusinessDayConvention convention,
192 bool endOfMonth,
193 const DayCounter& dayCounter,
195 Date customPillarDate = Date(),
196 bool useIndexedCoupon = true);
197 FraRateHelper(Rate rate,
198 Period periodToStart,
199 Natural lengthInMonths,
200 Natural fixingDays,
201 const Calendar& calendar,
202 BusinessDayConvention convention,
203 bool endOfMonth,
204 const DayCounter& dayCounter,
206 Date customPillarDate = Date(),
207 bool useIndexedCoupon = true);
208 FraRateHelper(const Handle<Quote>& rate,
209 Period periodToStart,
210 const ext::shared_ptr<IborIndex>& iborIndex,
212 Date customPillarDate = Date(),
213 bool useIndexedCoupon = true);
214 FraRateHelper(Rate rate,
215 Period periodToStart,
216 const ext::shared_ptr<IborIndex>& iborIndex,
218 Date customPillarDate = Date(),
219 bool useIndexedCoupon = true);
220 FraRateHelper(const Handle<Quote>& rate,
221 Natural immOffsetStart,
222 Natural immOffsetEnd,
223 const ext::shared_ptr<IborIndex>& iborIndex,
225 Date customPillarDate = Date(),
226 bool useIndexedCoupon = true);
227 FraRateHelper(Rate rate,
228 Natural immOffsetStart,
229 Natural immOffsetEnd,
230 const ext::shared_ptr<IborIndex>& iborIndex,
232 Date customPillarDate = Date(),
233 bool useIndexedCoupon = true);
234 //! \name RateHelper interface
235 //@{
236 Real impliedQuote() const override;
237 void setTermStructure(YieldTermStructure*) override;
238 //@}
239 //! \name Visitability
240 //@{
241 void accept(AcyclicVisitor&) override;
242 //@}
243 private:
244 void initializeDates() override;
246 ext::optional<Period> periodToStart_;
247 ext::optional<Natural> immOffsetStart_, immOffsetEnd_;
249 ext::shared_ptr<IborIndex> iborIndex_;
253 };
254
255
256 //! Rate helper for bootstrapping over swap rates
257 /*! \todo use input SwapIndex to create the swap */
259 public:
260 SwapRateHelper(const Handle<Quote>& rate,
261 const ext::shared_ptr<SwapIndex>& swapIndex,
263 const Period& fwdStart = 0 * Days,
264 // exogenous discounting curve
265 Handle<YieldTermStructure> discountingCurve = {},
267 Date customPillarDate = Date(),
268 bool endOfMonth = false,
269 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
270 SwapRateHelper(const Handle<Quote>& rate,
271 const Period& tenor,
272 Calendar calendar,
273 // fixed leg
274 Frequency fixedFrequency,
275 BusinessDayConvention fixedConvention,
276 DayCounter fixedDayCount,
277 // floating leg
278 const ext::shared_ptr<IborIndex>& iborIndex,
280 const Period& fwdStart = 0 * Days,
281 // exogenous discounting curve
282 Handle<YieldTermStructure> discountingCurve = {},
283 Natural settlementDays = Null<Natural>(),
285 Date customPillarDate = Date(),
286 bool endOfMonth = false,
287 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
288 SwapRateHelper(Rate rate,
289 const ext::shared_ptr<SwapIndex>& swapIndex,
291 const Period& fwdStart = 0 * Days,
292 // exogenous discounting curve
293 Handle<YieldTermStructure> discountingCurve = {},
295 Date customPillarDate = Date(),
296 bool endOfMonth = false,
297 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
298 SwapRateHelper(Rate rate,
299 const Period& tenor,
300 Calendar calendar,
301 // fixed leg
302 Frequency fixedFrequency,
303 BusinessDayConvention fixedConvention,
304 DayCounter fixedDayCount,
305 // floating leg
306 const ext::shared_ptr<IborIndex>& iborIndex,
308 const Period& fwdStart = 0 * Days,
309 // exogenous discounting curve
310 Handle<YieldTermStructure> discountingCurve = {},
311 Natural settlementDays = Null<Natural>(),
313 Date customPillarDate = Date(),
314 bool endOfMonth = false,
315 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
316 //! \name RateHelper interface
317 //@{
318 Real impliedQuote() const override;
319 void setTermStructure(YieldTermStructure*) override;
320 //@}
321 //! \name SwapRateHelper inspectors
322 //@{
323 Spread spread() const;
324 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
325 ext::shared_ptr<VanillaSwap> swap() const;
326 const Period& forwardStart() const;
327 //@}
328 //! \name Visitability
329 //@{
330 void accept(AcyclicVisitor&) override;
331 //@}
332 protected:
333 void initializeDates() override;
341 ext::shared_ptr<IborIndex> iborIndex_;
342 ext::shared_ptr<VanillaSwap> swap_;
349 ext::optional<bool> useIndexedCoupons_;
350 };
351
352
353 //! Rate helper for bootstrapping over BMA swap rates
355 public:
356 BMASwapRateHelper(const Handle<Quote>& liborFraction,
357 const Period& tenor, // swap maturity
358 Natural settlementDays,
359 Calendar calendar,
360 // bma leg
361 const Period& bmaPeriod,
362 BusinessDayConvention bmaConvention,
363 DayCounter bmaDayCount,
364 ext::shared_ptr<BMAIndex> bmaIndex,
365 // ibor leg
366 ext::shared_ptr<IborIndex> index);
367 //! \name RateHelper interface
368 //@{
369 Real impliedQuote() const override;
370 void setTermStructure(YieldTermStructure*) override;
371 //@}
372 //! \name Visitability
373 //@{
374 void accept(AcyclicVisitor&) override;
375 //@}
376 protected:
377 void initializeDates() override;
384 ext::shared_ptr<BMAIndex> bmaIndex_;
385 ext::shared_ptr<IborIndex> iborIndex_;
386
387 ext::shared_ptr<BMASwap> swap_;
389 };
390
391
392 //! Rate helper for bootstrapping over Fx Swap rates
393 /*! The forward is given by `fwdFx = spotFx + fwdPoint`.
394
395 `isFxBaseCurrencyCollateralCurrency` indicates if the base
396 currency of the FX currency pair is the one used as collateral.
397
398 `calendar` is usually the joint calendar of the two currencies
399 in the pair.
400
401 `tradingCalendar` can be used when the cross pairs don't
402 include the currency of the business center (usually USD; the
403 corresponding calendar is `UnitedStates`). If given, it will
404 be used for adjusting the earliest settlement date and for
405 setting the latest date. Due to FX spot market conventions, it
406 is not sufficient to pass a JointCalendar with UnitedStates
407 included as `calendar`; with regard the earliest date, this
408 calendar is only used in case the spot date of the two
409 currencies is not a US business day.
410
411 \warning The ON fx swaps can be achieved by setting
412 `fixingDays` to 0 and using a tenor of '1d'. The same
413 tenor should be used for TN swaps, with `fixingDays`
414 set to 1. However, handling ON and TN swaps for
415 cross rates without USD is not trivial and should be
416 treated with caution. If today is a US holiday, ON
417 trade is not possible. If tomorrow is a US Holiday,
418 the ON trade will be at least two business days long
419 in the other countries and the TN trade will not
420 exist. In such cases, if this helper is used for
421 curve construction, probably it is safer not to pass
422 a trading calendar to the ON and TN helpers and
423 provide fwdPoints that will yield proper level of
424 discount factors.
425 */
427 public:
428 FxSwapRateHelper(const Handle<Quote>& fwdPoint,
429 Handle<Quote> spotFx,
430 const Period& tenor,
433 BusinessDayConvention convention,
434 bool endOfMonth,
436 Handle<YieldTermStructure> collateralCurve,
438 //! \name RateHelper interface
439 //@{
440 Real impliedQuote() const override;
441 void setTermStructure(YieldTermStructure*) override;
442 //@}
443 //! \name FxSwapRateHelper inspectors
444 //@{
445 Real spot() const { return spot_->value(); }
446 Period tenor() const { return tenor_; }
447 Natural fixingDays() const { return fixingDays_; }
448 Calendar calendar() const { return cal_; }
450 bool endOfMonth() const { return eom_; }
455 //@}
456 //! \name Visitability
457 //@{
458 void accept(AcyclicVisitor&) override;
459 //@}
460 private:
461 void initializeDates() override;
467 bool eom_;
469
471
474
477 };
478
479 // inline
480
482 return spread_.empty() ? 0.0 : spread_->value();
483 }
484
485 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
486 inline ext::shared_ptr<VanillaSwap> SwapRateHelper::swap() const {
487 return swap_;
488 }
489
490 inline const Period& SwapRateHelper::forwardStart() const {
491 return fwdStart_;
492 }
493
494}
495
496#endif
swap paying Libor against BMA coupons
base helper class used for bootstrapping
calendar class
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:51
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:117
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.
day counter class
Futures.
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:46
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper
Definition: ratehelpers.hpp:48
Maps optional to either the boost or std implementation.
Type
Futures type enumeration.
Definition: futures.hpp:36
Choice
Enumeration for pillar determination alternatives.
@ LastRelevantDate
instruments maturity date
Simple fixed-rate vs Libor swap.