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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="robots" content="none">
<title>CallableBonds.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="185" height="50" 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 1.2</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="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="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="examples.html">Examples</a></li>
</ul>
</div>
<div id="content">
<!--Doxygen-generated content-->
<!-- Generated by Doxygen 1.7.6.1 -->
</div>
<div class="header">
<div class="headertitle">
<div class="title">CallableBonds.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>This examples prices a number of callable bonds and compares the results to known good data. It uses the experimental CallableBond class.</p>
<div class="fragment"><pre class="fragment"><span class="comment">/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */</span>
<span class="comment">/* This example sets up a callable fixed rate bond with a Hull White pricing</span>
<span class="comment"> engine and compares to Bloomberg's Hull White price/yield calculations.</span>
<span class="comment">*/</span>
<span class="preprocessor">#ifdef BOOST_MSVC</span>
<span class="preprocessor"></span><span class="comment">/* Uncomment the following lines to unmask floating-point</span>
<span class="comment"> exceptions. Warning: unpredictable results can arise...</span>
<span class="comment"></span>
<span class="comment"> See http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481</span>
<span class="comment"> Is there anyone with a definitive word about this?</span>
<span class="comment">*/</span>
<span class="comment">// #include <float.h></span>
<span class="comment">// namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); }</span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include <ql/quantlib.hpp></span>
<span class="preprocessor">#include <vector></span>
<span class="preprocessor">#include <cmath></span>
<span class="preprocessor">#include <iomanip></span>
<span class="preprocessor">#include <iostream></span>
<span class="preprocessor">#include <boost/timer.hpp></span>
<span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>QuantLib;
<span class="preprocessor">#if defined(QL_ENABLE_SESSIONS)</span>
<span class="preprocessor"></span><span class="keyword">namespace </span>QuantLib {
<a name="a0"></a><a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> sessionId() { <span class="keywordflow">return</span> 0; }
}
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
boost::shared_ptr<YieldTermStructure>
flatRate(<span class="keyword">const</span> <a name="_a1"></a><a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>& today,
<span class="keyword">const</span> boost::shared_ptr<Quote>& forward,
<span class="keyword">const</span> <a name="_a2"></a><a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a>& dc,
<span class="keyword">const</span> Compounding& compounding,
<span class="keyword">const</span> <a class="code" href="group__datetime.html#ga6d41db8ba0ea90d22df35889df452ada" title="Frequency of events.">Frequency</a>& frequency) {
<span class="keywordflow">return</span> boost::shared_ptr<YieldTermStructure>(
<span class="keyword">new</span> <a name="_a3"></a><a class="code" href="class_quant_lib_1_1_flat_forward.html" title="Flat interest-rate curve.">FlatForward</a>(today,
<a name="_a4"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle<Quote></a>(forward),
dc,
compounding,
frequency));
}
boost::shared_ptr<YieldTermStructure>
flatRate(<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>& today,
<a name="a5"></a><a class="code" href="group__types.html#gaede435af51236692b1107d7639581d39" title="interest rates">Rate</a> forward,
<span class="keyword">const</span> <a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a>& dc,
<span class="keyword">const</span> Compounding &compounding,
<span class="keyword">const</span> <a class="code" href="group__datetime.html#ga6d41db8ba0ea90d22df35889df452ada" title="Frequency of events.">Frequency</a> &frequency) {
<span class="keywordflow">return</span> flatRate(today,
boost::shared_ptr<Quote>(<span class="keyword">new</span> <a name="_a6"></a><a class="code" href="class_quant_lib_1_1_simple_quote.html" title="market element returning a stored value">SimpleQuote</a>(forward)),
dc,
compounding,
frequency);
}
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>* [])
{
<span class="keywordflow">try</span> {
boost::timer timer;
<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> today = <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>(16,October,2007);
Settings::instance().evaluationDate() = today;
cout << endl;
cout << <span class="stringliteral">"Pricing a callable fixed rate bond using"</span> << endl;
cout << <span class="stringliteral">"Hull White model w/ reversion parameter = 0.03"</span> << endl;
cout << <span class="stringliteral">"BAC4.65 09/15/12 ISIN: US06060WBJ36"</span> << endl;
cout << <span class="stringliteral">"roughly five year tenor, "</span>;
cout << <span class="stringliteral">"quarterly coupon and call dates"</span> << endl;
cout << <span class="stringliteral">"reference date is : "</span> << today << endl << endl;
<span class="comment">/* Bloomberg OAS1: "N" model (Hull White)</span>
<span class="comment"> varying volatility parameter</span>
<span class="comment"></span>
<span class="comment"> The curve entered into Bloomberg OAS1 is a flat curve,</span>
<span class="comment"> at constant yield = 5.5%, semiannual compounding.</span>
<span class="comment"> Assume here OAS1 curve uses an ACT/ACT day counter,</span>
<span class="comment"> as documented in PFC1 as a "default" in the latter case.</span>
<span class="comment"> */</span>
<span class="comment">// set up a flat curve corresponding to Bloomberg flat curve</span>
<a class="code" href="group__types.html#gaede435af51236692b1107d7639581d39" title="interest rates">Rate</a> bbCurveRate = 0.055;
<a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> bbDayCounter = <a name="_a7"></a><a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::Bond);
<a name="_a8"></a><a class="code" href="class_quant_lib_1_1_interest_rate.html" title="Concrete interest rate class.">InterestRate</a> bbIR(bbCurveRate,bbDayCounter,Compounded,<a name="a9"></a><a class="code" href="group__datetime.html#gga6d41db8ba0ea90d22df35889df452adaad1a5868a1c314bb7f6ab68e2fa182b2d" title="twice a year">Semiannual</a>);
<a name="_a10"></a><a class="code" href="class_quant_lib_1_1_handle.html">Handle<YieldTermStructure></a> termStructure(flatRate(today,
bbIR.rate(),
bbIR.dayCounter(),
bbIR.compounding(),
bbIR.frequency()));
<span class="comment">// set up the call schedule</span>
CallabilitySchedule callSchedule;
<a name="a11"></a><a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> callPrice = 100.;
<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> numberOfCallDates = 24;
<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> callDate = <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>(15,September,2006);
<span class="keywordflow">for</span> (<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> i=0; i< numberOfCallDates; i++) {
<a name="_a12"></a><a class="code" href="class_quant_lib_1_1_calendar.html" title="calendar class">Calendar</a> nullCalendar = <a name="_a13"></a><a class="code" href="class_quant_lib_1_1_null_calendar.html" title="Calendar for reproducing theoretical calculations.">NullCalendar</a>();
<a name="_a14"></a><a class="code" href="class_quant_lib_1_1_callability_1_1_price.html" title="amount to be paid upon callability">Callability::Price</a> myPrice(callPrice,
Callability::Price::Clean);
callSchedule.push_back(
boost::shared_ptr<Callability>(
<span class="keyword">new</span> <a name="_a15"></a><a class="code" href="class_quant_lib_1_1_callability.html" title="instrument callability">Callability</a>(myPrice,
Callability::Call,
callDate )));
callDate = nullCalendar.<a name="a16"></a><a class="code" href="class_quant_lib_1_1_calendar.html#ac47bb82bf7b147cfacf373991c2905ea">advance</a>(callDate, 3, Months);
}
<span class="comment">// set up the callable bond</span>
<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> dated = <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>(16,September,2004);
<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> issue = dated;
<a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a> maturity = <a class="code" href="class_quant_lib_1_1_date.html" title="Concrete date class.">Date</a>(15,September,2012);
<a name="a17"></a><a class="code" href="group__types.html#ga7e529c39c477ba1f5a22264d93e8457a" title="positive integer">Natural</a> settlementDays = 3; <span class="comment">// Bloomberg OAS1 settle is Oct 19, 2007</span>
<a class="code" href="class_quant_lib_1_1_calendar.html" title="calendar class">Calendar</a> bondCalendar = <a name="_a18"></a><a class="code" href="class_quant_lib_1_1_united_states.html" title="United States calendars.">UnitedStates</a>(UnitedStates::GovernmentBond);
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> coupon = .0465;
<a class="code" href="group__datetime.html#ga6d41db8ba0ea90d22df35889df452ada" title="Frequency of events.">Frequency</a> frequency = <a name="a19"></a><a class="code" href="group__datetime.html#gga6d41db8ba0ea90d22df35889df452adaab4fce358383d1822f7596659e00b07f7" title="every third month">Quarterly</a>;
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> redemption = 100.0;
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> faceAmount = 100.0;
<span class="comment">/* The 30/360 day counter Bloomberg uses for this bond cannot</span>
<span class="comment"> reproduce the US Bond/ISMA (constant) cashflows used in PFC1.</span>
<span class="comment"> Therefore use ActAct(Bond)</span>
<span class="comment"> */</span>
<a class="code" href="class_quant_lib_1_1_day_counter.html" title="day counter class">DayCounter</a> bondDayCounter = <a class="code" href="class_quant_lib_1_1_actual_actual.html" title="Actual/Actual day count.">ActualActual</a>(ActualActual::Bond);
<span class="comment">// PFC1 shows no indication dates are being adjusted</span>
<span class="comment">// for weekends/holidays for vanilla bonds</span>
<a class="code" href="group__datetime.html#gaff46c5ae9385d20709bedade86edd368" title="Business Day conventions.">BusinessDayConvention</a> accrualConvention = <a name="a20"></a><a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a5fb8b90b7fdf1a3a228fbbc083e64547">Unadjusted</a>;
<a class="code" href="group__datetime.html#gaff46c5ae9385d20709bedade86edd368" title="Business Day conventions.">BusinessDayConvention</a> paymentConvention = <a class="code" href="group__datetime.html#ggaff46c5ae9385d20709bedade86edd368a5fb8b90b7fdf1a3a228fbbc083e64547">Unadjusted</a>;
<a name="_a21"></a><a class="code" href="class_quant_lib_1_1_schedule.html" title="Payment schedule.">Schedule</a> sch(dated, maturity, <a name="_a22"></a><a class="code" href="class_quant_lib_1_1_period.html">Period</a>(frequency), bondCalendar,
accrualConvention, accrualConvention,
DateGeneration::Backward, <span class="keyword">false</span>);
<a class="code" href="group__types.html#gaf38bdb4c54463b1f456655efa95b5c77" title="size of a container">Size</a> maxIterations = 1000;
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> accuracy = 1e-8;
<a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> gridIntervals = 40;
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> reversionParameter = .03;
<span class="comment">// output price/yield results for varying volatility parameter</span>
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> sigma = <a name="a23"></a><a class="code" href="group__limit_macros.html#ga4f2e6bcf6b19224bce1a5a6234286c17">QL_EPSILON</a>; <span class="comment">// core dumps if zero on Cygwin</span>
boost::shared_ptr<ShortRateModel> hw0(
<span class="keyword">new</span> <a name="_a24"></a><a class="code" href="class_quant_lib_1_1_hull_white.html" title="Single-factor Hull-White (extended Vasicek) model class.">HullWhite</a>(termStructure,reversionParameter,sigma));
boost::shared_ptr<PricingEngine> engine0(
<span class="keyword">new</span> <a name="_a25"></a><a class="code" href="class_quant_lib_1_1_tree_callable_fixed_rate_bond_engine.html" title="Numerical lattice engine for callable fixed rate bonds.">TreeCallableFixedRateBondEngine</a>(hw0,gridIntervals));
<a name="_a26"></a><a class="code" href="class_quant_lib_1_1_callable_fixed_rate_bond.html" title="callable/puttable fixed rate bond">CallableFixedRateBond</a> callableBond(settlementDays, faceAmount, sch,
vector<Rate>(1, coupon),
bondDayCounter, paymentConvention,
redemption, issue, callSchedule);
callableBond.setPricingEngine(engine0);
cout << setprecision(2)
<< showpoint
<< fixed
<< <span class="stringliteral">"sigma/vol (%) = "</span>
<< 100.*sigma
<< endl;
cout << <span class="stringliteral">"QuantLib price/yld (%) "</span>;
cout << callableBond.cleanPrice() << <span class="stringliteral">" / "</span>
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << <span class="stringliteral">"Bloomberg price/yld (%) "</span>;
cout << <span class="stringliteral">"96.50 / 5.47"</span>
<< endl
<< endl;
sigma = .01;
cout << <span class="stringliteral">"sigma/vol (%) = "</span> << 100.*sigma << endl;
boost::shared_ptr<ShortRateModel> hw1(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_hull_white.html" title="Single-factor Hull-White (extended Vasicek) model class.">HullWhite</a>(termStructure,reversionParameter,sigma));
boost::shared_ptr<PricingEngine> engine1(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_tree_callable_fixed_rate_bond_engine.html" title="Numerical lattice engine for callable fixed rate bonds.">TreeCallableFixedRateBondEngine</a>(hw1,gridIntervals));
callableBond.setPricingEngine(engine1);
cout << <span class="stringliteral">"QuantLib price/yld (%) "</span>;
cout << callableBond.cleanPrice() << <span class="stringliteral">" / "</span>
<< 100.* callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << <span class="stringliteral">"Bloomberg price/yld (%) "</span>;
cout << <span class="stringliteral">"95.68 / 5.66"</span>
<< endl
<< endl;
sigma = .03;
boost::shared_ptr<ShortRateModel> hw2(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_hull_white.html" title="Single-factor Hull-White (extended Vasicek) model class.">HullWhite</a>(termStructure, reversionParameter, sigma));
boost::shared_ptr<PricingEngine> engine2(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_tree_callable_fixed_rate_bond_engine.html" title="Numerical lattice engine for callable fixed rate bonds.">TreeCallableFixedRateBondEngine</a>(hw2,gridIntervals));
callableBond.setPricingEngine(engine2);
cout << <span class="stringliteral">"sigma/vol (%) = "</span>
<< 100.*sigma
<< endl;
cout << <span class="stringliteral">"QuantLib price/yld (%) "</span>;
cout << callableBond.cleanPrice() << <span class="stringliteral">" / "</span>
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << <span class="stringliteral">"Bloomberg price/yld (%) "</span>;
cout << <span class="stringliteral">"92.34 / 6.49"</span>
<< endl
<< endl;
sigma = .06;
boost::shared_ptr<ShortRateModel> hw3(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_hull_white.html" title="Single-factor Hull-White (extended Vasicek) model class.">HullWhite</a>(termStructure, reversionParameter, sigma));
boost::shared_ptr<PricingEngine> engine3(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_tree_callable_fixed_rate_bond_engine.html" title="Numerical lattice engine for callable fixed rate bonds.">TreeCallableFixedRateBondEngine</a>(hw3,gridIntervals));
callableBond.setPricingEngine(engine3);
cout << <span class="stringliteral">"sigma/vol (%) = "</span>
<< 100.*sigma
<< endl;
cout << <span class="stringliteral">"QuantLib price/yld (%) "</span>;
cout << callableBond.cleanPrice() << <span class="stringliteral">" / "</span>
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << <span class="stringliteral">"Bloomberg price/yld (%) "</span>;
cout << <span class="stringliteral">"87.16 / 7.83"</span>
<< endl
<< endl;
sigma = .12;
boost::shared_ptr<ShortRateModel> hw4(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_hull_white.html" title="Single-factor Hull-White (extended Vasicek) model class.">HullWhite</a>(termStructure, reversionParameter, sigma));
boost::shared_ptr<PricingEngine> engine4(
<span class="keyword">new</span> <a class="code" href="class_quant_lib_1_1_tree_callable_fixed_rate_bond_engine.html" title="Numerical lattice engine for callable fixed rate bonds.">TreeCallableFixedRateBondEngine</a>(hw4,gridIntervals));
callableBond.setPricingEngine(engine4);
cout << <span class="stringliteral">"sigma/vol (%) = "</span>
<< 100.*sigma
<< endl;
cout << <span class="stringliteral">"QuantLib price/yld (%) "</span>;
cout << callableBond.cleanPrice() << <span class="stringliteral">" / "</span>
<< 100.* callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << <span class="stringliteral">"Bloomberg price/yld (%) "</span>;
cout << <span class="stringliteral">"77.31 / 10.65"</span>
<< endl
<< endl;
<a class="code" href="group__types.html#ga4bdf4bfe76b9ffa6fa64c47d8bfa0c78" title="real number">Real</a> seconds = timer.elapsed();
<a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> hours = int(seconds/3600);
seconds -= hours * 3600;
<a class="code" href="group__types.html#gab9c87440c314438e51a899a03d2442d0" title="integer number">Integer</a> minutes = int(seconds/60);
seconds -= minutes * 60;
cout << <span class="stringliteral">" \nRun completed in "</span>;
<span class="keywordflow">if</span> (hours > 0)
cout << hours << <span class="stringliteral">" h "</span>;
<span class="keywordflow">if</span> (hours > 0 || minutes > 0)
cout << minutes << <span class="stringliteral">" m "</span>;
cout << fixed << setprecision(0)
<< seconds << <span class="stringliteral">" s\n"</span> << endl;
<span class="keywordflow">return</span> 0;
} <span class="keywordflow">catch</span> (std::exception& e) {
std::cerr << e.what() << std::endl;
<span class="keywordflow">return</span> 1;
} <span class="keywordflow">catch</span> (...) {
std::cerr << <span class="stringliteral">"unknown error"</span> << std::endl;
<span class="keywordflow">return</span> 1;
}
}
</pre></div> </div><!-- contents -->
</div><!-- contents -->
</div>
<div class="footer">
<div class="endmatter">
Documentation generated by
<a href="http://www.doxygen.org">Doxygen</a> 1.7.6.1
</div>
</div>
</div>
</body>
</html>
|