Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
swaptionvolconstantspread.cpp File Reference
#include "swaptionmarketdata.hpp"
#include "toplevelfixture.hpp"
#include "yieldcurvemarketdata.hpp"
#include <boost/test/unit_test.hpp>
#include <qle/termstructures/swaptionvolatilityconverter.hpp>
#include <qle/termstructures/swaptionvolconstantspread.hpp>
#include <qle/termstructures/swaptionvolcube2.hpp>
#include <ql/indexes/swap/euriborswap.hpp>
#include <boost/assign/list_of.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testAtmNormalVolShiftPropagation)
 
 BOOST_AUTO_TEST_CASE (testAtmLogNormalVolShiftPropagation)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testAtmNormalVolShiftPropagation  )

Definition at line 124 of file swaptionvolconstantspread.cpp.

124 {
125 BOOST_TEST_MESSAGE("Testing ATM normal vol shift propagation...");
126
127 CommonVars vars1;
128 Real tolerance = 0.000001;
129 Real shift = 0.0050;
130 for (Size i = 0; i < vars1.atmVols.optionTenors.size(); ++i) {
131 for (Size j = 0; j < vars1.atmVols.swapTenors.size(); ++j) {
132 CommonVars vars2(i, j, shift);
133 Period expiry = vars1.atmVols.optionTenors[i];
134 Period term = vars1.atmVols.swapTenors[j];
135
136 Real atmVol = vars1.atmNormalVolMatrix->volatility(expiry, term, 0.0);
137 Real shiftedAtmVol = vars2.atmNormalVolMatrix->volatility(expiry, term, 0.0);
138 BOOST_CHECK_SMALL(shiftedAtmVol - atmVol - shift, tolerance);
139
140 // check that shift propagates to all strikes for this expiry/term
141 for (Real strike = 0.01; strike <= 0.08; strike += 0.005) {
142 Real otmVol = vars1.normalVolCubeConstantSpread->volatility(expiry, term, strike);
143 Real shiftedOtmVol = vars2.normalVolCubeConstantSpread->volatility(expiry, term, strike);
144 // BOOST_TEST_MESSAGE(i << "/" << j << "/" << strike << " : ATM Vol " << atmVol << " OTM Vol " << otmVol
145 // << " ATM Vol Shift " << shiftedAtmVol - atmVol << " OTM Vol Shift "
146 // << shiftedOtmVol - otmVol);
147 BOOST_CHECK_SMALL(shiftedOtmVol - otmVol - shift, tolerance);
148 }
149
150 // check that there is no shift in any other expiry/term
151 for (Size ii = 0; ii < vars1.atmVols.optionTenors.size(); ++ii) {
152 if (i == ii)
153 continue;
154 for (Size jj = 0; jj < vars1.atmVols.swapTenors.size(); ++jj) {
155 if (j == jj)
156 continue;
157 Period expiry = vars1.atmVols.optionTenors[ii];
158 Period term = vars1.atmVols.swapTenors[jj];
159 Real atmVol = vars1.atmNormalVolMatrix->volatility(expiry, term, 0.0);
160 Real shiftedAtmVol = vars2.atmNormalVolMatrix->volatility(expiry, term, 0.0);
161 BOOST_CHECK_SMALL(shiftedAtmVol - atmVol, tolerance);
162 for (Real strike = 0.01; strike <= 0.08; strike += 0.005) {
163 Real otmVol = vars1.normalVolCubeConstantSpread->volatility(expiry, term, strike);
164 Real shiftedOtmVol = vars2.normalVolCubeConstantSpread->volatility(expiry, term, strike);
165 BOOST_CHECK_SMALL(shiftedOtmVol - otmVol, tolerance);
166 }
167 }
168 }
169 }
170 }
171}

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testAtmLogNormalVolShiftPropagation  )

Definition at line 173 of file swaptionvolconstantspread.cpp.

173 {
174 BOOST_TEST_MESSAGE("Testing ATM log-normal vol shift propagation...");
175
176 CommonVars vars1;
177 Real tolerance = 0.000001;
178 Real shift = 0.1;
179 for (Size i = 0; i < vars1.atmVols.optionTenors.size(); ++i) {
180 for (Size j = 0; j < vars1.atmVols.swapTenors.size(); ++j) {
181 CommonVars vars2(i, j, shift);
182 Period expiry = vars1.atmVols.optionTenors[i];
183 Period term = vars1.atmVols.swapTenors[j];
184
185 Real atmVol = vars1.atmLogNormalVolMatrix->volatility(expiry, term, 0.0);
186 Real shiftedAtmVol = vars2.atmLogNormalVolMatrix->volatility(expiry, term, 0.0);
187 BOOST_CHECK_SMALL(shiftedAtmVol - atmVol - shift, tolerance);
188
189 // check that shift propagates to all strikes for this expiry/term
190 for (Real strike = 0.01; strike <= 0.08; strike += 0.005) {
191 Real otmVol = vars1.normalVolCubeConstantSpread->volatility(expiry, term, strike);
192 Real shiftedOtmVol = vars2.normalVolCubeConstantSpread->volatility(expiry, term, strike);
193 // BOOST_TEST_MESSAGE(i << "/" << j << "/" << strike << " : ATM Vol " << atmVol << " OTM Vol " << otmVol
194 // << " ATM Vol Shift " << shiftedAtmVol - atmVol << " OTM Vol Shift "
195 // << shiftedOtmVol - otmVol);
196 BOOST_CHECK_SMALL(shiftedOtmVol - otmVol - shift, tolerance);
197 }
198
199 // check that there is no shift in any other expiry/term
200 for (Size ii = 0; ii < vars1.atmVols.optionTenors.size(); ++ii) {
201 if (i == ii)
202 continue;
203 for (Size jj = 0; jj < vars1.atmVols.swapTenors.size(); ++jj) {
204 if (j == jj)
205 continue;
206 Period expiry = vars1.atmVols.optionTenors[ii];
207 Period term = vars1.atmVols.swapTenors[jj];
208 Real atmVol = vars1.atmLogNormalVolMatrix->volatility(expiry, term, 0.0);
209 Real shiftedAtmVol = vars2.atmLogNormalVolMatrix->volatility(expiry, term, 0.0);
210 BOOST_CHECK_SMALL(shiftedAtmVol - atmVol, tolerance);
211 for (Real strike = 0.01; strike <= 0.08; strike += 0.005) {
212 Real otmVol = vars1.logNormalVolCubeConstantSpread->volatility(expiry, term, strike);
213 Real shiftedOtmVol = vars2.logNormalVolCubeConstantSpread->volatility(expiry, term, strike);
214 BOOST_CHECK_SMALL(shiftedOtmVol - otmVol, tolerance);
215 }
216 }
217 }
218 }
219 }
220}