/src/quantlib/ql/termstructures/credit/survivalprobabilitystructure.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009 Ferdinando Ametrano |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | #include <ql/termstructures/credit/survivalprobabilitystructure.hpp> |
21 | | |
22 | | namespace QuantLib { |
23 | | |
24 | | SurvivalProbabilityStructure::SurvivalProbabilityStructure( |
25 | | const DayCounter& dc, |
26 | | const std::vector<Handle<Quote> >& jumps, |
27 | | const std::vector<Date>& jumpDates) |
28 | 0 | : DefaultProbabilityTermStructure(dc, jumps, jumpDates) {} |
29 | | |
30 | | SurvivalProbabilityStructure::SurvivalProbabilityStructure( |
31 | | const Date& refDate, |
32 | | const Calendar& cal, |
33 | | const DayCounter& dc, |
34 | | const std::vector<Handle<Quote> >& jumps, |
35 | | const std::vector<Date>& jumpDates) |
36 | 0 | : DefaultProbabilityTermStructure(refDate, cal, dc, jumps, jumpDates) {} |
37 | | |
38 | | SurvivalProbabilityStructure::SurvivalProbabilityStructure( |
39 | | Natural settlDays, |
40 | | const Calendar& cal, |
41 | | const DayCounter& dc, |
42 | | const std::vector<Handle<Quote> >& jumps, |
43 | | const std::vector<Date>& jumpDates) |
44 | 0 | : DefaultProbabilityTermStructure(settlDays, cal, dc, jumps, jumpDates) {} |
45 | | |
46 | 0 | Real SurvivalProbabilityStructure::defaultDensityImpl(Time t) const { |
47 | 0 | Time dt = 0.0001; |
48 | 0 | Time t1 = std::max(t-dt, 0.0); |
49 | 0 | Time t2 = t+dt; |
50 | |
|
51 | 0 | Probability p1 = survivalProbabilityImpl(t1); |
52 | 0 | Probability p2 = survivalProbabilityImpl(t2); |
53 | |
|
54 | 0 | return (p1-p2)/(t2-t1); |
55 | 0 | } |
56 | | |
57 | | } |