Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
crossccybasismtmresetswaphelper.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ql/currencies/all.hpp>
#include <ql/indexes/ibor/gbplibor.hpp>
#include <ql/indexes/ibor/usdlibor.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/yield/discountcurve.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/time/calendars/all.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/types.hpp>
#include <qle/pricingengines/crossccyswapengine.hpp>
#include <qle/termstructures/crossccybasismtmresetswaphelper.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testBootstrap)
 
 BOOST_AUTO_TEST_CASE (testSpotFxChange)
 
 BOOST_AUTO_TEST_CASE (testSpreadChange)
 
 BOOST_AUTO_TEST_CASE (testMovingEvaluationDate)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( testBootstrap  )

Definition at line 137 of file crossccybasismtmresetswaphelper.cpp.

137 {
138
139 BOOST_TEST_MESSAGE("Test simple bootstrap against cross currency MtM resetting swap");
140
141 SavedSettings backup;
142 CommonVars vars;
143 Settings::instance().evaluationDate() = vars.asof;
144
145 // Create bootstrapped curve
146 Handle<YieldTermStructure> discCurve = bootstrappedCurve(vars);
147
148 // Create the helper swap manually and price it using curve bootstrapped from helper
149 QuantLib::ext::shared_ptr<CrossCcyBasisMtMResetSwap> swap = makeTestSwap(vars, discCurve);
150
151 // Swap should have NPV = 0.0.
152 Real tol = 1e-5;
153 BOOST_CHECK_SMALL(swap->NPV(), tol);
154
155 // Check fair spreads match. Bootstrap uses 1e-12 accuracy.
156 Real relTol = 1e-10;
157 BOOST_CHECK_CLOSE(vars.spreadQuote->value(), swap->fairForeignSpread(), relTol);
158
159 // Check the 5Y discount factor
160 DiscountFactor expDisc = 0.91155524911218166;
161 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
162}

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( testSpotFxChange  )

Definition at line 164 of file crossccybasismtmresetswaphelper.cpp.

164 {
165
166 BOOST_TEST_MESSAGE("Test rebootstrap under spot FX change");
167
168 SavedSettings backup;
169
170 CommonVars vars;
171
172 Settings::instance().evaluationDate() = vars.asof;
173
174 // Create a helper and bootstrapped curve
175 Handle<YieldTermStructure> discCurve = bootstrappedCurve(vars);
176
177 // Create the helper swap manually and price it using curve bootstrapped from helper
178 QuantLib::ext::shared_ptr<CrossCcyBasisMtMResetSwap> swap = makeTestSwap(vars, discCurve);
179
180 // Check NPV = 0.0
181 Real absTol = 1e-5;
182 BOOST_CHECK_SMALL(swap->NPV(), absTol);
183
184 // Check fair spreads match. Bootstrap uses 1e-12 accuracy.
185 Real relTol = 1e-10;
186 BOOST_CHECK_CLOSE(vars.spreadQuote->value(), swap->fairForeignSpread(), relTol);
187
188 // Check the 5Y discount factor
189 DiscountFactor expDisc = 0.91155524911218166;
190 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
191
192 // Check the nominal of the helper swap
193 BOOST_CHECK_CLOSE(vars.spotFxQuote->value(), std::fabs(vars.helper->swap()->leg(2).front()->amount()), relTol);
194
195 // Bump the spot rate by 10%
196 vars.spotFxQuote->setValue(vars.spotFxQuote->value() * 1.1);
197
198 // Build a new swap using the updated spot FX rate
199 swap = makeTestSwap(vars, discCurve);
200
201 // Check that the new swap's NPV is 0.0
202 BOOST_CHECK_SMALL(swap->NPV(), absTol);
203
204 // Check the 5Y discount factor again. It should be the same.
205 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
206
207 // Check the nominal of the helper swap. Should now be the bumped amount
208 BOOST_CHECK_CLOSE(vars.spotFxQuote->value(), std::fabs(vars.helper->swap()->leg(2).front()->amount()), relTol);
209}

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( testSpreadChange  )

