Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
crossccyfixfloatswaphelper.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/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/crossccyfixfloatswaphelper.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 147 of file crossccyfixfloatswaphelper.cpp.

147 {
148
149 BOOST_TEST_MESSAGE("Test simple bootstrap against cross currency fix float swap");
150
151 SavedSettings backup;
152
153 CommonVars vars;
154
155 Settings::instance().evaluationDate() = vars.asof;
156
157 // Create a helper and bootstrapped curve
158 Handle<YieldTermStructure> tryDiscCurve = bootstrappedCurve(vars);
159
160 // Create the helper swap manually and price it using curve bootstrapped from helper
161 QuantLib::ext::shared_ptr<CrossCcyFixFloatSwap> swap = makeTestSwap(vars, tryDiscCurve);
162
163 // Swap should have NPV = 0.0. On notional = $10M i.e. TRY60.5M, 1e-5 is enough.
164 Real absTol = 1e-5;
165 BOOST_CHECK_SMALL(swap->NPV(), absTol);
166
167 // Check fair fixed rates match. Bootstrap uses 1e-12 accuracy.
168 Real relTol = 1e-10;
169 BOOST_CHECK_CLOSE(vars.rate->value(), swap->fairFixedRate(), relTol);
170
171 // Check the 5Y discount factor
172 DiscountFactor expDisc = 0.3299260408883904;
173 BOOST_CHECK_CLOSE(expDisc, tryDiscCurve->discount(vars.asof + 5 * Years), relTol);
174}

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( testSpotFxChange  )

Definition at line 176 of file crossccyfixfloatswaphelper.cpp.

176 {
177
178 BOOST_TEST_MESSAGE("Test rebootstrap under spot FX change");
179
180 SavedSettings backup;
181
182 CommonVars vars;
183
184 Settings::instance().evaluationDate() = vars.asof;
185
186 // Create a helper and bootstrapped curve
187 Handle<YieldTermStructure> tryDiscCurve = bootstrappedCurve(vars);
188
189 // Create the helper swap manually and price it using curve bootstrapped from helper
190 QuantLib::ext::shared_ptr<CrossCcyFixFloatSwap> swap = makeTestSwap(vars, tryDiscCurve);
191
192 // Check NPV = 0.0
193 Real absTol = 1e-5;
194 BOOST_CHECK_SMALL(swap->NPV(), absTol);
195
196 // Check the 5Y discount factor
197 Real relTol = 1e-10;
198 DiscountFactor expDisc = 0.3299260408883904;
199 BOOST_CHECK_CLOSE(expDisc, tryDiscCurve->discount(vars.asof + 5 * Years), relTol);
200
201 // Check the nominal of the helper swap
202 BOOST_CHECK_CLOSE(vars.spotFx->value(), vars.helper->swap()->fixedNominal(), relTol);
203
204 // Bump the spot rate by 10%
205 vars.spotFx->setValue(vars.spotFx->value() * 1.1);
206
207 // Build a new swap using the updated spot FX rate
208 swap = makeTestSwap(vars, tryDiscCurve);
209
210 // Check that the new swap's NPV is 0.0
211 BOOST_CHECK_SMALL(swap->NPV(), absTol);
212
213 // Check the 5Y discount factor again. It should be the same.
214 BOOST_CHECK_CLOSE(expDisc, tryDiscCurve->discount(vars.asof + 5 * Years), relTol);
215
216 // Check the nominal of the helper swap. Should now be the bumped amount
217 BOOST_CHECK_CLOSE(vars.spotFx->value(), vars.helper->swap()->fixedNominal(), relTol);
218}

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( testSpreadChange  )

Definition at line 220 of file crossccyfixfloatswaphelper.cpp.

220 {
221
222 BOOST_TEST_MESSAGE("Test rebootstrap under helper spread change");
223
224 SavedSettings backup;
225
226 CommonVars vars;
227
228 Settings::instance().evaluationDate() = vars.asof;
229
230 // Create a helper and bootstrapped curve
231 Handle<YieldTermStructure> tryDiscCurve = bootstrappedCurve(vars);
232
233 // Create the helper swap manually and price it using curve bootstrapped from helper
234 QuantLib::ext::shared_ptr<CrossCcyFixFloatSwap> swap = makeTestSwap(vars, tryDiscCurve);
235
236 // Check NPV = 0.0
237 Real absTol = 1e-5;
238 BOOST_CHECK_SMALL(swap->NPV(), absTol);
239
240 // Check the 5Y discount factor
241 Real relTol = 1e-10;
242 DiscountFactor expDisc = 0.3299260408883904;
243 BOOST_CHECK_CLOSE(expDisc, tryDiscCurve->discount(vars.asof + 5 * Years), relTol);
244
245 // Check the spread of the helper swap
246 BOOST_CHECK_CLOSE(vars.spread->value(), vars.helper->swap()->floatSpread(), relTol);
247
248 // Add a 10bps spread
249 vars.spread->setValue(0.0010);
250
251 // Build a new swap using the updated spread of 10bps
252 swap = makeTestSwap(vars, tryDiscCurve);
253
254 // Check that the new swap's NPV is 0.0
255 BOOST_CHECK_SMALL(swap->NPV(), absTol);
256
257 // Check the 5Y discount factor again. Added spread on float => higher discount factor.
258 expDisc = 0.3322218009717460;
259 BOOST_CHECK_CLOSE(expDisc, tryDiscCurve->discount(vars.asof + 5 * Years), relTol);
260
261 // Check the spread of the helper swap. Should now be 10bps.
262 BOOST_CHECK_CLOSE(vars.spread->value(), vars.helper->swap()->floatSpread(), relTol);
263}

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( testMovingEvaluationDate  )

Definition at line 265 of file crossccyfixfloatswaphelper.cpp.

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