Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
probabilitytraits.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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 qle/termstructures/probabilitytraits.hpp
20 \brief default probability bootstrap traits for QuantExt
21*/
22
23#ifndef quantext_probability_traits_hpp
24#define quantext_probability_traits_hpp
25
26#include <ql/termstructures/bootstraphelper.hpp>
27#include <ql/termstructures/credit/interpolateddefaultdensitycurve.hpp>
28#include <ql/termstructures/credit/interpolatedhazardratecurve.hpp>
29#include <ql/termstructures/credit/interpolatedsurvivalprobabilitycurve.hpp>
30
31namespace QuantExt {
32
33namespace detail {
34const QuantLib::Real avgHazardRate = 0.01;
35const QuantLib::Real maxHazardRate = 3.0;
36} // namespace detail
37
38//! Survival probability curve traits
40
41 // interpolated curve type
42 template <class Interpolator> struct curve {
43 typedef QuantLib::InterpolatedSurvivalProbabilityCurve<Interpolator> type;
44 };
45
46 // helper class
47 typedef QuantLib::BootstrapHelper<QuantLib::DefaultProbabilityTermStructure> helper;
48
49 // start of curve data
50 static QuantLib::Date initialDate(const QuantLib::DefaultProbabilityTermStructure* c) { return c->referenceDate(); }
51
52 // value at reference date
53 static QuantLib::Real initialValue(const QuantLib::DefaultProbabilityTermStructure*) { return 1.0; }
54
55 // guesses
56 template <class C> static QuantLib::Real guess(QuantLib::Size i, const C* c, bool validData, QuantLib::Size) {
57
58 // If have already bootstrapped some points, use the previous point
59 if (validData)
60 return c->data()[i];
61
62 // If haven't already bootstrapped some points, initial guess
63 if (i == 1)
64 return 1.0 / (1.0 + detail::avgHazardRate * 0.25);
65
66 // extrapolate
67 Date d = c->dates()[i];
68 return c->survivalProbability(d, true);
69 }
70
71 // constraints
72 template <class C>
73 static QuantLib::Real minValueAfter(QuantLib::Size i, const C* c, bool validData, QuantLib::Size) {
74
75 if (validData) {
76 return c->data().back() / 2.0;
77 }
78
79 Time dt = c->times()[i] - c->times()[i - 1];
80 return c->data()[i - 1] * std::exp(-detail::maxHazardRate * dt);
81 }
82
83 template <class C>
84 static QuantLib::Real maxValueAfter(QuantLib::Size i, const C* c, bool validData, QuantLib::Size) {
85 // survival probability cannot increase
86 return c->data()[i - 1];
87 }
88
89 // root-finding update
90 static void updateGuess(std::vector<QuantLib::Real>& data, QuantLib::Probability p, QuantLib::Size i) {
91 data[i] = p;
92 }
93
94 // upper bound for convergence loop
95 static QuantLib::Size maxIterations() { return 50; }
96};
97
98} // namespace QuantExt
99
100#endif
const QuantLib::Real maxHazardRate
const QuantLib::Real avgHazardRate
QuantLib::InterpolatedSurvivalProbabilityCurve< Interpolator > type
Survival probability curve traits.
static QuantLib::Real initialValue(const QuantLib::DefaultProbabilityTermStructure *)
static void updateGuess(std::vector< QuantLib::Real > &data, QuantLib::Probability p, QuantLib::Size i)
QuantLib::BootstrapHelper< QuantLib::DefaultProbabilityTermStructure > helper
static QuantLib::Size maxIterations()
static QuantLib::Real minValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
static QuantLib::Real guess(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)
static QuantLib::Date initialDate(const QuantLib::DefaultProbabilityTermStructure *c)
static QuantLib::Real maxValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size)