File: _gaussian1d_models_8cpp-example.html

package info (click to toggle)
quantlib-refman-html 1.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 103,140 kB
  • sloc: javascript: 13,408; makefile: 35
file content (775 lines) | stat: -rw-r--r-- 73,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>QuantLib: Gaussian1dModels.cpp</title>
<link href='https://fonts.googleapis.com/css?family=Merriweather+Sans:800' rel='stylesheet' type='text/css'>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="quantlibextra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://quantlib.org">
       <img alt="QuantLib" src="QL-title.jpg"></a>
   <div id="projectbrief">A free/open-source library for quantitative finance</div>
   <div id="projectnumber">Reference manual - version 1.20</div>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Gaussian1dModels.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>This example shows the use of Gaussian short rate model for interest rate derivatives.</p>
<div class="fragment"><div class="line"><span class="comment">/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> Copyright (C) 2014 Peter Caspers</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> This file is part of QuantLib, a free-software/open-source library</span></div>
<div class="line"><span class="comment"> for financial quantitative analysts and developers - http://quantlib.org/</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> QuantLib is free software: you can redistribute it and/or modify it</span></div>
<div class="line"><span class="comment"> under the terms of the QuantLib license.  You should have received a</span></div>
<div class="line"><span class="comment"> copy of the license along with this program; if not, please email</span></div>
<div class="line"><span class="comment"> &lt;quantlib-dev@lists.sf.net&gt;. The license is also available online at</span></div>
<div class="line"><span class="comment"> &lt;http://quantlib.org/license.shtml&gt;.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"> This program is distributed in the hope that it will be useful, but WITHOUT</span></div>
<div class="line"><span class="comment"> ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span></div>
<div class="line"><span class="comment"> FOR A PARTICULAR PURPOSE.  See the license for more details.</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;ql/qldefines.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#ifdef BOOST_MSVC</span></div>
<div class="line"><span class="preprocessor">#  include &lt;ql/auto_link.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/instruments/floatfloatswap.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/instruments/floatfloatswaption.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/instruments/nonstandardswaption.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/pricingengines/swap/discountingswapengine.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/pricingengines/swaption/gaussian1dswaptionengine.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/pricingengines/swaption/gaussian1dnonstandardswaptionengine.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/pricingengines/swaption/gaussian1dfloatfloatswaptionengine.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/models/shortrate/onefactormodels/gsr.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/models/shortrate/onefactormodels/markovfunctional.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/models/shortrate/calibrationhelpers/swaptionhelper.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/math/optimization/levenbergmarquardt.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/cashflows/lineartsrpricer.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/indexes/ibor/euribor.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/indexes/swap/euriborswap.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/termstructures/yield/flatforward.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/termstructures/volatility/swaption/swaptionconstantvol.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/rebatedexercise.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/quotes/simplequote.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/time/calendars/target.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/time/daycounters/actual360.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/time/daycounters/thirty360.hpp&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iomanip&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a>;</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if defined(QL_ENABLE_SESSIONS)</span></div>
<div class="line"><span class="keyword">namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a> {</div>
<div class="line"> </div>
<div class="line">    ThreadKey sessionId() { <span class="keywordflow">return</span> 0; }</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// helper function that prints a basket of calibrating swaptions to std::cout</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> printBasket(</div>
<div class="line">    <span class="keyword">const</span> std::vector&lt;ext::shared_ptr&lt;BlackCalibrationHelper&gt; &gt; &amp;basket) {</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span> &lt;&lt; std::left &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot;Expiry&quot;</span> &lt;&lt; std::setw(20)</div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;Maturity&quot;</span> &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot;Nominal&quot;</span> &lt;&lt; std::setw(14)</div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;Rate&quot;</span> &lt;&lt; std::setw(12) &lt;&lt; <span class="stringliteral">&quot;Pay/Rec&quot;</span> &lt;&lt; std::setw(14)</div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;Market ivol&quot;</span> &lt;&lt; std::fixed &lt;&lt; std::setprecision(6)</div>
<div class="line">              &lt;&lt; std::endl;</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;==================&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">    <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> j = 0; j &lt; basket.size(); ++j) {</div>
<div class="line">        ext::shared_ptr&lt;SwaptionHelper&gt; helper =</div>
<div class="line">            ext::dynamic_pointer_cast&lt;SwaptionHelper&gt;(basket[j]);</div>
<div class="line">        <a name="_a0"></a><a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> endDate = helper-&gt;underlyingSwap()-&gt;fixedSchedule().dates().back();</div>
<div class="line">        <a name="a1"></a><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> nominal = helper-&gt;underlyingSwap()-&gt;nominal();</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> vol = helper-&gt;volatility()-&gt;value();</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> <a name="a2"></a><a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">rate</a> = helper-&gt;underlyingSwap()-&gt;fixedRate();</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> expiry = helper-&gt;swaption()-&gt;exercise()-&gt;date(0);</div>
<div class="line">        VanillaSwap::Type type = helper-&gt;swaption()-&gt;type();</div>
<div class="line">        std::ostringstream expiryString, endDateString;</div>
<div class="line">        expiryString &lt;&lt; expiry;</div>
<div class="line">        endDateString &lt;&lt; endDate;</div>
<div class="line">        std::cout &lt;&lt; std::setw(20) &lt;&lt; expiryString.str() &lt;&lt; std::setw(20)</div>
<div class="line">                  &lt;&lt; endDateString.str() &lt;&lt; std::setw(20) &lt;&lt; nominal</div>
<div class="line">                  &lt;&lt; std::setw(14) &lt;&lt; <a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">rate</a> &lt;&lt; std::setw(12)</div>
<div class="line">                  &lt;&lt; (type == VanillaSwap::Payer ? <span class="stringliteral">&quot;Payer&quot;</span> : <span class="stringliteral">&quot;Receiver&quot;</span>)</div>
<div class="line">                  &lt;&lt; std::setw(14) &lt;&lt; vol &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// helper function that prints the result of a model calibraiton to std::cout</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> printModelCalibration(</div>
<div class="line">    <span class="keyword">const</span> std::vector&lt;ext::shared_ptr&lt;BlackCalibrationHelper&gt; &gt; &amp;basket,</div>
<div class="line">    <span class="keyword">const</span> <a name="_a3"></a><a class="code" href="class_quant_lib_1_1_array.html" title="1-D array used in linear algebra.">Array</a> &amp;<a name="a4"></a><a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>) {</div>
<div class="line"> </div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span> &lt;&lt; std::left &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot;Expiry&quot;</span> &lt;&lt; std::setw(14)</div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;Model sigma&quot;</span> &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot;Model price&quot;</span></div>
<div class="line">              &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot;market price&quot;</span> &lt;&lt; std::setw(14)</div>
<div class="line">              &lt;&lt; <span class="stringliteral">&quot;Model ivol&quot;</span> &lt;&lt; std::setw(14) &lt;&lt; <span class="stringliteral">&quot;Market ivol&quot;</span> &lt;&lt; std::fixed</div>
<div class="line">              &lt;&lt; std::setprecision(6) &lt;&lt; std::endl;</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span></div>
<div class="line">                 <span class="stringliteral">&quot;====================&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> j = 0; j &lt; basket.size(); ++j) {</div>
<div class="line">        ext::shared_ptr&lt;SwaptionHelper&gt; helper =</div>
<div class="line">            ext::dynamic_pointer_cast&lt;SwaptionHelper&gt;(basket[j]);</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> expiry = helper-&gt;swaption()-&gt;exercise()-&gt;date(0);</div>
<div class="line">        std::ostringstream expiryString;</div>
<div class="line">        expiryString &lt;&lt; expiry;</div>
<div class="line">        std::cout &lt;&lt; std::setw(20) &lt;&lt; expiryString.str() &lt;&lt; std::setw(14)</div>
<div class="line">                  &lt;&lt; <a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>[j] &lt;&lt; std::setw(20) &lt;&lt; basket[j]-&gt;modelValue()</div>
<div class="line">                  &lt;&lt; std::setw(20) &lt;&lt; basket[j]-&gt;marketValue() &lt;&lt; std::setw(14)</div>
<div class="line">                  &lt;&lt; basket[j]-&gt;impliedVolatility(basket[j]-&gt;modelValue(), 1E-6,</div>
<div class="line">                                                  1000, 0.0, 2.0)</div>
<div class="line">                  &lt;&lt; std::setw(14) &lt;&lt; basket[j]-&gt;volatility()-&gt;value()</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">if</span> (<a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>.size() &gt; basket.size()) <span class="comment">// only for markov model</span></div>
<div class="line">        std::cout &lt;&lt; std::setw(20) &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; <a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>.back() &lt;&lt; std::endl;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">// here the main part of the code starts</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) {</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">try</span> {</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nGaussian1dModel Examples&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is some example code showing how to use the GSR &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\n(Gaussian short rate) and Markov Functional model.&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> refDate(30, April, 2014);</div>
<div class="line">        <a name="a5"></a><a class="code" href="class_quant_lib_1_1_singleton.html#ab7455b7e1235d292c444095842349291" title="access to the unique instance">Settings::instance</a>().evaluationDate() = refDate;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe evaluation date for this example is set to &quot;</span></div>
<div class="line">                  &lt;&lt; <a class="code" href="class_quant_lib_1_1_singleton.html#ab7455b7e1235d292c444095842349291" title="access to the unique instance">Settings::instance</a>().evaluationDate() &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> forward6mLevel = 0.025;</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> oisLevel = 0.02;</div>
<div class="line"> </div>
<div class="line">        <a name="_a6"></a><a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a> forward6mQuote(</div>
<div class="line">            ext::make_shared&lt;SimpleQuote&gt;(forward6mLevel));</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a> oisQuote(ext::make_shared&lt;SimpleQuote&gt;(oisLevel));</div>
<div class="line"> </div>
<div class="line">        <a name="_a7"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a> yts6m(ext::make_shared&lt;FlatForward&gt;(</div>
<div class="line">            0, <a name="_a8"></a><a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(), forward6mQuote, <a name="_a9"></a><a class="code" href="class_quant_lib_1_1_actual365_fixed.html" title="Actual/365 (Fixed) day count convention.">Actual365Fixed</a>()));</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a> ytsOis(ext::make_shared&lt;FlatForward&gt;(</div>
<div class="line">            0, <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(), oisQuote, <a class="code" href="class_quant_lib_1_1_actual365_fixed.html" title="Actual/365 (Fixed) day count convention.">Actual365Fixed</a>()));</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;IborIndex&gt; euribor6m =</div>
<div class="line">            ext::make_shared&lt;Euribor&gt;(6 * Months, yts6m);</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nWe assume a multicurve setup, for simplicity with flat yield &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nterm structures. The discounting curve is an Eonia curve at&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\na level of &quot;</span> &lt;&lt; oisLevel</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot; and the forwarding curve is an Euribior 6m curve&quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nat a level of &quot;</span> &lt;&lt; forward6mLevel &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> volLevel = 0.20;</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a> volQuote(ext::make_shared&lt;SimpleQuote&gt;(volLevel));</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;SwaptionVolatilityStructure&gt;</a> swaptionVol(</div>
<div class="line">            ext::make_shared&lt;ConstantSwaptionVolatility&gt;(</div>
<div class="line">                0, <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(), <a name="a10"></a><a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, volQuote, <a class="code" href="class_quant_lib_1_1_actual365_fixed.html" title="Actual/365 (Fixed) day count convention.">Actual365Fixed</a>()));</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nFor the volatility we assume a flat swaption volatility at &quot;</span></div>
<div class="line">            &lt;&lt; volLevel &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> strike = 0.04;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nWe consider a standard 10y bermudan payer swaption &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nwith yearly exercises at a strike of &quot;</span> &lt;&lt; strike</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> effectiveDate = <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>().<a name="a11"></a><a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(refDate, 2 * Days);</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> maturityDate = <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>().<a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(effectiveDate, 10 * Years);</div>
<div class="line"> </div>
<div class="line">        <a name="_a12"></a><a class="code" href="class_quant_lib_1_1_schedule.html" title="Payment schedule.">Schedule</a> fixedSchedule(effectiveDate, maturityDate, 1 * Years, <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(),</div>
<div class="line">                               <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,</div>
<div class="line">                               <a name="a13"></a><a class="code" href="struct_quant_lib_1_1_date_generation.html#a11fcd51ef86118f65e603c1474377a78ae204c9c3e62b1e9a6b60e40cd05256c5">DateGeneration::Forward</a>, <span class="keyword">false</span>);</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_schedule.html" title="Payment schedule.">Schedule</a> floatingSchedule(effectiveDate, maturityDate, 6 * Months,</div>
<div class="line">                                  <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(), <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,</div>
<div class="line">                                  <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, <a class="code" href="struct_quant_lib_1_1_date_generation.html#a11fcd51ef86118f65e603c1474377a78ae204c9c3e62b1e9a6b60e40cd05256c5">DateGeneration::Forward</a>,</div>
<div class="line">                                  <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwap&gt; underlying =</div>
<div class="line">            ext::make_shared&lt;NonstandardSwap&gt;(<a name="_a14"></a><a class="code" href="class_quant_lib_1_1_vanilla_swap.html" title="Plain-vanilla swap: fix vs floating leg.">VanillaSwap</a>(</div>
<div class="line">                VanillaSwap::Payer, 1.0, fixedSchedule, strike, <a name="_a15"></a><a class="code" href="class_quant_lib_1_1_thirty360.html" title="30/360 day count convention">Thirty360</a>(),</div>
<div class="line">                floatingSchedule, euribor6m, 0.00, <a name="_a16"></a><a class="code" href="class_quant_lib_1_1_actual360.html" title="Actual/360 day count convention.">Actual360</a>()));</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Date&gt; exerciseDates;</div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 1; i &lt; 10; ++i)</div>
<div class="line">            exerciseDates.push_back(</div>
<div class="line">                <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>().advance(fixedSchedule[i], -2 * Days));</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;Exercise&gt; exercise =</div>
<div class="line">            ext::make_shared&lt;BermudanExercise&gt;(exerciseDates, <span class="keyword">false</span>);</div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwaption&gt; swaption =</div>
<div class="line">            ext::make_shared&lt;NonstandardSwaption&gt;(underlying, exercise);</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe model is a one factor Hull White model with piecewise &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nvolatility adapted to our exercise dates.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Date&gt; stepDates(exerciseDates.begin(),</div>
<div class="line">                                    exerciseDates.end() - 1);</div>
<div class="line">        std::vector&lt;Real&gt; sigmas(stepDates.size() + 1, 0.01);</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> reversion = 0.01;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe reversion is just kept constant at a level of &quot;</span></div>
<div class="line">                  &lt;&lt; reversion &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe model&#39;s curve is set to the 6m forward curve. Note that &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nthe model adapts automatically to other curves where &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;appropriate &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\n(e.g. if an index requires a different forwarding curve) or &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nwhere explicitly specified (e.g. in a swaption pricing &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;engine).&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;Gsr&gt; gsr = ext::make_shared&lt;Gsr&gt;(</div>
<div class="line">            yts6m, stepDates, sigmas, reversion);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; swaptionEngine =</div>
<div class="line">            ext::make_shared&lt;Gaussian1dSwaptionEngine&gt;(gsr, 64, 7.0, <span class="keyword">true</span>,</div>
<div class="line">                                                         <span class="keyword">false</span>, ytsOis);</div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; nonstandardSwaptionEngine =</div>
<div class="line">            ext::make_shared&lt;Gaussian1dNonstandardSwaptionEngine&gt;(</div>
<div class="line">                gsr, 64, 7.0, <span class="keyword">true</span>, <span class="keyword">false</span>, <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a>(), ytsOis);</div>
<div class="line"> </div>
<div class="line">        swaption-&gt;setPricingEngine(nonstandardSwaptionEngine);</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe engine can generate a calibration basket in two modes.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nThe first one is called Naive and generates ATM swaptions &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;adapted to&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nthe exercise dates of the swaption and its maturity date&quot;</span></div>
<div class="line">            &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe resulting basket looks as follows:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;SwapIndex&gt; swapBase =</div>
<div class="line">            ext::make_shared&lt;EuriborSwapIsdaFixA&gt;(10 * Years, yts6m, ytsOis);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        std::vector&lt;ext::shared_ptr&lt;BlackCalibrationHelper&gt; &gt; basket =</div>
<div class="line">            swaption-&gt;calibrationBasket(swapBase, *swaptionVol,</div>
<div class="line">                                        BasketGeneratingEngine::Naive);</div>
<div class="line">        printBasket(basket);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nLet&#39;s calibrate our model to this basket. We use a &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;specialized&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\ncalibration method calibrating the sigma function one by one &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;to&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nthe calibrating vanilla swaptions. The result of this is as &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;follows:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); ++i)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngine);</div>
<div class="line"> </div>
<div class="line">        <a name="_a17"></a><a class="code" href="class_quant_lib_1_1_levenberg_marquardt.html" title="Levenberg-Marquardt optimization method.">LevenbergMarquardt</a> method;</div>
<div class="line">        <a name="_a18"></a><a class="code" href="class_quant_lib_1_1_end_criteria.html" title="Criteria to end optimization process:">EndCriteria</a> ec(1000, 10, 1E-8, 1E-8,</div>
<div class="line">                       1E-8); <span class="comment">// only max iterations use actually used by LM</span></div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        gsr-&gt;calibrateVolatilitiesIterative(basket, method, ec);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printModelCalibration(basket, gsr-&gt;volatility());</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFinally we price our bermudan swaption in the &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;calibrated model:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv = swaption-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nBermudan swaption NPV (ATM calibrated GSR) = &quot;</span></div>
<div class="line">                  &lt;&lt; std::fixed &lt;&lt; std::setprecision(6) &lt;&lt; npv &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThere is another mode to generate a calibration basket called&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nMaturityStrikeByDeltaGamma. This means that the maturity,&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nthe strike and the nominal of the calibrating swaptions are&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nobtained matching the NPV, first derivative and second derivative&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nof the swap you will exercise into at at each bermudan call date.&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nThe derivatives are taken with respect to the model&#39;s state variable.&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nLet&#39;s try this in our case.&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        basket = swaption-&gt;calibrationBasket(</div>
<div class="line">            swapBase, *swaptionVol,</div>
<div class="line">            BasketGeneratingEngine::MaturityStrikeByDeltaGamma);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printBasket(basket);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe calibrated nominal is close to the exotics nominal.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nThe expiries and maturity dates of the vanillas are the same&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nas in the case above. The difference is the strike which&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nis now equal to the exotics strike.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nLet&#39;s see how this affects the exotics npv. The &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nrecalibrated model is:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); ++i)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngine);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        gsr-&gt;calibrateVolatilitiesIterative(basket, method, ec);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printModelCalibration(basket, gsr-&gt;volatility());</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nAnd the bermudan&#39;s price becomes:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        npv = swaption-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nBermudan swaption NPV (deal strike calibrated GSR) = &quot;</span></div>
<div class="line">                  &lt;&lt; std::setprecision(6) &lt;&lt; npv &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nWe can do more complicated things, let&#39;s e.g. modify the&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nnominal schedule to be linear amortizing and see what&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nthe effect on the generated calibration basket is:&quot;</span></div>
<div class="line">            &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Real&gt; nominalFixed, nominalFloating;</div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; fixedSchedule.size() - 1; ++i) {</div>
<div class="line">            <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> tmpNom = 1.0 - (<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>)i / (fixedSchedule.size() - 1);</div>
<div class="line">            nominalFixed.push_back(tmpNom);</div>
<div class="line">            nominalFloating.push_back(tmpNom);</div>
<div class="line">            nominalFloating.push_back(</div>
<div class="line">                tmpNom); <span class="comment">// we use that the swap is 6m vs. 1y here</span></div>
<div class="line">        }</div>
<div class="line">        std::vector&lt;Real&gt; strikes(nominalFixed.size(), strike);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwap&gt; underlying2(<span class="keyword">new</span> <a name="_a19"></a><a class="code" href="class_quant_lib_1_1_nonstandard_swap.html" title="nonstandard swap">NonstandardSwap</a>(</div>
<div class="line">            VanillaSwap::Payer, nominalFixed, nominalFloating, fixedSchedule,</div>
<div class="line">            strikes, <a class="code" href="class_quant_lib_1_1_thirty360.html" title="30/360 day count convention">Thirty360</a>(), floatingSchedule, euribor6m, 1.0, 0.0,</div>
<div class="line">            <a class="code" href="class_quant_lib_1_1_actual360.html" title="Actual/360 day count convention.">Actual360</a>()));</div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwaption&gt; swaption2 =</div>
<div class="line">            ext::make_shared&lt;NonstandardSwaption&gt;(underlying2, exercise);</div>
<div class="line"> </div>
<div class="line">        swaption2-&gt;setPricingEngine(nonstandardSwaptionEngine);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        basket = swaption2-&gt;calibrationBasket(</div>
<div class="line">            swapBase, *swaptionVol,</div>
<div class="line">            BasketGeneratingEngine::MaturityStrikeByDeltaGamma);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printBasket(basket);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe notional is weighted over the underlying exercised &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ninto and the maturity is adjusted downwards. The rate&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\non the other hand is not affected.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nYou can also price exotic bond&#39;s features. If you have e.g. a&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nbermudan callable fixed bond you can set up the call right &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nas a swaption to enter into a one leg swap with notional&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nreimbursement at maturity.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nThe exercise should then be written as a rebated exercise&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\npaying the notional in case of exercise.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe calibration basket looks like this:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Real&gt; nominalFixed2(nominalFixed.size(), 1.0);</div>
<div class="line">        std::vector&lt;Real&gt; nominalFloating2(nominalFloating.size(),</div>
<div class="line">                                           0.0); <span class="comment">// null the second leg</span></div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwap&gt; underlying3(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_nonstandard_swap.html" title="nonstandard swap">NonstandardSwap</a>(</div>
<div class="line">            VanillaSwap::Receiver, nominalFixed2, nominalFloating2,</div>
<div class="line">            fixedSchedule, strikes, <a class="code" href="class_quant_lib_1_1_thirty360.html" title="30/360 day count convention">Thirty360</a>(), floatingSchedule, euribor6m,</div>
<div class="line">            1.0, 0.0, <a class="code" href="class_quant_lib_1_1_actual360.html" title="Actual/360 day count convention.">Actual360</a>(), <span class="keyword">false</span>,</div>
<div class="line">            <span class="keyword">true</span>)); <span class="comment">// final capital exchange</span></div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;RebatedExercise&gt; exercise2 =</div>
<div class="line">            ext::make_shared&lt;RebatedExercise&gt;(*exercise, -1.0, 2, <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>());</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;NonstandardSwaption&gt; swaption3 =</div>
<div class="line">            ext::make_shared&lt;NonstandardSwaption&gt;(underlying3, exercise2);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;SimpleQuote&gt; oas0 =</div>
<div class="line">            ext::make_shared&lt;SimpleQuote&gt;(0.0);</div>
<div class="line">        ext::shared_ptr&lt;SimpleQuote&gt; oas100 =</div>
<div class="line">            ext::make_shared&lt;SimpleQuote&gt;(0.01);</div>
<div class="line">        <a name="_a20"></a><a class="code" href="class_quant_lib_1_1_relinkable_handle.html" title="Relinkable handle to an observable.">RelinkableHandle&lt;Quote&gt;</a> oas(oas0);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; nonstandardSwaptionEngine2 =</div>
<div class="line">            ext::make_shared&lt;Gaussian1dNonstandardSwaptionEngine&gt;(</div>
<div class="line">                gsr, 64, 7.0, <span class="keyword">true</span>, <span class="keyword">false</span>, oas); <span class="comment">// change discounting to 6m</span></div>
<div class="line"> </div>
<div class="line">        swaption3-&gt;setPricingEngine(nonstandardSwaptionEngine2);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        basket = swaption3-&gt;calibrationBasket(</div>
<div class="line">            swapBase, *swaptionVol,</div>
<div class="line">            BasketGeneratingEngine::MaturityStrikeByDeltaGamma);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printBasket(basket);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nNote that nominals are not exactly 1.0 here. This is&quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nbecause we do our bond discounting on 6m level while&quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nthe swaptions are still discounted on OIS level.&quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\n(You can try this by changing the OIS level to the &quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\n6m level, which will produce nominals near 1.0).&quot;</span></div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe npv of the call right is (after recalibrating the model)&quot;</span></div>
<div class="line">            &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); i++)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngine);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        gsr-&gt;calibrateVolatilitiesIterative(basket, method, ec);</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv3 = swaption3-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nBond&#39;s bermudan call right npv = &quot;</span></div>
<div class="line">                  &lt;&lt; std::setprecision(6) &lt;&lt; npv3 &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nUp to now, no credit spread is included in the pricing.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nWe can do so by specifying an oas in the pricing engine.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nLet&#39;s set the spread level to 100bp and regenerate&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nthe calibration basket.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        oas.linkTo(oas100);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        basket = swaption3-&gt;calibrationBasket(</div>
<div class="line">            swapBase, *swaptionVol,</div>
<div class="line">            BasketGeneratingEngine::MaturityStrikeByDeltaGamma);</div>
<div class="line">        </div>
<div class="line">        printBasket(basket);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe adjusted basket takes the credit spread into account.&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nThis is consistent to a hedge where you would have a&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nmargin on the float leg around 100bp,too.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe npv becomes:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); i++)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngine);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        gsr-&gt;calibrateVolatilitiesIterative(basket, method, ec);</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv4 = swaption3-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nBond&#39;s bermudan call right npv (oas = 100bp) = &quot;</span></div>
<div class="line">                  &lt;&lt; std::setprecision(6) &lt;&lt; npv4 &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nThe next instrument we look at is a CMS 10Y vs Euribor &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\n6M swaption. The maturity is again 10 years and the option&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\nis exercisable on a yearly basis&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;FloatFloatSwap&gt; underlying4(<span class="keyword">new</span> <a name="_a21"></a><a class="code" href="class_quant_lib_1_1_float_float_swap.html" title="float float swap">FloatFloatSwap</a>(</div>
<div class="line">                VanillaSwap::Payer, 1.0, 1.0, fixedSchedule, swapBase,</div>
<div class="line">                <a class="code" href="class_quant_lib_1_1_thirty360.html" title="30/360 day count convention">Thirty360</a>(), floatingSchedule, euribor6m, <a class="code" href="class_quant_lib_1_1_actual360.html" title="Actual/360 day count convention.">Actual360</a>(), <span class="keyword">false</span>,</div>
<div class="line">                <span class="keyword">false</span>, 1.0, 0.0, <a name="_a22"></a><a class="code" href="class_quant_lib_1_1_null.html" title="template class providing a null value for a given type.">Null&lt;Real&gt;</a>(), <a class="code" href="class_quant_lib_1_1_null.html" title="template class providing a null value for a given type.">Null&lt;Real&gt;</a>(), 1.0, 0.0010));</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;FloatFloatSwaption&gt; swaption4 =</div>
<div class="line">            ext::make_shared&lt;FloatFloatSwaption&gt;(underlying4, exercise);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;Gaussian1dFloatFloatSwaptionEngine&gt;</div>
<div class="line">            floatSwaptionEngine(<span class="keyword">new</span> <a name="_a23"></a><a class="code" href="class_quant_lib_1_1_gaussian1d_float_float_swaption_engine.html" title="One factor model float float swaption engine.">Gaussian1dFloatFloatSwaptionEngine</a>(</div>
<div class="line">                    gsr, 64, 7.0, <span class="keyword">true</span>, <span class="keyword">false</span>, <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a>(), ytsOis, <span class="keyword">true</span>));</div>
<div class="line"> </div>
<div class="line">        swaption4-&gt;setPricingEngine(floatSwaptionEngine);</div>
<div class="line"> </div>
<div class="line">        std::cout</div>
<div class="line">            &lt;&lt; <span class="stringliteral">&quot;\nSince the underlying is quite exotic already, we start with&quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;\npricing this using the LinearTsrPricer for CMS coupon &quot;</span></div>
<div class="line">               <span class="stringliteral">&quot;estimation&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a> reversionQuote(</div>
<div class="line">            ext::make_shared&lt;SimpleQuote&gt;(reversion));</div>
<div class="line"> </div>
<div class="line">        <span class="keyword">const</span> <a class="code" href="namespace_quant_lib.html#afd0d2e08465e4b7e928c75416bd8dc4b" title="Sequence of cash-flows.">Leg</a> &amp;leg0 = underlying4-&gt;leg(0);</div>
<div class="line">        <span class="keyword">const</span> <a class="code" href="namespace_quant_lib.html#afd0d2e08465e4b7e928c75416bd8dc4b" title="Sequence of cash-flows.">Leg</a> &amp;leg1 = underlying4-&gt;leg(1);</div>
<div class="line">        ext::shared_ptr&lt;CmsCouponPricer&gt; cmsPricer =</div>
<div class="line">            ext::make_shared&lt;LinearTsrPricer&gt;(swaptionVol, reversionQuote);</div>
<div class="line">        ext::shared_ptr&lt;IborCouponPricer&gt; iborPricer(<span class="keyword">new</span> <a name="_a24"></a><a class="code" href="class_quant_lib_1_1_black_ibor_coupon_pricer.html">BlackIborCouponPricer</a>);</div>
<div class="line"> </div>
<div class="line">        setCouponPricer(leg0, cmsPricer);</div>
<div class="line">        setCouponPricer(leg1, iborPricer);</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; swapPricer =</div>
<div class="line">            ext::make_shared&lt;DiscountingSwapEngine&gt;(ytsOis);</div>
<div class="line"> </div>
<div class="line">        underlying4-&gt;setPricingEngine(swapPricer);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv5 = underlying4-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Underlying CMS Swap NPV = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; npv5 &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;       CMS     Leg  NPV = &quot;</span> &lt;&lt; underlying4-&gt;legNPV(0)</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;       Euribor Leg  NPV = &quot;</span> &lt;&lt; underlying4-&gt;legNPV(1)</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nWe generate a naive calibration basket and calibrate &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nthe GSR model to it:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        basket = swaption4-&gt;calibrationBasket(swapBase, *swaptionVol,</div>
<div class="line">                                              BasketGeneratingEngine::Naive);</div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); ++i)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngine);</div>
<div class="line">        gsr-&gt;calibrateVolatilitiesIterative(basket, method, ec);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printBasket(basket);</div>
<div class="line">        printModelCalibration(basket, gsr-&gt;volatility());</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe npv of the bermudan swaption is&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv6 = swaption4-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFloat swaption NPV (GSR) = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; npv6 &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nIn this case it is also interesting to look at the &quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nunderlying swap npv in the GSR model.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFloat swap NPV (GSR) = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; swaption4-&gt;result&lt;<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>&gt;(<span class="stringliteral">&quot;underlyingValue&quot;</span>) &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nNot surprisingly, the underlying is priced differently&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ncompared to the LinearTsrPricer, since a different&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nsmile is implied by the GSR model.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is exactly where the Markov functional model&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\ncomes into play, because it can calibrate to any&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\ngiven underlying smile (as long as it is arbitrage&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nfree). We try this now. Of course the usual use case&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nis not to calibrate to a flat smile as in our simple&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nexample, still it should be possible, of course...&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Date&gt; markovStepDates(exerciseDates.begin(),</div>
<div class="line">                                          exerciseDates.end());</div>
<div class="line">        <span class="keyword">const</span> std::vector&lt;Date&gt;&amp; cmsFixingDates(markovStepDates);</div>
<div class="line">        std::vector&lt;Real&gt; markovSigmas(markovStepDates.size() + 1, 0.01);</div>
<div class="line">        std::vector&lt;Period&gt; tenors(cmsFixingDates.size(), 10 * Years);</div>
<div class="line">        ext::shared_ptr&lt;MarkovFunctional&gt; markov =</div>
<div class="line">            ext::make_shared&lt;MarkovFunctional&gt;(</div>
<div class="line">                yts6m, reversion, markovStepDates, markovSigmas, swaptionVol,</div>
<div class="line">                cmsFixingDates, tenors, swapBase,</div>
<div class="line">                MarkovFunctional::ModelSettings().withYGridPoints(16));</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;Gaussian1dSwaptionEngine&gt; swaptionEngineMarkov =</div>
<div class="line">            ext::make_shared&lt;Gaussian1dSwaptionEngine&gt;(markov, 8, 5.0, <span class="keyword">true</span>,</div>
<div class="line">                                                         <span class="keyword">false</span>, ytsOis);</div>
<div class="line">        ext::shared_ptr&lt;Gaussian1dFloatFloatSwaptionEngine&gt;</div>
<div class="line">            floatEngineMarkov =</div>
<div class="line">                ext::make_shared&lt;Gaussian1dFloatFloatSwaptionEngine&gt;(</div>
<div class="line">                    markov, 16, 7.0, <span class="keyword">true</span>, <span class="keyword">false</span>, <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;Quote&gt;</a>(), ytsOis,</div>
<div class="line">                    <span class="keyword">true</span>);</div>
<div class="line"> </div>
<div class="line">        swaption4-&gt;setPricingEngine(floatEngineMarkov);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv7 = swaption4-&gt;NPV();</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe option npv is the markov model is:&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFloat swaption NPV (Markov) = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; npv7 &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is not too far from the GSR price.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nMore interesting is the question how well the Markov&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nmodel did its job to match our input smile. For this&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nwe look at the underlying npv under the Markov model&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFloat swap NPV (Markov) = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; swaption4-&gt;result&lt;<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>&gt;(<span class="stringliteral">&quot;underlyingValue&quot;</span>) &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is closer to our terminal swap rate model price.&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nA perfect match is not expected anyway, because the&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ndynamics of the underlying rate in the linear&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nmodel is different from the Markov model, of&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ncourse.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThe Markov model can not only calibrate to the&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nunderlying smile, but has at the same time a&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nsigma function (similar to the GSR model) which&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ncan be used to calibrate to a second instrument&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nset. We do this here to calibrate to our coterminal&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nATM swaptions from above.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is a computationally demanding task, so&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\ndepending on your machine, this may take a&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nwhile now...&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i = 0; i &lt; basket.size(); ++i)</div>
<div class="line">            basket[i]-&gt;setPricingEngine(swaptionEngineMarkov);</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        markov-&gt;calibrate(basket, method, ec);</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        printModelCalibration(basket, markov-&gt;volatility());</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nNow let&#39;s have a look again at the underlying pricing.&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nIt shouldn&#39;t have changed much, because the underlying&quot;</span></div>
<div class="line">                     <span class="stringliteral">&quot;\nsmile is still matched.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> npv8 = swaption4-&gt;result&lt;<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a>&gt;(<span class="stringliteral">&quot;underlyingValue&quot;</span>);</div>
<div class="line">        </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nFloat swap NPV (Markov) = &quot;</span> &lt;&lt; std::setprecision(6)</div>
<div class="line">                  &lt;&lt; npv8 &lt;&lt; std::endl;</div>
<div class="line">        </div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThis is close to the previous value as expected.&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nAs a final remark we note that the calibration to&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\ncoterminal swaptions is not particularly reasonable&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nhere, because the european call rights are not&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nwell represented by these swaptions.&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nSecondly, our CMS swaption is sensitive to the&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\ncorrelation between the 10y swap rate and the&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nEuribor 6M rate. Since the Markov model is one factor&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nit will most probably underestimate the market value&quot;</span></div>
<div class="line">                  &lt;&lt; <span class="stringliteral">&quot;\nby construction.&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;\nThat was it. Thank you for running this demo. Bye.&quot;</span></div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line">    } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a25"></a><a class="code" href="class_quant_lib_1_1_error.html" title="Base error class.">QuantLib::Error</a>&amp; e) {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;terminated with a ql exception: &quot;</span> &lt;&lt; e.<a name="a26"></a><a class="code" href="class_quant_lib_1_1_error.html#a79009ed133fa02b942ddce8f0b987f3e" title="returns the error message.">what</a>()</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::exception&amp; e) {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;terminated with a general exception: &quot;</span> &lt;&lt; e.what()</div>
<div class="line">                  &lt;&lt; std::endl;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.9.1-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
1.8.20
</small></address>
</body>
</html>