QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
zerospreadedtermstructure.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) 2007, 2008 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file zerospreadedtermstructure.hpp
22 \brief Zero spreaded term structure
23*/
24
25#ifndef quantlib_zero_spreaded_term_structure_hpp
26#define quantlib_zero_spreaded_term_structure_hpp
27
28#include <ql/quote.hpp>
30#include <utility>
31
32namespace QuantLib {
33
34 //! Term structure with an added spread on the zero yield rate
35 /*! \note This term structure will remain linked to the original
36 structure, i.e., any changes in the latter will be
37 reflected in this structure as well.
38
39 \ingroup yieldtermstructures
40
41 \test
42 - the correctness of the returned values is tested by
43 checking them against numerical calculations.
44 - observability against changes in the underlying term
45 structure and in the added spread is checked.
46 */
48 public:
50 Handle<Quote> spread,
53 DayCounter dc = DayCounter());
54 //! \name YieldTermStructure interface
55 //@{
56 DayCounter dayCounter() const override;
57 Calendar calendar() const override;
58 Natural settlementDays() const override;
59 const Date& referenceDate() const override;
60 Date maxDate() const override;
61 Time maxTime() const override;
62 //@}
63 //! \name Observer interface
64 //@{
65 void update() override;
66 //@}
67 protected:
68 //! returns the spreaded zero yield rate
69 Rate zeroYieldImpl(Time) const override;
70 //! returns the spreaded forward rate
71 /* This method must disappear should the spread become a curve */
72 Rate forwardImpl(Time) const;
73 private:
79 };
80
82 Handle<Quote> spread,
83 Compounding comp,
84 Frequency freq,
85 DayCounter dc)
86 : originalCurve_(std::move(h)), spread_(std::move(spread)), comp_(comp), freq_(freq),
87 dc_(std::move(dc)) {
88 if (!originalCurve_.empty())
89 enableExtrapolation(originalCurve_->allowsExtrapolation());
92 }
93
95 return originalCurve_->dayCounter();
96 }
97
99 return originalCurve_->calendar();
100 }
101
103 return originalCurve_->settlementDays();
104 }
105
107 return originalCurve_->referenceDate();
108 }
109
111 return originalCurve_->maxDate();
112 }
113
115 return originalCurve_->maxTime();
116 }
117
119 if (!originalCurve_.empty()) {
121 enableExtrapolation(originalCurve_->allowsExtrapolation());
122 } else {
123 /* The implementation inherited from YieldTermStructure
124 asks for our reference date, which we don't have since
125 the original curve is still not set. Therefore, we skip
126 over that and just call the base-class behavior. */
127 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
129 }
130 }
131
133 // to be fixed: user-defined daycounter should be used
135 originalCurve_->zeroRate(t, comp_, freq_, true);
136 InterestRate spreadedRate(zeroRate + spread_->value(),
140 return spreadedRate.equivalentRate(Continuous, NoFrequency, t);
141 }
142
144 return originalCurve_->forwardRate(t, t, comp_, freq_, true)
145 + spread_->value();
146 }
147
148}
149
150#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
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.
const DayCounter & dayCounter() const
Compounding compounding() const
Frequency frequency() const
InterestRate equivalentRate(Compounding comp, Frequency freq, Time t) const
equivalent interest rate for a compounding period t.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
void update() override
InterestRate zeroRate(const Date &d, const DayCounter &resultDayCounter, Compounding comp, Frequency freq=Annual, bool extrapolate=false) const
Term structure with an added spread on the zero yield rate.
Calendar calendar() const override
the calendar used for reference and/or option date calculation
Rate zeroYieldImpl(Time) const override
returns the spreaded zero yield rate
ZeroSpreadedTermStructure(Handle< YieldTermStructure >, Handle< Quote > spread, Compounding comp=Continuous, Frequency freq=NoFrequency, DayCounter dc=DayCounter())
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
Rate forwardImpl(Time) const
returns the spreaded forward rate
Time maxTime() const override
the latest time for which the curve can return values
Zero-yield term structure.
const DefaultType & t
Frequency
Frequency of events.
Definition: frequency.hpp:37
@ NoFrequency
null frequency
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Compounding
Interest rate coumpounding rule.
Definition: compounding.hpp:32
STL namespace.
purely virtual base class for market observables
Zero-yield based term structure.