QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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:
53 FuturesRateHelper(const std::variant<Real, Handle<Quote>>& price,
54 const Date& iborStartDate,
55 Natural lengthInMonths,
56 const Calendar& calendar,
57 BusinessDayConvention convention,
58 bool endOfMonth,
59 const DayCounter& dayCounter,
60 const std::variant<Real, Handle<Quote>>& convexityAdjustment = 0.0,
62 FuturesRateHelper(const std::variant<Real, Handle<Quote>>& price,
63 const Date& iborStartDate,
64 const Date& iborEndDate,
65 const DayCounter& dayCounter,
66 const std::variant<Real, Handle<Quote>>& convexityAdjustment = 0.0,
68 FuturesRateHelper(const std::variant<Real, Handle<Quote>>& price,
69 const Date& iborStartDate,
70 const ext::shared_ptr<IborIndex>& iborIndex,
71 const std::variant<Real, Handle<Quote>>& convexityAdjustment = 0.0,
73 //! \name RateHelper interface
74 //@{
75 Real impliedQuote() const override;
76 //@}
77 //! \name FuturesRateHelper inspectors
78 //@{
80 //@}
81 //! \name Visitability
82 //@{
83 void accept(AcyclicVisitor&) override;
84 //@}
85 private:
88 };
89
90
91 //! Rate helper for bootstrapping over deposit rates
93 public:
94 DepositRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
95 const Period& tenor,
96 Natural fixingDays,
97 const Calendar& calendar,
98 BusinessDayConvention convention,
99 bool endOfMonth,
100 const DayCounter& dayCounter);
101 DepositRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
102 const ext::shared_ptr<IborIndex>& iborIndex);
103 DepositRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
104 Date fixingDate,
105 const ext::shared_ptr<IborIndex>& iborIndex);
106 //! \name RateHelper interface
107 //@{
108 Real impliedQuote() const override;
109 void setTermStructure(YieldTermStructure*) override;
110 //@}
111 //! \name Visitability
112 //@{
113 void accept(AcyclicVisitor&) override;
114 //@}
115 private:
116 void initializeDates() override;
118 ext::shared_ptr<IborIndex> iborIndex_;
120 };
121
122
123 //! Rate helper for bootstrapping over %FRA rates
125 public:
126 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
127 Natural monthsToStart,
128 Natural monthsToEnd,
129 Natural fixingDays,
130 const Calendar& calendar,
131 BusinessDayConvention convention,
132 bool endOfMonth,
133 const DayCounter& dayCounter,
135 Date customPillarDate = Date(),
136 bool useIndexedCoupon = true);
137 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
138 Natural monthsToStart,
139 const ext::shared_ptr<IborIndex>& iborIndex,
141 Date customPillarDate = Date(),
142 bool useIndexedCoupon = true);
143 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
144 Period periodToStart,
145 Natural lengthInMonths,
146 Natural fixingDays,
147 const Calendar& calendar,
148 BusinessDayConvention convention,
149 bool endOfMonth,
150 const DayCounter& dayCounter,
152 Date customPillarDate = Date(),
153 bool useIndexedCoupon = true);
154 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
155 Period periodToStart,
156 const ext::shared_ptr<IborIndex>& iborIndex,
158 Date customPillarDate = Date(),
159 bool useIndexedCoupon = true);
160 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
161 Natural immOffsetStart,
162 Natural immOffsetEnd,
163 const ext::shared_ptr<IborIndex>& iborIndex,
165 Date customPillarDate = Date(),
166 bool useIndexedCoupon = true);
167 FraRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
168 Date startDate,
169 Date endDate,
170 const ext::shared_ptr<IborIndex>& iborIndex,
172 Date customPillarDate = Date(),
173 bool useIndexedCoupon = true);
174 //! \name RateHelper interface
175 //@{
176 Real impliedQuote() const override;
177 void setTermStructure(YieldTermStructure*) override;
178 //@}
179 //! \name Visitability
180 //@{
181 void accept(AcyclicVisitor&) override;
182 //@}
183 private:
184 void initializeDates() override;
186 ext::optional<Period> periodToStart_;
187 ext::optional<Natural> immOffsetStart_, immOffsetEnd_;
189 ext::shared_ptr<IborIndex> iborIndex_;
193 };
194
195
196 //! Rate helper for bootstrapping over swap rates
197 /*! \todo use input SwapIndex to create the swap */
199 public:
200 SwapRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
201 const ext::shared_ptr<SwapIndex>& swapIndex,
203 const Period& fwdStart = 0 * Days,
204 // exogenous discounting curve
205 Handle<YieldTermStructure> discountingCurve = {},
207 Date customPillarDate = Date(),
208 bool endOfMonth = false,
209 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
210 SwapRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
211 const Period& tenor,
212 Calendar calendar,
213 // fixed leg
214 Frequency fixedFrequency,
215 BusinessDayConvention fixedConvention,
216 DayCounter fixedDayCount,
217 // floating leg
218 const ext::shared_ptr<IborIndex>& iborIndex,
220 const Period& fwdStart = 0 * Days,
221 // exogenous discounting curve
222 Handle<YieldTermStructure> discountingCurve = {},
223 Natural settlementDays = Null<Natural>(),
225 Date customPillarDate = Date(),
226 bool endOfMonth = false,
227 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
228 SwapRateHelper(const std::variant<Rate, Handle<Quote>>& rate,
229 const Date& startDate,
230 const Date& endDate,
231 Calendar calendar,
232 // fixed leg
233 Frequency fixedFrequency,
234 BusinessDayConvention fixedConvention,
235 DayCounter fixedDayCount,
236 // floating leg
237 const ext::shared_ptr<IborIndex>& iborIndex,
239 // exogenous discounting curve
240 Handle<YieldTermStructure> discountingCurve = {},
242 Date customPillarDate = Date(),
243 bool endOfMonth = false,
244 const ext::optional<bool>& useIndexedCoupons = ext::nullopt);
245 //! \name RateHelper interface
246 //@{
247 Real impliedQuote() const override;
248 void setTermStructure(YieldTermStructure*) override;
249 //@}
250 //! \name SwapRateHelper inspectors
251 //@{
252 Spread spread() const;
253 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
254 ext::shared_ptr<VanillaSwap> swap() const;
255 const Period& forwardStart() const;
256 //@}
257 //! \name Visitability
258 //@{
259 void accept(AcyclicVisitor&) override;
260 //@}
261 protected:
262 void initialize(const ext::shared_ptr<IborIndex>& iborIndex,
263 Date customPillarDate);
264 void initializeDates() override;
273 ext::shared_ptr<IborIndex> iborIndex_;
274 ext::shared_ptr<VanillaSwap> swap_;
281 ext::optional<bool> useIndexedCoupons_;
282 };
283
284
285 //! Rate helper for bootstrapping over BMA swap rates
287 public:
288 BMASwapRateHelper(const Handle<Quote>& liborFraction,
289 const Period& tenor, // swap maturity
290 Natural settlementDays,
291 Calendar calendar,
292 // bma leg
293 const Period& bmaPeriod,
294 BusinessDayConvention bmaConvention,
295 DayCounter bmaDayCount,
296 ext::shared_ptr<BMAIndex> bmaIndex,
297 // ibor leg
298 ext::shared_ptr<IborIndex> index);
299 //! \name RateHelper interface
300 //@{
301 Real impliedQuote() const override;
302 void setTermStructure(YieldTermStructure*) override;
303 //@}
304 //! \name Visitability
305 //@{
306 void accept(AcyclicVisitor&) override;
307 //@}
308 protected:
309 void initializeDates() override;
316 ext::shared_ptr<BMAIndex> bmaIndex_;
317 ext::shared_ptr<IborIndex> iborIndex_;
318
319 ext::shared_ptr<BMASwap> swap_;
321 };
322
323
324 //! Rate helper for bootstrapping over Fx Swap rates
325 /*! The forward is given by `fwdFx = spotFx + fwdPoint`.
326
327 `isFxBaseCurrencyCollateralCurrency` indicates if the base
328 currency of the FX currency pair is the one used as collateral.
329
330 `calendar` is usually the joint calendar of the two currencies
331 in the pair.
332
333 `tradingCalendar` can be used when the cross pairs don't
334 include the currency of the business center (usually USD; the
335 corresponding calendar is `UnitedStates`). If given, it will
336 be used for adjusting the earliest settlement date and for
337 setting the latest date. Due to FX spot market conventions, it
338 is not sufficient to pass a JointCalendar with UnitedStates
339 included as `calendar`; with regard the earliest date, this
340 calendar is only used in case the spot date of the two
341 currencies is not a US business day.
342
343 \warning The ON fx swaps can be achieved by setting
344 `fixingDays` to 0 and using a tenor of '1d'. The same
345 tenor should be used for TN swaps, with `fixingDays`
346 set to 1. However, handling ON and TN swaps for
347 cross rates without USD is not trivial and should be
348 treated with caution. If today is a US holiday, ON
349 trade is not possible. If tomorrow is a US Holiday,
350 the ON trade will be at least two business days long
351 in the other countries and the TN trade will not
352 exist. In such cases, if this helper is used for
353 curve construction, probably it is safer not to pass
354 a trading calendar to the ON and TN helpers and
355 provide fwdPoints that will yield proper level of
356 discount factors.
357 */
359 public:
360 FxSwapRateHelper(const Handle<Quote>& fwdPoint,
361 Handle<Quote> spotFx,
362 const Period& tenor,
365 BusinessDayConvention convention,
366 bool endOfMonth,
368 Handle<YieldTermStructure> collateralCurve,
370 //! \name RateHelper interface
371 //@{
372 Real impliedQuote() const override;
373 void setTermStructure(YieldTermStructure*) override;
374 //@}
375 //! \name FxSwapRateHelper inspectors
376 //@{
377 Real spot() const { return spot_->value(); }
378 Period tenor() const { return tenor_; }
379 Natural fixingDays() const { return fixingDays_; }
380 Calendar calendar() const { return cal_; }
382 bool endOfMonth() const { return eom_; }
387 //@}
388 //! \name Visitability
389 //@{
390 void accept(AcyclicVisitor&) override;
391 //@}
392 private:
393 void initializeDates() override;
399 bool eom_;
401
403
406
409 };
410
411 // inline
412
414 return spread_.empty() ? 0.0 : spread_->value();
415 }
416
417 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
418 inline ext::shared_ptr<VanillaSwap> SwapRateHelper::swap() const {
419 return swap_;
420 }
421
422 inline const Period& SwapRateHelper::forwardStart() const {
423 return fwdStart_;
424 }
425
426}
427
428#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.
Definition: ratehelpers.hpp:92
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:59
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
void initialize(const ext::shared_ptr< IborIndex > &iborIndex, Date customPillarDate)
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
constexpr const boost::none_t & nullopt
Definition: optional.hpp:44
Definition: any.hpp:37
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
Alternatives ways of determining the pillar date.
@ LastRelevantDate
instruments maturity date
Simple fixed-rate vs Libor swap.