Definition at line 211 of file crossccybasismtmresetswaphelper.cpp.

211 {
212
213 BOOST_TEST_MESSAGE("Test rebootstrap under helper spread change");
214
215 SavedSettings backup;
216
217 CommonVars vars;
218
219 Settings::instance().evaluationDate() = vars.asof;
220
221 // Create a helper and bootstrapped curve
222 Handle<YieldTermStructure> discCurve = bootstrappedCurve(vars);
223
224 // Create the helper swap manually and price it using curve bootstrapped from helper
225 QuantLib::ext::shared_ptr<CrossCcyBasisMtMResetSwap> swap = makeTestSwap(vars, discCurve);
226
227 // Check NPV = 0.0
228 Real absTol = 1e-5;
229 BOOST_CHECK_SMALL(swap->NPV(), absTol);
230
231 // Check fair spreads match. Bootstrap uses 1e-12 accuracy.
232 Real relTol = 1e-10;
233 BOOST_CHECK_CLOSE(vars.spreadQuote->value(), swap->fairForeignSpread(), relTol);
234
235 // Check the 5Y discount factor
236 DiscountFactor expDisc = 0.91155524911218166;
237 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
238
239 // Add a 10bps spread
240 vars.spreadQuote->setValue(0.0015);
241
242 // Build a new swap using the updated spread of 10bps
243 swap = makeTestSwap(vars, discCurve);
244
245 // Check that the new swap's NPV is 0.0
246 BOOST_CHECK_SMALL(swap->NPV(), absTol);
247
248 // Check the 5Y discount factor again. More spread on foreign leg => more significant discount factor.
249 expDisc = 0.89807807922008731;
250 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
251
252 // Check the spread of the helper swap. Should now be 15bps.
253 BOOST_CHECK_CLOSE(vars.spreadQuote->value(), swap->fairForeignSpread(), relTol);
254}

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( testMovingEvaluationDate  )

Definition at line 256 of file crossccybasismtmresetswaphelper.cpp.

256 {
257
258 BOOST_TEST_MESSAGE("Test rebootstrap after moving evaluation date");
259
260 SavedSettings backup;
261
262 CommonVars vars;
263
264 Settings::instance().evaluationDate() = vars.asof;
265
266 // Create a helper and bootstrapped curve
267 Handle<YieldTermStructure> discCurve = bootstrappedCurve(vars);
268
269 // Create the helper swap manually and price it using curve bootstrapped from helper
270 QuantLib::ext::shared_ptr<CrossCcyBasisMtMResetSwap> swap = makeTestSwap(vars, discCurve);
271
272 // Check NPV = 0.0
273 Real absTol = 1e-5;
274 BOOST_CHECK_SMALL(swap->NPV(), absTol);
275
276 // Check fair spreads match. Bootstrap uses 1e-12 accuracy.
277 Real relTol = 1e-10;
278 BOOST_CHECK_CLOSE(vars.spreadQuote->value(), swap->fairForeignSpread(), relTol);
279
280 // Check the 5Y discount factor
281 DiscountFactor expDisc = 0.91155524911218166;
282 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
283
284 // Check the start date of the helper swap
285 BOOST_CHECK_EQUAL(swap->startDate(), vars.helper->swap()->startDate());
286
287 // Move evaluation date forward
288 vars.asof = vars.asof + 1 * Days;
289 Settings::instance().evaluationDate() = vars.asof;
290
291 // Build a new swap using new evaluation date
292 swap = makeTestSwap(vars, discCurve);
293
294 // Check that the new swap's NPV is 0.0
295 BOOST_CHECK_SMALL(swap->NPV(), absTol);
296
297 // Check the 5Y discount factor again. Changes slightly due to helper holidays/weekends.
298 expDisc = 0.91155524848230363;
299 BOOST_CHECK_CLOSE(expDisc, discCurve->discount(vars.asof + 5 * Years), relTol);
300
301 // Check the start date of the helper swap. Should be 1 day greater.
302 BOOST_CHECK_EQUAL(swap->startDate(), vars.helper->swap()->startDate());
303}