File: _c_v_a_i_r_s_8cpp-example.html

package info (click to toggle)
quantlib-refman-html 1.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 103,140 kB
  • sloc: javascript: 13,408; makefile: 35
file content (339 lines) | stat: -rw-r--r-- 29,812 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
<!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: CVAIRS.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">CVAIRS.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>This example shows how to calculate credit value adjustment for an interest rate swap.</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) 2015 Jose Aparicio</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/vanillaswap.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/instruments/makevanillaswap.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/swap/cvaswapengine.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/termstructures/yield/piecewiseyieldcurve.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/termstructures/yield/ratehelpers.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/termstructures/credit/interpolatedhazardratecurve.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/time/calendars/target.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/time/daycounters/actualactual.hpp&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;ql/time/daycounters/actual360.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>std;</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">/*</span></div>
<div class="line"><span class="comment">  This example reproduces Table 2 on page 11 of </span></div>
<div class="line"><span class="comment">  A Formula for Interest Rate Swaps Valuation under</span></div>
<div class="line"><span class="comment">  Counterparty Risk in presence of Netting Agreements</span></div>
<div class="line"><span class="comment">  </span></div>
<div class="line"><span class="comment">  Damiano Brigo and Massimo Masetti; May 4, 2005</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>* []) {</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; std::endl;</div>
<div class="line"> </div>
<div class="line">        <a name="_a0"></a><a class="code" href="class_quant_lib_1_1_calendar.html" title="calendar class">Calendar</a> calendar = <a name="_a1"></a><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 name="_a2"></a><a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> todaysDate(10, March, 2004);</div>
<div class="line">        <span class="comment">// must be a business day</span></div>
<div class="line">        todaysDate = calendar.<a name="a3"></a><a class="code" href="class_quant_lib_1_1_calendar.html#a712629806d9ef9a39f8144f368c81e4b">adjust</a>(todaysDate);</div>
<div class="line"> </div>
<div class="line">        Settings::instance().evaluationDate() = todaysDate;</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;IborIndex&gt;  yieldIndx(<span class="keyword">new</span> <a name="_a4"></a><a class="code" href="class_quant_lib_1_1_euribor3_m.html" title="3-months Euribor index">Euribor3M</a>());</div>
<div class="line">        <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> tenorsSwapMkt[] = {5, 10, 15, 20, 25, 30};</div>
<div class="line">        </div>
<div class="line">        <span class="comment">// rates ignoring counterparty risk:</span></div>
<div class="line">        <a name="a5"></a><a class="code" href="group__types.html#gaede435af51236692b1107d7639581d39" title="interest rates">Rate</a> ratesSwapmkt[] = {.03249, .04074, .04463, .04675, .04775, .04811};</div>
<div class="line"> </div>
<div class="line">        vector&lt;ext::shared_ptr&lt;RateHelper&gt; &gt; swapHelpers;</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;<span class="keyword">sizeof</span>(tenorsSwapMkt)/<span class="keyword">sizeof</span>(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a>); i++)</div>
<div class="line">            swapHelpers.push_back(ext::make_shared&lt;SwapRateHelper&gt;(</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>(ext::shared_ptr&lt;Quote&gt;(</div>
<div class="line">                                   <span class="keyword">new</span> <a name="_a7"></a><a class="code" href="class_quant_lib_1_1_simple_quote.html" title="market element returning a stored value">SimpleQuote</a>(ratesSwapmkt[i]))),</div>
<div class="line">                    tenorsSwapMkt[i] * Years,</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>(),</div>
<div class="line">                    <a name="a8"></a><a class="code" href="group__datetime.html#gga6d41db8ba0ea90d22df35889df452adaab4fce358383d1822f7596659e00b07f7" title="every third month">Quarterly</a>,</div>
<div class="line">                    <a name="a9"></a><a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,</div>
<div class="line">                    <a name="_a10"></a><a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::ISDA),</div>
<div class="line">                    yieldIndx));</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;YieldTermStructure&gt; swapTS(</div>
<div class="line">            <span class="keyword">new</span> <a name="_a11"></a><a class="code" href="class_quant_lib_1_1_piecewise_yield_curve.html" title="Piecewise yield term structure.">PiecewiseYieldCurve&lt;Discount,LogLinear&gt;</a>(</div>
<div class="line">             2, <a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>(), swapHelpers, <a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::ISDA)));</div>
<div class="line">        swapTS-&gt;enableExtrapolation();</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; riskFreeEngine(</div>
<div class="line">            ext::make_shared&lt;DiscountingSwapEngine&gt;(</div>
<div class="line">                 <a name="_a12"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a>(swapTS)));</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Handle&lt;DefaultProbabilityTermStructure&gt; &gt;</div>
<div class="line">            defaultIntensityTS;</div>
<div class="line">        </div>
<div class="line">        <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> defaultTenors[] = {0, 12, 36, 60, 84, 120, 180, 240, 300, </div>
<div class="line">                                360};<span class="comment">// months</span></div>
<div class="line">        <span class="comment">// Three risk levels:</span></div>
<div class="line">        <a name="a13"></a><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> intensitiesLow[] = {0.0036, 0.0036, 0.0065, 0.0099, 0.0111, </div>
<div class="line">                                 0.0177, 0.0177, 0.0177, 0.0177, 0.0177, </div>
<div class="line">                                 0.0177};</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> intensitiesMedium[] = {0.0202, 0.0202, 0.0231, 0.0266, 0.0278, </div>
<div class="line">                                    0.0349, 0.0349, 0.0349, 0.0349, 0.0349,</div>
<div class="line">                                    0.0349};</div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> intensitiesHigh[] = {0.0534, 0.0534, 0.0564, 0.06, 0.0614, 0.0696,</div>
<div class="line">                                  0.0696, 0.0696, 0.0696, 0.0696, 0.0696};</div>
<div class="line">        <span class="comment">// Recovery rates:</span></div>
<div class="line">        <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> ctptyRRLow = 0.4, ctptyRRMedium = 0.35, ctptyRRHigh = 0.3;</div>
<div class="line"> </div>
<div class="line">        std::vector&lt;Date&gt; defaultTSDates;</div>
<div class="line">        std::vector&lt;Real&gt; intesitiesVLow, intesitiesVMedium, intesitiesVHigh;</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;<span class="keyword">sizeof</span>(defaultTenors)/<span class="keyword">sizeof</span>(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a>); i++) {</div>
<div class="line">            defaultTSDates.push_back(<a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html" title="TARGET calendar">TARGET</a>().<a name="a14"></a><a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(todaysDate, </div>
<div class="line">                <a name="_a15"></a><a class="code" href="class_quant_lib_1_1_period.html">Period</a>(defaultTenors[i], Months)));</div>
<div class="line">            intesitiesVLow.push_back(intensitiesLow[i]);</div>
<div class="line">            intesitiesVMedium.push_back(intensitiesMedium[i]);</div>
<div class="line">            intesitiesVHigh.push_back(intensitiesHigh[i]);</div>
<div class="line">        }</div>
<div class="line"> </div>
<div class="line">        defaultIntensityTS.push_back(<a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;DefaultProbabilityTermStructure&gt;</a>(</div>
<div class="line">            ext::shared_ptr&lt;DefaultProbabilityTermStructure&gt;(</div>
<div class="line">                 <span class="keyword">new</span> <a name="_a16"></a><a class="code" href="class_quant_lib_1_1_interpolated_hazard_rate_curve.html" title="DefaultProbabilityTermStructure based on interpolation of hazard rates.">InterpolatedHazardRateCurve&lt;BackwardFlat&gt;</a>(</div>
<div class="line">                   defaultTSDates, </div>
<div class="line">                   intesitiesVLow,</div>
<div class="line">                   <a name="_a17"></a><a class="code" href="class_quant_lib_1_1_actual360.html" title="Actual/360 day count convention.">Actual360</a>(),</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>()))));</div>
<div class="line">        defaultIntensityTS.push_back(<a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;DefaultProbabilityTermStructure&gt;</a>(</div>
<div class="line">            ext::shared_ptr&lt;DefaultProbabilityTermStructure&gt;(</div>
<div class="line">                 <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_interpolated_hazard_rate_curve.html" title="DefaultProbabilityTermStructure based on interpolation of hazard rates.">InterpolatedHazardRateCurve&lt;BackwardFlat&gt;</a>(</div>
<div class="line">                   defaultTSDates,</div>
<div class="line">                   intesitiesVMedium,</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">                   <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">        defaultIntensityTS.push_back(<a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle&lt;DefaultProbabilityTermStructure&gt;</a>(</div>
<div class="line">            ext::shared_ptr&lt;DefaultProbabilityTermStructure&gt;(</div>
<div class="line">                 <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_interpolated_hazard_rate_curve.html" title="DefaultProbabilityTermStructure based on interpolation of hazard rates.">InterpolatedHazardRateCurve&lt;BackwardFlat&gt;</a>(</div>
<div class="line">                   defaultTSDates, </div>
<div class="line">                   intesitiesVHigh,</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">                   <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">        <a name="a18"></a><a class="code" href="group__types.html#gaaa95ab7fe66935e3f7535413fad2a7d3" title="volatility">Volatility</a> blackVol = 0.15;   </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; ctptySwapCvaLow = </div>
<div class="line">            ext::make_shared&lt;CounterpartyAdjSwapEngine&gt;(</div>
<div class="line">                 <a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a>(swapTS), </div>
<div class="line">                 blackVol,</div>
<div class="line">                 defaultIntensityTS[0], </div>
<div class="line">                 ctptyRRLow</div>
<div class="line">                 );</div>
<div class="line"> </div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; ctptySwapCvaMedium = </div>
<div class="line">            ext::make_shared&lt;CounterpartyAdjSwapEngine&gt;(</div>
<div class="line">                 <a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a>(swapTS), </div>
<div class="line">                 blackVol, </div>
<div class="line">                 defaultIntensityTS[1],</div>
<div class="line">                 ctptyRRMedium);</div>
<div class="line">        ext::shared_ptr&lt;PricingEngine&gt; ctptySwapCvaHigh = </div>
<div class="line">            ext::make_shared&lt;CounterpartyAdjSwapEngine&gt;(</div>
<div class="line">                 <a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a>(swapTS), </div>
<div class="line">                 blackVol,</div>
<div class="line">                 defaultIntensityTS[2],</div>
<div class="line">                 ctptyRRHigh);</div>
<div class="line">        </div>
<div class="line">        defaultIntensityTS[0]-&gt;enableExtrapolation();</div>
<div class="line">        defaultIntensityTS[1]-&gt;enableExtrapolation();</div>
<div class="line">        defaultIntensityTS[2]-&gt;enableExtrapolation();</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">        <span class="comment">// fixed leg</span></div>
<div class="line">        <a class="code" href="group__datetime.html#ga6d41db8ba0ea90d22df35889df452ada" title="Frequency of events.">Frequency</a> fixedLegFrequency = <a class="code" href="group__datetime.html#gga6d41db8ba0ea90d22df35889df452adaab4fce358383d1822f7596659e00b07f7" title="every third month">Quarterly</a>;</div>
<div class="line">        <a class="code" href="group__datetime.html#gaff46c5ae9385d20709bedade86edd368" title="Business Day conventions.">BusinessDayConvention</a> fixedLegConvention = <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>;</div>
<div class="line">        <a name="_a19"></a><a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> fixedLegDayCounter = <a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::ISDA);</div>
<div class="line">        <a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> floatingLegDayCounter = <a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::ISDA);</div>
<div class="line"> </div>
<div class="line">        VanillaSwap::Type swapType = </div>
<div class="line">            <span class="comment">//VanillaSwap::Receiver ;</span></div>
<div class="line">            VanillaSwap::Payer;</div>
<div class="line">        ext::shared_ptr&lt;IborIndex&gt; yieldIndxS(</div>
<div class="line">             <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_euribor3_m.html" title="3-months Euribor index">Euribor3M</a>(<a class="code" href="class_quant_lib_1_1_handle.html">Handle&lt;YieldTermStructure&gt;</a>(swapTS)));</div>
<div class="line">        std::vector&lt;VanillaSwap&gt; riskySwaps;</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;<span class="keyword">sizeof</span>(tenorsSwapMkt)/<span class="keyword">sizeof</span>(<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a>); i++) </div>
<div class="line">            riskySwaps.push_back(<a name="_a20"></a><a class="code" href="class_quant_lib_1_1_make_vanilla_swap.html" title="helper class">MakeVanillaSwap</a>(tenorsSwapMkt[i]*Years,</div>
<div class="line">                yieldIndxS,</div>
<div class="line">                ratesSwapmkt[i], </div>
<div class="line">                0*Days)</div>
<div class="line">            .<a name="a21"></a>withSettlementDays(2)</div>
<div class="line">            .<a name="a22"></a>withFixedLegDayCount(fixedLegDayCounter)</div>
<div class="line">            .<a name="a23"></a>withFixedLegTenor(<a class="code" href="class_quant_lib_1_1_period.html">Period</a>(fixedLegFrequency))</div>
<div class="line">            .<a name="a24"></a>withFixedLegConvention(fixedLegConvention)</div>
<div class="line">            .<a name="a25"></a>withFixedLegTerminationDateConvention(fixedLegConvention)</div>
<div class="line">            .<a name="a26"></a>withFixedLegCalendar(calendar)</div>
<div class="line">            .<a name="a27"></a>withFloatingLegCalendar(calendar)</div>
<div class="line">            .<a name="a28"></a>withNominal(100.)</div>
<div class="line">            .<a name="a29"></a>withType(swapType));</div>
<div class="line"> </div>
<div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;-- Correction in the contract fix rate in bp --&quot;</span> &lt;&lt; endl;</div>
<div class="line">        <span class="comment">/* The paper plots correction to be substracted, here is printed</span></div>
<div class="line"><span class="comment">           with its sign </span></div>
<div class="line"><span class="comment">        */</span></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;riskySwaps.size(); i++) {</div>
<div class="line">            cout &lt;&lt; fixed &lt;&lt; setprecision(3);</div>
<div class="line">            cout &lt;&lt; setw(4);</div>
<div class="line">            riskySwaps[i].setPricingEngine(riskFreeEngine);</div>
<div class="line">            <span class="comment">// should recover the input here:</span></div>
<div class="line">            <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> nonRiskyFair = riskySwaps[i].fairRate();</div>
<div class="line">            cout &lt;&lt; tenorsSwapMkt[i];</div>
<div class="line">            cout &lt;&lt; setw(5);</div>
<div class="line"> </div>
<div class="line">            cout &lt;&lt; <span class="stringliteral">&quot; | &quot;</span> &lt;&lt; <a name="a30"></a><a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">io::rate</a>(nonRiskyFair);</div>
<div class="line">            cout &lt;&lt; fixed &lt;&lt; setprecision(2);</div>
<div class="line">            cout &lt;&lt; setw(5);</div>
<div class="line">            <span class="comment">// Low Risk:</span></div>
<div class="line">            riskySwaps[i].setPricingEngine(ctptySwapCvaLow);</div>
<div class="line">            cout &lt;&lt; <span class="stringliteral">&quot; | &quot;</span> &lt;&lt; setw(6) </div>
<div class="line">                 &lt;&lt; 10000.*(riskySwaps[i].fairRate() - nonRiskyFair);</div>
<div class="line">            <span class="comment">//cout &lt;&lt; &quot; | &quot; &lt;&lt; setw(6) &lt;&lt; riskySwaps[i].NPV() ;</span></div>
<div class="line"> </div>
<div class="line">            <span class="comment">// Medium Risk:</span></div>
<div class="line">            riskySwaps[i].setPricingEngine(ctptySwapCvaMedium);</div>
<div class="line">            cout &lt;&lt; <span class="stringliteral">&quot; | &quot;</span> &lt;&lt; setw(6) </div>
<div class="line">                 &lt;&lt; 10000.*(riskySwaps[i].fairRate() - nonRiskyFair);</div>
<div class="line">            <span class="comment">//cout &lt;&lt; &quot; | &quot; &lt;&lt; setw(6) &lt;&lt; riskySwaps[i].NPV() ;</span></div>
<div class="line"> </div>
<div class="line">            riskySwaps[i].setPricingEngine(ctptySwapCvaHigh);</div>
<div class="line">            cout &lt;&lt; <span class="stringliteral">&quot; | &quot;</span> &lt;&lt; setw(6) </div>
<div class="line">                 &lt;&lt; 10000.*(riskySwaps[i].fairRate() - nonRiskyFair);</div>
<div class="line">            <span class="comment">//cout &lt;&lt; &quot; | &quot; &lt;&lt; setw(6) &lt;&lt; riskySwaps[i].NPV() ;</span></div>
<div class="line"> </div>
<div class="line">            cout &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line"> </div>
<div class="line">        cout &lt;&lt; endl;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">return</span> 0;</div>
<div class="line">    } <span class="keywordflow">catch</span> (exception&amp; e) {</div>
<div class="line">        cerr &lt;&lt; e.what() &lt;&lt; endl;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    } <span class="keywordflow">catch</span> (...) {</div>
<div class="line">        cerr &lt;&lt; <span class="stringliteral">&quot;unknown error&quot;</span> &lt;&lt; endl;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</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>