QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
ultimateforwardtermstructure.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2020 Marcin Rybacki
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_ultimate_forward_term_structure_hpp
25#define quantlib_ultimate_forward_term_structure_hpp
26
27#include <ql/quote.hpp>
28#include <ql/termstructures/yield/zeroyieldstructure.hpp>
29#include <utility>
30
31namespace QuantLib {
32
34
71 public:
73 Handle<Quote> lastLiquidForwardRate,
74 Handle<Quote> ultimateForwardRate,
75 const Period& firstSmoothingPoint,
76 Real alpha);
78
79 DayCounter dayCounter() const override;
80 Calendar calendar() const override;
81 Natural settlementDays() const override;
82 const Date& referenceDate() const override;
83 Date maxDate() const override;
85
87 void update() override;
89 protected:
91 Rate zeroYieldImpl(Time) const override;
93 private:
99 };
100
101 // inline definitions
102
105 Handle<Quote> lastLiquidForwardRate,
106 Handle<Quote> ultimateForwardRate,
107 const Period& firstSmoothingPoint,
108 Real alpha)
109 : originalCurve_(std::move(h)), llfr_(std::move(lastLiquidForwardRate)),
110 ufr_(std::move(ultimateForwardRate)), fsp_(firstSmoothingPoint), alpha_(alpha) {
111 QL_REQUIRE(fsp_.length() > 0,
112 "first smoothing point must be a period with positive length");
113 if (!originalCurve_.empty())
114 enableExtrapolation(originalCurve_->allowsExtrapolation());
118 }
119
121 return originalCurve_->dayCounter();
122 }
123
125 return originalCurve_->calendar();
126 }
127
129 return originalCurve_->settlementDays();
130 }
131
133 return originalCurve_->referenceDate();
134 }
135
137
139 if (!originalCurve_.empty()) {
141 enableExtrapolation(originalCurve_->allowsExtrapolation());
142 } else {
143 /* The implementation inherited from YieldTermStructure
144 asks for our reference date, which we don't have since
145 the original curve is still not set. Therefore, we skip
146 over that and just call the base-class behavior. */
147 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
149 }
150 }
151
153 Time cutOffTime = originalCurve_->timeFromReference(referenceDate() + fsp_);
154 Time deltaT = t - cutOffTime;
155 /* If time to maturity (T) exceeds the cut-off point (T_c),
156 i.e. the first smoothing point, the forward rate f is
157 extrapolated as follows:
158
159 f(t,T_c,T) = UFR(t) + (LLFR(t) - UFR(t)) * B(T-T_c),
160
161 where:
162 UFR(t) - Ultimate Forward Rate quote,
163 LLFR(t) - Last Liquid Forward Rate quote,
164 B(t-T_c) = [1 - exp(-a * (T-T_c))] / [a * (T-T_c)],
165 with a being the growth factor (alpha). */
166 if (deltaT > 0.0) {
167 InterestRate baseRate = originalCurve_->zeroRate(cutOffTime, Continuous, NoFrequency);
168 Real beta = (1.0 - std::exp(-alpha_ * deltaT)) / (alpha_ * deltaT);
169 Rate extrapolatedForward = ufr_->value() + (llfr_->value() - ufr_->value()) * beta;
170 return (cutOffTime * baseRate + deltaT * extrapolatedForward) / t;
171 }
172 return originalCurve_->zeroRate(t, Continuous, NoFrequency);
173 }
174}
175
176#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
static Date maxDate()
latest allowed date
Definition: date.cpp:771
day counter class
Definition: daycounter.hpp:44
void enableExtrapolation(bool b=true)
enable extrapolation in subsequent calls
Shared handle to an observable.
Definition: handle.hpp:41
Concrete interest rate class.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Integer length() const
Definition: period.hpp:50
void update() override
Calendar calendar() const override
the calendar used for reference and/or option date calculation
Rate zeroYieldImpl(Time) const override
returns the UFR extended zero yield rate
const Date & referenceDate() const override
the date at which discount = 1.0 and/or variance = 0.0
Natural settlementDays() const override
the settlementDays used for reference date calculation
DayCounter dayCounter() const override
the day counter used for date/time conversion
Date maxDate() const override
the latest date for which the curve can return values
UltimateForwardTermStructure(Handle< YieldTermStructure >, Handle< Quote > lastLiquidForwardRate, Handle< Quote > ultimateForwardRate, const Period &firstSmoothingPoint, Real alpha)
Zero-yield term structure.
@ NoFrequency
null frequency
Definition: frequency.hpp:37
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 Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.