QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
defaultprobabilitykey.cpp
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
21#include <ql/experimental/credit/defaultprobabilitykey.hpp>
22#if defined(QL_PATCH_MSVC)
23#pragma warning(push)
24#pragma warning(disable:4181)
25#endif
26#include <algorithm>
27#include <set>
28#include <utility>
29
30namespace QuantLib {
31
32 namespace {
33
34 struct points_to {
35 explicit points_to(const DefaultType& t) : t(t) {}
36 bool operator()(const ext::shared_ptr<DefaultType>& p) const {
37 return *p == t;
38 }
39 const DefaultType& t;
40 };
41
42 }
43
44 bool operator==(const DefaultProbKey& lhs, const DefaultProbKey& rhs) {
45 if(lhs.seniority() != rhs.seniority()) return false;
46 if(lhs.currency() != rhs.currency()) return false;
47
48 Size mySize = rhs.eventTypes().size();
49 if(mySize != lhs.eventTypes().size()) return false;
50 // the all types must be equal in the weak sense.
51 for(Size i=0; i<mySize; i++) {
52 if(std::find_if(lhs.eventTypes().begin(), lhs.eventTypes().end(),
53 points_to(*rhs.eventTypes()[i])) == lhs.eventTypes().end())
54 return false;
55 }// naah, I bet this can be done with a double lambda
56 return true;
57 }
58
60
61 DefaultProbKey::DefaultProbKey(std::vector<ext::shared_ptr<DefaultType> > eventTypes,
62 Currency cur,
63 Seniority sen)
64 : eventTypes_(std::move(eventTypes)), obligationCurrency_(std::move(cur)), seniority_(sen) {
65 std::set<AtomicDefault::Type> buffer;
66 Size numEvents = eventTypes_.size();
67 for(Size i=0; i< numEvents; i++)
68 buffer.insert(eventTypes_[i]->defaultType());
69 QL_REQUIRE(buffer.size() == numEvents,
70 "Duplicated event type in contract definition");
71 }
72
74 const Currency& currency,
75 Seniority sen,
76 Period graceFailureToPay,
77 Real amountFailure,
78 Restructuring::Type resType)
79 : DefaultProbKey(std::vector<ext::shared_ptr<DefaultType> >(),
80 currency, sen) {
81 eventTypes_.push_back( ext::shared_ptr<DefaultType>(
82 new FailureToPay(graceFailureToPay,
83 amountFailure)));
84 // no specifics for Bankruptcy
85 eventTypes_.push_back( ext::make_shared<DefaultType>(
89 eventTypes_.push_back( ext::make_shared<DefaultType>(
91 }
92
93}
94
95#if defined(QL_PATCH_MSVC)
96#pragma warning(pop)
97#endif
Currency specification
Definition: currency.hpp:36
const Currency & currency() const
const std::vector< ext::shared_ptr< DefaultType > > & eventTypes() const
std::vector< ext::shared_ptr< DefaultType > > eventTypes_
aggregation of event types for which the contract is sensitive.
Atomic credit-event type.
Failure to Pay atomic event type.
NorthAmericaCorpDefaultKey(const Currency &currency, Seniority sen, Period graceFailureToPay=Period(30, Days), Real amountFailure=1.e6, Restructuring::Type resType=Restructuring::CR)
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
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:191
Seniority
Seniority of a bond.
Definition: defaulttype.hpp:37
STL namespace.