QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
defaultdensitystructure.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Chris Kenyon
5 Copyright (C) 2008 Roland Lichters
6 Copyright (C) 2008 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/math/integrals/gaussianquadratures.hpp>
23#include <ql/termstructures/credit/defaultdensitystructure.hpp>
24#include <utility>
25
26namespace QuantLib {
27
28 namespace {
29
30 template <class F>
31 struct t_remapper {
32 F f;
33 Time T;
34 t_remapper(F f, Time T) : f(std::move(f)), T(T) {}
35 // This remaps [-1,1] to [0,T]. No differential included.
36 Real operator()(Real x) const {
37 const Real arg = (x+1.0)*T/2.0;
38 return f(arg);
39 }
40 };
41
42 template <class F>
43 t_remapper<F> remap_t(const F& f, Time T) {
44 return t_remapper<F>(f,T);
45 }
46
47 }
48
50 const DayCounter& dc,
51 const std::vector<Handle<Quote> >& jumps,
52 const std::vector<Date>& jumpDates)
53 : DefaultProbabilityTermStructure(dc, jumps, jumpDates) {}
54
56 const Date& refDate,
57 const Calendar& cal,
58 const DayCounter& dc,
59 const std::vector<Handle<Quote> >& jumps,
60 const std::vector<Date>& jumpDates)
61 : DefaultProbabilityTermStructure(refDate, cal, dc, jumps, jumpDates) {}
62
64 Natural settlDays,
65 const Calendar& cal,
66 const DayCounter& dc,
67 const std::vector<Handle<Quote> >& jumps,
68 const std::vector<Date>& jumpDates)
69 : DefaultProbabilityTermStructure(settlDays, cal, dc, jumps, jumpDates) {}
70
72 static GaussChebyshevIntegration integral(48);
73 // the Gauss-Chebyshev quadratures integrate over [-1,1],
74 // hence the remapping (and the Jacobian term t/2)
75 Probability P = 1.0 - integral(remap_t([&](Time tau){ return defaultDensityImpl(tau); }, t)) * t / 2.0;
76 //QL_ENSURE(P >= 0.0, "negative survival probability");
77 return std::max<Real>(P, 0.0);
78 }
79
80}
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
DefaultDensityStructure(const DayCounter &dayCounter=DayCounter(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={})
Probability survivalProbabilityImpl(Time) const override
survival probability calculation
Default probability term structure.
virtual Real defaultDensityImpl(Time) const =0
default density calculation
Shared handle to an observable.
Definition: handle.hpp:41
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Probability
probability
Definition: types.hpp:82
Definition: any.hpp:35
STL namespace.