Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
formulabasedcoupon.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/assign/std/vector.hpp>
#include <qle/cashflows/formulabasedcoupon.hpp>
#include <qle/cashflows/mcgaussianformulabasedcouponpricer.hpp>
#include <qle/indexes/formulabasedindex.hpp>
#include <ql/cashflows/capflooredcoupon.hpp>
#include <ql/cashflows/cmscoupon.hpp>
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/cashflows/lineartsrpricer.hpp>
#include <ql/currencies/america.hpp>
#include <ql/currencies/europe.hpp>
#include <ql/experimental/coupons/lognormalcmsspreadpricer.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/indexes/swap/euriborswap.hpp>
#include <ql/math/array.hpp>
#include <ql/math/comparison.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
#include <ql/termstructures/volatility/swaption/swaptionconstantvol.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <qle/cashflows/quantocouponpricer.hpp>
#include <qle/termstructures/flatcorrelation.hpp>
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/timer/timer.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCappedLiborCoupon)
 
 BOOST_AUTO_TEST_CASE (testCappedCmsCoupon)
 
 BOOST_AUTO_TEST_CASE (testCappedCmsSpreadCoupon)
 
 BOOST_AUTO_TEST_CASE (testQuantoLiborCoupon)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( testCappedLiborCoupon  )

Definition at line 187 of file formulabasedcoupon.cpp.

187 {
188
189 BOOST_TEST_MESSAGE("Testing formula based coupons against capped Libor coupon...");
190
191 TestData d;
192
193 auto euribor6m = QuantLib::ext::make_shared<Euribor>(6 * Months, d.yts2);
194
195 CompiledFormula formulaPlain = CompiledFormula(Size(0)); // plain payoff
196 CompiledFormula formulaCapped = min(CompiledFormula(Size(0)), CompiledFormula(0.03)); // capped ibor coupon, at 0.03
197
198 auto indexPlain = QuantLib::ext::make_shared<FormulaBasedIndex>(
199 "libor-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{euribor6m}, formulaPlain,
200 euribor6m->fixingCalendar());
201 auto indexCapped = QuantLib::ext::make_shared<FormulaBasedIndex>(
202 "libor-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{euribor6m}, formulaCapped,
203 euribor6m->fixingCalendar());
204
205 auto undRef = QuantLib::ext::make_shared<IborCoupon>(Date(23, February, 2029), 10000.0, Date(23, February, 2028),
206 Date(23, February, 2029), 2, euribor6m, 1.0, 0.0, Date(), Date(),
207 Actual360(), false);
208 auto cappedRef = QuantLib::ext::make_shared<CappedFlooredCoupon>(undRef, 0.03);
209
210 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> und(
211 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
212 Date(23, February, 2029), 2, indexPlain, Date(), Date(), Actual360(), false));
213 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> capped(
214 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
215 Date(23, February, 2029), 2, indexCapped, Date(), Date(), Actual360(), false));
216
217 runTest(und, undRef, d.formulaPricerLn, d.blackPricerLn, "Plain Ibor Coupon, Lognormal", 0.05);
218 runTest(und, undRef, d.formulaPricerSln, d.blackPricerSln, "Plain Ibor Coupon, ShiftedLN", 0.05);
219 runTest(und, undRef, d.formulaPricerN, d.blackPricerN, "Plain Ibor Coupon, Normal", 0.05);
220
221 runTest(capped, cappedRef, d.formulaPricerLn, d.blackPricerLn, "Capped Ibor Coupon, Lognormal", 0.05);
222 runTest(capped, cappedRef, d.formulaPricerSln, d.blackPricerSln, "Capped Ibor Coupon, ShiftedLN", 0.05);
223 runTest(capped, cappedRef, d.formulaPricerN, d.blackPricerN, "Capped Ibor Coupon, Normal", 0.05);
224}
helper class representing a formula with variables given by an id v
formula based coupon class
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( testCappedCmsCoupon  )

Definition at line 226 of file formulabasedcoupon.cpp.

