1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 StatPro Italia srl
5 Copyright (C) 2009 Jose Aparicio
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file defaulttype.hpp
22 \brief Classes for default-event description.
23*/
24
25
26#ifndef quantlib_default_type_hpp
27#define quantlib_default_type_hpp
28
29#include <ql/time/period.hpp>
30
31namespace QuantLib {
32
33 //! Seniority of a bond.
34 /*! They are also ISDA tier/seniorities used for CDS conventional
35 spreads.
36 */
37 enum Seniority {
38 SecDom = 0,
39 SnrFor,
40 SubLT2,
41 JrSubT2,
42 PrefT1,
43 // Unassigned value, allows for default RR quote
44 NoSeniority,
45 // markit parlance
46 SeniorSec = SecDom,
47 SeniorUnSec = SnrFor,
48 SubTier1 = PrefT1,
49 SubUpperTier2 = JrSubT2,
50 SubLoweTier2 = SubLT2
51 };
52
53
54 //! Atomic (single contractual event) default events.
55 /*! Default types defined as enum to allow easy aggregation of
56 types. Theres an event algebra logic by default provided by
57 DefaultType. If your new type requires more sofisticated test
58 you need to derive from it as in FailureToPay
59 */
60 struct AtomicDefault {
61 enum Type {
62 // Includes one of the restructuring cases
63 Restructuring = 0,
64 Bankruptcy,
65 FailureToPay,
66 RepudiationMoratorium,
67 Acceleration,
68 Default,
69 // synonyms
70 ObligationAcceleration = Acceleration,
71 ObligationDefault = Default,
72 CrossDefault = Default,
73 // Other non-isda
74 Downgrade, // Non-ISDA, not in FpML
75 MergerEvent // Non-ISDA, not in FpML
76 };
77 };
78
79
80 // these could be merged with the ones above if not because
81 // restructuring types can not be combined together.
82
83 //! Restructuring type
84 struct Restructuring {
85 enum Type {
86 NoRestructuring = 0,
87 ModifiedRestructuring,
88 ModifiedModifiedRestructuring,
89 FullRestructuring,
90 AnyRestructuring,
91 // Markit notation:
92 XR = NoRestructuring,
93 MR = ModifiedRestructuring,
94 MM = ModifiedModifiedRestructuring,
95 CR = FullRestructuring
96 };
97 };
98
99
100 //! Atomic credit-event type.
101 /*! This class encapsulates the ISDA default contractual types and
102 their combinations. Non-atomicity works only at the atomic
103 type level, obviating the specific event characteristics which
104 it is accounted for only in derived classes.
105 */
106 class DefaultType {
107 public:
108 explicit DefaultType(AtomicDefault::Type defType =
109 AtomicDefault::Bankruptcy,
110 Restructuring::Type restType = Restructuring::XR);
111
112 virtual ~DefaultType() = default;
113
114 AtomicDefault::Type defaultType() const {
115 return defTypes_;
116 }
117 Restructuring::Type restructuringType() const {return restrType_;}
118 bool isRestructuring() const {
119 return restrType_ != Restructuring::NoRestructuring;
120 }
121
122 // bool isAtomic() const { return defTypes_.size() == 1;}
123
124 /*! Returns true if one or a set of event types is within this
125 one and as such will be recognised as a trigger. Not the
126 same as equality.
127
128 Notice that these methods do not include any event logical
129 hierarchy. The match is in a strict sense. If event B is
130 contained in (implied by) event A this would not send a
131 match. This policies should be implemented at the
132 CreditEvent class, which is polymorphic.
133 */
134 bool containsDefaultType(AtomicDefault::Type defType) const {
135 return defTypes_ == defType;
136 }
137
138 bool containsRestructuringType(Restructuring::Type resType) const {
139 return (restrType_ == resType) ||
140 (Restructuring::AnyRestructuring == resType);
141 }
142 protected:
143 //std::set<AtomicDefault::Type> defTypes_;
144 AtomicDefault::Type defTypes_;
145 Restructuring::Type restrType_;
146 };
147
148
149 /*! Equality is the criteria for indexing the curves. This depends
150 only on the atomic types and not on idiosincracies of derived
151 type as mentioned in the functional documentation (specific
152 event characteristics are relevant to credit event matching
153 but not to the probability meaning). operator== is also used
154 to remove duplicates in some containers. This ensures we do
155 not have two equal events (despite having different
156 characteristics) in those containers. This makes sense, theres
157 no logic in having two FailureToPay in a contract even if they
158 have different characteristics.
159 */
160 bool operator==(const DefaultType& lhs, const DefaultType& rhs);
161
162
163
164 //! Failure to Pay atomic event type.
165 class FailureToPay : public DefaultType {
166 public:
167 // Only atomic construction.
168 // Amount contract by default is in dollars as per ISDA doc and not
169 // the contract curr. Theres an issue here...... FIX ME
170 explicit FailureToPay(const Period& grace,
171 Real amount = 1.e+6)
172 : DefaultType(AtomicDefault::FailureToPay, Restructuring::XR),
173 gracePeriod_(grace), amountRequired_(amount) {}
174
175 Real amountRequired() const {return amountRequired_;}
176 const Period& gracePeriod() const {return gracePeriod_;}
177 private:
178 // Grace period to consider the event. If payment occurs during
179 // the period the event should be removed from its container.
180 Period gracePeriod_;
181 // Minimum default amount triggering the event
182 Real amountRequired_;
183 };
184
185}
186
187#endif
188

source code of quantlib/ql/experimental/credit/defaulttype.hpp