QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
defaultevent.hpp
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
25#ifndef quantlib_default_event_hpp
26#define quantlib_default_event_hpp
27
28#include <ql/event.hpp>
29#include <ql/currency.hpp>
30#include <ql/math/comparison.hpp>
31#include <ql/experimental/credit/defaulttype.hpp>
32#include <ql/experimental/credit/defaultprobabilitykey.hpp>
33#include <map>
34
35namespace QuantLib {
36
49 class DefaultEvent : public Event {
50 public:
51 class DefaultSettlement : public Event {
52 public:
53 friend class DefaultEvent;
54 protected:
63 const std::map<Seniority, Real>& recoveryRates);
68 Seniority seniority = NoSeniority,
69 Real recoveryRate = 0.4);
70 public:
71 Date date() const override;
75 Real recoveryRate(Seniority sen) const;
76 void accept(AcyclicVisitor&) override;
77
78 private:
81 std::map<Seniority, Real> recoveryRates_;
82 };
83 private:
84 // for some reason, gcc chokes on the default parameter below
85 // unless we use the typedef
86 typedef std::map<Seniority, Real> rate_map;
87 public:
94 DefaultEvent(const Date& creditEventDate,
95 const DefaultType& atomicEvType,
96 Currency curr,
97 Seniority bondsSen,
98 // Settlement information:
99 const Date& settleDate = Null<Date>(),
100 const std::map<Seniority, Real>& recoveryRates = rate_map());
105 DefaultEvent(const Date& creditEventDate,
106 const DefaultType& atomicEvType,
107 Currency curr,
108 Seniority bondsSen,
109 // Settlement information:
110 const Date& settleDate = Null<Date>(),
111 Real recoveryRate = 0.4);
112
113 Date date() const override;
114 bool isRestructuring() const { return eventType_.isRestructuring(); }
115 bool isDefault() const { return !isRestructuring();}
116 bool hasSettled() const {
117 return defSettlement_.date() != Null<Date>();
118 }
120 return defSettlement_;
121 }
122 const DefaultType& defaultType() const {
123 return eventType_;
124 }
126 const Currency& currency() const {
127 return bondsCurrency_;
128 }
131 return bondsSeniority_;
132 }
137 virtual Real recoveryRate(Seniority seniority) const {
138 if(hasSettled()) {
139 return defSettlement_.recoveryRate(seniority);
140 }
141 return Null<Real>();
142 }
143
150 virtual bool matchesEventType(
151 const ext::shared_ptr<DefaultType>& contractEvType) const {
152 // remember we are made of an atomic type.
153 // behaviour by default...
154 return
155 contractEvType->containsRestructuringType(
157 contractEvType->containsDefaultType(
159 }
163 virtual bool matchesDefaultKey(const DefaultProbKey& contractKey) const;
164
165 void accept(AcyclicVisitor&) override;
166
167 protected:
173 };
174
182 bool operator==(const DefaultEvent& lhs, const DefaultEvent& rhs);
183
184 inline bool operator!=(const DefaultEvent& lhs, const DefaultEvent& rhs) {
185 return !(lhs == rhs);
186 }
187
188 template<>
190 bool operator()(const DefaultEvent& e1,
191 const DefaultEvent& e2) const {
192 return e1.date() < e2.date();
193 }
194 };
195
196
197 // ------------------------------------------------------------------------
198
200 public:
201 FailureToPayEvent(const Date& creditEventDate,
202 const Currency& curr,
203 Seniority bondsSen,
204 Real defaultedAmount,
205 // Settlement information:
206 const Date& settleDate,
207 const std::map<Seniority, Real>& recoveryRates);
208 FailureToPayEvent(const Date& creditEventDate,
209 const Currency& curr,
210 Seniority bondsSen,
211 Real defaultedAmount,
212 // Settlement information:
213 const Date& settleDate,
214 Real recoveryRates);
216 bool matchesEventType(const ext::shared_ptr<DefaultType>& contractEvType) const override;
217
218 private:
220 };
221
222
223 // ------------------------------------------------------------------------
224
226 public:
227 BankruptcyEvent(const Date& creditEventDate,
228 const Currency& curr,
229 Seniority bondsSen,
230 // Settlement information:
231 const Date& settleDate,
232 const std::map<Seniority, Real>& recoveryRates);
233 BankruptcyEvent(const Date& creditEventDate,
234 const Currency& curr,
235 Seniority bondsSen,
236 // Settlement information:
237 const Date& settleDate,
238 // means same for all
239 Real recoveryRates);
241 bool matchesEventType(const ext::shared_ptr<DefaultType>&) const override { return true; }
242 };
243
244}
245
246#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
bool matchesEventType(const ext::shared_ptr< DefaultType > &) const override
This is a stronger than all event and will trigger all of them.
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
void accept(AcyclicVisitor &) override
Real recoveryRate(Seniority sen) const
std::map< Seniority, Real > recoveryRates_
Realized recovery rates.
Date date() const override
returns the date at which the event occurs
Credit event on a bond of a certain seniority(ies)/currency.
virtual Real recoveryRate(Seniority seniority) const
virtual bool matchesEventType(const ext::shared_ptr< DefaultType > &contractEvType) const
const DefaultSettlement & settlement() const
const Currency & currency() const
returns the currency of the bond this event refers to.
void accept(AcyclicVisitor &) override
std::map< Seniority, Real > rate_map
virtual bool matchesDefaultKey(const DefaultProbKey &contractKey) const
Date date() const override
returns the date at which the event occurs
bool isRestructuring() const
DefaultSettlement defSettlement_
const DefaultType & defaultType() const
Seniority eventSeniority() const
returns the seniority of the bond that triggered the event.
Atomic credit-event type.
Restructuring::Type restructuringType() const
bool isRestructuring() const
AtomicDefault::Type defaultType() const
Base class for event.
Definition: event.hpp:40
bool matchesEventType(const ext::shared_ptr< DefaultType > &contractEvType) const override
template class providing a null value for a given type.
Definition: null.hpp:76
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:191
Seniority
Seniority of a bond.
Definition: defaulttype.hpp:37
bool operator!=(const Currency &c1, const Currency &c2)
Definition: currency.hpp:196
bool operator()(const DefaultEvent &e1, const DefaultEvent &e2) const
compare two objects by date
Definition: comparison.hpp:130