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
|
<!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: ConvertibleBonds.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&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&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">ConvertibleBonds.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>For a given set of option parameters, this example computes the value of a convertible bond with an embedded put option for two different equity options types (with european and american exercise features) using the Tsiveriotis-Fernandes method with different implied tree algorithms. The tree types are Jarrow-Rudd, Cox-Ross-Rubinstein, Additive equiprobabilities, Trigeorgis, Tian and Leisen-Reimer.</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="preprocessor">#include <ql/qldefines.hpp></span></div>
<div class="line"><span class="preprocessor">#ifdef BOOST_MSVC</span></div>
<div class="line"><span class="preprocessor"># include <ql/auto_link.hpp></span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor">#include <ql/experimental/convertiblebonds/convertiblebond.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/experimental/convertiblebonds/binomialconvertibleengine.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/time/calendars/target.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/time/daycounters/thirty360.hpp></span></div>
<div class="line"><span class="preprocessor">#include <ql/utilities/dataformatters.hpp></span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <iostream></span></div>
<div class="line"><span class="preprocessor">#include <iomanip></span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define LENGTH(a) (sizeof(a)/sizeof(a[0]))</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a>;</div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if defined(QL_ENABLE_SESSIONS)</span></div>
<div class="line"><span class="keyword">namespace </span><a class="code" href="namespace_quant_lib.html">QuantLib</a> {</div>
<div class="line"> </div>
<div class="line"> ThreadKey sessionId() { <span class="keywordflow">return</span> 0; }</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"> </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 << std::endl;</div>
<div class="line"> </div>
<div class="line"> Option::Type type(Option::Put);</div>
<div class="line"> <a name="a0"></a><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> underlying = 36.0;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> spreadRate = 0.005;</div>
<div class="line"> </div>
<div class="line"> <a name="a1"></a><a class="code" href="group__types.html#gae7427f4743503002b0c6eeeefae91a3d" title="spreads on interest rates">Spread</a> dividendYield = 0.02;</div>
<div class="line"> <a name="a2"></a><a class="code" href="group__types.html#gaede435af51236692b1107d7639581d39" title="interest rates">Rate</a> riskFreeRate = 0.06;</div>
<div class="line"> <a name="a3"></a><a class="code" href="group__types.html#gaaa95ab7fe66935e3f7535413fad2a7d3" title="volatility">Volatility</a> <a name="a4"></a><a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a> = 0.20;</div>
<div class="line"> </div>
<div class="line"> <a name="a5"></a><a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> settlementDays = 3;</div>
<div class="line"> <a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> length = 5;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> redemption = 100.0;</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> conversionRatio = redemption/underlying; <span class="comment">// at the money</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// set up dates/schedules</span></div>
<div class="line"> <a name="_a6"></a><a class="code" href="class_quant_lib_1_1_calendar.html" title="calendar class">Calendar</a> calendar = <a name="_a7"></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="_a8"></a><a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> today = calendar.<a name="a9"></a><a class="code" href="class_quant_lib_1_1_calendar.html#a712629806d9ef9a39f8144f368c81e4b">adjust</a>(<a name="a10"></a><a class="code" href="class_quant_lib_1_1_date.html#aa3b3414c408337e640d21c0936602c66" title="today's date.">Date::todaysDate</a>());</div>
<div class="line"> </div>
<div class="line"> <a name="a11"></a><a class="code" href="class_quant_lib_1_1_singleton.html#ab7455b7e1235d292c444095842349291" title="access to the unique instance">Settings::instance</a>().evaluationDate() = today;</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> settlementDate = calendar.<a name="a12"></a><a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(today, settlementDays, Days);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> exerciseDate = calendar.<a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(settlementDate, length, Years);</div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> issueDate = calendar.<a class="code" href="class_quant_lib_1_1_calendar.html#ab3fc4d2c4ba5243c3f5d51dcb3077ceb">advance</a>(exerciseDate, -length, Years);</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__datetime.html#gaff46c5ae9385d20709bedade86edd368" title="Business Day conventions.">BusinessDayConvention</a> convention = <a name="a13"></a><a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a013e092c359f6031cc0563fd413ce707">ModifiedFollowing</a>;</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__datetime.html#ga6d41db8ba0ea90d22df35889df452ada" title="Frequency of events.">Frequency</a> frequency = <a name="a14"></a><a class="code" href="group__datetime.html#gga6d41db8ba0ea90d22df35889df452adaa508b18014c96e2d466c12b39d7f4e426" title="once a year">Annual</a>;</div>
<div class="line"> </div>
<div class="line"> <a name="_a15"></a><a class="code" href="class_quant_lib_1_1_schedule.html" title="Payment schedule.">Schedule</a> schedule(issueDate, exerciseDate,</div>
<div class="line"> <a name="_a16"></a><a class="code" href="class_quant_lib_1_1_period.html">Period</a>(frequency), calendar,</div>
<div class="line"> convention, convention,</div>
<div class="line"> <a name="a17"></a><a class="code" href="struct_quant_lib_1_1_date_generation.html#a11fcd51ef86118f65e603c1474377a78a67e19347f85332c3bbfd61266cecbe4e">DateGeneration::Backward</a>, <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line"> DividendSchedule dividends;</div>
<div class="line"> CallabilitySchedule callability;</div>
<div class="line"> </div>
<div class="line"> std::vector<Real> coupons(1, 0.05);</div>
<div class="line"> </div>
<div class="line"> <a name="_a18"></a><a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> bondDayCount = <a name="_a19"></a><a class="code" href="class_quant_lib_1_1_thirty360.html" title="30/360 day count convention">Thirty360</a>();</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> callLength[] = { 2, 4 }; <span class="comment">// Call dates, years 2, 4.</span></div>
<div class="line"> <a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> putLength[] = { 3 }; <span class="comment">// Put dates year 3</span></div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> callPrices[] = { 101.5, 100.85 };</div>
<div class="line"> <a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> putPrices[]= { 105.0 };</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Load call schedules</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<LENGTH(callLength); i++) {</div>
<div class="line"> callability.push_back(</div>
<div class="line"> ext::make_shared<SoftCallability>(<a name="_a20"></a><a class="code" href="class_quant_lib_1_1_bond_1_1_price.html" title="Bond price information.">Bond::Price</a>(callPrices[i],</div>
<div class="line"> Bond::Price::Clean),</div>
<div class="line"> schedule.date(callLength[i]),</div>
<div class="line"> 1.20));</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> j=0; j<LENGTH(putLength); j++) {</div>
<div class="line"> callability.push_back(</div>
<div class="line"> ext::make_shared<Callability>(<a class="code" href="class_quant_lib_1_1_bond_1_1_price.html" title="Bond price information.">Bond::Price</a>(putPrices[j],</div>
<div class="line"> Bond::Price::Clean),</div>
<div class="line"> Callability::Put,</div>
<div class="line"> schedule.date(putLength[j])));</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Assume dividends are paid every 6 months.</span></div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> d = today + 6*Months; d < exerciseDate; d += 6*Months) {</div>
<div class="line"> dividends.push_back(</div>
<div class="line"> ext::shared_ptr<Dividend>(<span class="keyword">new</span> <a name="_a21"></a><a class="code" href="class_quant_lib_1_1_fixed_dividend.html" title="Predetermined cash flow.">FixedDividend</a>(1.0, d)));</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> dayCounter = <a name="_a22"></a><a class="code" href="class_quant_lib_1_1_actual365_fixed.html" title="Actual/365 (Fixed) day count convention.">Actual365Fixed</a>();</div>
<div class="line"> <a name="a23"></a><a class="code" href="group__types.html#ga14fb8fca43a68f4168654e1f9f7e22f7" title="continuous quantity with 1-year units">Time</a> maturity = dayCounter.<a name="a24"></a><a class="code" href="class_quant_lib_1_1_day_counter.html#a28170faaec75755611ff6fc220c1fab8" title="Returns the period between two dates as a fraction of year.">yearFraction</a>(settlementDate,</div>
<div class="line"> exerciseDate);</div>
<div class="line"> </div>
<div class="line"> std::cout << <span class="stringliteral">"option type = "</span> << type << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Time to maturity = "</span> << maturity</div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Underlying price = "</span> << underlying</div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Risk-free interest rate = "</span> << <a name="a25"></a><a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">io::rate</a>(riskFreeRate)</div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Dividend yield = "</span> << <a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">io::rate</a>(dividendYield)</div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Volatility = "</span> << <a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">io::volatility</a>(<a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>)</div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << std::endl;</div>
<div class="line"> </div>
<div class="line"> std::string method;</div>
<div class="line"> std::cout << std::endl ;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// write column headings</span></div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> widths[] = { 35, 14, 14 };</div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> totalWidth = widths[0] + widths[1] + widths[2];</div>
<div class="line"> std::string rule(totalWidth, <span class="charliteral">'-'</span>), dblrule(totalWidth, <span class="charliteral">'='</span>);</div>
<div class="line"> </div>
<div class="line"> std::cout << dblrule << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"Tsiveriotis-Fernandes method"</span> << std::endl;</div>
<div class="line"> std::cout << dblrule << std::endl;</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << <span class="stringliteral">"Tree type"</span></div>
<div class="line"> << std::setw(widths[1]) << std::left << <span class="stringliteral">"European"</span></div>
<div class="line"> << std::setw(widths[1]) << std::left << <span class="stringliteral">"American"</span></div>
<div class="line"> << std::endl;</div>
<div class="line"> std::cout << rule << std::endl;</div>
<div class="line"> </div>
<div class="line"> ext::shared_ptr<Exercise> exercise(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a26"></a><a class="code" href="class_quant_lib_1_1_european_exercise.html" title="European exercise.">EuropeanExercise</a>(exerciseDate));</div>
<div class="line"> ext::shared_ptr<Exercise> amExercise(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a27"></a><a class="code" href="class_quant_lib_1_1_american_exercise.html" title="American exercise.">AmericanExercise</a>(settlementDate,</div>
<div class="line"> exerciseDate));</div>
<div class="line"> </div>
<div class="line"> <a name="_a28"></a><a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle<Quote></a> underlyingH(</div>
<div class="line"> ext::shared_ptr<Quote>(<span class="keyword">new</span> <a name="_a29"></a><a class="code" href="class_quant_lib_1_1_simple_quote.html" title="market element returning a stored value">SimpleQuote</a>(underlying)));</div>
<div class="line"> </div>
<div class="line"> <a name="_a30"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> flatTermStructure(</div>
<div class="line"> ext::shared_ptr<YieldTermStructure>(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a31"></a><a class="code" href="class_quant_lib_1_1_flat_forward.html" title="Flat interest-rate curve.">FlatForward</a>(settlementDate, riskFreeRate, dayCounter)));</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> flatDividendTS(</div>
<div class="line"> ext::shared_ptr<YieldTermStructure>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_flat_forward.html" title="Flat interest-rate curve.">FlatForward</a>(settlementDate, dividendYield, dayCounter)));</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle<BlackVolTermStructure></a> flatVolTS(</div>
<div class="line"> ext::shared_ptr<BlackVolTermStructure>(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a32"></a><a class="code" href="class_quant_lib_1_1_black_constant_vol.html" title="Constant Black volatility, no time-strike dependence.">BlackConstantVol</a>(settlementDate, calendar,</div>
<div class="line"> <a class="code" href="group__manips.html#gac402ef7c87f63f7c603ee87210b5750c" title="output volatilities as percentages">volatility</a>, dayCounter)));</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> ext::shared_ptr<BlackScholesMertonProcess> stochasticProcess(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a33"></a><a class="code" href="class_quant_lib_1_1_black_scholes_merton_process.html" title="Merton (1973) extension to the Black-Scholes stochastic process.">BlackScholesMertonProcess</a>(underlyingH,</div>
<div class="line"> flatDividendTS,</div>
<div class="line"> flatTermStructure,</div>
<div class="line"> flatVolTS));</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> timeSteps = 801;</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle<Quote></a> creditSpread(</div>
<div class="line"> ext::shared_ptr<Quote>(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html" title="market element returning a stored value">SimpleQuote</a>(spreadRate)));</div>
<div class="line"> </div>
<div class="line"> ext::shared_ptr<Quote> <a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">rate</a>(<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_simple_quote.html" title="market element returning a stored value">SimpleQuote</a>(riskFreeRate));</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> discountCurve(</div>
<div class="line"> ext::shared_ptr<YieldTermStructure>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_flat_forward.html" title="Flat interest-rate curve.">FlatForward</a>(today, <a class="code" href="class_quant_lib_1_1_handle.html" title="Shared handle to an observable.">Handle<Quote></a>(<a class="code" href="group__manips.html#gac63ea3dad10259db3764c7d15a61cde5" title="output rates and spreads as percentages">rate</a>), dayCounter)));</div>
<div class="line"> </div>
<div class="line"> ext::shared_ptr<PricingEngine> engine(</div>
<div class="line"> <span class="keyword">new</span> <a name="_a34"></a><a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<JarrowRudd></a>(stochasticProcess,</div>
<div class="line"> timeSteps));</div>
<div class="line"> </div>
<div class="line"> <a name="_a35"></a><a class="code" href="class_quant_lib_1_1_convertible_fixed_coupon_bond.html" title="convertible fixed-coupon bond">ConvertibleFixedCouponBond</a> europeanBond(</div>
<div class="line"> exercise, conversionRatio, dividends, callability,</div>
<div class="line"> creditSpread, issueDate, settlementDays,</div>
<div class="line"> coupons, bondDayCount, schedule, redemption);</div>
<div class="line"> europeanBond.setPricingEngine(engine);</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="class_quant_lib_1_1_convertible_fixed_coupon_bond.html" title="convertible fixed-coupon bond">ConvertibleFixedCouponBond</a> americanBond(</div>
<div class="line"> amExercise, conversionRatio, dividends, callability,</div>
<div class="line"> creditSpread, issueDate, settlementDays,</div>
<div class="line"> coupons, bondDayCount, schedule, redemption);</div>
<div class="line"> americanBond.setPricingEngine(engine);</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Jarrow-Rudd"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<JarrowRudd></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<JarrowRudd></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Cox-Ross-Rubinstein"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<CoxRossRubinstein></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<CoxRossRubinstein></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Additive equiprobabilities"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<AdditiveEQPBinomialTree></a>(</div>
<div class="line"> stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<AdditiveEQPBinomialTree></a>(</div>
<div class="line"> stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Trigeorgis"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Trigeorgis></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Trigeorgis></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Tian"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Tian></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Tian></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Leisen-Reimer"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<LeisenReimer></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<LeisenReimer></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> method = <span class="stringliteral">"Joshi"</span>;</div>
<div class="line"> europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Joshi4></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(</div>
<div class="line"> <span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_binomial_convertible_engine.html" title="Binomial Tsiveriotis-Fernandes engine for convertible bonds.">BinomialConvertibleEngine<Joshi4></a>(stochasticProcess,</div>
<div class="line"> timeSteps)));</div>
<div class="line"> std::cout << std::setw(widths[0]) << std::left << method</div>
<div class="line"> << std::fixed</div>
<div class="line"> << std::setw(widths[1]) << std::left << europeanBond.NPV()</div>
<div class="line"> << std::setw(widths[2]) << std::left << americanBond.NPV()</div>
<div class="line"> << std::endl;</div>
<div class="line"> </div>
<div class="line"> std::cout << dblrule << std::endl;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"> } <span class="keywordflow">catch</span> (std::exception& e) {</div>
<div class="line"> std::cerr << e.what() << std::endl;</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> } <span class="keywordflow">catch</span> (...) {</div>
<div class="line"> std::cerr << <span class="stringliteral">"unknown error"</span> << std::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 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>
|