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 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<meta name="robots" content="none">
<title>QuantLib: swapvaluation.cpp</title>
<link rel="stylesheet" href="quantlib.css" type="text/css">
<link rel="stylesheet" href="print.css" type="text/css" media="print">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<div id="container">
<div id="header">
<img class="titleimage"
src="QL-title.jpg" width="212" height="47" border="0"
alt="QuantLib">
<br>
<h3 class="subtitle">A free/open-source library for quantitative finance</h3>
</div>
<div id="menu">
<h3 class="navbartitle">Version 0.3.14</h3>
<hr>
<h3 class="navbartitle">Getting started</h3>
<ul class="navbarlist">
<li class="navlink"><a href="index.html">Introduction</a></li>
<li class="navlink"><a href="overview.html">Project overview</a></li>
<li class="navlink"><a href="where.html">Where to get QuantLib</a></li>
<li class="navlink"><a href="install.html">Installation</a></li>
<li class="navlink"><a href="config.html">Configuration</a></li>
<li class="navlink"><a href="usage.html">Usage</a></li>
<li class="navlink"><a href="faq.html">Frequently asked questions</a></li>
<li class="navlink"><a href="history.html">Version history</a></li>
<li class="navlink"><a href="resources.html">Additional resources</a></li>
<li class="navlink"><a href="group.html">The QuantLib group</a></li>
<li class="navlink"><a href="license.html">Copyright and license</a></li>
</ul>
<hr>
<h3 class="navbartitle">Reference manual</h3>
<ul class="navbarlist">
<li class="navlink"><a href="modules.html">Modules</a></li>
<li class="navlink"><a href="hierarchy.html">Class Hierarchy</a></li>
<li class="navlink"><a href="annotated.html">Compound List</a></li>
<li class="navlink"><a href="files.html">File List</a></li>
<li class="navlink"><a href="functions.html">Compound Members</a></li>
<li class="navlink"><a href="globals.html">File Members</a></li>
<li class="navlink"><a href="todo.html">Todo List</a></li>
<li class="navlink"><a href="bug.html">Known Bugs</a></li>
<li class="navlink"><a href="caveats.html">Caveats</a></li>
<li class="navlink"><a href="test.html">Test Suite</a></li>
<li class="navlink"><a href="deprecated.html">Deprecated Features</a></li>
<li class="navlink"><a href="examples.html">Examples</a></li>
</ul>
</div>
<div id="content">
<!--Doxygen-generated content-->
<!-- Generated by Doxygen 1.5.1 -->
<h1>swapvaluation.cpp</h1>This is an example of using the QuantLib Term Structure for pricing a simple swap.<p>
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */</span>
<a name="l00002"></a>00002
<a name="l00022"></a>00022 <span class="comment">/* This example shows how to set up a Term Structure and then price a simple</span>
<a name="l00023"></a>00023 <span class="comment"> swap.</span>
<a name="l00024"></a>00024 <span class="comment">*/</span>
<a name="l00025"></a>00025
<a name="l00026"></a>00026 <span class="comment">// the only header you need to use QuantLib</span>
<a name="l00027"></a>00027 <span class="preprocessor">#define BOOST_LIB_DIAGNOSTIC</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor"># include <ql/quantlib.hpp></span>
<a name="l00029"></a>00029 <span class="preprocessor">#undef BOOST_LIB_DIAGNOSTIC</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#ifdef BOOST_MSVC</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="comment">/* Uncomment the following lines to unmask floating-point</span>
<a name="l00033"></a>00033 <span class="comment"> exceptions. Warning: unpredictable results can arise...</span>
<a name="l00034"></a>00034 <span class="comment"></span>
<a name="l00035"></a>00035 <span class="comment"> See http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481</span>
<a name="l00036"></a>00036 <span class="comment"> Is there anyone with a definitive word about this?</span>
<a name="l00037"></a>00037 <span class="comment">*/</span>
<a name="l00038"></a>00038 <span class="comment">// #include <float.h></span>
<a name="l00039"></a>00039 <span class="comment">// namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); }</span>
<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>
<a name="l00042"></a>00042 <span class="preprocessor">#include <boost/timer.hpp></span>
<a name="l00043"></a>00043 <span class="preprocessor">#include <iostream></span>
<a name="l00044"></a>00044 <span class="preprocessor">#include <iomanip></span>
<a name="l00045"></a>00045
<a name="l00046"></a>00046 <span class="keyword">using namespace </span>QuantLib;
<a name="l00047"></a>00047
<a name="l00048"></a>00048 <span class="preprocessor">#if defined(QL_ENABLE_SESSIONS)</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span><span class="keyword">namespace </span>QuantLib {
<a name="l00050"></a>00050
<a name="l00051"></a>00051 <a name="a0"></a><a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> sessionId() { <span class="keywordflow">return</span> 0; }
<a name="l00052"></a>00052
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 <span class="preprocessor">#endif</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span>
<a name="l00056"></a>00056
<a name="l00057"></a>00057 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>* [])
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059 <span class="keywordflow">try</span> {
<a name="l00060"></a>00060 <a name="a1"></a><a class="code" href="group__misc_macros.html#g11d8e34f54505b0bf6f550508278673d">QL_IO_INIT</a>
<a name="l00061"></a>00061
<a name="l00062"></a>00062 boost::timer timer;
<a name="l00063"></a>00063 std::cout << std::endl;
<a name="l00064"></a>00064
<a name="l00065"></a>00065 <span class="comment">/*********************</span>
<a name="l00066"></a>00066 <span class="comment"> *** MARKET DATA ***</span>
<a name="l00067"></a>00067 <span class="comment"> *********************/</span>
<a name="l00068"></a>00068
<a name="l00069"></a>00069 <a name="_a2"></a><a class="code" href="class_quant_lib_1_1_calendar.html">Calendar</a> calendar = <a name="_a3"></a><a class="code" href="class_quant_lib_1_1_t_a_r_g_e_t.html">TARGET</a>();
<a name="l00070"></a>00070 <span class="comment">// uncommenting the following line generates an error</span>
<a name="l00071"></a>00071 <span class="comment">// calendar = Tokyo();</span>
<a name="l00072"></a>00072 <a name="_a4"></a><a class="code" href="class_quant_lib_1_1_date.html">Date</a> settlementDate(22, September, 2004);
<a name="l00073"></a>00073 <span class="comment">// must be a business day</span>
<a name="l00074"></a>00074 settlementDate = calendar.<a name="a5"></a><a class="code" href="class_quant_lib_1_1_calendar.html#8ae8c4c962667ddf0c19c99142c667b6">adjust</a>(settlementDate);
<a name="l00075"></a>00075
<a name="l00076"></a>00076 <a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> fixingDays = 2;
<a name="l00077"></a>00077 <a class="code" href="class_quant_lib_1_1_date.html">Date</a> todaysDate = calendar.<a name="a6"></a><a class="code" href="class_quant_lib_1_1_calendar.html#b3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(settlementDate, -fixingDays, Days);
<a name="l00078"></a>00078 <span class="comment">// nothing to do with Date::todaysDate</span>
<a name="l00079"></a>00079 Settings::instance().evaluationDate() = todaysDate;
<a name="l00080"></a>00080
<a name="l00081"></a>00081
<a name="l00082"></a>00082 todaysDate = Settings::instance().evaluationDate();
<a name="l00083"></a>00083 std::cout << <span class="stringliteral">"Today: "</span> << todaysDate.<a name="a7"></a><a class="code" href="class_quant_lib_1_1_date.html#8beb14a6b168772900b48e3161b4c0e6">weekday</a>()
<a name="l00084"></a>00084 << <span class="stringliteral">", "</span> << todaysDate << std::endl;
<a name="l00085"></a>00085
<a name="l00086"></a>00086 std::cout << <span class="stringliteral">"Settlement date: "</span> << settlementDate.<a class="code" href="class_quant_lib_1_1_date.html#8beb14a6b168772900b48e3161b4c0e6">weekday</a>()
<a name="l00087"></a>00087 << <span class="stringliteral">", "</span> << settlementDate << std::endl;
<a name="l00088"></a>00088
<a name="l00089"></a>00089 <span class="comment">// deposits</span>
<a name="l00090"></a>00090 <a name="a8"></a><a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d1wQuote=0.0382;
<a name="l00091"></a>00091 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d1mQuote=0.0372;
<a name="l00092"></a>00092 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d3mQuote=0.0363;
<a name="l00093"></a>00093 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d6mQuote=0.0353;
<a name="l00094"></a>00094 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d9mQuote=0.0348;
<a name="l00095"></a>00095 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> d1yQuote=0.0345;
<a name="l00096"></a>00096 <span class="comment">// FRAs</span>
<a name="l00097"></a>00097 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> fra3x6Quote=0.037125;
<a name="l00098"></a>00098 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> fra6x9Quote=0.037125;
<a name="l00099"></a>00099 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> fra6x12Quote=0.037125;
<a name="l00100"></a>00100 <span class="comment">// futures</span>
<a name="l00101"></a>00101 <a name="a9"></a><a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut1Quote=96.2875;
<a name="l00102"></a>00102 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut2Quote=96.7875;
<a name="l00103"></a>00103 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut3Quote=96.9875;
<a name="l00104"></a>00104 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut4Quote=96.6875;
<a name="l00105"></a>00105 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut5Quote=96.4875;
<a name="l00106"></a>00106 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut6Quote=96.3875;
<a name="l00107"></a>00107 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut7Quote=96.2875;
<a name="l00108"></a>00108 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> fut8Quote=96.0875;
<a name="l00109"></a>00109 <span class="comment">// swaps</span>
<a name="l00110"></a>00110 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> s2yQuote=0.037125;
<a name="l00111"></a>00111 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> s3yQuote=0.0398;
<a name="l00112"></a>00112 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> s5yQuote=0.0443;
<a name="l00113"></a>00113 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> s10yQuote=0.05165;
<a name="l00114"></a>00114 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> s15yQuote=0.055175;
<a name="l00115"></a>00115
<a name="l00116"></a>00116
<a name="l00117"></a>00117 <span class="comment">/********************</span>
<a name="l00118"></a>00118 <span class="comment"> *** QUOTES ***</span>
<a name="l00119"></a>00119 <span class="comment"> ********************/</span>
<a name="l00120"></a>00120
<a name="l00121"></a>00121 <span class="comment">// SimpleQuote stores a value which can be manually changed;</span>
<a name="l00122"></a>00122 <span class="comment">// other Quote subclasses could read the value from a database</span>
<a name="l00123"></a>00123 <span class="comment">// or some kind of data feed.</span>
<a name="l00124"></a>00124
<a name="l00125"></a>00125 <span class="comment">// deposits</span>
<a name="l00126"></a>00126 boost::shared_ptr<Quote> d1wRate(<span class="keyword">new</span> <a name="_a10"></a><a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d1wQuote));
<a name="l00127"></a>00127 boost::shared_ptr<Quote> d1mRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d1mQuote));
<a name="l00128"></a>00128 boost::shared_ptr<Quote> d3mRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d3mQuote));
<a name="l00129"></a>00129 boost::shared_ptr<Quote> d6mRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d6mQuote));
<a name="l00130"></a>00130 boost::shared_ptr<Quote> d9mRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d9mQuote));
<a name="l00131"></a>00131 boost::shared_ptr<Quote> d1yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(d1yQuote));
<a name="l00132"></a>00132 <span class="comment">// FRAs</span>
<a name="l00133"></a>00133 boost::shared_ptr<Quote> fra3x6Rate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fra3x6Quote));
<a name="l00134"></a>00134 boost::shared_ptr<Quote> fra6x9Rate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fra6x9Quote));
<a name="l00135"></a>00135 boost::shared_ptr<Quote> fra6x12Rate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fra6x12Quote));
<a name="l00136"></a>00136 <span class="comment">// futures</span>
<a name="l00137"></a>00137 boost::shared_ptr<Quote> fut1Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut1Quote));
<a name="l00138"></a>00138 boost::shared_ptr<Quote> fut2Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut2Quote));
<a name="l00139"></a>00139 boost::shared_ptr<Quote> fut3Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut3Quote));
<a name="l00140"></a>00140 boost::shared_ptr<Quote> fut4Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut4Quote));
<a name="l00141"></a>00141 boost::shared_ptr<Quote> fut5Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut5Quote));
<a name="l00142"></a>00142 boost::shared_ptr<Quote> fut6Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut6Quote));
<a name="l00143"></a>00143 boost::shared_ptr<Quote> fut7Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut7Quote));
<a name="l00144"></a>00144 boost::shared_ptr<Quote> fut8Price(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(fut8Quote));
<a name="l00145"></a>00145 <span class="comment">// swaps</span>
<a name="l00146"></a>00146 boost::shared_ptr<Quote> s2yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(s2yQuote));
<a name="l00147"></a>00147 boost::shared_ptr<Quote> s3yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(s3yQuote));
<a name="l00148"></a>00148 boost::shared_ptr<Quote> s5yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(s5yQuote));
<a name="l00149"></a>00149 boost::shared_ptr<Quote> s10yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(s10yQuote));
<a name="l00150"></a>00150 boost::shared_ptr<Quote> s15yRate(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html">SimpleQuote</a>(s15yQuote));
<a name="l00151"></a>00151
<a name="l00152"></a>00152
<a name="l00153"></a>00153 <span class="comment">/*********************</span>
<a name="l00154"></a>00154 <span class="comment"> *** RATE HELPERS ***</span>
<a name="l00155"></a>00155 <span class="comment"> *********************/</span>
<a name="l00156"></a>00156
<a name="l00157"></a>00157 <span class="comment">// RateHelpers are built from the above quotes together with</span>
<a name="l00158"></a>00158 <span class="comment">// other instrument dependant infos. Quotes are passed in</span>
<a name="l00159"></a>00159 <span class="comment">// relinkable handles which could be relinked to some other</span>
<a name="l00160"></a>00160 <span class="comment">// data source later.</span>
<a name="l00161"></a>00161
<a name="l00162"></a>00162 <span class="comment">// deposits</span>
<a name="l00163"></a>00163 <a name="_a11"></a><a class="code" href="class_quant_lib_1_1_day_counter.html">DayCounter</a> depositDayCounter = <a name="_a12"></a><a class="code" href="class_quant_lib_1_1_actual360.html">Actual360</a>();
<a name="l00164"></a>00164
<a name="l00165"></a>00165 boost::shared_ptr<RateHelper> d1w(<span class="keyword">new</span> <a name="_a13"></a><a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00166"></a>00166 <a name="_a14"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d1wRate),
<a name="l00167"></a>00167 1*Weeks, fixingDays,
<a name="l00168"></a>00168 calendar, <a name="a15"></a><a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00169"></a>00169 boost::shared_ptr<RateHelper> d1m(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00170"></a>00170 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d1mRate),
<a name="l00171"></a>00171 1*Months, fixingDays,
<a name="l00172"></a>00172 calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00173"></a>00173 boost::shared_ptr<RateHelper> d3m(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00174"></a>00174 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d3mRate),
<a name="l00175"></a>00175 3*Months, fixingDays,
<a name="l00176"></a>00176 calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00177"></a>00177 boost::shared_ptr<RateHelper> d6m(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00178"></a>00178 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d6mRate),
<a name="l00179"></a>00179 6*Months, fixingDays,
<a name="l00180"></a>00180 calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00181"></a>00181 boost::shared_ptr<RateHelper> d9m(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00182"></a>00182 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d9mRate),
<a name="l00183"></a>00183 9*Months, fixingDays,
<a name="l00184"></a>00184 calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00185"></a>00185 boost::shared_ptr<RateHelper> d1y(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_deposit_rate_helper.html">DepositRateHelper</a>(
<a name="l00186"></a>00186 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(d1yRate),
<a name="l00187"></a>00187 1*Years, fixingDays,
<a name="l00188"></a>00188 calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>, depositDayCounter));
<a name="l00189"></a>00189
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="comment">// setup FRAs</span>
<a name="l00192"></a>00192 boost::shared_ptr<RateHelper> fra3x6(<span class="keyword">new</span> <a name="_a16"></a><a class="code" href="class_quant_lib_1_1_fra_rate_helper.html">FraRateHelper</a>(
<a name="l00193"></a>00193 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fra3x6Rate),
<a name="l00194"></a>00194 3, 6, fixingDays, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00195"></a>00195 depositDayCounter));
<a name="l00196"></a>00196 boost::shared_ptr<RateHelper> fra6x9(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_fra_rate_helper.html">FraRateHelper</a>(
<a name="l00197"></a>00197 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fra6x9Rate),
<a name="l00198"></a>00198 6, 9, fixingDays, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00199"></a>00199 depositDayCounter));
<a name="l00200"></a>00200 boost::shared_ptr<RateHelper> fra6x12(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_fra_rate_helper.html">FraRateHelper</a>(
<a name="l00201"></a>00201 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fra6x12Rate),
<a name="l00202"></a>00202 6, 12, fixingDays, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00203"></a>00203 depositDayCounter));
<a name="l00204"></a>00204
<a name="l00205"></a>00205
<a name="l00206"></a>00206 <span class="comment">// setup futures</span>
<a name="l00207"></a>00207 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> convexityAdjustment = 0.0;
<a name="l00208"></a>00208 <a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> futMonths = 3;
<a name="l00209"></a>00209 <a class="code" href="class_quant_lib_1_1_date.html">Date</a> imm = Date::nextIMMdate(settlementDate);
<a name="l00210"></a>00210 boost::shared_ptr<RateHelper> fut1(<span class="keyword">new</span> <a name="_a17"></a><a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00211"></a>00211 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00212"></a>00212 imm,
<a name="l00213"></a>00213 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00214"></a>00214 depositDayCounter, convexityAdjustment));
<a name="l00215"></a>00215 imm = Date::nextIMMdate(imm+1);
<a name="l00216"></a>00216 boost::shared_ptr<RateHelper> fut2(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00217"></a>00217 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00218"></a>00218 imm,
<a name="l00219"></a>00219 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00220"></a>00220 depositDayCounter, convexityAdjustment));
<a name="l00221"></a>00221 imm = Date::nextIMMdate(imm+1);
<a name="l00222"></a>00222 boost::shared_ptr<RateHelper> fut3(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00223"></a>00223 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00224"></a>00224 imm,
<a name="l00225"></a>00225 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00226"></a>00226 depositDayCounter, convexityAdjustment));
<a name="l00227"></a>00227 imm = Date::nextIMMdate(imm+1);
<a name="l00228"></a>00228 boost::shared_ptr<RateHelper> fut4(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00229"></a>00229 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00230"></a>00230 imm,
<a name="l00231"></a>00231 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00232"></a>00232 depositDayCounter, convexityAdjustment));
<a name="l00233"></a>00233 imm = Date::nextIMMdate(imm+1);
<a name="l00234"></a>00234 boost::shared_ptr<RateHelper> fut5(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00235"></a>00235 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00236"></a>00236 imm,
<a name="l00237"></a>00237 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00238"></a>00238 depositDayCounter, convexityAdjustment));
<a name="l00239"></a>00239 imm = Date::nextIMMdate(imm+1);
<a name="l00240"></a>00240 boost::shared_ptr<RateHelper> fut6(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00241"></a>00241 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00242"></a>00242 imm,
<a name="l00243"></a>00243 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00244"></a>00244 depositDayCounter, convexityAdjustment));
<a name="l00245"></a>00245 imm = Date::nextIMMdate(imm+1);
<a name="l00246"></a>00246 boost::shared_ptr<RateHelper> fut7(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00247"></a>00247 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00248"></a>00248 imm,
<a name="l00249"></a>00249 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00250"></a>00250 depositDayCounter, convexityAdjustment));
<a name="l00251"></a>00251 imm = Date::nextIMMdate(imm+1);
<a name="l00252"></a>00252 boost::shared_ptr<RateHelper> fut8(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_futures_rate_helper.html">FuturesRateHelper</a>(
<a name="l00253"></a>00253 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(fut1Price),
<a name="l00254"></a>00254 imm,
<a name="l00255"></a>00255 futMonths, calendar, <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>,
<a name="l00256"></a>00256 depositDayCounter, convexityAdjustment));
<a name="l00257"></a>00257
<a name="l00258"></a>00258
<a name="l00259"></a>00259 <span class="comment">// setup swaps</span>
<a name="l00260"></a>00260 <a class="code" href="group__datetime.html#g6d41db8ba0ea90d22df35889df452ada">Frequency</a> swFixedLegFrequency = <a name="a18"></a><a class="code" href="group__datetime.html#gg6d41db8ba0ea90d22df35889df452ada508b18014c96e2d466c12b39d7f4e426">Annual</a>;
<a name="l00261"></a>00261 <a class="code" href="group__datetime.html#gff46c5ae9385d20709bedade86edd368">BusinessDayConvention</a> swFixedLegConvention = <a name="a19"></a><a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd3685fb8b90b7fdf1a3a228fbbc083e64547">Unadjusted</a>;
<a name="l00262"></a>00262 <a class="code" href="class_quant_lib_1_1_day_counter.html">DayCounter</a> swFixedLegDayCounter = <a name="_a20"></a><a class="code" href="class_quant_lib_1_1_thirty360.html">Thirty360</a>(Thirty360::European);
<a name="l00263"></a>00263 boost::shared_ptr<Xibor> swFloatingLegIndex(<span class="keyword">new</span> <a name="_a21"></a><a class="code" href="class_quant_lib_1_1_euribor6_m.html">Euribor6M</a>);
<a name="l00264"></a>00264
<a name="l00265"></a>00265 boost::shared_ptr<RateHelper> s2y(<span class="keyword">new</span> <a name="_a22"></a><a class="code" href="class_quant_lib_1_1_swap_rate_helper.html">SwapRateHelper</a>(
<a name="l00266"></a>00266 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(s2yRate),
<a name="l00267"></a>00267 2*Years, fixingDays,
<a name="l00268"></a>00268 calendar, swFixedLegFrequency,
<a name="l00269"></a>00269 swFixedLegConvention, swFixedLegDayCounter,
<a name="l00270"></a>00270 swFloatingLegIndex));
<a name="l00271"></a>00271 boost::shared_ptr<RateHelper> s3y(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_swap_rate_helper.html">SwapRateHelper</a>(
<a name="l00272"></a>00272 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(s3yRate),
<a name="l00273"></a>00273 3*Years, fixingDays,
<a name="l00274"></a>00274 calendar, swFixedLegFrequency,
<a name="l00275"></a>00275 swFixedLegConvention, swFixedLegDayCounter,
<a name="l00276"></a>00276 swFloatingLegIndex));
<a name="l00277"></a>00277 boost::shared_ptr<RateHelper> s5y(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_swap_rate_helper.html">SwapRateHelper</a>(
<a name="l00278"></a>00278 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(s5yRate),
<a name="l00279"></a>00279 5*Years, fixingDays,
<a name="l00280"></a>00280 calendar, swFixedLegFrequency,
<a name="l00281"></a>00281 swFixedLegConvention, swFixedLegDayCounter,
<a name="l00282"></a>00282 swFloatingLegIndex));
<a name="l00283"></a>00283 boost::shared_ptr<RateHelper> s10y(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_swap_rate_helper.html">SwapRateHelper</a>(
<a name="l00284"></a>00284 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(s10yRate),
<a name="l00285"></a>00285 10*Years, fixingDays,
<a name="l00286"></a>00286 calendar, swFixedLegFrequency,
<a name="l00287"></a>00287 swFixedLegConvention, swFixedLegDayCounter,
<a name="l00288"></a>00288 swFloatingLegIndex));
<a name="l00289"></a>00289 boost::shared_ptr<RateHelper> s15y(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_swap_rate_helper.html">SwapRateHelper</a>(
<a name="l00290"></a>00290 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(s15yRate),
<a name="l00291"></a>00291 15*Years, fixingDays,
<a name="l00292"></a>00292 calendar, swFixedLegFrequency,
<a name="l00293"></a>00293 swFixedLegConvention, swFixedLegDayCounter,
<a name="l00294"></a>00294 swFloatingLegIndex));
<a name="l00295"></a>00295
<a name="l00296"></a>00296
<a name="l00297"></a>00297 <span class="comment">/*********************</span>
<a name="l00298"></a>00298 <span class="comment"> ** CURVE BUILDING **</span>
<a name="l00299"></a>00299 <span class="comment"> *********************/</span>
<a name="l00300"></a>00300
<a name="l00301"></a>00301 <span class="comment">// Any DayCounter would be fine.</span>
<a name="l00302"></a>00302 <span class="comment">// ActualActual::ISDA ensures that 30 years is 30.0</span>
<a name="l00303"></a>00303 <a class="code" href="class_quant_lib_1_1_day_counter.html">DayCounter</a> termStructureDayCounter =
<a name="l00304"></a>00304 <a name="_a23"></a><a class="code" href="class_quant_lib_1_1_actual_actual.html">ActualActual</a>(ActualActual::ISDA);
<a name="l00305"></a>00305
<a name="l00306"></a>00306
<a name="l00307"></a>00307 <span class="keywordtype">double</span> tolerance = 1.0e-15;
<a name="l00308"></a>00308
<a name="l00309"></a>00309 <span class="comment">// A depo-swap curve</span>
<a name="l00310"></a>00310 std::vector<boost::shared_ptr<RateHelper> > depoSwapInstruments;
<a name="l00311"></a>00311 depoSwapInstruments.push_back(d1w);
<a name="l00312"></a>00312 depoSwapInstruments.push_back(d1m);
<a name="l00313"></a>00313 depoSwapInstruments.push_back(d3m);
<a name="l00314"></a>00314 depoSwapInstruments.push_back(d6m);
<a name="l00315"></a>00315 depoSwapInstruments.push_back(d9m);
<a name="l00316"></a>00316 depoSwapInstruments.push_back(d1y);
<a name="l00317"></a>00317 depoSwapInstruments.push_back(s2y);
<a name="l00318"></a>00318 depoSwapInstruments.push_back(s3y);
<a name="l00319"></a>00319 depoSwapInstruments.push_back(s5y);
<a name="l00320"></a>00320 depoSwapInstruments.push_back(s10y);
<a name="l00321"></a>00321 depoSwapInstruments.push_back(s15y);
<a name="l00322"></a>00322 boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(<span class="keyword">new</span>
<a name="l00323"></a>00323 <a name="a24"></a><a class="code" href="group__yieldtermstructures.html#g28315d9869896575fe9dde6a150f7c3b">PiecewiseFlatForward</a>(settlementDate, depoSwapInstruments,
<a name="l00324"></a>00324 termStructureDayCounter, tolerance));
<a name="l00325"></a>00325
<a name="l00326"></a>00326
<a name="l00327"></a>00327 <span class="comment">// A depo-futures-swap curve</span>
<a name="l00328"></a>00328 std::vector<boost::shared_ptr<RateHelper> > depoFutSwapInstruments;
<a name="l00329"></a>00329 depoFutSwapInstruments.push_back(d1w);
<a name="l00330"></a>00330 depoFutSwapInstruments.push_back(d1m);
<a name="l00331"></a>00331 depoFutSwapInstruments.push_back(fut1);
<a name="l00332"></a>00332 depoFutSwapInstruments.push_back(fut2);
<a name="l00333"></a>00333 depoFutSwapInstruments.push_back(fut3);
<a name="l00334"></a>00334 depoFutSwapInstruments.push_back(fut4);
<a name="l00335"></a>00335 depoFutSwapInstruments.push_back(fut5);
<a name="l00336"></a>00336 depoFutSwapInstruments.push_back(fut6);
<a name="l00337"></a>00337 depoFutSwapInstruments.push_back(fut7);
<a name="l00338"></a>00338 depoFutSwapInstruments.push_back(fut8);
<a name="l00339"></a>00339 depoFutSwapInstruments.push_back(s3y);
<a name="l00340"></a>00340 depoFutSwapInstruments.push_back(s5y);
<a name="l00341"></a>00341 depoFutSwapInstruments.push_back(s10y);
<a name="l00342"></a>00342 depoFutSwapInstruments.push_back(s15y);
<a name="l00343"></a>00343 boost::shared_ptr<YieldTermStructure> depoFutSwapTermStructure(<span class="keyword">new</span>
<a name="l00344"></a>00344 <a class="code" href="group__yieldtermstructures.html#g28315d9869896575fe9dde6a150f7c3b">PiecewiseFlatForward</a>(settlementDate, depoFutSwapInstruments,
<a name="l00345"></a>00345 termStructureDayCounter, tolerance));
<a name="l00346"></a>00346
<a name="l00347"></a>00347
<a name="l00348"></a>00348 <span class="comment">// A depo-FRA-swap curve</span>
<a name="l00349"></a>00349 std::vector<boost::shared_ptr<RateHelper> > depoFRASwapInstruments;
<a name="l00350"></a>00350 depoFRASwapInstruments.push_back(d1w);
<a name="l00351"></a>00351 depoFRASwapInstruments.push_back(d1m);
<a name="l00352"></a>00352 depoFRASwapInstruments.push_back(d3m);
<a name="l00353"></a>00353 depoFRASwapInstruments.push_back(fra3x6);
<a name="l00354"></a>00354 depoFRASwapInstruments.push_back(fra6x9);
<a name="l00355"></a>00355 depoFRASwapInstruments.push_back(fra6x12);
<a name="l00356"></a>00356 depoFRASwapInstruments.push_back(s2y);
<a name="l00357"></a>00357 depoFRASwapInstruments.push_back(s3y);
<a name="l00358"></a>00358 depoFRASwapInstruments.push_back(s5y);
<a name="l00359"></a>00359 depoFRASwapInstruments.push_back(s10y);
<a name="l00360"></a>00360 depoFRASwapInstruments.push_back(s15y);
<a name="l00361"></a>00361 boost::shared_ptr<YieldTermStructure> depoFRASwapTermStructure(<span class="keyword">new</span>
<a name="l00362"></a>00362 <a class="code" href="group__yieldtermstructures.html#g28315d9869896575fe9dde6a150f7c3b">PiecewiseFlatForward</a>(settlementDate, depoFRASwapInstruments,
<a name="l00363"></a>00363 termStructureDayCounter, tolerance));
<a name="l00364"></a>00364
<a name="l00365"></a>00365
<a name="l00366"></a>00366 <span class="comment">// Term structures that will be used for pricing:</span>
<a name="l00367"></a>00367 <span class="comment">// the one used for discounting cash flows</span>
<a name="l00368"></a>00368 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> discountingTermStructure;
<a name="l00369"></a>00369 <span class="comment">// the one used for forward rate forecasting</span>
<a name="l00370"></a>00370 <a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> forecastingTermStructure;
<a name="l00371"></a>00371
<a name="l00372"></a>00372
<a name="l00373"></a>00373 <span class="comment">/*********************</span>
<a name="l00374"></a>00374 <span class="comment"> * SWAPS TO BE PRICED *</span>
<a name="l00375"></a>00375 <span class="comment"> **********************/</span>
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <span class="comment">// constant nominal 1,000,000 Euro</span>
<a name="l00378"></a>00378 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> nominal = 1000000.0;
<a name="l00379"></a>00379 <span class="comment">// fixed leg</span>
<a name="l00380"></a>00380 <a class="code" href="group__datetime.html#g6d41db8ba0ea90d22df35889df452ada">Frequency</a> fixedLegFrequency = <a class="code" href="group__datetime.html#gg6d41db8ba0ea90d22df35889df452ada508b18014c96e2d466c12b39d7f4e426">Annual</a>;
<a name="l00381"></a>00381 <a class="code" href="group__datetime.html#gff46c5ae9385d20709bedade86edd368">BusinessDayConvention</a> fixedLegConvention = <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd3685fb8b90b7fdf1a3a228fbbc083e64547">Unadjusted</a>;
<a name="l00382"></a>00382 <a class="code" href="group__datetime.html#gff46c5ae9385d20709bedade86edd368">BusinessDayConvention</a> floatingLegConvention = <a class="code" href="group__datetime.html#ggff46c5ae9385d20709bedade86edd368013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>;
<a name="l00383"></a>00383 <a class="code" href="class_quant_lib_1_1_day_counter.html">DayCounter</a> fixedLegDayCounter = <a class="code" href="class_quant_lib_1_1_thirty360.html">Thirty360</a>(Thirty360::European);
<a name="l00384"></a>00384 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> fixedRate = 0.04;
<a name="l00385"></a>00385 <a class="code" href="class_quant_lib_1_1_day_counter.html">DayCounter</a> floatingLegDayCounter = <a class="code" href="class_quant_lib_1_1_actual360.html">Actual360</a>();
<a name="l00386"></a>00386
<a name="l00387"></a>00387 <span class="comment">// floating leg</span>
<a name="l00388"></a>00388 <a class="code" href="group__datetime.html#g6d41db8ba0ea90d22df35889df452ada">Frequency</a> floatingLegFrequency = <a name="a25"></a><a class="code" href="group__datetime.html#gg6d41db8ba0ea90d22df35889df452adad1a5868a1c314bb7f6ab68e2fa182b2d">Semiannual</a>;
<a name="l00389"></a>00389 boost::shared_ptr<Xibor> euriborIndex(
<a name="l00390"></a>00390 <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_euribor6_m.html">Euribor6M</a>(forecastingTermStructure));
<a name="l00391"></a>00391 <a name="a26"></a><a class="code" href="group__types.html#ge7427f4743503002b0c6eeeefae91a3d">Spread</a> spread = 0.0;
<a name="l00392"></a>00392
<a name="l00393"></a>00393 <a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> lenghtInYears = 5;
<a name="l00394"></a>00394 <span class="keywordtype">bool</span> payFixedRate = <span class="keyword">true</span>;
<a name="l00395"></a>00395
<a name="l00396"></a>00396 <a class="code" href="class_quant_lib_1_1_date.html">Date</a> maturity = settlementDate + lenghtInYears*Years;
<a name="l00397"></a>00397 <a name="_a27"></a><a class="code" href="class_quant_lib_1_1_schedule.html">Schedule</a> fixedSchedule(settlementDate, maturity, <a name="_a28"></a><a class="code" href="class_quant_lib_1_1_period.html">Period</a>(fixedLegFrequency),
<a name="l00398"></a>00398 calendar, fixedLegConvention, fixedLegConvention,
<a name="l00399"></a>00399 <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l00400"></a>00400 <a class="code" href="class_quant_lib_1_1_schedule.html">Schedule</a> floatSchedule(settlementDate, maturity, <a class="code" href="class_quant_lib_1_1_period.html">Period</a>(floatingLegFrequency),
<a name="l00401"></a>00401 calendar, floatingLegConvention, floatingLegConvention,
<a name="l00402"></a>00402 <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l00403"></a>00403 <a name="_a29"></a><a class="code" href="class_quant_lib_1_1_vanilla_swap.html">VanillaSwap</a> spot5YearSwap(
<a name="l00404"></a>00404 payFixedRate, nominal,
<a name="l00405"></a>00405 fixedSchedule, fixedRate, fixedLegDayCounter,
<a name="l00406"></a>00406 floatSchedule, euriborIndex, spread,
<a name="l00407"></a>00407 floatingLegDayCounter, discountingTermStructure);
<a name="l00408"></a>00408
<a name="l00409"></a>00409 <a class="code" href="class_quant_lib_1_1_date.html">Date</a> fwdStart = calendar.<a class="code" href="class_quant_lib_1_1_calendar.html#b3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(settlementDate, 1, Years);
<a name="l00410"></a>00410 <a class="code" href="class_quant_lib_1_1_date.html">Date</a> fwdMaturity = fwdStart + lenghtInYears*Years;
<a name="l00411"></a>00411 <a class="code" href="class_quant_lib_1_1_schedule.html">Schedule</a> fwdFixedSchedule(fwdStart, fwdMaturity, <a class="code" href="class_quant_lib_1_1_period.html">Period</a>(fixedLegFrequency),
<a name="l00412"></a>00412 calendar, fixedLegConvention, fixedLegConvention,
<a name="l00413"></a>00413 <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l00414"></a>00414 <a class="code" href="class_quant_lib_1_1_schedule.html">Schedule</a> fwdFloatSchedule(fwdStart, fwdMaturity, <a class="code" href="class_quant_lib_1_1_period.html">Period</a>(floatingLegFrequency),
<a name="l00415"></a>00415 calendar, floatingLegConvention, floatingLegConvention,
<a name="l00416"></a>00416 <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l00417"></a>00417 <a class="code" href="class_quant_lib_1_1_vanilla_swap.html">VanillaSwap</a> oneYearForward5YearSwap(
<a name="l00418"></a>00418 payFixedRate, nominal,
<a name="l00419"></a>00419 fwdFixedSchedule, fixedRate, fixedLegDayCounter,
<a name="l00420"></a>00420 fwdFloatSchedule, euriborIndex, spread,
<a name="l00421"></a>00421 floatingLegDayCounter, discountingTermStructure);
<a name="l00422"></a>00422
<a name="l00423"></a>00423
<a name="l00424"></a>00424 <span class="comment">/***************</span>
<a name="l00425"></a>00425 <span class="comment"> * SWAP PRICING *</span>
<a name="l00426"></a>00426 <span class="comment"> ****************/</span>
<a name="l00427"></a>00427
<a name="l00428"></a>00428 <span class="comment">// utilities for reporting</span>
<a name="l00429"></a>00429 std::vector<std::string> headers(4);
<a name="l00430"></a>00430 headers[0] = <span class="stringliteral">"term structure"</span>;
<a name="l00431"></a>00431 headers[1] = <span class="stringliteral">"net present value"</span>;
<a name="l00432"></a>00432 headers[2] = <span class="stringliteral">"fair spread"</span>;
<a name="l00433"></a>00433 headers[3] = <span class="stringliteral">"fair fixed rate"</span>;
<a name="l00434"></a>00434 std::string separator = <span class="stringliteral">" | "</span>;
<a name="l00435"></a>00435 <a name="a30"></a><a class="code" href="group__types.html#gf38bdb4c54463b1f456655efa95b5c77">Size</a> width = headers[0].size() + separator.size()
<a name="l00436"></a>00436 + headers[1].size() + separator.size()
<a name="l00437"></a>00437 + headers[2].size() + separator.size()
<a name="l00438"></a>00438 + headers[3].size() + separator.size() - 1;
<a name="l00439"></a>00439 std::string rule(width, <span class="charliteral">'-'</span>), dblrule(width, <span class="charliteral">'='</span>);
<a name="l00440"></a>00440 std::string tab(8, <span class="charliteral">' '</span>);
<a name="l00441"></a>00441
<a name="l00442"></a>00442 <span class="comment">// calculations</span>
<a name="l00443"></a>00443
<a name="l00444"></a>00444 std::cout << dblrule << std::endl;
<a name="l00445"></a>00445 std::cout << <span class="stringliteral">"5-year market swap-rate = "</span>
<a name="l00446"></a>00446 << std::setprecision(2) << <a name="a31"></a><a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(s5yRate->value())
<a name="l00447"></a>00447 << std::endl;
<a name="l00448"></a>00448 std::cout << dblrule << std::endl;
<a name="l00449"></a>00449
<a name="l00450"></a>00450 std::cout << tab << <span class="stringliteral">"5-years swap paying "</span>
<a name="l00451"></a>00451 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fixedRate) << std::endl;
<a name="l00452"></a>00452 std::cout << headers[0] << separator
<a name="l00453"></a>00453 << headers[1] << separator
<a name="l00454"></a>00454 << headers[2] << separator
<a name="l00455"></a>00455 << headers[3] << separator << std::endl;
<a name="l00456"></a>00456 std::cout << rule << std::endl;
<a name="l00457"></a>00457
<a name="l00458"></a>00458 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> NPV;
<a name="l00459"></a>00459 <a class="code" href="group__types.html#gede435af51236692b1107d7639581d39">Rate</a> fairRate;
<a name="l00460"></a>00460 <a class="code" href="group__types.html#ge7427f4743503002b0c6eeeefae91a3d">Spread</a> fairSpread;
<a name="l00461"></a>00461
<a name="l00462"></a>00462 <span class="comment">// Of course, you're not forced to really use different curves</span>
<a name="l00463"></a>00463 forecastingTermStructure.<a name="a32"></a><a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00464"></a>00464 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00465"></a>00465
<a name="l00466"></a>00466 NPV = spot5YearSwap.NPV();
<a name="l00467"></a>00467 fairSpread = spot5YearSwap.fairSpread();
<a name="l00468"></a>00468 fairRate = spot5YearSwap.fairRate();
<a name="l00469"></a>00469
<a name="l00470"></a>00470 std::cout << std::setw(headers[0].size())
<a name="l00471"></a>00471 << <span class="stringliteral">"depo-swap"</span> << separator;
<a name="l00472"></a>00472 std::cout << std::setw(headers[1].size())
<a name="l00473"></a>00473 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00474"></a>00474 std::cout << std::setw(headers[2].size())
<a name="l00475"></a>00475 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00476"></a>00476 std::cout << std::setw(headers[3].size())
<a name="l00477"></a>00477 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00478"></a>00478 std::cout << std::endl;
<a name="l00479"></a>00479
<a name="l00480"></a>00480
<a name="l00481"></a>00481 <span class="comment">// let's check that the 5 years swap has been correctly re-priced</span>
<a name="l00482"></a>00482 <a name="a33"></a><a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yQuote)<1e-8,
<a name="l00483"></a>00483 <span class="stringliteral">"5-years swap mispriced by "</span>
<a name="l00484"></a>00484 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(std::fabs(fairRate-s5yQuote)));
<a name="l00485"></a>00485
<a name="l00486"></a>00486
<a name="l00487"></a>00487 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00488"></a>00488 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00489"></a>00489
<a name="l00490"></a>00490 NPV = spot5YearSwap.NPV();
<a name="l00491"></a>00491 fairSpread = spot5YearSwap.fairSpread();
<a name="l00492"></a>00492 fairRate = spot5YearSwap.fairRate();
<a name="l00493"></a>00493
<a name="l00494"></a>00494 std::cout << std::setw(headers[0].size())
<a name="l00495"></a>00495 << <span class="stringliteral">"depo-fut-swap"</span> << separator;
<a name="l00496"></a>00496 std::cout << std::setw(headers[1].size())
<a name="l00497"></a>00497 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00498"></a>00498 std::cout << std::setw(headers[2].size())
<a name="l00499"></a>00499 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00500"></a>00500 std::cout << std::setw(headers[3].size())
<a name="l00501"></a>00501 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00502"></a>00502 std::cout << std::endl;
<a name="l00503"></a>00503
<a name="l00504"></a>00504 <a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yQuote)<1e-8,
<a name="l00505"></a>00505 <span class="stringliteral">"5-years swap mispriced!"</span>);
<a name="l00506"></a>00506
<a name="l00507"></a>00507
<a name="l00508"></a>00508 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00509"></a>00509 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00510"></a>00510
<a name="l00511"></a>00511 NPV = spot5YearSwap.NPV();
<a name="l00512"></a>00512 fairSpread = spot5YearSwap.fairSpread();
<a name="l00513"></a>00513 fairRate = spot5YearSwap.fairRate();
<a name="l00514"></a>00514
<a name="l00515"></a>00515 std::cout << std::setw(headers[0].size())
<a name="l00516"></a>00516 << <span class="stringliteral">"depo-FRA-swap"</span> << separator;
<a name="l00517"></a>00517 std::cout << std::setw(headers[1].size())
<a name="l00518"></a>00518 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00519"></a>00519 std::cout << std::setw(headers[2].size())
<a name="l00520"></a>00520 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00521"></a>00521 std::cout << std::setw(headers[3].size())
<a name="l00522"></a>00522 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00523"></a>00523 std::cout << std::endl;
<a name="l00524"></a>00524
<a name="l00525"></a>00525 <a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yQuote)<1e-8,
<a name="l00526"></a>00526 <span class="stringliteral">"5-years swap mispriced!"</span>);
<a name="l00527"></a>00527
<a name="l00528"></a>00528
<a name="l00529"></a>00529 std::cout << rule << std::endl;
<a name="l00530"></a>00530
<a name="l00531"></a>00531 <span class="comment">// now let's price the 1Y forward 5Y swap</span>
<a name="l00532"></a>00532
<a name="l00533"></a>00533 std::cout << tab << <span class="stringliteral">"5-years, 1-year forward swap paying "</span>
<a name="l00534"></a>00534 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fixedRate) << std::endl;
<a name="l00535"></a>00535 std::cout << headers[0] << separator
<a name="l00536"></a>00536 << headers[1] << separator
<a name="l00537"></a>00537 << headers[2] << separator
<a name="l00538"></a>00538 << headers[3] << separator << std::endl;
<a name="l00539"></a>00539 std::cout << rule << std::endl;
<a name="l00540"></a>00540
<a name="l00541"></a>00541
<a name="l00542"></a>00542 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00543"></a>00543 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00544"></a>00544
<a name="l00545"></a>00545 NPV = oneYearForward5YearSwap.NPV();
<a name="l00546"></a>00546 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00547"></a>00547 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00548"></a>00548
<a name="l00549"></a>00549 std::cout << std::setw(headers[0].size())
<a name="l00550"></a>00550 << <span class="stringliteral">"depo-swap"</span> << separator;
<a name="l00551"></a>00551 std::cout << std::setw(headers[1].size())
<a name="l00552"></a>00552 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00553"></a>00553 std::cout << std::setw(headers[2].size())
<a name="l00554"></a>00554 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00555"></a>00555 std::cout << std::setw(headers[3].size())
<a name="l00556"></a>00556 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00557"></a>00557 std::cout << std::endl;
<a name="l00558"></a>00558
<a name="l00559"></a>00559
<a name="l00560"></a>00560 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00561"></a>00561 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00562"></a>00562
<a name="l00563"></a>00563 NPV = oneYearForward5YearSwap.NPV();
<a name="l00564"></a>00564 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00565"></a>00565 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00566"></a>00566
<a name="l00567"></a>00567 std::cout << std::setw(headers[0].size())
<a name="l00568"></a>00568 << <span class="stringliteral">"depo-fut-swap"</span> << separator;
<a name="l00569"></a>00569 std::cout << std::setw(headers[1].size())
<a name="l00570"></a>00570 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00571"></a>00571 std::cout << std::setw(headers[2].size())
<a name="l00572"></a>00572 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00573"></a>00573 std::cout << std::setw(headers[3].size())
<a name="l00574"></a>00574 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00575"></a>00575 std::cout << std::endl;
<a name="l00576"></a>00576
<a name="l00577"></a>00577
<a name="l00578"></a>00578 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00579"></a>00579 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00580"></a>00580
<a name="l00581"></a>00581 NPV = oneYearForward5YearSwap.NPV();
<a name="l00582"></a>00582 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00583"></a>00583 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00584"></a>00584
<a name="l00585"></a>00585 std::cout << std::setw(headers[0].size())
<a name="l00586"></a>00586 << <span class="stringliteral">"depo-FRA-swap"</span> << separator;
<a name="l00587"></a>00587 std::cout << std::setw(headers[1].size())
<a name="l00588"></a>00588 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00589"></a>00589 std::cout << std::setw(headers[2].size())
<a name="l00590"></a>00590 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00591"></a>00591 std::cout << std::setw(headers[3].size())
<a name="l00592"></a>00592 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00593"></a>00593 std::cout << std::endl;
<a name="l00594"></a>00594
<a name="l00595"></a>00595
<a name="l00596"></a>00596 <span class="comment">// now let's say that the 5-years swap rate goes up to 4.60%.</span>
<a name="l00597"></a>00597 <span class="comment">// A smarter market element--say, connected to a data source-- would</span>
<a name="l00598"></a>00598 <span class="comment">// notice the change itself. Since we're using SimpleQuotes,</span>
<a name="l00599"></a>00599 <span class="comment">// we'll have to change the value manually--which forces us to</span>
<a name="l00600"></a>00600 <span class="comment">// downcast the handle and use the SimpleQuote</span>
<a name="l00601"></a>00601 <span class="comment">// interface. In any case, the point here is that a change in the</span>
<a name="l00602"></a>00602 <span class="comment">// value contained in the Quote triggers a new bootstrapping</span>
<a name="l00603"></a>00603 <span class="comment">// of the curve and a repricing of the swap.</span>
<a name="l00604"></a>00604
<a name="l00605"></a>00605 boost::shared_ptr<SimpleQuote> fiveYearsRate =
<a name="l00606"></a>00606 boost::dynamic_pointer_cast<SimpleQuote>(s5yRate);
<a name="l00607"></a>00607 fiveYearsRate->setValue(0.0460);
<a name="l00608"></a>00608
<a name="l00609"></a>00609 std::cout << dblrule << std::endl;
<a name="l00610"></a>00610 std::cout << <span class="stringliteral">"5-year market swap-rate = "</span>
<a name="l00611"></a>00611 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(s5yRate->value()) << std::endl;
<a name="l00612"></a>00612 std::cout << dblrule << std::endl;
<a name="l00613"></a>00613
<a name="l00614"></a>00614 std::cout << tab << <span class="stringliteral">"5-years swap paying "</span>
<a name="l00615"></a>00615 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fixedRate) << std::endl;
<a name="l00616"></a>00616 std::cout << headers[0] << separator
<a name="l00617"></a>00617 << headers[1] << separator
<a name="l00618"></a>00618 << headers[2] << separator
<a name="l00619"></a>00619 << headers[3] << separator << std::endl;
<a name="l00620"></a>00620 std::cout << rule << std::endl;
<a name="l00621"></a>00621
<a name="l00622"></a>00622 <span class="comment">// now get the updated results</span>
<a name="l00623"></a>00623 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00624"></a>00624 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00625"></a>00625
<a name="l00626"></a>00626 NPV = spot5YearSwap.NPV();
<a name="l00627"></a>00627 fairSpread = spot5YearSwap.fairSpread();
<a name="l00628"></a>00628 fairRate = spot5YearSwap.fairRate();
<a name="l00629"></a>00629
<a name="l00630"></a>00630 std::cout << std::setw(headers[0].size())
<a name="l00631"></a>00631 << <span class="stringliteral">"depo-swap"</span> << separator;
<a name="l00632"></a>00632 std::cout << std::setw(headers[1].size())
<a name="l00633"></a>00633 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00634"></a>00634 std::cout << std::setw(headers[2].size())
<a name="l00635"></a>00635 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00636"></a>00636 std::cout << std::setw(headers[3].size())
<a name="l00637"></a>00637 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00638"></a>00638 std::cout << std::endl;
<a name="l00639"></a>00639
<a name="l00640"></a>00640 <a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yRate->value())<1e-8,
<a name="l00641"></a>00641 <span class="stringliteral">"5-years swap mispriced!"</span>);
<a name="l00642"></a>00642
<a name="l00643"></a>00643
<a name="l00644"></a>00644 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00645"></a>00645 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00646"></a>00646
<a name="l00647"></a>00647 NPV = spot5YearSwap.NPV();
<a name="l00648"></a>00648 fairSpread = spot5YearSwap.fairSpread();
<a name="l00649"></a>00649 fairRate = spot5YearSwap.fairRate();
<a name="l00650"></a>00650
<a name="l00651"></a>00651 std::cout << std::setw(headers[0].size())
<a name="l00652"></a>00652 << <span class="stringliteral">"depo-fut-swap"</span> << separator;
<a name="l00653"></a>00653 std::cout << std::setw(headers[1].size())
<a name="l00654"></a>00654 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00655"></a>00655 std::cout << std::setw(headers[2].size())
<a name="l00656"></a>00656 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00657"></a>00657 std::cout << std::setw(headers[3].size())
<a name="l00658"></a>00658 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00659"></a>00659 std::cout << std::endl;
<a name="l00660"></a>00660
<a name="l00661"></a>00661 <a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yRate->value())<1e-8,
<a name="l00662"></a>00662 <span class="stringliteral">"5-years swap mispriced!"</span>);
<a name="l00663"></a>00663
<a name="l00664"></a>00664
<a name="l00665"></a>00665 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00666"></a>00666 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00667"></a>00667
<a name="l00668"></a>00668 NPV = spot5YearSwap.NPV();
<a name="l00669"></a>00669 fairSpread = spot5YearSwap.fairSpread();
<a name="l00670"></a>00670 fairRate = spot5YearSwap.fairRate();
<a name="l00671"></a>00671
<a name="l00672"></a>00672 std::cout << std::setw(headers[0].size())
<a name="l00673"></a>00673 << <span class="stringliteral">"depo-FRA-swap"</span> << separator;
<a name="l00674"></a>00674 std::cout << std::setw(headers[1].size())
<a name="l00675"></a>00675 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00676"></a>00676 std::cout << std::setw(headers[2].size())
<a name="l00677"></a>00677 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00678"></a>00678 std::cout << std::setw(headers[3].size())
<a name="l00679"></a>00679 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00680"></a>00680 std::cout << std::endl;
<a name="l00681"></a>00681
<a name="l00682"></a>00682 <a class="code" href="errors_8hpp.html#7a9bcab8006882bc7d5302a0861ab1a6">QL_REQUIRE</a>(std::fabs(fairRate-s5yRate->value())<1e-8,
<a name="l00683"></a>00683 <span class="stringliteral">"5-years swap mispriced!"</span>);
<a name="l00684"></a>00684
<a name="l00685"></a>00685 std::cout << rule << std::endl;
<a name="l00686"></a>00686
<a name="l00687"></a>00687 <span class="comment">// the 1Y forward 5Y swap changes as well</span>
<a name="l00688"></a>00688
<a name="l00689"></a>00689 std::cout << tab << <span class="stringliteral">"5-years, 1-year forward swap paying "</span>
<a name="l00690"></a>00690 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fixedRate) << std::endl;
<a name="l00691"></a>00691 std::cout << headers[0] << separator
<a name="l00692"></a>00692 << headers[1] << separator
<a name="l00693"></a>00693 << headers[2] << separator
<a name="l00694"></a>00694 << headers[3] << separator << std::endl;
<a name="l00695"></a>00695 std::cout << rule << std::endl;
<a name="l00696"></a>00696
<a name="l00697"></a>00697
<a name="l00698"></a>00698 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00699"></a>00699 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoSwapTermStructure);
<a name="l00700"></a>00700
<a name="l00701"></a>00701 NPV = oneYearForward5YearSwap.NPV();
<a name="l00702"></a>00702 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00703"></a>00703 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00704"></a>00704
<a name="l00705"></a>00705 std::cout << std::setw(headers[0].size())
<a name="l00706"></a>00706 << <span class="stringliteral">"depo-swap"</span> << separator;
<a name="l00707"></a>00707 std::cout << std::setw(headers[1].size())
<a name="l00708"></a>00708 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00709"></a>00709 std::cout << std::setw(headers[2].size())
<a name="l00710"></a>00710 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00711"></a>00711 std::cout << std::setw(headers[3].size())
<a name="l00712"></a>00712 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00713"></a>00713 std::cout << std::endl;
<a name="l00714"></a>00714
<a name="l00715"></a>00715
<a name="l00716"></a>00716 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00717"></a>00717 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFutSwapTermStructure);
<a name="l00718"></a>00718
<a name="l00719"></a>00719 NPV = oneYearForward5YearSwap.NPV();
<a name="l00720"></a>00720 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00721"></a>00721 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00722"></a>00722
<a name="l00723"></a>00723 std::cout << std::setw(headers[0].size())
<a name="l00724"></a>00724 << <span class="stringliteral">"depo-fut-swap"</span> << separator;
<a name="l00725"></a>00725 std::cout << std::setw(headers[1].size())
<a name="l00726"></a>00726 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00727"></a>00727 std::cout << std::setw(headers[2].size())
<a name="l00728"></a>00728 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00729"></a>00729 std::cout << std::setw(headers[3].size())
<a name="l00730"></a>00730 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00731"></a>00731 std::cout << std::endl;
<a name="l00732"></a>00732
<a name="l00733"></a>00733
<a name="l00734"></a>00734 forecastingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00735"></a>00735 discountingTermStructure.<a class="code" href="class_quant_lib_1_1_handle.html#7eec88ccb240dcc59ac81e7347c335bd">linkTo</a>(depoFRASwapTermStructure);
<a name="l00736"></a>00736
<a name="l00737"></a>00737 NPV = oneYearForward5YearSwap.NPV();
<a name="l00738"></a>00738 fairSpread = oneYearForward5YearSwap.fairSpread();
<a name="l00739"></a>00739 fairRate = oneYearForward5YearSwap.fairRate();
<a name="l00740"></a>00740
<a name="l00741"></a>00741 std::cout << std::setw(headers[0].size())
<a name="l00742"></a>00742 << <span class="stringliteral">"depo-FRA-swap"</span> << separator;
<a name="l00743"></a>00743 std::cout << std::setw(headers[1].size())
<a name="l00744"></a>00744 << std::fixed << std::setprecision(2) << NPV << separator;
<a name="l00745"></a>00745 std::cout << std::setw(headers[2].size())
<a name="l00746"></a>00746 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairSpread) << separator;
<a name="l00747"></a>00747 std::cout << std::setw(headers[3].size())
<a name="l00748"></a>00748 << <a class="code" href="group__manips.html#gc63ea3dad10259db3764c7d15a61cde5">io::rate</a>(fairRate) << separator;
<a name="l00749"></a>00749 std::cout << std::endl;
<a name="l00750"></a>00750
<a name="l00751"></a>00751 <a class="code" href="group__types.html#g4bdf4bfe76b9ffa6fa64c47d8bfa0c78">Real</a> seconds = timer.elapsed();
<a name="l00752"></a>00752 <a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> hours = int(seconds/3600);
<a name="l00753"></a>00753 seconds -= hours * 3600;
<a name="l00754"></a>00754 <a class="code" href="group__types.html#gb9c87440c314438e51a899a03d2442d0">Integer</a> minutes = int(seconds/60);
<a name="l00755"></a>00755 seconds -= minutes * 60;
<a name="l00756"></a>00756 std::cout << <span class="stringliteral">" \nRun completed in "</span>;
<a name="l00757"></a>00757 <span class="keywordflow">if</span> (hours > 0)
<a name="l00758"></a>00758 std::cout << hours << <span class="stringliteral">" h "</span>;
<a name="l00759"></a>00759 <span class="keywordflow">if</span> (hours > 0 || minutes > 0)
<a name="l00760"></a>00760 std::cout << minutes << <span class="stringliteral">" m "</span>;
<a name="l00761"></a>00761 std::cout << std::fixed << std::setprecision(0)
<a name="l00762"></a>00762 << seconds << <span class="stringliteral">" s\n"</span> << std::endl;
<a name="l00763"></a>00763
<a name="l00764"></a>00764 <span class="keywordflow">return</span> 0;
<a name="l00765"></a>00765
<a name="l00766"></a>00766 } <span class="keywordflow">catch</span> (std::exception& e) {
<a name="l00767"></a>00767 std::cout << e.what() << std::endl;
<a name="l00768"></a>00768 <span class="keywordflow">return</span> 1;
<a name="l00769"></a>00769 } <span class="keywordflow">catch</span> (...) {
<a name="l00770"></a>00770 std::cout << <span class="stringliteral">"unknown error"</span> << std::endl;
<a name="l00771"></a>00771 <span class="keywordflow">return</span> 1;
<a name="l00772"></a>00772 }
<a name="l00773"></a>00773 }
<a name="l00774"></a>00774
</pre></div>
</div>
<div class="footer">
<table align="top" width="100%">
<tr>
<td align="middle" width="33%">
<strong>QuantLib.org</strong><br>
<a href="http://quantlib.org/">
<img src="QL-small.jpg" alt="QuantLib" align="middle" border=0>
</a>
</td>
<td align="middle" width="33%">
<strong>Hosted by</strong><br>
<a href="http://sourceforge.net"><img src=
"sfnetlogo.png" width="88" height="31"
border="0" alt="SourceForge.net Logo"></a>
</td>
<td align="middle" width="33%">
<strong>Documentation generated by</strong><br>
<a href="http://www.doxygen.org">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53>
</a></td>
</tr>
</table>
</div>
</div>
</body>
</html>
|