QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
recoveryratequote.hpp
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 <http://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
27namespace QuantLib {
28
30 class RecoveryRateQuote : public Quote {
31 friend std::map<Seniority, Real> makeIsdaConvMap();
32 public:
37 return IsdaConvRecoveries[sen];
38 }
42
43 Real value() const override;
44 Seniority seniority() const;
45 bool isValid() const override;
47
49
51 void reset();
53
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.
66 // The recovery value. In fractional units.
68 };
69
71 return seniority_;
72 }
73
75 QL_ENSURE(isValid(), "invalid Recovery Quote");
76 return recoveryRate_;
77 }
78
79 inline bool RecoveryRateQuote::isValid() const {
80 // not to be consufed with proper initialization [0-1]
81 return recoveryRate_!=Null<Real>();/* &&
82 seniority_ != NoSeniority;*/
83 }
84
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 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 std::map<Seniority, Real> isdaMap;
98 for(Size i=0; i<N; i++) {
99 auto isdaType = Seniority(i); // compiler dependent?
100 isdaMap[isdaType] = arrayIsdaRR[i];
101 }
102 return isdaMap;
103 }
104}
105
106#endif
template class providing a null value for a given type.
Definition: null.hpp:76
purely virtual base class for market observables
Definition: quote.hpp:37
Stores a recovery rate market quote and the associated seniority.
friend std::map< Seniority, Real > makeIsdaConvMap()
Helper function for conventional recoveries. Returns the ISDA.
static std::map< Seniority, Real > makeIsdaMap(const Real(&(arrayIsdaRR))[N])
Real setValue(Real value=Null< Real >())
returns the difference between the new value and the old value
static Real conventionalRecovery(Seniority sen)
static const Real IsdaConvRecoveries[]
Real value() const override
returns the current value
bool isValid() const override
returns true if the Quote holds a valid value
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::map< Seniority, Real > makeIsdaConvMap()
Helper function for conventional recoveries. Returns the ISDA.
Seniority
Seniority of a bond.
Definition: defaulttype.hpp:37