Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
lgmimplieddefaulttermstructure.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 lgmimplieddefaulttermstructure.hpp
20 \brief default probability structure implied by a LGM model
21 \ingroup models
22*/
23
24#ifndef quantext_lgm_implied_survivalprob_ts_hpp
25#define quantext_lgm_implied_survivalprob_ts_hpp
26
28
29#include <ql/termstructures/credit/survivalprobabilitystructure.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! Lgm Implied Default Term Structure
35/*! The termstructure has the reference date of the model's
36 termstructure at construction, but you can vary this
37 as well as the state.
38 The purely time based variant is mainly there for
39 performance reasons, note that it does not provide the
40 full term structure interface and does not send
41 notifications on reference time updates.
42
43 \ingroup models
44 */
45
47public:
48 LgmImpliedDefaultTermStructure(const QuantLib::ext::shared_ptr<CrossAssetModel>& model, const Size index,
49 const Size currency, const DayCounter& dc = DayCounter(),
50 const bool purelyTimeBased = false);
51
52 Date maxDate() const override;
53 Time maxTime() const override;
54
55 const Date& referenceDate() const override;
56
57 void referenceDate(const Date& d);
58 void referenceTime(const Time t);
59 void state(const Real z, const Real y);
60 void move(const Date& d, const Real z, const Real y);
61 void move(const Time t, const Real z, const Real y);
62
63 void update() override;
64
65protected:
66 Probability survivalProbabilityImpl(Time) const override;
67
68 const QuantLib::ext::shared_ptr<CrossAssetModel> model_;
69 const Size index_, currency_;
70 const bool purelyTimeBased_;
73};
74
75// inline
76
78 // we don't care - let the underlying classes throw
79 // exceptions if applicable
80 return Date::maxDate();
81}
82
84 // see maxDate
85 return QL_MAX_REAL;
86}
87
89 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
90 "time based term structure");
91 return referenceDate_;
92}
93
95 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
96 "time based term structure");
98 update();
99}
100
102 QL_REQUIRE(purelyTimeBased_, "reference time can only be set for purely "
103 "time based term structure");
104 relativeTime_ = t;
105}
106
107inline void LgmImpliedDefaultTermStructure::state(const Real z, const Real y) {
108 z_ = z;
109 y_ = y;
110}
111
112inline void LgmImpliedDefaultTermStructure::move(const Date& d, const Real z, const Real y) {
113 state(z, y);
114 referenceDate(d);
115}
116
117inline void LgmImpliedDefaultTermStructure::move(const Time t, const Real z, const Real y) {
118 state(z, y);
119 referenceTime(t);
120}
121
123 if (!purelyTimeBased_) {
124 relativeTime_ = dayCounter().yearFraction(model_->irlgm1f(0)->termStructure()->referenceDate(), referenceDate_);
125 }
126 notifyObservers();
127}
128
130 QL_REQUIRE(t >= 0.0, "negative time (" << t << ") given");
131 return model_->crlgm1fS(index_, currency_, relativeTime_, relativeTime_ + t, z_, y_).second;
132}
133
134} // namespace QuantExt
135
136#endif
void move(const Date &d, const Real z, const Real y)
const QuantLib::ext::shared_ptr< CrossAssetModel > model_
cross asset model