This example prices a number of callable bonds and compares the results to known good data.
#if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC)
#endif
#include <vector>
#include <cmath>
#include <iomanip>
#include <iostream>
ext::shared_ptr<YieldTermStructure>
flatRate(
const Date& today,
const ext::shared_ptr<Quote>& forward,
return ext::make_shared<FlatForward>(today,
dc,
compounding,
frequency);
}
ext::shared_ptr<YieldTermStructure>
flatRate(
const Date& today,
return flatRate(today,
ext::make_shared<SimpleQuote>(forward),
dc,
compounding,
frequency);
}
int main(int, char* [])
{
try {
Settings::instance().evaluationDate() = today;
cout << endl;
cout << "Pricing a callable fixed rate bond using" << endl;
cout << "Hull White model w/ reversion parameter = 0.03" << endl;
cout << "BAC4.65 09/15/12 ISIN: US06060WBJ36" << endl;
cout << "roughly five year tenor, ";
cout << "quarterly coupon and call dates" << endl;
cout << "reference date is : " << today << endl << endl;
Rate bbCurveRate = 0.055;
InterestRate bbIR(bbCurveRate,bbDayCounter,Compounded,Semiannual);
bbIR.rate(),
bbIR.dayCounter(),
bbIR.compounding(),
bbIR.frequency()));
Size numberOfCallDates = 24;
Date callDate =
Date(15,September,2006);
for (
Size i=0; i< numberOfCallDates; i++) {
callSchedule.push_back(
ext::make_shared<Callability>(
myPrice,
Callability::Call,
callDate ));
callDate = nullCalendar.
advance(callDate, 3, Months);
}
Date maturity =
Date(15,September,2012);
accrualConvention, accrualConvention,
DateGeneration::Backward, false);
Size maxIterations = 1000;
Real reversionParameter = .03;
auto hw0 = ext::make_shared<HullWhite>(termStructure,reversionParameter,
sigma);
auto engine0 = ext::make_shared<TreeCallableFixedRateBondEngine>(hw0,gridIntervals);
vector<Rate>(1, coupon),
bondDayCounter, paymentConvention,
redemption, issue, callSchedule);
callableBond.setPricingEngine(engine0);
cout << setprecision(2)
<< showpoint
<< fixed
<< "sigma/vol (%) = "
<< endl;
cout << "QuantLib price/yld (%) ";
cout << callableBond.cleanPrice() << " / "
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << "Bloomberg price/yld (%) ";
cout << "96.50 / 5.47"
<< endl
<< endl;
cout <<
"sigma/vol (%) = " << 100.*
sigma << endl;
auto hw1 = ext::make_shared<HullWhite>(termStructure,reversionParameter,
sigma);
auto engine1 = ext::make_shared<TreeCallableFixedRateBondEngine>(hw1,gridIntervals);
callableBond.setPricingEngine(engine1);
cout << "QuantLib price/yld (%) ";
cout << callableBond.cleanPrice() << " / "
<< 100.* callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << "Bloomberg price/yld (%) ";
cout << "95.68 / 5.66"
<< endl
<< endl;
auto hw2 = ext::make_shared<HullWhite>(termStructure, reversionParameter,
sigma);
auto engine2 = ext::make_shared<TreeCallableFixedRateBondEngine>(hw2,gridIntervals);
callableBond.setPricingEngine(engine2);
cout << "sigma/vol (%) = "
<< endl;
cout << "QuantLib price/yld (%) ";
cout << callableBond.cleanPrice() << " / "
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << "Bloomberg price/yld (%) ";
cout << "92.34 / 6.49"
<< endl
<< endl;
auto hw3 = ext::make_shared<HullWhite>(termStructure, reversionParameter,
sigma);
auto engine3 = ext::make_shared<TreeCallableFixedRateBondEngine>(hw3,gridIntervals);
callableBond.setPricingEngine(engine3);
cout << "sigma/vol (%) = "
<< endl;
cout << "QuantLib price/yld (%) ";
cout << callableBond.cleanPrice() << " / "
<< 100. * callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << "Bloomberg price/yld (%) ";
cout << "87.16 / 7.83"
<< endl
<< endl;
auto hw4 = ext::make_shared<HullWhite>(termStructure, reversionParameter,
sigma);
auto engine4 = ext::make_shared<TreeCallableFixedRateBondEngine>(hw4,gridIntervals);
callableBond.setPricingEngine(engine4);
cout << "sigma/vol (%) = "
<< endl;
cout << "QuantLib price/yld (%) ";
cout << callableBond.cleanPrice() << " / "
<< 100.* callableBond.yield(bondDayCounter,
Compounded,
frequency,
accuracy,
maxIterations)
<< endl;
cout << "Bloomberg price/yld (%) ";
cout << "77.31 / 10.65"
<< endl
<< endl;
return 0;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "unknown error" << std::endl;
return 1;
}
}
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
callable/puttable fixed rate bond
Shared handle to an observable.
Concrete interest rate class.
Calendar for reproducing theoretical calculations.
flat forward rate term structure
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
@ Quarterly
every third month
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
Compounding
Interest rate coumpounding rule.
std::vector< ext::shared_ptr< Callability > > CallabilitySchedule
Global definitions and compiler switches.
Numerical lattice engines for callable/puttable bonds.