Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/credit/recoveryratequote.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Jose Aparicio
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#ifndef quantlib_recoveryrate_quote_hpp
21
#define quantlib_recoveryrate_quote_hpp
22
23
#include <ql/quote.hpp>
24
#include <ql/experimental/credit/defaulttype.hpp>
25
#include <map>
26
27
namespace QuantLib {
28
29
    //! Stores a recovery rate market quote and the associated seniority.
30
    class RecoveryRateQuote : public Quote {
31
        friend std::map<Seniority, Real> makeIsdaConvMap();
32
    public:
33
        /*! Returns a map with the ISDA conventional (values by
34
            default) of the recovery rate per each ISDA seniority.
35
        */
36
0
        static Real conventionalRecovery(Seniority sen) {
37
0
            return IsdaConvRecoveries[sen];
38
0
        }
39
        RecoveryRateQuote(Real value = Null<Real>(),
40
                          Seniority seniority = NoSeniority);
41
        //! \name Quote interface
42
        //@{
43
        Real value() const override;
44
        Seniority seniority() const;
45
        bool isValid() const override;
46
        //@}
47
        //! \name Modifiers
48
        //@{
49
        //! returns the difference between the new value and the old value
50
        Real setValue(Real value = Null<Real>());
51
        void reset();
52
        //@}
53
54
        /*! Turn a set of recoveries into a seniority-recovery map
55
            (intended to be used in an event construction)
56
        */
57
        // member? move to friend?
58
        template <Size N>
59
        static std::map<Seniority, Real> makeIsdaMap(const Real (&(arrayIsdaRR))[N]);
60
61
      private:
62
        // Conventional recoveries for ISDA seniorities
63
        static const Real IsdaConvRecoveries[];
64
        // The seniority this recovery is quoted for.
65
        Seniority seniority_;
66
        // The recovery value. In fractional units.
67
        Real recoveryRate_;
68
    };
69
70
0
    inline Seniority RecoveryRateQuote::seniority() const {
71
0
        return seniority_;
72
0
    }
73
74
0
    inline Real RecoveryRateQuote::value() const {
75
0
        QL_ENSURE(isValid(), "invalid Recovery Quote");
76
0
        return recoveryRate_;
77
0
    }
78
79
0
    inline bool RecoveryRateQuote::isValid() const {
80
        // not to be consufed with proper initialization [0-1]
81
0
        return recoveryRate_!=Null<Real>();/* &&
82
            seniority_ != NoSeniority;*/
83
0
    }
84
85
    //! Helper function for conventional recoveries. Returns the ISDA
86
    //    conventional recovery rates for the ISDA seniorities.
87
    std::map<Seniority, Real> makeIsdaConvMap();
88
89
90
    // template definitions
91
92
    // helpers allow further automatic inclusion of seniorities
93
    template <Size N>
94
0
    std::map<Seniority, Real> RecoveryRateQuote::makeIsdaMap(const Real (&(arrayIsdaRR))[N]) {
95
        // TO DO: include check on sizes... not to go beyond enum sizes.
96
        // TO DO: check Reals are valid, i.e. non Null and within [0-1] range
97
0
        std::map<Seniority, Real> isdaMap;
98
0
        for(Size i=0; i<N; i++) {
99
0
            auto isdaType = Seniority(i); // compiler dependent?
100
0
            isdaMap[isdaType] = arrayIsdaRR[i];
101
0
        }
102
0
        return isdaMap;
103
0
    }
104
}
105
106
#endif