226 {
227
228 BOOST_TEST_MESSAGE("Testing formula based coupons against capped CMS coupon...");
229
230 TestData d;
231
232 auto cms10y = QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(10 * Years, d.yts2, d.yts2);
233
234 CompiledFormula formulaPlain = CompiledFormula(Size(0)); // plain payoff
235 CompiledFormula formulaCapped = min(CompiledFormula(Size(0)), CompiledFormula(0.03)); // capped cms coupon, at 0.03
236
237 auto indexPlain =
238 QuantLib::ext::make_shared<FormulaBasedIndex>("cms-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{cms10y},
239 formulaPlain, cms10y->fixingCalendar());
240 auto indexCapped =
241 QuantLib::ext::make_shared<FormulaBasedIndex>("cms-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{cms10y},
242 formulaCapped, cms10y->fixingCalendar());
243
244 auto undRef = QuantLib::ext::make_shared<CmsCoupon>(Date(23, February, 2029), 10000.0, Date(23, February, 2028),
245 Date(23, February, 2029), 2, cms10y, 1.0, 0.0, Date(), Date(),
246 Actual360(), false);
247 auto cappedRef = QuantLib::ext::make_shared<CappedFlooredCoupon>(undRef, 0.03);
248
249 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> und(
250 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
251 Date(23, February, 2029), 2, indexPlain, Date(), Date(), Actual360(), false));
252 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> capped(
253 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
254 Date(23, February, 2029), 2, indexCapped, Date(), Date(), Actual360(), false));
255
256 runTest(und, undRef, d.formulaPricerLn, d.cmsPricerLn, "Plain CMS Coupon, Lognormal", 0.05);
257 runTest(und, undRef, d.formulaPricerSln, d.cmsPricerSln, "Plain CMS Coupon, ShiftedLN", 0.05);
258 runTest(und, undRef, d.formulaPricerN, d.cmsPricerN, "Plain CMS Coupon, Normal", 0.05);
259
260 // the replication model and the model in the formula coupon pricer are not identical,
261 // so we can not check for identical results; there should be reaosonably close though,
262 // check for 2bp difference
263 runTest(capped, cappedRef, d.formulaPricerLn, d.cmsPricerLn, "Capped CMS Coupon, Lognormal", 2.0);
264 runTest(capped, cappedRef, d.formulaPricerSln, d.cmsPricerSln, "Capped CMS Coupon, ShiftedLN", 2.0);
265 runTest(capped, cappedRef, d.formulaPricerN, d.cmsPricerN, "Capped CMS Coupon, Normal", 2.0);
266}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( testCappedCmsSpreadCoupon  )

Definition at line 268 of file formulabasedcoupon.cpp.

268 {
269
270 BOOST_TEST_MESSAGE("Testing formula based coupons against capped CMS spread coupon...");
271
272 TestData d;
273
274 auto cms2y = QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(2 * Years, d.yts2, d.yts2);
275 auto cms10y = QuantLib::ext::make_shared<EuriborSwapIsdaFixA>(10 * Years, d.yts2, d.yts2);
276 auto cms10y2y = QuantLib::ext::make_shared<SwapSpreadIndex>("cms10y2y", cms10y, cms2y);
277
278 CompiledFormula formulaPlain = CompiledFormula(Size(1)) - CompiledFormula(Size(0)); // plain payoff
279 CompiledFormula formulaCapped = min(CompiledFormula(Size(1)) - CompiledFormula(Size(0)),
280 CompiledFormula(0.03)); // capped cms sp coupon, at 0.03
281
282 auto indexPlain = QuantLib::ext::make_shared<FormulaBasedIndex>(
283 "cmssp-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{cms2y, cms10y}, formulaPlain,
284 cms10y2y->fixingCalendar());
285 auto indexCapped = QuantLib::ext::make_shared<FormulaBasedIndex>(
286 "cmssp-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{cms2y, cms10y}, formulaCapped,
287 cms10y2y->fixingCalendar());
288
289 auto undRef = QuantLib::ext::make_shared<CmsSpreadCoupon>(Date(23, February, 2029), 10000.0, Date(23, February, 2028),
290 Date(23, February, 2029), 2, cms10y2y, 1.0, 0.0, Date(), Date(),
291 Actual360(), false);
292 auto cappedRef = QuantLib::ext::make_shared<CappedFlooredCoupon>(undRef, 0.03);
293
294 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> und(
295 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
296 Date(23, February, 2029), 2, indexPlain, Date(), Date(), Actual360(), false));
297 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> capped(
298 new QuantExt::FormulaBasedCoupon(EURCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
299 Date(23, February, 2029), 2, indexCapped, Date(), Date(), Actual360(), false));
300
301 runTest(und, undRef, d.formulaPricerLn, d.cmsspPricerLn, "Plain CmsSp Coupon, Lognormal", 0.05);
302 runTest(und, undRef, d.formulaPricerSln, d.cmsspPricerSln, "Plain CmsSp Coupon, ShiftedLN", 0.05);
303 runTest(und, undRef, d.formulaPricerN, d.cmsspPricerN, "Plain CmsSp Coupon, Normal", 0.05);
304
305 runTest(capped, cappedRef, d.formulaPricerLn, d.cmsspPricerLn, "Capped CmsSp Coupon, Lognormal", 0.05);
306 runTest(capped, cappedRef, d.formulaPricerSln, d.cmsspPricerSln, "Capped CmsSp Coupon, ShiftedLN", 0.05);
307 runTest(capped, cappedRef, d.formulaPricerN, d.cmsspPricerN, "Capped CmsSp Coupon, Normal", 0.05);
308}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( testQuantoLiborCoupon  )

