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
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2006 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/reference/license.html>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include "convertiblebonds.hpp"
#include "utilities.hpp"
#include <ql/Instruments/convertiblebond.hpp>
#include <ql/Instruments/zerocouponbond.hpp>
#include <ql/Instruments/fixedcouponbond.hpp>
#include <ql/Instruments/floatingratebond.hpp>
#include <ql/Instruments/vanillaoption.hpp>
#include <ql/PricingEngines/Hybrid/binomialconvertibleengine.hpp>
#include <ql/PricingEngines/Vanilla/binomialengine.hpp>
#include <ql/Calendars/target.hpp>
#include <ql/DayCounters/actual360.hpp>
#include <ql/Indexes/euribor.hpp>
#include <ql/TermStructures/flatforward.hpp>
#include <ql/TermStructures/forwardspreadedtermstructure.hpp>
#include <ql/Volatilities/blackconstantvol.hpp>
#include <ql/Utilities/dataformatters.hpp>
using namespace QuantLib;
using namespace boost::unit_test_framework;
QL_BEGIN_TEST_LOCALS(ConvertibleBondTest)
Date today_, issueDate_, maturityDate_;
Calendar calendar_;
DayCounter dayCounter_;
Frequency frequency_;
Integer settlementDays_;
Handle<Quote> underlying_;
Handle<YieldTermStructure> dividendYield_, riskFreeRate_;
Handle<BlackVolTermStructure> volatility_;
boost::shared_ptr<StochasticProcess> process_;
Handle<Quote> creditSpread_;
CallabilitySchedule no_callability;
DividendSchedule no_dividends;
Real redemption_, conversionRatio_;
void setup() {
calendar_ = TARGET();
today_ = calendar_.adjust(Date::todaysDate());
Settings::instance().evaluationDate() = today_;
dayCounter_ = Actual360();
frequency_ = Annual;
settlementDays_ = 3;
issueDate_ = calendar_.advance(today_,2,Days);
maturityDate_ = calendar_.advance(issueDate_, 10, Years);
// reset to avoid inconsistencies as the schedule is backwards
issueDate_ = calendar_.advance(maturityDate_, -10, Years);
underlying_.linkTo(boost::shared_ptr<Quote>(new SimpleQuote(50.0)));
dividendYield_.linkTo(flatRate(today_, 0.02, dayCounter_));
riskFreeRate_.linkTo(flatRate(today_, 0.05, dayCounter_));
volatility_.linkTo(flatVol(today_, 0.15, dayCounter_));
process_ = boost::shared_ptr<StochasticProcess>(
new BlackScholesMertonProcess(underlying_, dividendYield_,
riskFreeRate_, volatility_));
creditSpread_.linkTo(boost::shared_ptr<Quote>(new SimpleQuote(0.005)));
redemption_ = 100.0;
conversionRatio_ = redemption_/underlying_->value();
}
void teardown() {
Settings::instance().evaluationDate() = Date();
}
QL_END_TEST_LOCALS(ConvertibleBondTest)
void ConvertibleBondTest::testBond() {
/* when deeply out-of-the-money, the value of the convertible bond
should equal that of the underlying plain-vanilla bond. */
BOOST_MESSAGE(
"Testing out-of-the-money convertible bonds against vanilla bonds...");
QL_TEST_BEGIN
QL_TEST_SETUP
conversionRatio_ = 1.0e-16;
boost::shared_ptr<Exercise> euExercise(
new EuropeanExercise(maturityDate_));
boost::shared_ptr<Exercise> amExercise(
new AmericanExercise(issueDate_,
maturityDate_));
Size timeSteps = 1001;
boost::shared_ptr<PricingEngine> engine(
new BinomialConvertibleEngine<CoxRossRubinstein>(timeSteps));
Handle<YieldTermStructure> discountCurve(
boost::shared_ptr<YieldTermStructure>(
new ForwardSpreadedTermStructure(riskFreeRate_, creditSpread_)));
// zero-coupon
Schedule schedule = MakeSchedule(calendar_,
issueDate_, maturityDate_,
Once, Following).backwards();
ConvertibleZeroCouponBond euZero(process_, euExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
dayCounter_, schedule, redemption_);
ConvertibleZeroCouponBond amZero(process_, amExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
dayCounter_, schedule, redemption_);
ZeroCouponBond zero(issueDate_, maturityDate_, settlementDays_,
dayCounter_, calendar_, Following,
redemption_, discountCurve);
Real tolerance = 1.0e-2;
Real error = std::fabs(euZero.NPV()-zero.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce zero-coupon bond price:"
<< std::setprecision(5)
<< "\n calculated: " << euZero.NPV()
<< "\n expected: " << zero.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
error = std::fabs(amZero.NPV()-zero.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce zero-coupon bond price:"
<< std::setprecision(5)
<< "\n calculated: " << amZero.NPV()
<< "\n expected: " << zero.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
// coupon
std::vector<Rate> coupons(1, 0.05);
schedule = MakeSchedule(calendar_,
issueDate_, maturityDate_,
frequency_, Following).backwards();
ConvertibleFixedCouponBond euFixed(process_, euExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
coupons, dayCounter_,
schedule, redemption_);
ConvertibleFixedCouponBond amFixed(process_, amExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
coupons, dayCounter_,
schedule, redemption_);
FixedCouponBond fixed(issueDate_, issueDate_, maturityDate_,
settlementDays_, coupons, frequency_,
calendar_, dayCounter_, Following, Following,
redemption_, discountCurve);
tolerance = 2.0e-2;
error = std::fabs(euFixed.NPV()-fixed.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce fixed-coupon bond price:"
<< std::setprecision(5)
<< "\n calculated: " << euFixed.NPV()
<< "\n expected: " << fixed.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
error = std::fabs(amFixed.NPV()-fixed.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce fixed-coupon bond price:"
<< std::setprecision(5)
<< "\n calculated: " << amFixed.NPV()
<< "\n expected: " << fixed.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
// floating-rate
boost::shared_ptr<Xibor> index(new Euribor1Y(discountCurve));
Integer fixingDays = 2;
std::vector<Real> gearings(1, 1.0);
std::vector<Rate> spreads;
ConvertibleFloatingRateBond euFloating(process_, euExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
index, fixingDays, spreads,
dayCounter_, schedule, redemption_);
ConvertibleFloatingRateBond amFloating(process_, amExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
index, fixingDays, spreads,
dayCounter_, schedule, redemption_);
FloatingRateBond floating(issueDate_, issueDate_, maturityDate_,
settlementDays_, index, fixingDays, gearings,
spreads, frequency_, calendar_, dayCounter_,
Following, Following, redemption_,
discountCurve);
tolerance = 2.0e-2;
error = std::fabs(euFloating.NPV()-floating.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce floating-rate bond price:"
<< std::setprecision(5)
<< "\n calculated: " << euFloating.NPV()
<< "\n expected: " << floating.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
error = std::fabs(amFloating.NPV()-floating.NPV());
if (error > tolerance) {
BOOST_ERROR("failed to reproduce floating-rate bond price:"
<< std::setprecision(5)
<< "\n calculated: " << amFloating.NPV()
<< "\n expected: " << floating.NPV()
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
QL_TEST_TEARDOWN
}
void ConvertibleBondTest::testOption() {
/* a zero-coupon convertible bond with no credit spread is
equivalent to a call option. */
BOOST_MESSAGE(
"Testing zero-coupon convertible bonds against vanilla option...");
QL_TEST_BEGIN
QL_TEST_SETUP
boost::shared_ptr<Exercise> euExercise(
new EuropeanExercise(maturityDate_));
settlementDays_ = 0;
Size timeSteps = 1001;
boost::shared_ptr<PricingEngine> engine(
new BinomialConvertibleEngine<CoxRossRubinstein>(timeSteps));
boost::shared_ptr<PricingEngine> vanillaEngine(
new BinomialVanillaEngine<CoxRossRubinstein>(timeSteps));
creditSpread_.linkTo(boost::shared_ptr<Quote>(new SimpleQuote(0.0)));
Real conversionStrike = redemption_/conversionRatio_;
boost::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(Option::Call, conversionStrike));
Schedule schedule = MakeSchedule(calendar_,
issueDate_, maturityDate_,
Once, Following).backwards();
ConvertibleZeroCouponBond euZero(process_, euExercise, engine,
conversionRatio_, no_dividends,
no_callability, creditSpread_,
issueDate_, settlementDays_,
dayCounter_, schedule, redemption_);
VanillaOption euOption(process_, payoff, euExercise, vanillaEngine);
Real tolerance = 5.0e-2;
Real expected = redemption_ * riskFreeRate_->discount(maturityDate_)
+ conversionRatio_* euOption.NPV();
Real error = std::fabs(euZero.NPV()-expected);
if (error > tolerance) {
BOOST_ERROR("failed to reproduce plain-option price:"
<< std::setprecision(5)
<< "\n calculated: " << euZero.NPV()
<< "\n expected: " << expected
<< std::setprecision(2)
<< QL_SCIENTIFIC
<< "\n error: " << error);
}
QL_TEST_TEARDOWN
}
test_suite* ConvertibleBondTest::suite() {
test_suite* suite = BOOST_TEST_SUITE("Convertible bond tests");
suite->add(BOOST_TEST_CASE(&ConvertibleBondTest::testBond));
suite->add(BOOST_TEST_CASE(&ConvertibleBondTest::testOption));
return suite;
}
|