19#include <boost/assign/list_of.hpp>
20#include <boost/make_shared.hpp>
21#include <boost/test/unit_test.hpp>
22#include <ql/math/comparison.hpp>
23#include <ql/settings.hpp>
24#include <ql/termstructures/yield/discountcurve.hpp>
25#include <ql/termstructures/yield/flatforward.hpp>
26#include <ql/termstructures/yield/zerocurve.hpp>
27#include <ql/time/calendars/nullcalendar.hpp>
32using namespace boost::unit_test_framework;
33using namespace boost::assign;
38BOOST_AUTO_TEST_SUITE(DiscountingRatioModifiedCurveTest)
42 BOOST_TEST_MESSAGE(
"Testing discount ratio modified curve with some standard curves");
46 Date today(15, Aug, 2018);
47 Settings::instance().evaluationDate() = today;
52 vector<Date> baseDates = list_of(today)(today + 1 * Years);
53 vector<Real> baseDfs = list_of(1.0)(0.98);
54 Handle<YieldTermStructure> baseCurve(QuantLib::ext::make_shared<DiscountCurve>(baseDates, baseDfs, dc));
55 baseCurve->enableExtrapolation();
58 vector<Date> numDates = list_of(today)(today + 1 * Years)(today + 2 * Years);
59 vector<Real> numZeroes = list_of(0.025)(0.025)(0.026);
60 Handle<YieldTermStructure> numCurve(QuantLib::ext::make_shared<ZeroCurve>(numDates, numZeroes, dc));
61 numCurve->enableExtrapolation();
64 Handle<YieldTermStructure> denCurve(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, dc));
68 Date discountDate = today + 18 * Months;
70 close(curve.discount(discountDate),
71 baseCurve->discount(discountDate) * numCurve->discount(discountDate) / denCurve->discount(discountDate)));
73 discountDate = today + 3 * Years;
75 close(curve.discount(discountDate),
76 baseCurve->discount(discountDate) * numCurve->discount(discountDate) / denCurve->discount(discountDate)));
81 Settings::instance().evaluationDate() = today + 3 * Months;
82 BOOST_TEST_MESSAGE(
"Changed evaluation date to " << Settings::instance().evaluationDate());
85 !close(curve.discount(discountDate), baseCurve->discount(discountDate) * numCurve->discount(discountDate) /
86 denCurve->discount(discountDate)));
87 Time t = dc.yearFraction(curve.
referenceDate(), discountDate);
88 BOOST_CHECK(close(curve.discount(discountDate),
89 baseCurve->discount(discountDate) * numCurve->discount(discountDate) / denCurve->discount(t)));
94 BOOST_TEST_MESSAGE(
"Testing extrapolation settings for discount ratio modified curve");
98 Date today(15, Aug, 2018);
99 Settings::instance().evaluationDate() = today;
104 vector<Date> baseDates = list_of(today)(Date(15, Aug, 2019));
105 vector<Real> baseDfs = list_of(1.0)(0.98);
106 Handle<YieldTermStructure> baseCurve(QuantLib::ext::make_shared<DiscountCurve>(baseDates, baseDfs, dc));
109 vector<Date> numDates = list_of(today)(Date(15, Aug, 2019))(Date(15, Aug, 2020));
110 vector<Real> numZeroes = list_of(0.025)(0.025)(0.026);
111 Handle<YieldTermStructure> numCurve(QuantLib::ext::make_shared<ZeroCurve>(numDates, numZeroes, dc));
114 Handle<YieldTermStructure> denCurve(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, dc));
120 BOOST_CHECK(curve.allowsExtrapolation());
123 BOOST_CHECK_EQUAL(curve.
maxDate(), Date::maxDate());
126 BOOST_CHECK_NO_THROW(curve.discount(Date(15, Aug, 2019)));
127 BOOST_CHECK_THROW(curve.discount(Date(15, Aug, 2019) + 1 * Days), QuantLib::Error);
128 baseCurve->enableExtrapolation();
129 BOOST_CHECK_NO_THROW(curve.discount(Date(15, Aug, 2019) + 1 * Days));
130 BOOST_CHECK_THROW(curve.discount(Date(15, Aug, 2020) + 1 * Days), QuantLib::Error);
131 numCurve->enableExtrapolation();
132 BOOST_CHECK_NO_THROW(curve.discount(Date(15, Aug, 2020) + 1 * Days));
137 BOOST_TEST_MESSAGE(
"Testing construction with null underlying curves throw");
139 QuantLib::ext::shared_ptr<DiscountRatioModifiedCurve> curve;
142 Handle<YieldTermStructure> baseCurve;
143 Handle<YieldTermStructure> numCurve;
144 Handle<YieldTermStructure> denCurve;
145 BOOST_CHECK_THROW(curve = QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(baseCurve, numCurve, denCurve),
149 Handle<YieldTermStructure> baseCurve_1(
150 QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
151 BOOST_CHECK_THROW(curve = QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(baseCurve_1, numCurve, denCurve),
155 Handle<YieldTermStructure> numCurve_1(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
156 BOOST_CHECK_THROW(curve = QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(baseCurve_1, numCurve_1, denCurve),
160 Handle<YieldTermStructure> denCurve_1(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
161 BOOST_CHECK_NO_THROW(curve = QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(baseCurve_1, numCurve_1, denCurve_1));
166 BOOST_TEST_MESSAGE(
"Testing that linking with null underlying curves throw");
168 QuantLib::ext::shared_ptr<DiscountRatioModifiedCurve> curve;
171 RelinkableHandle<YieldTermStructure> baseCurve(
172 QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
173 RelinkableHandle<YieldTermStructure> numCurve(
174 QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
175 RelinkableHandle<YieldTermStructure> denCurve(
176 QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), 0.0255, Actual365Fixed()));
179 BOOST_CHECK_NO_THROW(curve = QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(baseCurve, numCurve, denCurve));
182 BOOST_CHECK_THROW(baseCurve.linkTo(QuantLib::ext::shared_ptr<YieldTermStructure>()), QuantLib::Error);
183 BOOST_CHECK_NO_THROW(baseCurve.linkTo(*numCurve));
186 BOOST_CHECK_THROW(numCurve.linkTo(QuantLib::ext::shared_ptr<YieldTermStructure>()), QuantLib::Error);
187 BOOST_CHECK_NO_THROW(numCurve.linkTo(*denCurve));
190 BOOST_CHECK_THROW(denCurve.linkTo(QuantLib::ext::shared_ptr<YieldTermStructure>()), QuantLib::Error);
193BOOST_AUTO_TEST_SUITE_END()
195BOOST_AUTO_TEST_SUITE_END()
const QuantLib::Date & referenceDate() const override
Returns the reference date from the base curve.
QuantLib::Date maxDate() const override
All range checks happen in the underlying curves.
discount curve modified by the ratio of two other discount curves
BOOST_AUTO_TEST_CASE(testStandardCurves)
Fixture that can be used at top level.