QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
constantlosslatentmodel.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014 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
21#ifndef quantlib_constantloss_latentmodel_hpp
22#define quantlib_constantloss_latentmodel_hpp
23
25// take the loss model to a different file and avoid this inclusion
27
28namespace QuantLib {
29
30 /*! Constant deterministic loss amount default latent model. Integrable
31 implementation.
32 */
33 /* \todo:
34 Several options: Refer to a set of individual RR models, have quotes to
35 RRs (registered)
36 */
37 template <class copulaPolicy>
38 class ConstantLossLatentmodel : public DefaultLatentModel<copulaPolicy> {
39 private:
40 const std::vector<Real> recoveries_;
41 typedef typename copulaPolicy::initTraits initTraits;
42 public:
44 const std::vector<std::vector<Real> >& factorWeights,
45 const std::vector<Real>& recoveries,
47 const initTraits& ini = initTraits()
48 )
49 : DefaultLatentModel<copulaPolicy>(factorWeights, integralType, ini),
51
52 QL_REQUIRE(recoveries.size() == factorWeights.size(),
53 "Incompatible factors and recovery sizes.");
54 }
55
57 const Handle<Quote>& mktCorrel,
58 const std::vector<Real>& recoveries,
60 Size nVariables,
61 const initTraits& ini = initTraits()
62 )
63 : DefaultLatentModel<copulaPolicy>(mktCorrel, nVariables,
64 integralType, ini),
66 // actually one could define the other and get rid of the variable
67 // here and in other similar models
68 QL_REQUIRE(recoveries.size() == nVariables,
69 "Incompatible model and recovery sizes.");
70 }
71
73 const std::vector<Real>& mktFactors) const {
74 return recoveries_[iName];
75 }
76
78 const std::vector<Real>& mktFactors) const {
79 return recoveries_[iName];
80 }
81
82 Real conditionalRecoveryInvP(Real invUncondDefP, Size iName,
83 const std::vector<Real>& mktFactors) const {
84 return recoveries_[iName];
85 }
86
87 Real conditionalRecovery(Real latentVarSample,
88 Size iName, const Date& d) const {
89 return recoveries_[iName];
90 }
91
92 const std::vector<Real>& recoveries() const {
93 return recoveries_;
94 }
95
96 // this is really an interface to rr models even if not imposed. Default
97 // loss models do have an interface for this one. Enforced only through
98 // duck typing.
100 const DefaultProbKey& defKeys) const {
101 return recoveries_[iName];
102 }
103 };
104
105 typedef ConstantLossLatentmodel<GaussianCopulaPolicy>
108
109
110 /*! ConstantLossLatentModel interface for loss models.
111 While it does not provide distribution type losses (e.g. expected tranche
112 losses) because it lacks an integration algorithm it serves to allow
113 pricing of digital type products like NTDs.
114
115 Alternatively fuse with the aboves class.
116 */
117 template <class copulaPolicy>
119 public virtual ConstantLossLatentmodel<copulaPolicy>,
120 public virtual DefaultLossModel
121 {
122 public:
124 const std::vector<std::vector<Real> >& factorWeights,
125 const std::vector<Real>& recoveries,
127 const typename copulaPolicy::initTraits& ini =
128 copulaPolicy::initTraits())
130 integralType, ini) {}
131
133 const Handle<Quote>& mktCorrel,
134 const std::vector<Real>& recoveries,
136 Size nVariables,
137 const typename copulaPolicy::initTraits& ini =
138 copulaPolicy::initTraits())
140 integralType, nVariables,ini) {}
141
142 protected:
143 //std::vector<Probability> probsBeingNthEvent(
144 // Size n, const Date& d) const {
145 // return
146 // ConstantLossLatentmodel<copulaPolicy>::probsBeingNthEvent(n, d);
147 //}
148 Real defaultCorrelation(const Date& d, Size iName, Size jName) const override {
150 }
151 Probability probAtLeastNEvents(Size n, const Date& d) const override {
153 }
154 Real expectedRecovery(const Date& d, Size iName, const DefaultProbKey& k) const override {
156 }
157
158 private:
159 void resetModel() override {
160 // update the default latent model we derive from
162 DefaultLossModel::basket_.currentLink()); // forces interface
163 }
164 };
165
166}
167
168#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
Probability probAtLeastNEvents(Size n, const Date &d) const override
Real defaultCorrelation(const Date &d, Size iName, Size jName) const override
Pearsons' default probability correlation.
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())
void resetModel() override
Concrete models do now any updates/inits they need on basket reset.
Real expectedRecovery(const Date &d, Size iName, const DefaultProbKey &k) const override
Concrete date class.
Definition: date.hpp:125
void resetBasket(const ext::shared_ptr< Basket > &basket) const
Real defaultCorrelation(const Date &d, Size iNamei, Size iNamej) const
Probability probAtLeastNEvents(Size n, const Date &date) const
RelinkableHandle< Basket > basket_
Shared handle to an observable.
Definition: handle.hpp:41
const std::vector< std::vector< Real > > & factorWeights() const
Provides values of the factors .
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
QL_REAL Real
real number
Definition: types.hpp:50
Real Probability
probability
Definition: types.hpp:82
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
ConstantLossLatentmodel< TCopulaPolicy > TConstantLossLM
ConstantLossLatentmodel< GaussianCopulaPolicy > GaussianConstantLossLM