QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
issuer.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008, 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#include <ql/experimental/credit/issuer.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 namespace {
27 bool between(const ext::shared_ptr<DefaultEvent>& e,
28 const Date& start,
29 const Date& end,
30 bool includeRefDate = false) {
31 return !e->hasOccurred(start, includeRefDate) &&
32 e->hasOccurred(end, includeRefDate);
33 }
34 }
35
36 Issuer::Issuer(std::vector<std::pair<DefaultProbKey, Handle<DefaultProbabilityTermStructure> > >
37 probabilities,
38 DefaultEventSet events)
39 : probabilities_(std::move(probabilities)), events_(std::move(events)) {}
40
41 Issuer::Issuer(const std::vector<std::vector<ext::shared_ptr<DefaultType> > >& eventTypes,
42 const std::vector<Currency>& currencies,
43 const std::vector<Seniority>& seniorities,
44 const std::vector<Handle<DefaultProbabilityTermStructure> >& curves,
45 DefaultEventSet events)
46 : events_(std::move(events)) {
47 QL_REQUIRE((eventTypes.size() == curves.size()) &&
48 (curves.size()== currencies.size()) &&
49 (currencies.size() == seniorities.size()),
50 "Incompatible size of Issuer parameters.");
51
52 for(Size i=0; i <eventTypes.size(); i++) {
53 DefaultProbKey keytmp(eventTypes[i], currencies[i],
54 seniorities[i]);
55 probabilities_.emplace_back(keytmp, curves[i]);
56 }
57 }
58
61 for (const auto& probabilitie : probabilities_)
62 if (key == probabilitie.first)
63 return probabilitie.second;
64 QL_FAIL("Probability curve not available.");
65 }
66
67 ext::shared_ptr<DefaultEvent>
69 const Date& end,
70 const DefaultProbKey& contractKey,
71 bool includeRefDate
72 ) const
73 {
74 // to do: the set is ordered, see how to use it to speed this up
75 for (const auto& event : events_) {
76 if (event->matchesDefaultKey(contractKey) && between(event, start, end, includeRefDate))
77 return event;
78 }
79 return ext::shared_ptr<DefaultEvent>();
80 }
81
82
83 std::vector<ext::shared_ptr<DefaultEvent> >
85 const Date& end,
86 const DefaultProbKey& contractKey,
87 bool includeRefDate
88 ) const
89 {
90 std::vector<ext::shared_ptr<DefaultEvent> > defaults;
91 // to do: the set is ordered, see how to use it to speed this up
92 for (const auto& event : events_) {
93 if (event->matchesDefaultKey(contractKey) && between(event, start, end, includeRefDate))
94 defaults.push_back(event);
95 }
96 return defaults;
97 }
98
99}
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
ext::shared_ptr< DefaultEvent > defaultedBetween(const Date &start, const Date &end, const DefaultProbKey &key, bool includeRefDate=false) const
If a default event with the required seniority and.
Definition: issuer.cpp:68
DefaultEventSet events_
History of past events affecting this issuer. Notice it is possible.
Definition: issuer.hpp:98
const Handle< DefaultProbabilityTermStructure > & defaultProbability(const DefaultProbKey &key) const
Definition: issuer.cpp:60
std::vector< std::pair< DefaultProbKey, Handle< DefaultProbabilityTermStructure > > > probabilities_
probabilities of events for each bond collection
Definition: issuer.hpp:94
std::vector< ext::shared_ptr< DefaultEvent > > defaultsBetween(const Date &start, const Date &end, const DefaultProbKey &contractKey, bool includeRefDate) const
Definition: issuer.cpp:84
Issuer(std::vector< key_curve_pair > probabilities=std::vector< key_curve_pair >(), DefaultEventSet events=DefaultEventSet())
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::set< ext::shared_ptr< DefaultEvent >, earlier_than< ext::shared_ptr< DefaultEvent > > > DefaultEventSet
Definition: issuer.hpp:38
STL namespace.