Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
discountcurve.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/test/unit_test.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <qle/termstructures/interpolateddiscountcurve2.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testDiscountCurve)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testDiscountCurve  )

Definition at line 35 of file discountcurve.cpp.

35 {
36
37 // FIXME: test curve1 or 2 or both
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 // rate
57 Real rate = 0.01 + i * 0.001;
58 // 1 year apart
59 dates.push_back(Date(1, Dec, startYear + i));
60 Time t = dc.yearFraction(today, dates.back());
61 times.push_back(t);
62
63 // set up Quote of DiscountFactors
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 // Test against the QL curve
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
76 QuantLib::ext::shared_ptr<YieldTermStructure> ytsTest(new QuantExt::InterpolatedDiscountCurve2(times, quotes, dc));
77
78 // now check that they give the same discount factors (including extrapolation)
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...