21#include <boost/test/unit_test.hpp>
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/volatility/swaption/swaptionvolmatrix.hpp>
27#include <ql/time/calendars/target.hpp>
29#include <ql/time/daycounters/actual365fixed.hpp>
33using namespace boost::unit_test_framework;
39 TestData() : origRefDate(20, Jan, 2016), atmVols(2, 2) {
41 Settings::instance().evaluationDate() = origRefDate;
43 optionTenors.push_back(3 * Months);
44 optionTenors.push_back(5 * Years);
45 swapTenors.push_back(1 * Years);
46 swapTenors.push_back(2 * Years);
48 atmVols[0][0] = 0.0050;
49 atmVols[0][1] = 0.0060;
50 atmVols[1][0] = 0.0100;
51 atmVols[1][1] = 0.0160;
54 atmSurface = QuantLib::ext::make_shared<SwaptionVolatilityMatrix>(origRefDate, TARGET(), Following, optionTenors,
55 swapTenors, atmVols, Actual365Fixed(),
false, Normal);
59 const Date origRefDate;
60 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> atmSurface;
61 std::vector<Period> optionTenors, swapTenors;
69BOOST_AUTO_TEST_SUITE(DynamicSwaptionVolMatrixTest)
73 BOOST_TEST_MESSAGE(
"Testing constant variance dynamics of "
74 "DynamicSwaptionVolatilityMatrix...");
78 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
79 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(),
ConstantVariance);
81 dyn->enableExtrapolation();
89 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 1 * Years, strike),
90 d.atmSurface->volatility(1 * Months, 1 * Years, strike), tol);
91 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 2 * Years, strike),
92 d.atmSurface->volatility(1 * Months, 2 * Years, strike), tol);
93 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 1 * Years, strike),
94 d.atmSurface->volatility(1 * Years, 1 * Years, strike), tol);
95 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 2 * Years, strike),
96 d.atmSurface->volatility(1 * Years, 2 * Years, strike), tol);
100 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
102 BOOST_CHECK_CLOSE(dyn->volatility(0.1, 1.0, strike), d.atmSurface->volatility(0.1, 1.0, strike), tol);
103 BOOST_CHECK_CLOSE(dyn->volatility(0.1, 2.0, strike), d.atmSurface->volatility(0.1, 2.0, strike), tol);
104 BOOST_CHECK_CLOSE(dyn->volatility(1.0, 1.0, strike), d.atmSurface->volatility(1.0, 1.0, strike), tol);
105 BOOST_CHECK_CLOSE(dyn->volatility(1.0, 2.0, strike), d.atmSurface->volatility(1.0, 2.0, strike), tol);
111 BOOST_TEST_MESSAGE(
"Testing forward forward variance dynamics of "
112 "DynamicSwaptionVolatilityMatrix");
115 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
116 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(),
ForwardForwardVariance);
118 dyn->enableExtrapolation();
126 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 1 * Years, strike),
127 d.atmSurface->volatility(1 * Months, 1 * Years, strike), tol);
128 BOOST_CHECK_CLOSE(dyn->volatility(1 * Months, 2 * Years, strike),
129 d.atmSurface->volatility(1 * Months, 2 * Years, strike), tol);
130 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 1 * Years, strike),
131 d.atmSurface->volatility(1 * Years, 1 * Years, strike), tol);
132 BOOST_CHECK_CLOSE(dyn->volatility(1 * Years, 2 * Years, strike),
133 d.atmSurface->volatility(1 * Years, 2 * Years, strike), tol);
137 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
138 Real tf = d.atmSurface->timeFromReference(Settings::instance().evaluationDate());
140 BOOST_CHECK_CLOSE(dyn->blackVariance(0.1, 1.0, strike),
141 d.atmSurface->blackVariance(tf + 0.1, 1.0, strike) - d.atmSurface->blackVariance(tf, 1.0, strike),
143 BOOST_CHECK_CLOSE(dyn->blackVariance(0.1, 2.0, strike),
144 d.atmSurface->blackVariance(tf + 0.1, 2.0, strike) - d.atmSurface->blackVariance(tf, 2.0, strike),
146 BOOST_CHECK_CLOSE(dyn->blackVariance(1.0, 1.0, strike),
147 d.atmSurface->blackVariance(tf + 1.0, 1.0, strike) - d.atmSurface->blackVariance(tf, 1.0, strike),
149 BOOST_CHECK_CLOSE(dyn->blackVariance(1.0, 2.0, strike),
150 d.atmSurface->blackVariance(tf + 1.0, 2.0, strike) - d.atmSurface->blackVariance(tf, 2.0, strike),
155BOOST_AUTO_TEST_SUITE_END()
157BOOST_AUTO_TEST_SUITE_END()
dynamic swaption volatility matrix
BOOST_AUTO_TEST_CASE(testConstantVariance)
Fixture that can be used at top level.
helper macros and methods for tests