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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCorrectedYts)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testCorrectedYts  )

Definition at line 39 of file staticallycorrectedyieldtermstructure.cpp.

39 {
40
41 SavedSettings backup;
42
43 Date refDate(18, Feb, 2016);
44 Settings::instance().evaluationDate() = refDate;
45
46 QuantLib::ext::shared_ptr<SimpleQuote> q = QuantLib::ext::make_shared<SimpleQuote>(0.02);
47 Handle<Quote> hq(q);
48 Handle<YieldTermStructure> floating(QuantLib::ext::make_shared<FlatForward>(0, NullCalendar(), hq, Actual365Fixed()));
49
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()));
52
53 // we can not test the flavours of roll down with flat
54 // termstructures, todo add tests with non-flat ts for this
55
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));
60
61 Real tol = 1.0E-12;
62
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);
73
74 // move market data
75 q->setValue(0.03);
76
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);
95
96 // move forward in time
97 Settings::instance().evaluationDate() = Date(18, Feb, 2022);
98 Real t = Actual365Fixed().yearFraction(refDate, Settings::instance().evaluationDate());
99
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);
121}
@ ConstantDiscounts