21#include <boost/test/unit_test.hpp>
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/yield/flatforward.hpp>
27#include <ql/time/calendars/nullcalendar.hpp>
29#include <boost/make_shared.hpp>
33using namespace boost::unit_test_framework;
37BOOST_AUTO_TEST_SUITE(StaticallyCorrectedYieVldTermStructureTest)
43 Date refDate(18, Feb, 2016);
44 Settings::instance().evaluationDate() = refDate;
46 QuantLib::ext::shared_ptr<SimpleQuote> q = QuantLib::ext::make_shared<SimpleQuote>(0.02);
48 Handle<YieldTermStructure> floating(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), hq, Actual365Fixed()));
50 Handle<YieldTermStructure> source(QuantLib::ext::make_shared<FlatForward>(refDate, 0.02, Actual365Fixed()));
51 Handle<YieldTermStructure> target(QuantLib::ext::make_shared<FlatForward>(refDate, 0.03, Actual365Fixed()));
56 Handle<YieldTermStructure> corrected1(
57 QuantLib::ext::make_shared<StaticallyCorrectedYieldTermStructure>(floating, source, target,
ConstantDiscounts));
58 Handle<YieldTermStructure> corrected2(
59 QuantLib::ext::make_shared<StaticallyCorrectedYieldTermStructure>(floating, source, target,
ForwardForward));
63 BOOST_CHECK_MESSAGE(std::fabs(target->discount(1.0) - corrected1->discount(1.0)) < tol,
64 "can not verify corrected1 df ("
65 << corrected1->discount(1.0) <<
") against target df (" << target->discount(1.0)
66 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
67 << (corrected1->discount(1.0) - target->discount(1.0)) <<
", tolerance is " << tol);
68 BOOST_CHECK_MESSAGE(std::fabs(target->discount(1.0) - corrected2->discount(1.0)) < tol,
69 "can not verify corrected2 df ("
70 << corrected2->discount(1.0) <<
") against target df (" << target->discount(1.0)
71 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
72 << (corrected2->discount(1.0) - target->discount(1.0)) <<
", tolerance is " << tol);
77 BOOST_CHECK_MESSAGE(std::fabs(floating->discount(1.0) * target->discount(1.0) / source->discount(1.0) -
78 corrected1->discount(1.0)) < tol,
79 "can not verify corrected1 df ("
80 << corrected1->discount(1.0) <<
") against expected df ("
81 << floating->discount(1.0) * target->discount(1.0) / source->discount(1.0)
82 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
83 << (corrected1->discount(1.0) -
84 floating->discount(1.0) * target->discount(1.0) / source->discount(1.0))
85 <<
", tolerance is " << tol);
86 BOOST_CHECK_MESSAGE(std::fabs(floating->discount(1.0) * target->discount(1.0) / source->discount(1.0) -
87 corrected2->discount(1.0)) < tol,
88 "can not verify corrected2 df ("
89 << corrected2->discount(1.0) <<
") against expected df ("
90 << floating->discount(1.0) * target->discount(1.0) / source->discount(1.0)
91 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
92 << (corrected2->discount(1.0) -
93 floating->discount(1.0) * target->discount(1.0) / source->discount(1.0))
94 <<
", tolerance is " << tol);
97 Settings::instance().evaluationDate() = Date(18, Feb, 2022);
98 Real t = Actual365Fixed().yearFraction(refDate, Settings::instance().evaluationDate());
100 BOOST_CHECK_MESSAGE(std::fabs(floating->discount(1.0) * target->discount(1.0) / source->discount(1.0) -
101 corrected1->discount(1.0)) < tol,
102 "can not verify corrected1 df ("
103 << corrected1->discount(1.0) <<
") against expected df ("
104 << floating->discount(1.0) * target->discount(1.0) / source->discount(1.0)
105 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
106 << (corrected1->discount(1.0) -
107 floating->discount(1.0) * target->discount(1.0) / source->discount(1.0))
108 <<
", tolerance is " << tol);
109 BOOST_CHECK_MESSAGE(std::fabs(floating->discount(1.0) * target->discount(t + 1.0) * source->discount(t) /
110 (target->discount(t) * source->discount(t + 1.0)) -
111 corrected2->discount(1.0)) < tol,
112 "can not verify corrected2 df ("
113 << corrected2->discount(1.0) <<
") against expected df ("
114 << floating->discount(1.0) * target->discount(t + 1.0) * source->discount(t) /
115 (target->discount(t) * source->discount(t + 1.0))
116 <<
") on eval date " << Settings::instance().evaluationDate() <<
", difference is "
117 << floating->discount(1.0) * target->discount(t + 1.0) * source->discount(t) /
118 (target->discount(t) * source->discount(t + 1.0)) -
119 corrected2->discount(1.0)
120 <<
", tolerance is " << tol);
123BOOST_AUTO_TEST_SUITE_END()
125BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testCorrectedYts)
Statically corrected yield term structure.
Fixture that can be used at top level.
helper macros and methods for tests