QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
pool.cpp
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
24namespace QuantLib {
25
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(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(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(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(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(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(defaultKeys_.size());
80 for (const auto & i : defaultKeys_)
81 defaultKeys.push_back(i.second);
82 return defaultKeys;
83 }
84
85}
86
87
const Issuer & get(const std::string &name) const
Definition: pool.cpp:54
std::map< std::string, Real > time_
Definition: pool.hpp:51
void add(const std::string &name, const Issuer &issuer, const DefaultProbKey &contractTrigger=NorthAmericaCorpDefaultKey(Currency(), SeniorSec, Period(), 1.))
Definition: pool.cpp:44
std::vector< DefaultProbKey > defaultKeys() const
Definition: pool.cpp:77
const DefaultProbKey & defaultKey(const std::string &name) const
Definition: pool.cpp:59
std::map< std::string, Issuer > data_
Definition: pool.hpp:50
Real getTime(const std::string &name) const
Definition: pool.cpp:64
void setTime(const std::string &name, Real time)
Definition: pool.cpp:69
const std::vector< std::string > & names() const
Definition: pool.cpp:73
bool has(const std::string &name) const
Definition: pool.cpp:40
std::vector< std::string > names_
Definition: pool.hpp:52
void clear()
Definition: pool.cpp:34
Size size() const
Definition: pool.cpp:30
std::map< std::string, DefaultProbKey > defaultKeys_
Definition: pool.hpp:55
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35