| 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 | /*! \file issuer.hpp |
| 22 | \brief Classes for credit-name handling. |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_issuer_hpp |
| 26 | #define quantlib_issuer_hpp |
| 27 | |
| 28 | #include <ql/experimental/credit/defaultevent.hpp> |
| 29 | #include <ql/experimental/credit/defaultprobabilitykey.hpp> |
| 30 | #include <ql/termstructures/defaulttermstructure.hpp> |
| 31 | #include <set> |
| 32 | #include <vector> |
| 33 | |
| 34 | namespace QuantLib { |
| 35 | |
| 36 | typedef std::set<ext::shared_ptr<DefaultEvent>, |
| 37 | earlier_than<ext::shared_ptr<DefaultEvent> > > |
| 38 | DefaultEventSet; |
| 39 | |
| 40 | class Issuer { |
| 41 | public: |
| 42 | typedef std::pair<DefaultProbKey, |
| 43 | Handle<DefaultProbabilityTermStructure> > |
| 44 | key_curve_pair; |
| 45 | /*! The first argument represents the probability of an issuer |
| 46 | of having any of its bonds with the given seniority, |
| 47 | currency incurring in that particular event. The second |
| 48 | argument represents the history of past events. Theres no |
| 49 | check on whether the event list makes sense, events can |
| 50 | occur several times and several of them can take place on |
| 51 | the same date. |
| 52 | |
| 53 | To do: add settlement event access |
| 54 | */ |
| 55 | Issuer(std::vector<key_curve_pair> probabilities = std::vector<key_curve_pair>(), |
| 56 | DefaultEventSet events = DefaultEventSet()); |
| 57 | |
| 58 | Issuer(const std::vector<std::vector<ext::shared_ptr<DefaultType> > >& eventTypes, |
| 59 | const std::vector<Currency>& currencies, |
| 60 | const std::vector<Seniority>& seniorities, |
| 61 | const std::vector<Handle<DefaultProbabilityTermStructure> >& curves, |
| 62 | DefaultEventSet events = DefaultEventSet()); |
| 63 | |
| 64 | //! \name Inspectors |
| 65 | //@{ |
| 66 | const Handle<DefaultProbabilityTermStructure>& |
| 67 | defaultProbability(const DefaultProbKey& key) const; |
| 68 | |
| 69 | //@} |
| 70 | |
| 71 | //! \name Utilities |
| 72 | //@{ |
| 73 | //! If a default event with the required seniority and |
| 74 | // restructuring type is found, it is returned for |
| 75 | // inspection; otherwise, the method returns an empty pointer. |
| 76 | ext::shared_ptr<DefaultEvent> |
| 77 | defaultedBetween(const Date& start, |
| 78 | const Date& end, |
| 79 | const DefaultProbKey& key, |
| 80 | bool includeRefDate = false |
| 81 | ) const; |
| 82 | |
| 83 | //@} |
| 84 | std::vector<ext::shared_ptr<DefaultEvent> > |
| 85 | defaultsBetween(const Date& start, |
| 86 | const Date& end, |
| 87 | const DefaultProbKey& contractKey, |
| 88 | bool includeRefDate |
| 89 | ) const ; |
| 90 | private: |
| 91 | //! probabilities of events for each bond collection |
| 92 | // vector of pairs preferred over maps for performance |
| 93 | std::vector<std::pair<DefaultProbKey, |
| 94 | Handle<DefaultProbabilityTermStructure> > > probabilities_; |
| 95 | //! History of past events affecting this issuer. Notice it is possible |
| 96 | // for the same event to occur on the same bond several times along |
| 97 | // time. |
| 98 | DefaultEventSet events_; |
| 99 | }; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | #endif |
| 104 | |