Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
yieldplusdefaultyieldtermstructure.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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 yieldplusdefaultyieldtermstructure.hpp
20 \brief yield term structure given as a yield ts plus weighted sum of default term structures
21 \ingroup models
22*/
23
24#ifndef quantext_yieldplusdefault_yts_hpp
25#define quantext_yieldplusdefault_yts_hpp
26
27#include <ql/termstructures/defaulttermstructure.hpp>
28#include <ql/termstructures/yieldtermstructure.hpp>
29
30namespace QuantExt {
31using namespace QuantLib;
32
33//! yield plus default yield term structure
34/*! this yield term structure is defined by discount factors given by a weighted sum of survival probabilities of
35 underlying default curves plus the discount factor of a reference yield curve
36*/
37class YieldPlusDefaultYieldTermStructure : public YieldTermStructure {
38public:
39 YieldPlusDefaultYieldTermStructure(const Handle<YieldTermStructure>& yts,
40 const std::vector<Handle<DefaultProbabilityTermStructure> >& df,
41 const std::vector<Handle<Quote> >& rr, const std::vector<Real>& weights)
42 : YieldTermStructure(yts->dayCounter()), yts_(yts), df_(df), rr_(rr), weights_(weights) {
43 QL_REQUIRE(df_.size() == weights_.size(), "YieldPlusDefaultYieldTermStructure: default curve size ("
44 << df_.size() << ") must match weights size (" << weights_.size()
45 << ")");
46 QL_REQUIRE(df_.size() == rr_.size(), "YieldPlusDefaultYieldTermStructure: rec rate size ("
47 << rr_.size() << ") must match weights size (" << weights_.size()
48 << ")");
49 // todo check consistent day counters?
50 registerWith(yts);
51 for (Size i = 0; i < df_.size(); ++i)
52 registerWith(df_[i]);
53 for (Size i = 0; i < rr_.size(); ++i)
54 registerWith(rr_[i]);
55 }
56 Date maxDate() const override;
57 const Date& referenceDate() const override;
58
59protected:
60 Real discountImpl(Time t) const override;
61 const Handle<YieldTermStructure> yts_;
62 const std::vector<Handle<DefaultProbabilityTermStructure> > df_;
63 const std::vector<Handle<Quote> > rr_;
64 const std::vector<Real> weights_;
65};
66
67// inline
68
69inline Date YieldPlusDefaultYieldTermStructure::maxDate() const { return yts_->maxDate(); }
70
72 // todo check consistent reference dates?
73 return yts_->referenceDate();
74}
75
77 Real d = yts_->discount(t);
78 for (Size i = 0; i < df_.size(); ++i) {
79 // use implied surv prob adjusted by a factor corresponding to a market value recovery model:
80 // adj_S = S^{1-R}
81 d *= std::pow(df_[i]->survivalProbability(t), weights_[i] * (1.0 - rr_[i]->value()));
82 }
83 return d;
84}
85
86} // namespace QuantExt
87
88#endif
const std::vector< Handle< DefaultProbabilityTermStructure > > df_
YieldPlusDefaultYieldTermStructure(const Handle< YieldTermStructure > &yts, const std::vector< Handle< DefaultProbabilityTermStructure > > &df, const std::vector< Handle< Quote > > &rr, const std::vector< Real > &weights)