Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
crossccyfixfloatswap.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/time/calendars/all.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/types.hpp>
#include <qle/instruments/crossccyfixfloatswap.hpp>
#include <qle/pricingengines/crossccyswapengine.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testSwapPricing)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( testSwapPricing  )

Definition at line 248 of file crossccyfixfloatswap.cpp.

248 {
249
250 BOOST_TEST_MESSAGE("Test cross currency fix float swap pricing against known results");
251
252 SavedSettings backup;
253
254 Settings::instance().evaluationDate() = Date(11, Sep, 2018);
255
256 // Create swap, USD 3M Libor vs TRY annual fixed
257 Rate spotFx = 6.4304;
258 Rate rate = 0.249;
259 Spread spread = 0.0;
260 QuantLib::ext::shared_ptr<CrossCcyFixFloatSwap> swap = makeTestSwap(spotFx, rate, spread);
261
262 // Attach pricing engine
263 Handle<Quote> fxSpotQuote = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0 / spotFx));
264 QuantLib::ext::shared_ptr<PricingEngine> engine = QuantLib::ext::make_shared<CrossCcySwapEngine>(
265 USDCurrency(), usdDiscountCurve(), TRYCurrency(), tryDiscountCurve(), fxSpotQuote);
266 swap->setPricingEngine(engine);
267
268 // Check values
269 Real usdTolerance = 0.01;
270
271 Real expNpv = 129777.91;
272 BOOST_CHECK_SMALL(swap->NPV() - expNpv, usdTolerance);
273
274 Real expPayLegNpv = -12286.45;
275 Real expPayLegBps = -2628.39;
276 BOOST_CHECK_SMALL(swap->legNPV(0) - expPayLegNpv, usdTolerance);
277 BOOST_CHECK_SMALL(swap->legBPS(0) - expPayLegBps, usdTolerance);
278 BOOST_CHECK_SMALL(swap->inCcyLegNPV(0) - expPayLegNpv * spotFx, usdTolerance * spotFx);
279 BOOST_CHECK_SMALL(swap->inCcyLegBPS(0) - expPayLegBps * spotFx, usdTolerance * spotFx);
280
281 Real expRecLegNpv = 142064.36;
282 Real expRecLegBps = 4735.03;
283 BOOST_CHECK_SMALL(swap->legNPV(1) - expRecLegNpv, usdTolerance);
284 BOOST_CHECK_SMALL(swap->legBPS(1) - expRecLegBps, usdTolerance);
285 BOOST_CHECK_SMALL(swap->inCcyLegNPV(1) - expRecLegNpv, usdTolerance);
286 BOOST_CHECK_SMALL(swap->inCcyLegBPS(1) - expRecLegBps, usdTolerance);
287
288 BOOST_CHECK_SMALL(0.253937551076 - swap->fairFixedRate(), 1e-10);
289 BOOST_CHECK_SMALL(-0.002740802104 - swap->fairSpread(), 1e-10);
290}