/src/quantlib/ql/models/marketmodels/curvestate.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2006, 2007 Ferdinando Ametrano |
5 | | Copyright (C) 2006, 2007 Mark Joshi |
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 | | |
22 | | #ifndef quantlib_curve_state_hpp |
23 | | #define quantlib_curve_state_hpp |
24 | | |
25 | | #include <ql/math/array.hpp> |
26 | | #include <vector> |
27 | | #include <memory> |
28 | | |
29 | | namespace QuantLib { |
30 | | |
31 | | //! %Curve state for market-model simulations |
32 | | /*! This class stores the state of the yield curve associated to the |
33 | | fixed calendar times within the simulation. |
34 | | This is the workhorse discounting object associated to the rate times |
35 | | of the simulation. It's important to pass the rates via an object like |
36 | | this to the product rather than directly to make it easier to switch |
37 | | to other engines such as a coterminal swap rate engine. |
38 | | Many products will not need expired rates and others will only require |
39 | | the first rate. |
40 | | */ |
41 | | class CurveState { |
42 | | /* There will n+1 rate times expressing payment and reset times |
43 | | of forward rates. |
44 | | |
45 | | |-----|-----|-----|-----|-----| (size = 6) |
46 | | t0 t1 t2 t3 t4 t5 rateTimes |
47 | | f0 f1 f2 f3 f4 forwardRates |
48 | | d0 d1 d2 d3 d4 d5 discountBonds |
49 | | d0/d0 d1/d0 d2/d0 d3/d0 d4/d0 d5/d0 discountRatios |
50 | | sr0 sr1 sr2 sr3 sr4 cotSwaps |
51 | | */ |
52 | | public: |
53 | | CurveState(const std::vector<Time>& rateTimes); |
54 | 0 | virtual ~CurveState() = default; |
55 | | |
56 | | //! \name Inspectors |
57 | | //@{ |
58 | 0 | Size numberOfRates() const { return numberOfRates_; } |
59 | | |
60 | 0 | const std::vector<Time>& rateTimes() const { return rateTimes_; } |
61 | 0 | const std::vector<Time>& rateTaus() const { return rateTaus_; } |
62 | | |
63 | | virtual Real discountRatio(Size i, |
64 | | Size j) const = 0; |
65 | | virtual Rate forwardRate(Size i) const = 0; |
66 | | virtual Rate coterminalSwapAnnuity(Size numeraire, |
67 | | Size i) const = 0; |
68 | | virtual Rate coterminalSwapRate(Size i) const = 0; |
69 | | virtual Rate cmSwapAnnuity(Size numeraire, |
70 | | Size i, |
71 | | Size spanningForwards) const = 0; |
72 | | virtual Rate cmSwapRate(Size i, |
73 | | Size spanningForwards) const = 0; |
74 | | |
75 | | virtual const std::vector<Rate>& forwardRates() const = 0; |
76 | | virtual const std::vector<Rate>& coterminalSwapRates() const = 0; |
77 | | virtual const std::vector<Rate>& cmSwapRates(Size spanningForwards) const = 0; |
78 | | Rate swapRate(Size begin, |
79 | | Size end) const; |
80 | | |
81 | | virtual std::unique_ptr<CurveState> clone() const = 0; |
82 | | //@} |
83 | | protected: |
84 | | Size numberOfRates_; |
85 | | std::vector<Time> rateTimes_, rateTaus_; |
86 | | }; |
87 | | |
88 | | void forwardsFromDiscountRatios(Size firstValidIndex, |
89 | | const std::vector<DiscountFactor>& ds, |
90 | | const std::vector<Time>& taus, |
91 | | std::vector<Rate>& fwds); |
92 | | |
93 | | void coterminalFromDiscountRatios(Size firstValidIndex, |
94 | | const std::vector<DiscountFactor>& ds, |
95 | | const std::vector<Time>& taus, |
96 | | std::vector<Rate>& cotSwapRates, |
97 | | std::vector<Real>& cotSwapAnnuities); |
98 | | |
99 | | void constantMaturityFromDiscountRatios( // Size i, // to be added later |
100 | | Size spanningForwards, |
101 | | Size firstValidIndex, |
102 | | const std::vector<DiscountFactor>& ds, |
103 | | const std::vector<Time>& taus, |
104 | | std::vector<Rate>& cotSwapRates, |
105 | | std::vector<Real>& cotSwapAnnuities); |
106 | | } |
107 | | |
108 | | #endif |