| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|---|---|
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2008 Roland Lichters |
| 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 | #include <ql/experimental/credit/pool.hpp> |
| 21 | #include <ql/functional.hpp> |
| 22 | #include <iterator> |
| 23 | |
| 24 | namespace QuantLib { |
| 25 | |
| 26 | Pool::Pool() { |
| 27 | clear(); |
| 28 | } |
| 29 | |
| 30 | Size Pool::size() const { |
| 31 | return names_.size(); |
| 32 | } |
| 33 | |
| 34 | void Pool::clear() { |
| 35 | data_.clear(); |
| 36 | time_.clear(); |
| 37 | names_.clear(); |
| 38 | } |
| 39 | |
| 40 | bool Pool::has(const std::string& name) const { |
| 41 | return data_.find(x: name) != data_.end(); |
| 42 | } |
| 43 | |
| 44 | void Pool::add (const std::string& name, const Issuer& issuer, |
| 45 | const DefaultProbKey& contractTrigger) { |
| 46 | if (!has(name)) { |
| 47 | data_[name] = issuer; |
| 48 | time_[name] = 0.0; |
| 49 | names_.push_back(x: name); |
| 50 | defaultKeys_[name] = contractTrigger; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | const Issuer& Pool::get (const std::string& name) const { |
| 55 | QL_REQUIRE(has(name), name + " not found"); |
| 56 | return data_.find(x: name)->second; |
| 57 | } |
| 58 | |
| 59 | const DefaultProbKey& Pool::defaultKey (const std::string& name) const { |
| 60 | QL_REQUIRE(has(name), name + " not found"); |
| 61 | return defaultKeys_.find(x: name)->second; |
| 62 | } |
| 63 | |
| 64 | Real Pool::getTime (const std::string& name) const { |
| 65 | QL_REQUIRE(has(name), name + " not found"); |
| 66 | return time_.find(x: name)->second; |
| 67 | } |
| 68 | |
| 69 | void Pool::setTime(const std::string& name, Real time) { |
| 70 | time_[name] = time; |
| 71 | } |
| 72 | |
| 73 | const std::vector<std::string>& Pool::names() const { |
| 74 | return names_; |
| 75 | } |
| 76 | |
| 77 | std::vector<DefaultProbKey> Pool::defaultKeys() const { |
| 78 | std::vector<DefaultProbKey> defaultKeys; |
| 79 | defaultKeys.reserve(n: defaultKeys_.size()); |
| 80 | for (const auto & i : defaultKeys_) |
| 81 | defaultKeys.push_back(x: i.second); |
| 82 | return defaultKeys; |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | |
| 87 | |
| 88 |
