QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
compositezeroyieldstructure.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5Copyright (C) 2007, 2008 StatPro Italia srl
6Copyright (C) 2017 Francois Botha
7
8This file is part of QuantLib, a free-software/open-source library
9for financial quantitative analysts and developers - http://quantlib.org/
10
11QuantLib is free software: you can redistribute it and/or modify it
12under the terms of the QuantLib license. You should have received a
13copy of the license along with this program; if not, please email
14<quantlib-dev@lists.sf.net>. The license is also available online at
15<http://quantlib.org/license.shtml>.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file compositezeroyieldstructure.hpp
23\brief Composite zero term structure
24*/
25
26#ifndef quantlib_composite_zero_yield_structure
27#define quantlib_composite_zero_yield_structure
28
29
31#include <utility>
32
33namespace QuantLib {
34 template <class BinaryFunction>
36 public:
39 const BinaryFunction& f,
41 Frequency freq = NoFrequency);
42
43 //! \name YieldTermStructure interface
44 //@{
45 DayCounter dayCounter() const override;
46 Calendar calendar() const override;
47 Natural settlementDays() const override;
48 const Date& referenceDate() const override;
49 Date maxDate() const override;
50 Time maxTime() const override;
51 //@}
52 //! \name Observer interface
53 //@{
54 void update() override;
55 //@}
56 protected:
57 //! returns the composite zero yield rate
58 Rate zeroYieldImpl(Time) const override;
59
60 private:
63 BinaryFunction f_;
66 };
67
68 // inline definitions
69
70 template <class BinaryFunction>
74 const BinaryFunction& f,
75 Compounding comp,
76 Frequency freq)
77 : curve1_(std::move(h1)), curve2_(std::move(h2)), f_(f), comp_(comp), freq_(freq) {
78 if (!curve1_.empty() && !curve2_.empty())
79 enableExtrapolation(curve1_->allowsExtrapolation() && curve2_->allowsExtrapolation());
80
83 }
84
85 template <class BinaryFunction>
87 return curve1_->dayCounter();
88 }
89
90 template <class BinaryFunction>
92 return curve1_->calendar();
93 }
94
95 template <class BinaryFunction>
97 return curve1_->settlementDays();
98 }
99
100 template <class BinaryFunction>
102 return curve1_->referenceDate();
103 }
104
105 template <class BinaryFunction>
107 return curve1_->maxDate();
108 }
109
110 template <class BinaryFunction>
112 return curve1_->maxTime();
113 }
114
115 template <class BinaryFunction>
117 if (!curve1_.empty() && !curve2_.empty()) {
119 enableExtrapolation(curve1_->allowsExtrapolation() && curve2_->allowsExtrapolation());
120 }
121 else {
122 /* The implementation inherited from YieldTermStructure
123 asks for our reference date, which we don't have since
124 the original curve is still not set. Therefore, we skip
125 over that and just call the base-class behavior. */
126 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
128 }
129 }
130
131 template <class BinaryFunction>
133 Rate zeroRate1 =
134 curve1_->zeroRate(t, comp_, freq_, true);
135
136 InterestRate zeroRate2 =
137 curve2_->zeroRate(t, comp_, freq_, true);
138
139 InterestRate compositeRate(f_(zeroRate1, zeroRate2), dayCounter(), comp_, freq_);
140 return compositeRate.equivalentRate(Continuous, NoFrequency, t);
141 }
142}
143#endif
calendar class
Definition: calendar.hpp:61
Calendar calendar() const override
the calendar used for reference and/or option date calculation
Rate zeroYieldImpl(Time) const override
returns the composite zero yield rate
const Date & referenceDate() const override
the date at which discount = 1.0 and/or variance = 0.0
CompositeZeroYieldStructure(Handle< YieldTermStructure > h1, Handle< YieldTermStructure > h2, const BinaryFunction &f, Compounding comp=Continuous, Frequency freq=NoFrequency)
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
Time maxTime() const override
the latest time for which the curve can return values
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.
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
Zero-yield term structure.
ext::function< Real(Real)> f_
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.
Zero-yield based term structure.