39 {
40
41 BOOST_TEST_MESSAGE("Testing QuantExt::SurvivalProbabilityCurve...");
42
43 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
44 Date today = Settings::instance().evaluationDate();
45
46 vector<Date> dates;
47 vector<Real> times;
48 vector<Probability> sps;
49 vector<Handle<Quote> > quotes;
50 vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
51
52 Size numYears = 30;
53 int startYear = 2015;
54 DayCounter dc = ActualActual(ActualActual::ISDA);
55 Calendar cal = NullCalendar();
56
57 for (Size i = 0; i < numYears; i++) {
58
59
60 Real rate = 0.01 + i * 0.001;
61
62 dates.push_back(Date(1, Dec, startYear + i));
63 Time t = dc.yearFraction(today, dates.back());
64 times.push_back(t);
65
66
67 Probability sp = ::exp(-rate * t);
68
69 QuantLib::ext::shared_ptr<SimpleQuote> q(new SimpleQuote(sp));
70 simpleQuotes.push_back(q);
71 Handle<Quote> qh(q);
72 quotes.push_back(qh);
73 sps.push_back(sp);
74 }
75
76
77 QuantLib::ext::shared_ptr<DefaultProbabilityTermStructure> dtsBase;
78 dtsBase = QuantLib::ext::shared_ptr<DefaultProbabilityTermStructure>(
79 new QuantLib::InterpolatedSurvivalProbabilityCurve<Linear>(dates, sps, dc, cal));
80 dtsBase->enableExtrapolation();
81
82 QuantLib::ext::shared_ptr<DefaultProbabilityTermStructure> dtsTest(
84
85
86 for (Time t = 0.1; t < numYears + 10.0; t += 0.1) {
87 BOOST_CHECK_CLOSE(dtsBase->survivalProbability(t, true), dtsTest->survivalProbability(t, true), 1e-12);
88 }
89
90 for (Size i = 0; i < numYears; i++) {
91 Probability sp = sps[i] + 0.1;
92 simpleQuotes[i]->setValue(sp);
93 }
94
95 for (Time t = 0.1; t < numYears + 10.0; t += 0.1) {
96 BOOST_CHECK_PREDICATE(std::not_equal_to<Probability>(),
97 (dtsBase->survivalProbability(t, true))(dtsTest->survivalProbability(t, true)));
98 }
99}
DefaultProbabilityTermStructure based on interpolation of survival probability quotes.