Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
dynamicswaptionvolmatrix.cpp File Reference
#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <boost/test/unit_test.hpp>
#include <qle/termstructures/dynamicswaptionvolmatrix.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/volatility/swaption/swaptionvolmatrix.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testConstantVariance)
 
 BOOST_AUTO_TEST_CASE (testForwardForwardVariance)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testConstantVariance  )

Definition at line 71 of file dynamicswaptionvolmatrix.cpp.

71 {
72
73 BOOST_TEST_MESSAGE("Testing constant variance dynamics of "
74 "DynamicSwaptionVolatilityMatrix...");
75
76 TestData d;
77
78 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
79 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(), ConstantVariance);
80
81 dyn->enableExtrapolation();
82
83 Real tol = 1.0E-8;
84
85 Real strike = 0.05; // dummy strike
86
87 // initially we should get the same volatilities
88
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);
97
98 // move forward in time, we expect a constant surface
99
100 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
101
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);
106
107} // testConstantVariance
@ ConstantVariance

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testForwardForwardVariance  )

Definition at line 109 of file dynamicswaptionvolmatrix.cpp.

109 {
110
111 BOOST_TEST_MESSAGE("Testing forward forward variance dynamics of "
112 "DynamicSwaptionVolatilityMatrix");
113 TestData d;
114
115 QuantLib::ext::shared_ptr<SwaptionVolatilityStructure> dyn =
116 QuantLib::ext::make_shared<DynamicSwaptionVolatilityMatrix>(d.atmSurface, 0, TARGET(), ForwardForwardVariance);
117
118 dyn->enableExtrapolation();
119
120 Real tol = 1.0E-8;
121
122 Real strike = 0.05; // dummy strike
123
124 // initially we should get the same volatilities again
125
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);
134
135 // move forward in time, we expect the forward forward variance
136
137 Settings::instance().evaluationDate() = TARGET().advance(d.origRefDate, 5 * Months);
138 Real tf = d.atmSurface->timeFromReference(Settings::instance().evaluationDate());
139
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),
142 tol);
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),
145 tol);
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),
148 tol);
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),
151 tol);
152
153} // testForwardForwardVariance
@ ForwardForwardVariance