QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
randomdefaultmodel.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Roland Lichters
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 randomdefaultmodel.hpp
22 \brief Random default-time scenarios for a pool of credit names
23*/
24
25#ifndef quantlib_random_default_model_hpp
26#define quantlib_random_default_model_hpp
27
32
33namespace QuantLib {
34
35 //! Base class for random default models
36 /*! Provides sequences of random default times for each name in the pool. */
37 class RandomDefaultModel : public Observer, public Observable {
38 public:
39 RandomDefaultModel(const ext::shared_ptr<Pool>& pool,
40 const std::vector<DefaultProbKey>& defaultKeys)
41 : pool_(pool), defaultKeys_(defaultKeys) {
42 // assuming none defaulted this is true.
43 QL_REQUIRE(defaultKeys.size() == pool->size(), "Incompatible pool and keys sizes.");
44 }
45 ~RandomDefaultModel() override = default;
46 void update() override { notifyObservers(); }
47 /*!
48 Generate a sequence of random default times, one for each name in the
49 pool, and store the result in the Pool using method setTime(name).
50 tmax denotes the maximum relevant time- default times > tmax are not
51 computed but set to tmax + 1 instead to save coputation time.
52 */
53 virtual void nextSequence(Real tmax = QL_MAX_REAL) = 0;
54 virtual void reset() = 0;
55 protected:
56 ext::shared_ptr<Pool> pool_;
57 std::vector<DefaultProbKey> defaultKeys_;
58 };
59
60 /*!
61 Random default times using a one-factor Gaussian copula.
62 */
64 public:
65 GaussianRandomDefaultModel(const ext::shared_ptr<Pool>& pool,
66 const std::vector<DefaultProbKey>& defaultKeys,
67 const Handle<OneFactorCopula>& copula,
68 Real accuracy,
69 long seed);
70 void nextSequence(Real tmax = QL_MAX_REAL) override;
71 void reset() override;
72
73 private:
76 long seed_;
78 };
79
80}
81
82#endif
void nextSequence(Real tmax=QL_MAX_REAL) override
Shared handle to an observable.
Definition: handle.hpp:41
Inverse cumulative random sequence generator.
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
Base class for random default models.
ext::shared_ptr< Pool > pool_
std::vector< DefaultProbKey > defaultKeys_
RandomDefaultModel(const ext::shared_ptr< Pool > &pool, const std::vector< DefaultProbKey > &defaultKeys)
virtual void nextSequence(Real tmax=QL_MAX_REAL)=0
~RandomDefaultModel() override=default
Classes for default-event description.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_MAX_REAL
Definition: qldefines.hpp:176
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
One-factor copula base class.
pool of issuers
random-number generation policies