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.
#include <ql/qldefines.hpp>
#ifdef BOOST_MSVC
# include <ql/auto_link.hpp>
#endif
#include <ql/experimental/convertiblebonds/convertiblebond.hpp>
#include <ql/experimental/convertiblebonds/binomialconvertibleengine.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/thirty360.hpp>
#include <ql/utilities/dataformatters.hpp>
#include <iostream>
#include <iomanip>
#define LENGTH(a) (sizeof(a)/sizeof(a[0]))
#if defined(QL_ENABLE_SESSIONS)
ThreadKey sessionId() { return 0; }
}
#endif
int main(int, char* []) {
try {
std::cout << std::endl;
Option::Type type(Option::Put);
Rate riskFreeRate = 0.06;
Real conversionRatio = redemption/underlying;
Date settlementDate = calendar.
advance(today, settlementDays, Days);
Date exerciseDate = calendar.
advance(settlementDate, length, Years);
Date issueDate = calendar.
advance(exerciseDate, -length, Years);
Schedule schedule(issueDate, exerciseDate,
convention, convention,
DividendSchedule dividends;
CallabilitySchedule callability;
std::vector<Real> coupons(1, 0.05);
Real callPrices[] = { 101.5, 100.85 };
Real putPrices[]= { 105.0 };
for (
Size i=0; i<LENGTH(callLength); i++) {
callability.push_back(
ext::make_shared<SoftCallability>(
Bond::Price(callPrices[i],
Bond::Price::Clean),
schedule.date(callLength[i]),
1.20));
}
for (
Size j=0; j<LENGTH(putLength); j++) {
callability.push_back(
ext::make_shared<Callability>(
Bond::Price(putPrices[j],
Bond::Price::Clean),
Callability::Put,
schedule.date(putLength[j])));
}
for (
Date d = today + 6*Months; d < exerciseDate; d += 6*Months) {
dividends.push_back(
}
exerciseDate);
std::cout << "option type = " << type << std::endl;
std::cout << "Time to maturity = " << maturity
<< std::endl;
std::cout << "Underlying price = " << underlying
<< std::endl;
std::cout <<
"Risk-free interest rate = " <<
io::rate(riskFreeRate)
<< std::endl;
std::cout <<
"Dividend yield = " <<
io::rate(dividendYield)
<< std::endl;
<< std::endl;
std::cout << std::endl;
std::string method;
std::cout << std::endl ;
Size widths[] = { 35, 14, 14 };
Size totalWidth = widths[0] + widths[1] + widths[2];
std::string rule(totalWidth, '-'), dblrule(totalWidth, '=');
std::cout << dblrule << std::endl;
std::cout << "Tsiveriotis-Fernandes method" << std::endl;
std::cout << dblrule << std::endl;
std::cout << std::setw(widths[0]) << std::left << "Tree type"
<< std::setw(widths[1]) << std::left << "European"
<< std::setw(widths[1]) << std::left << "American"
<< std::endl;
std::cout << rule << std::endl;
ext::shared_ptr<Exercise> exercise(
ext::shared_ptr<Exercise> amExercise(
exerciseDate));
ext::shared_ptr<YieldTermStructure>(
new FlatForward(settlementDate, riskFreeRate, dayCounter)));
ext::shared_ptr<YieldTermStructure>(
new FlatForward(settlementDate, dividendYield, dayCounter)));
ext::shared_ptr<BlackVolTermStructure>(
ext::shared_ptr<BlackScholesMertonProcess> stochasticProcess(
flatDividendTS,
flatTermStructure,
flatVolTS));
ext::shared_ptr<YieldTermStructure>(
ext::shared_ptr<PricingEngine> engine(
timeSteps));
exercise, conversionRatio, dividends, callability,
creditSpread, issueDate, settlementDays,
coupons, bondDayCount, schedule, redemption);
europeanBond.setPricingEngine(engine);
amExercise, conversionRatio, dividends, callability,
creditSpread, issueDate, settlementDays,
coupons, bondDayCount, schedule, redemption);
americanBond.setPricingEngine(engine);
method = "Jarrow-Rudd";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Cox-Ross-Rubinstein";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Additive equiprobabilities";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
stochasticProcess,
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
stochasticProcess,
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Trigeorgis";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Tian";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Leisen-Reimer";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
method = "Joshi";
europeanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
americanBond.setPricingEngine(ext::shared_ptr<PricingEngine>(
timeSteps)));
std::cout << std::setw(widths[0]) << std::left << method
<< std::fixed
<< std::setw(widths[1]) << std::left << europeanBond.NPV()
<< std::setw(widths[2]) << std::left << americanBond.NPV()
<< std::endl;
std::cout << dblrule << std::endl;
return 0;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "unknown error" << std::endl;
return 1;
}
}