/src/quantlib/ql/termstructures/yield/impliedtermstructure.hpp
Line | Count | Source |
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) 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 | | <https://www.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 impliedtermstructure.hpp |
22 | | \brief Implied term structure |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_implied_term_structure_hpp |
26 | | #define quantlib_implied_term_structure_hpp |
27 | | |
28 | | #include <ql/termstructures/yieldtermstructure.hpp> |
29 | | #include <utility> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | //! Implied term structure at a given date in the future |
34 | | /*! The given date will be the implied reference date. |
35 | | |
36 | | \note This term structure will remain linked to the original |
37 | | structure, i.e., any changes in the latter will be |
38 | | reflected in this structure as well. |
39 | | |
40 | | \ingroup yieldtermstructures |
41 | | |
42 | | \test |
43 | | - the correctness of the returned values is tested by |
44 | | checking them against numerical calculations. |
45 | | - observability against changes in the underlying term |
46 | | structure is checked. |
47 | | */ |
48 | | class ImpliedTermStructure : public YieldTermStructure { |
49 | | public: |
50 | | ImpliedTermStructure(Handle<YieldTermStructure>, const Date& referenceDate); |
51 | | //! \name YieldTermStructure interface |
52 | | //@{ |
53 | | DayCounter dayCounter() const override; |
54 | | Calendar calendar() const override; |
55 | | Natural settlementDays() const override; |
56 | | Date maxDate() const override; |
57 | | |
58 | | protected: |
59 | | DiscountFactor discountImpl(Time) const override; |
60 | | //@} |
61 | | private: |
62 | | Handle<YieldTermStructure> originalCurve_; |
63 | | }; |
64 | | |
65 | | |
66 | | // inline definitions |
67 | | |
68 | | inline ImpliedTermStructure::ImpliedTermStructure(Handle<YieldTermStructure> h, |
69 | | const Date& referenceDate) |
70 | | : YieldTermStructure(referenceDate), originalCurve_(std::move(h)) { |
71 | | registerWith(originalCurve_); |
72 | | } |
73 | | |
74 | 0 | inline DayCounter ImpliedTermStructure::dayCounter() const { |
75 | 0 | return originalCurve_->dayCounter(); |
76 | 0 | } |
77 | | |
78 | 0 | inline Calendar ImpliedTermStructure::calendar() const { |
79 | 0 | return originalCurve_->calendar(); |
80 | 0 | } |
81 | | |
82 | 0 | inline Natural ImpliedTermStructure::settlementDays() const { |
83 | 0 | return originalCurve_->settlementDays(); |
84 | 0 | } |
85 | | |
86 | 0 | inline Date ImpliedTermStructure::maxDate() const { |
87 | 0 | return originalCurve_->maxDate(); |
88 | 0 | } |
89 | | |
90 | 0 | inline DiscountFactor ImpliedTermStructure::discountImpl(Time t) const { |
91 | | /* t is relative to the current reference date |
92 | | and needs to be converted to the time relative |
93 | | to the reference date of the original curve */ |
94 | 0 | Date ref = referenceDate(); |
95 | 0 | Time originalTime = t + dayCounter().yearFraction( |
96 | 0 | originalCurve_->referenceDate(), ref); |
97 | | /* discount at evaluation date cannot be cached |
98 | | since the original curve could change between |
99 | | invocations of this method */ |
100 | 0 | return originalCurve_->discount(originalTime, true) / |
101 | 0 | originalCurve_->discount(ref, true); |
102 | 0 | } |
103 | | |
104 | | } |
105 | | |
106 | | |
107 | | #endif |