20#include <boost/test/unit_test.hpp>
21#include <ql/math/interpolations/loginterpolation.hpp>
22#include <ql/quotes/simplequote.hpp>
23#include <ql/termstructures/credit/interpolatedsurvivalprobabilitycurve.hpp>
24#include <ql/termstructures/defaulttermstructure.hpp>
25#include <ql/termstructures/interpolatedcurve.hpp>
26#include <ql/termstructures/yieldtermstructure.hpp>
27#include <ql/time/calendars/nullcalendar.hpp>
28#include <ql/time/daycounters/actualactual.hpp>
31using namespace boost::unit_test_framework;
37BOOST_AUTO_TEST_SUITE(SurvivalProbabilityCruveTest)
41 BOOST_TEST_MESSAGE(
"Testing QuantExt::SurvivalProbabilityCurve...");
43 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
44 Date today = Settings::instance().evaluationDate();
48 vector<Probability> sps;
49 vector<Handle<Quote> > quotes;
50 vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
54 DayCounter dc = ActualActual(ActualActual::ISDA);
55 Calendar cal = NullCalendar();
57 for (Size i = 0; i < numYears; i++) {
60 Real rate = 0.01 + i * 0.001;
62 dates.push_back(Date(1, Dec, startYear + i));
63 Time t = dc.yearFraction(today, dates.back());
67 Probability sp = ::exp(-rate * t);
69 QuantLib::ext::shared_ptr<SimpleQuote> q(
new SimpleQuote(sp));
70 simpleQuotes.push_back(q);
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();
82 QuantLib::ext::shared_ptr<DefaultProbabilityTermStructure> dtsTest(
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);
90 for (Size i = 0; i < numYears; i++) {
91 Probability sp = sps[i] + 0.1;
92 simpleQuotes[i]->setValue(sp);
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)));
101BOOST_AUTO_TEST_SUITE_END()
103BOOST_AUTO_TEST_SUITE_END()
DefaultProbabilityTermStructure based on interpolation of survival probability quotes.
BOOST_AUTO_TEST_CASE(testSurvivalProbabilityCurve)
interpolated survival probability term structure
Fixture that can be used at top level.