Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/models/marketmodels/evolutiondescription.hpp
Line
Count
Source
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
 <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
#ifndef quantlib_evolution_description_hpp
22
#define quantlib_evolution_description_hpp
23
24
#include <ql/types.hpp>
25
#include <vector>
26
27
namespace QuantLib {
28
29
    //! Market-model evolution description
30
    /*! This class stores:
31
        -# evolutionTimes = the times at which the rates need to be known,
32
        -# rateTimes = the times defining the rates that are to be evolved,
33
        -# relevanceRates = which rates need to be known at each time.
34
35
        This class is really just a tuple of evolution and rate times;
36
        - there will be n+1 rate times expressing payment and reset
37
          times of forward rates.
38
        - there will be any number of evolution times.
39
        - we also store which part of the rates are relevant for
40
          pricing via relevance rates. The important part for the i-th
41
          step will then range from relevanceRates[i].first to
42
          relevanceRates[i].second. Default values for relevance rates
43
          will be 0 and n.
44
        - example for n = 5:
45
        <pre>
46
           |-----|-----|-----|-----|-----|      (size = 6)
47
           t0    t1    t2    t3    t4    t5     rateTimes
48
           f0    f1    f2    f3    f4           forwardRates
49
           d0    d1    d2    d3    d4    d5     discountBonds
50
           d0/d0 d1/d0 d2/d0 d3/d0 d4/d0 d5/d0  discountRatios
51
           sr0   sr1   sr2   sr3   sr4          coterminalSwaps
52
        </pre>
53
    */
54
    class EvolutionDescription {
55
        // This typedef is used so that gcc 3.3 can parse the
56
        // constructor declaration (not even parenthesizing the
57
        // default argument worked)
58
        typedef std::pair<Size,Size> range;
59
      public:
60
0
        EvolutionDescription() = default;
61
        explicit EvolutionDescription(
62
            const std::vector<Time>& rateTimes,
63
            const std::vector<Time>& evolutionTimes = std::vector<Time>(),
64
            const std::vector<std::pair<Size,Size> >& relevanceRates =
65
                                                        std::vector<range>());
66
        const std::vector<Time>& rateTimes() const;
67
        const std::vector<Time>& rateTaus() const;
68
        const std::vector<Time>& evolutionTimes() const;
69
        //const Matrix& effectiveStopTimes() const;
70
        const std::vector<Size>& firstAliveRate() const;
71
        const std::vector<std::pair<Size,Size> >& relevanceRates() const;
72
        Size numberOfRates() const;
73
        Size numberOfSteps() const;
74
      private:
75
        Size numberOfRates_;
76
        std::vector<Time> rateTimes_, evolutionTimes_;
77
        std::vector<std::pair<Size,Size> > relevanceRates_;
78
        // convenience variables
79
        std::vector<Time> rateTaus_;
80
        std::vector<Size> firstAliveRate_;
81
    };
82
83
    // Numeraire functions
84
85
    /*! Check that there is one numeraire for each evolution time.
86
        Each numeraire must be an index amongst the rate times so it ranges
87
        from 0 to n. Each numeraire must not have expired before the end of
88
        the step.
89
    */
90
    void checkCompatibility(const EvolutionDescription& evolution,
91
                            const std::vector<Size>& numeraires);
92
93
    bool isInTerminalMeasure(const EvolutionDescription& evolution,
94
                             const std::vector<Size>& numeraires);
95
    bool isInMoneyMarketPlusMeasure(const EvolutionDescription& evolution,
96
                                    const std::vector<Size>& numeraires,
97
                                    Size offset = 1);
98
    bool isInMoneyMarketMeasure(const EvolutionDescription& evolution,
99
                                const std::vector<Size>& numeraires);
100
101
    //! Terminal measure: the last bond is used as numeraire.
102
    std::vector<Size> terminalMeasure(const EvolutionDescription& evolution);
103
104
    /*! Offsetted discretely compounded money market account measure:
105
        for each step the offset-th unexpired bond is used as numeraire.
106
        When offset=0 the result is the usual discretely compounded money
107
        market account measure
108
    */
109
    std::vector<Size> moneyMarketPlusMeasure(const EvolutionDescription&,
110
                                             Size offset = 1);
111
112
    /*! Discretely compounded money market account measure:
113
        for each step the first unexpired bond is used as numeraire.
114
    */
115
    std::vector<Size> moneyMarketMeasure(const EvolutionDescription&);
116
117
}
118
119
#endif