35 {
36
37
38 BOOST_TEST_MESSAGE("Testing QuantExt::InteroplatedDiscountCurve2...");
39
40 SavedSettings backup;
41 Settings::instance().evaluationDate() = Date(1, Dec, 2015);
42 Date today = Settings::instance().evaluationDate();
43
44 vector<Date> dates;
45 vector<Real> times;
46 vector<DiscountFactor> dfs;
47 vector<Handle<Quote> > quotes;
48
49 Size numYears = 30;
50 int startYear = 2015;
51 DayCounter dc = ActualActual(ActualActual::ISDA);
52 Calendar cal = NullCalendar();
53
54 for (Size i = 0; i < numYears; i++) {
55
56
57 Real rate = 0.01 + i * 0.001;
58
59 dates.push_back(Date(1, Dec, startYear + i));
60 Time t = dc.yearFraction(today, dates.back());
61 times.push_back(t);
62
63
64 DiscountFactor df = ::exp(-rate * t);
65 Handle<Quote> q(QuantLib::ext::make_shared<SimpleQuote>(df));
66 quotes.push_back(q);
67 dfs.push_back(df);
68 }
69
70
71 QuantLib::ext::shared_ptr<YieldTermStructure> ytsBase;
72 ytsBase =
73 QuantLib::ext::shared_ptr<YieldTermStructure>(new QuantLib::InterpolatedDiscountCurve<LogLinear>(dates, dfs, dc, cal));
74 ytsBase->enableExtrapolation();
75
77
78
79 for (Time t = 0.1; t < numYears + 10.0; t += 0.1) {
80 BOOST_CHECK_CLOSE(ytsBase->discount(t), ytsTest->discount(t), 1e-12);
81 }
82}
InterpolatedDiscountCurve2 as in QuantLib, but with floating discount quotes and floating reference d...