/src/quantlib/ql/experimental/credit/recoveryratemodel.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_recovery_rate_model_hpp |
21 | | #define quantlib_recovery_rate_model_hpp |
22 | | |
23 | | #include <ql/settings.hpp> |
24 | | #include <ql/handle.hpp> |
25 | | #include <ql/experimental/credit/defaultprobabilitykey.hpp> |
26 | | #include <ql/experimental/credit/recoveryratequote.hpp> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | /*! Models of the recovery rate provide future values of a recovery |
31 | | rate in the event of a default. |
32 | | */ |
33 | | class RecoveryRateModel : public virtual Observable { |
34 | | public: |
35 | | /*! returns the expected recovery rate at a future time conditional |
36 | | on some default event type and seniority. |
37 | | */ |
38 | | virtual Real recoveryValue(const Date& defaultDate, |
39 | 0 | const DefaultProbKey& defaultKey = DefaultProbKey()) const { |
40 | | // no check on dates... |
41 | 0 | return recoveryValueImpl(defaultDate, defaultKey); |
42 | 0 | } |
43 | | /*! Returns true if the model will return recovery rates for |
44 | | the requested seniority. |
45 | | */ |
46 | | virtual bool appliesToSeniority(Seniority) const = 0; |
47 | 0 | ~RecoveryRateModel() override = default; |
48 | | |
49 | | protected: |
50 | | /*! Returns Null<Real> if unable to produce a recovery for |
51 | | the requested seniority. |
52 | | */ |
53 | | virtual Real recoveryValueImpl(const Date&, |
54 | | const DefaultProbKey& defaultKey |
55 | | ) const = 0; |
56 | | }; |
57 | | |
58 | | |
59 | | /*! Simple Recovery Rate model returning the constant value of the quote |
60 | | independently of the date and the seniority. |
61 | | */ |
62 | | class ConstantRecoveryModel : public RecoveryRateModel, |
63 | | public Observer { |
64 | | public: |
65 | | explicit ConstantRecoveryModel(const Handle<RecoveryRateQuote>& quote); |
66 | | explicit ConstantRecoveryModel(Real recovery, |
67 | | Seniority sen = NoSeniority); |
68 | 0 | void update() override { notifyObservers(); } |
69 | 0 | bool appliesToSeniority(Seniority) const override { return true; } |
70 | | |
71 | | protected: |
72 | | /*! Notice the quote's value is returned without a |
73 | | check on a match of the seniorties of the |
74 | | quote and the request. |
75 | | */ |
76 | 0 | Real recoveryValueImpl(const Date&, const DefaultProbKey&) const override { |
77 | | // no match on requested seniority, all pass |
78 | 0 | return quote_->value(); |
79 | 0 | } |
80 | | |
81 | | private: |
82 | | Handle<RecoveryRateQuote> quote_; |
83 | | }; |
84 | | |
85 | | } |
86 | | |
87 | | #endif |