Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cirppimplieddefaulttermstructure.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file cirppimplieddefaulttermstructure.hpp
20 \brief default probability structure implied by a CIRPP model
21 \ingroup models
22*/
23
24#ifndef quantext_cirpp_implied_survivalprob_ts_hpp
25#define quantext_cirpp_implied_survivalprob_ts_hpp
26
28
29#include <ql/termstructures/credit/survivalprobabilitystructure.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34/*! The termstructure has the reference date of the model's
35 termstructure at construction, but you can vary this
36 as well as the state.
37 The purely time based variant is mainly there for
38 performance reasons, note that it does not provide the
39 full term structure interface and does not send
40 notifications on reference time updates.
41
42 \ingroup models
43 */
44
46public:
47 CirppImpliedDefaultTermStructure(const QuantLib::ext::shared_ptr<CrCirpp>& model, const Size index,
48 const DayCounter& dc = DayCounter(), const bool purelyTimeBased = false);
49
50 Date maxDate() const override;
51 Time maxTime() const override;
52
53 const Date& referenceDate() const override;
54
55 void referenceDate(const Date& d);
56 void referenceTime(const Time t);
57 void state(const Real y);
58 void move(const Date& d, const Real y);
59 void move(const Time t, const Real y);
60
61 void update() override;
62
63protected:
64 Probability survivalProbabilityImpl(Time) const override;
65
66 const QuantLib::ext::shared_ptr<CrCirpp> model_;
67 const Size index_;
68 const bool purelyTimeBased_;
71};
72
73// inline
74
76 // we don't care - let the underlying classes throw
77 // exceptions if applicable
78 return Date::maxDate();
79}
80
82 // see maxDate
83 return QL_MAX_REAL;
84}
85
87 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
88 "time based term structure");
89 return referenceDate_;
90}
91
93 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
94 "time based term structure");
96 update();
97}
98
100 QL_REQUIRE(purelyTimeBased_, "reference time can only be set for purely "
101 "time based term structure");
102 relativeTime_ = t;
103}
104
106 y_ = y;
107}
108
109inline void CirppImpliedDefaultTermStructure::move(const Date& d, const Real y) {
110 state(y);
111 referenceDate(d);
112}
113
114inline void CirppImpliedDefaultTermStructure::move(const Time t, const Real y) {
115 state(y);
116 referenceTime(t);
117}
118
120 if (!purelyTimeBased_) {
121 relativeTime_ = dayCounter().yearFraction(model_->defaultCurve()->referenceDate(), referenceDate_);
122 }
123 notifyObservers();
124}
125
127 QL_REQUIRE(t >= 0.0, "negative time (" << t << ") given");
128 if (QuantLib::close_enough(t, 0))
129 return 1.0;
130 return model_->survivalProbability(relativeTime_, relativeTime_+ t, y_);
131}
132
133} // namespace QuantExt
134
135#endif
const QuantLib::ext::shared_ptr< CrCirpp > model_
CIR++ credit model class.