Definition at line 310 of file formulabasedcoupon.cpp.

310 {
311
312 BOOST_TEST_MESSAGE("Testing formula based coupons against (capped) Quanto Libor coupon...");
313
314 TestData d;
315
316 auto euribor6m = QuantLib::ext::make_shared<Euribor>(6 * Months, d.yts2);
317
318 CompiledFormula formulaPlain = CompiledFormula(Size(0)); // plain payoff
319 CompiledFormula formulaCapped = min(CompiledFormula(Size(0)), CompiledFormula(0.03)); // capped ibor coupon, at 0.03
320
321 auto indexPlain = QuantLib::ext::make_shared<FormulaBasedIndex>(
322 "libor-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{euribor6m}, formulaPlain,
323 euribor6m->fixingCalendar());
324 auto indexCapped = QuantLib::ext::make_shared<FormulaBasedIndex>(
325 "libor-family", std::vector<QuantLib::ext::shared_ptr<InterestRateIndex>>{euribor6m}, formulaCapped,
326 euribor6m->fixingCalendar());
327
328 auto undRef = QuantLib::ext::make_shared<IborCoupon>(Date(23, February, 2029), 10000.0, Date(23, February, 2028),
329 Date(23, February, 2029), 2, euribor6m, 1.0, 0.0, Date(), Date(),
330 Actual360(), false);
331 auto cappedRef = QuantLib::ext::make_shared<CappedFlooredCoupon>(undRef, 0.03);
332
333 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> und(
334 new QuantExt::FormulaBasedCoupon(USDCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
335 Date(23, February, 2029), 2, indexPlain, Date(), Date(), Actual360(), false));
336 QuantLib::ext::shared_ptr<QuantExt::FormulaBasedCoupon> capped(
337 new QuantExt::FormulaBasedCoupon(USDCurrency(), Date(23, February, 2029), 10000.0, Date(23, February, 2028),
338 Date(23, February, 2029), 2, indexCapped, Date(), Date(), Actual360(), false));
339
340 runTest(und, undRef, d.formulaPricerUSDLn, d.blackQuantoPricerLn, "Plain Quanto Ibor Coupon, Lognormal", 0.05);
341 runTest(und, undRef, d.formulaPricerUSDSln, d.blackQuantoPricerSln, "Plain Quanto Ibor Coupon, ShiftedLN", 0.05);
342 runTest(und, undRef, d.formulaPricerUSDN, d.blackQuantoPricerN, "Plain Quanto Ibor Coupon, Normal", 0.05);
343
344 runTest(capped, cappedRef, d.formulaPricerUSDLn, d.blackQuantoPricerLn, "Capped Quanto Ibor Coupon, Lognormal",
345 0.05);
346 runTest(capped, cappedRef, d.formulaPricerUSDSln, d.blackQuantoPricerSln, "Capped Quanto Ibor Coupon, ShiftedLN",
347 0.05);
348 runTest(capped, cappedRef, d.formulaPricerUSDN, d.blackQuantoPricerN, "Capped Quanto Ibor Coupon, Normal", 0.05);
349}
+ Here is the call graph for this function: