QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
zerospreadedtermstructure.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) 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
25#ifndef quantlib_zero_spreaded_term_structure_hpp
26#define quantlib_zero_spreaded_term_structure_hpp
27
28#include <ql/quote.hpp>
29#include <ql/termstructures/yield/zeroyieldstructure.hpp>
30#include <utility>
31
32namespace QuantLib {
33
35
48 public:
50 Handle<Quote> spread,
53 DayCounter dc = DayCounter());
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;
63
65 void update() override;
67 protected:
69 Rate zeroYieldImpl(Time) const override;
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.
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.