Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
constantlosslatentmodel.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#ifndef quantext_constantloss_latentmodel_hpp
20#define quantext_constantloss_latentmodel_hpp
21
22//#include <ql/experimental/credit/defaultprobabilitylatentmodel.hpp>
24// take the loss model to a different file and avoid this inclusion
25//#include <ql/experimental/credit/defaultlossmodel.hpp>
27
28namespace QuantExt {
29using namespace QuantLib;
30
31/*! Constant deterministic loss amount default latent model. Integrable
32 implementation.
33*/
34/* \todo:
35 Several options: Refer to a set of individual RR models, have quotes to
36 RRs (registered)
37*/
38template <class copulaPolicy> class ConstantLossLatentmodel : public DefaultLatentModel<copulaPolicy> {
39private:
40 const std::vector<Real> recoveries_;
41 typedef typename copulaPolicy::initTraits initTraits;
42
43public:
44 ConstantLossLatentmodel(const std::vector<std::vector<Real>>& factorWeights, const std::vector<Real>& recoveries,
45 LatentModelIntegrationType::LatentModelIntegrationType integralType,
46 const initTraits& ini = initTraits())
47 : DefaultLatentModel<copulaPolicy>(factorWeights, integralType, ini), recoveries_(recoveries) {
48
49 QL_REQUIRE(recoveries.size() == factorWeights.size(), "Incompatible factors and recovery sizes.");
50 }
51
52 ConstantLossLatentmodel(const Handle<Quote>& mktCorrel, const std::vector<Real>& recoveries,
53 LatentModelIntegrationType::LatentModelIntegrationType integralType, Size nVariables,
54 const initTraits& ini = initTraits())
55 : DefaultLatentModel<copulaPolicy>(mktCorrel, nVariables, integralType, ini), recoveries_(recoveries) {
56 // actually one could define the other and get rid of the variable
57 // here and in other similar models
58 QL_REQUIRE(recoveries.size() == nVariables, "Incompatible model and recovery sizes.");
59 }
60
61 Real conditionalRecovery(const Date& d, Size iName, const std::vector<Real>& mktFactors) const {
62 return recoveries_[iName];
63 }
64
65 Real conditionalRecovery(Probability uncondDefP, Size iName, const std::vector<Real>& mktFactors) const {
66 return recoveries_[iName];
67 }
68
69 Real conditionalRecoveryInvP(Real invUncondDefP, Size iName, const std::vector<Real>& mktFactors) const {
70 return recoveries_[iName];
71 }
72
73 Real conditionalRecovery(Real latentVarSample, Size iName, const Date& d) const { return recoveries_[iName]; }
74
75 const std::vector<Real>& recoveries() const { return recoveries_; }
76
77 // this is really an interface to rr models even if not imposed. Default
78 // loss models do have an interface for this one. Enforced only through
79 // duck typing.
80 Real expectedRecovery(const Date& d, Size iName, const DefaultProbKey& defKeys) const { return recoveries_[iName]; }
81};
82
85
86/*! ConstantLossLatentModel interface for loss models.
87While it does not provide distribution type losses (e.g. expected tranche
88losses) because it lacks an integration algorithm it serves to allow
89pricing of digital type products like NTDs.
90
91Alternatively fuse with the aboves class.
92*/
93template <class copulaPolicy>
94class ConstantLossModel : public virtual ConstantLossLatentmodel<copulaPolicy>, public virtual DefaultLossModel {
95public:
96 ConstantLossModel(const std::vector<std::vector<Real>>& factorWeights, const std::vector<Real>& recoveries,
97 LatentModelIntegrationType::LatentModelIntegrationType integralType,
98 const typename copulaPolicy::initTraits& ini = copulaPolicy::initTraits())
99 : ConstantLossLatentmodel<copulaPolicy>(factorWeights, recoveries, integralType, ini) {}
100
101 ConstantLossModel(const Handle<Quote>& mktCorrel, const std::vector<Real>& recoveries,
102 LatentModelIntegrationType::LatentModelIntegrationType integralType, Size nVariables,
103 const typename copulaPolicy::initTraits& ini = copulaPolicy::initTraits())
104 : ConstantLossLatentmodel<copulaPolicy>(mktCorrel, recoveries, integralType, nVariables, ini) {}
105
106protected:
107 // Disposable<std::vector<Probability> > probsBeingNthEvent(
108 // Size n, const Date& d) const {
109 // return
110 // ConstantLossLatentmodel<copulaPolicy>::probsBeingNthEvent(n, d);
111 //}
112 Real defaultCorrelation(const Date& d, Size iName, Size jName) const {
114 }
115 Probability probAtLeastNEvents(Size n, const Date& d) const {
117 }
118 Real expectedRecovery(const Date& d, Size iName, const DefaultProbKey& k) const {
120 }
121
122private:
123 virtual void resetModel() {
124 // update the default latent model we derive from
126 }
127};
128
129} // namespace QuantExt
130
131#endif
Real conditionalRecovery(const Date &d, Size iName, const std::vector< Real > &mktFactors) const
Real expectedRecovery(const Date &d, Size iName, const DefaultProbKey &defKeys) const
ConstantLossLatentmodel(const std::vector< std::vector< Real > > &factorWeights, const std::vector< Real > &recoveries, LatentModelIntegrationType::LatentModelIntegrationType integralType, const initTraits &ini=initTraits())
Real conditionalRecovery(Real latentVarSample, Size iName, const Date &d) const
ConstantLossLatentmodel(const Handle< Quote > &mktCorrel, const std::vector< Real > &recoveries, LatentModelIntegrationType::LatentModelIntegrationType integralType, Size nVariables, const initTraits &ini=initTraits())
Real conditionalRecoveryInvP(Real invUncondDefP, Size iName, const std::vector< Real > &mktFactors) const
const std::vector< Real > & recoveries() const
Real conditionalRecovery(Probability uncondDefP, Size iName, const std::vector< Real > &mktFactors) const
Real defaultCorrelation(const Date &d, Size iName, Size jName) const
Pearsons' default probability correlation.
Real expectedRecovery(const Date &d, Size iName, const DefaultProbKey &k) const
virtual void resetModel()
Concrete models do now any updates/inits they need on basket reset.
ConstantLossModel(const std::vector< std::vector< Real > > &factorWeights, const std::vector< Real > &recoveries, LatentModelIntegrationType::LatentModelIntegrationType integralType, const typename copulaPolicy::initTraits &ini=copulaPolicy::initTraits())
ConstantLossModel(const Handle< Quote > &mktCorrel, const std::vector< Real > &recoveries, LatentModelIntegrationType::LatentModelIntegrationType integralType, Size nVariables, const typename copulaPolicy::initTraits &ini=copulaPolicy::initTraits())
Probability probAtLeastNEvents(Size n, const Date &d) const
Real defaultCorrelation(const Date &d, Size iNamei, Size iNamej) const
void resetBasket(const QuantLib::ext::shared_ptr< Basket > basket) const
Probability probAtLeastNEvents(Size n, const Date &date) const
RelinkableHandle< QuantExt::Basket > basket_
ConstantLossLatentmodel< TCopulaPolicy > TConstantLossLM
ConstantLossLatentmodel< GaussianCopulaPolicy > GaussianConstantLossLM