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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2006 Cristina Duminuco
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/license.shtml>.
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 "capflooredcoupon.hpp"
#include "utilities.hpp"
#include <ql/instruments/capfloor.hpp>
#include <ql/instruments/vanillaswap.hpp>
#include <ql/cashflows/cashflowvectors.hpp>
#include <ql/termstructures/yield/flatforward.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/pricingengines/capfloor/blackcapfloorengine.hpp>
#include <ql/pricingengines/swap/discountingswapengine.hpp>
#include <ql/math/matrix.hpp>
#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
#include <ql/time/daycounters/thirty360.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/time/schedule.hpp>
#include <ql/utilities/dataformatters.hpp>
#include <ql/cashflows/cashflows.hpp>
#include <ql/cashflows/couponpricer.hpp>
using namespace QuantLib;
using namespace boost::unit_test_framework;
QL_BEGIN_TEST_LOCALS(CapFlooredCouponTest)
// global data
Date today_, settlement_, startDate_;
Calendar calendar_;
Real nominal_;
std::vector<Real> nominals_;
BusinessDayConvention convention_;
Frequency frequency_;
boost::shared_ptr<IborIndex> index_;
Natural settlementDays_, fixingDays_;
RelinkableHandle<YieldTermStructure> termStructure_;
std::vector<Rate> caps_;
std::vector<Rate> floors_;
Integer length_;
Volatility volatility_;
void setup() {
length_ = 20; //years
volatility_ = 0.20;
nominal_ = 100.;
nominals_ = std::vector<Real>(length_,nominal_);
frequency_ = Annual;
index_ = boost::shared_ptr<IborIndex>(new Euribor1Y(termStructure_));
calendar_ = index_->fixingCalendar();
convention_ = ModifiedFollowing;
today_ = calendar_.adjust(Date::todaysDate());
Settings::instance().evaluationDate() = today_;
settlementDays_ = 2;
fixingDays_ = 2;
settlement_ = calendar_.advance(today_,settlementDays_,Days);
startDate_ = settlement_;
termStructure_.linkTo(flatRate(settlement_,0.05,
ActualActual(ActualActual::ISDA)));
}
// utilities
Leg makeFixedLeg(const Date& startDate,
Integer length) {
Date endDate = calendar_.advance(startDate, length, Years, convention_);
Schedule schedule(startDate, endDate, Period(frequency_), calendar_,
convention_, convention_, DateGeneration::Forward, false);
std::vector<Rate> coupons(length, 0.0);
return FixedRateLeg(schedule, Thirty360())
.withNotionals(nominals_)
.withCouponRates(coupons);
}
Leg makeFloatingLeg(const Date& startDate,
Integer length,
const Rate gearing = 1.0,
const Rate spread = 0.0) {
Date endDate = calendar_.advance(startDate,length,Years,convention_);
Schedule schedule(startDate,endDate,Period(frequency_),calendar_,
convention_,convention_, DateGeneration::Forward, false);
std::vector<Real> gearingVector(length_, gearing);
std::vector<Spread> spreadVector(length_, spread);
return IborLeg(schedule, index_)
.withNotionals(nominals_)
.withPaymentDayCounter(index_->dayCounter())
.withPaymentAdjustment(convention_)
.withFixingDays(fixingDays_)
.withGearings(gearingVector)
.withSpreads(spreadVector);
}
Leg makeCapFlooredLeg(const Date& startDate,
Integer length,
const std::vector<Rate> caps,
const std::vector<Rate> floors,
Volatility volatility,
const Rate gearing = 1.0,
const Rate spread = 0.0) {
Date endDate = calendar_.advance(startDate,length,Years,convention_);
Schedule schedule(startDate,endDate,Period(frequency_),calendar_,
convention_,convention_, DateGeneration::Forward, false);
Handle<OptionletVolatilityStructure> vol;
vol = Handle<OptionletVolatilityStructure>(
boost::shared_ptr<OptionletVolatilityStructure>(new
ConstantOptionletVol(volatility, calendar_, Actual365Fixed())));
boost::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer(vol));
std::vector<Rate> gearingVector(length_, gearing);
std::vector<Spread> spreadVector(length_, spread);
Leg iborLeg = IborLeg(schedule, index_)
.withNotionals(nominals_)
.withPaymentDayCounter(index_->dayCounter())
.withPaymentAdjustment(convention_)
.withFixingDays(fixingDays_)
.withGearings(gearingVector)
.withSpreads(spreadVector)
.withCaps(caps)
.withFloors(floors);
setCouponPricer(iborLeg, pricer);
return iborLeg;
}
boost::shared_ptr<PricingEngine> makeEngine(Volatility volatility) {
Handle<Quote> vol(boost::shared_ptr<Quote>(new SimpleQuote(volatility)));
return boost::shared_ptr<PricingEngine>(
new BlackCapFloorEngine(termStructure_, vol));
}
boost::shared_ptr<CapFloor> makeCapFloor(CapFloor::Type type,
const Leg& leg,
Rate capStrike, Rate floorStrike,
Volatility volatility) {
boost::shared_ptr<CapFloor> result;
switch (type) {
case CapFloor::Cap:
result = boost::shared_ptr<CapFloor>(
new Cap(leg, std::vector<Rate>(1, capStrike)));
break;
case CapFloor::Floor:
result = boost::shared_ptr<CapFloor>(
new Floor(leg, std::vector<Rate>(1, floorStrike)));
break;
case CapFloor::Collar:
result = boost::shared_ptr<CapFloor>(
new Collar(leg,
std::vector<Rate>(1, capStrike),
std::vector<Rate>(1, floorStrike)));
break;
default:
QL_FAIL("unknown cap/floor type");
}
result->setPricingEngine(makeEngine(volatility));
return result;
}
std::string typeToString(CapFloor::Type type) {
switch (type) {
case CapFloor::Cap:
return "cap";
case CapFloor::Floor:
return "floor";
case CapFloor::Collar:
return "collar";
default:
QL_FAIL("unknown cap/floor type");
}
}
QL_END_TEST_LOCALS(CapFlooredCouponTest)
void CapFlooredCouponTest::testLargeRates() {
BOOST_MESSAGE("Testing degenerate collared coupon...");
SavedSettings backup;
setup();
/* A vanilla floating leg and a capped floating leg with strike
equal to 100 and floor equal to 0 must have (about) the same NPV
(depending on variance: option expiry and volatility)
*/
std::vector<Rate> caps(length_,100.0);
std::vector<Rate> floors(length_,0.0);
Real tolerance = 1e-10;
// fixed leg with zero rate
Leg fixedLeg =
makeFixedLeg(startDate_,length_);
Leg floatLeg =
makeFloatingLeg(startDate_,length_);
Leg collaredLeg =
makeCapFlooredLeg(startDate_,length_,caps,floors,volatility_);
boost::shared_ptr<PricingEngine> engine(
new DiscountingSwapEngine(termStructure_));
Swap vanillaLeg(fixedLeg,floatLeg);
Swap collarLeg(fixedLeg,collaredLeg);
vanillaLeg.setPricingEngine(engine);
collarLeg.setPricingEngine(engine);
if (std::abs(vanillaLeg.NPV()-collarLeg.NPV())>tolerance) {
BOOST_MESSAGE("Lenght: " << length_ << " y" << "\n" <<
"Volatility: " << volatility_*100 << "%\n" <<
"Notional: " << nominal_ << "\n" <<
"Vanilla floating leg NPV: " << vanillaLeg.NPV()
<< "\n" <<
"Collared floating leg NPV (strikes 0 and 100): " << collarLeg.NPV()
<< "\n" <<
"Diff: " << std::abs(vanillaLeg.NPV()-collarLeg.NPV()));
}
}
void CapFlooredCouponTest::testDecomposition() {
BOOST_MESSAGE("Testing collared coupon against its decomposition...");
SavedSettings backup;
setup();
Real tolerance = 1e-12;
Real npvVanilla,npvCappedLeg,npvFlooredLeg,npvCollaredLeg,npvCap,npvFloor,npvCollar;
Real error;
Rate floorstrike = 0.05;
Rate capstrike = 0.10;
std::vector<Rate> caps(length_,capstrike);
std::vector<Rate> caps0 = std::vector<Rate>();
std::vector<Rate> floors(length_,floorstrike);
std::vector<Rate> floors0 = std::vector<Rate>();
Rate gearing_p = Rate(0.5);
Spread spread_p = Spread(0.002);
Rate gearing_n = Rate(-1.5);
Spread spread_n = Spread(0.12);
// fixed leg with zero rate
Leg fixedLeg =
makeFixedLeg(startDate_,length_);
// floating leg with gearing=1 and spread=0
Leg floatLeg =
makeFloatingLeg(startDate_,length_);
// floating leg with positive gearing (gearing_p) and spread<>0
Leg floatLeg_p =
makeFloatingLeg(startDate_,length_,gearing_p,spread_p);
// floating leg with negative gearing (gearing_n) and spread<>0
Leg floatLeg_n =
makeFloatingLeg(startDate_,length_,gearing_n,spread_n);
// Swap with null fixed leg and floating leg with gearing=1 and spread=0
Swap vanillaLeg(fixedLeg,floatLeg);
// Swap with null fixed leg and floating leg with positive gearing and spread<>0
Swap vanillaLeg_p(fixedLeg,floatLeg_p);
// Swap with null fixed leg and floating leg with negative gearing and spread<>0
Swap vanillaLeg_n(fixedLeg,floatLeg_n);
boost::shared_ptr<PricingEngine> engine(
new DiscountingSwapEngine(termStructure_));
vanillaLeg.setPricingEngine(engine);
vanillaLeg_p.setPricingEngine(engine);
vanillaLeg_n.setPricingEngine(engine);
/* CAPPED coupon - Decomposition of payoff
Payoff = Nom * Min(rate,strike) * accrualperiod =
= Nom * [rate + Min(0,strike-rate)] * accrualperiod =
= Nom * rate * accrualperiod - Nom * Max(rate-strike,0) * accrualperiod =
= VanillaFloatingLeg - Call
*/
// Case gearing = 1 and spread = 0
Leg cappedLeg =
makeCapFlooredLeg(startDate_,length_,caps,floors0,volatility_);
Swap capLeg(fixedLeg,cappedLeg);
capLeg.setPricingEngine(engine);
Cap cap(floatLeg, std::vector<Rate>(1, capstrike));
cap.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg.NPV();
npvCappedLeg = capLeg.NPV();
npvCap = cap.NPV();
error = std::abs(npvCappedLeg - (npvVanilla-npvCap));
if (error>tolerance) {
BOOST_ERROR("\nCapped Leg: gearing=1, spread=0%, strike=" << capstrike*100 <<
"%\n" <<
" Capped Floating Leg NPV: " << npvCappedLeg << "\n" <<
" Floating Leg NPV - Cap NPV: " << npvVanilla - npvCap << "\n" <<
" Diff: " << error );
}
/* gearing = 1 and spread = 0
FLOORED coupon - Decomposition of payoff
Payoff = Nom * Max(rate,strike) * accrualperiod =
= Nom * [rate + Max(0,strike-rate)] * accrualperiod =
= Nom * rate * accrualperiod + Nom * Max(strike-rate,0) * accrualperiod =
= VanillaFloatingLeg + Put
*/
Leg flooredLeg =
makeCapFlooredLeg(startDate_,length_,caps0,floors,volatility_);
Swap floorLeg(fixedLeg,flooredLeg);
floorLeg.setPricingEngine(engine);
Floor floor(floatLeg, std::vector<Rate>(1, floorstrike));
floor.setPricingEngine(makeEngine(volatility_));
npvFlooredLeg = floorLeg.NPV();
npvFloor = floor.NPV();
error = std::abs(npvFlooredLeg-(npvVanilla + npvFloor));
if (error>tolerance) {
BOOST_ERROR("Floored Leg: gearing=1, spread=0%, strike=" << floorstrike *100 <<
"%\n" <<
" Floored Floating Leg NPV: " << npvFlooredLeg << "\n" <<
" Floating Leg NPV + Floor NPV: " << npvVanilla + npvFloor << "\n" <<
" Diff: " << error );
}
/* gearing = 1 and spread = 0
COLLARED coupon - Decomposition of payoff
Payoff = Nom * Min(strikem,Max(rate,strikeM)) * accrualperiod =
= VanillaFloatingLeg - Collar
*/
Leg collaredLeg =
makeCapFlooredLeg(startDate_,length_,caps,floors,volatility_);
Swap collarLeg(fixedLeg,collaredLeg);
collarLeg.setPricingEngine(engine);
Collar collar(floatLeg,
std::vector<Rate>(1, capstrike),
std::vector<Rate>(1, floorstrike));
collar.setPricingEngine(makeEngine(volatility_));
npvCollaredLeg = collarLeg.NPV();
npvCollar = collar.NPV();
error = std::abs(npvCollaredLeg -(npvVanilla - npvCollar));
if (error>tolerance) {
BOOST_ERROR("\nCollared Leg: gearing=1, spread=0%, strike=" <<
floorstrike*100 << "% and " << capstrike*100 << "%\n" <<
" Collared Floating Leg NPV: " << npvCollaredLeg << "\n" <<
" Floating Leg NPV - Collar NPV: " << npvVanilla - npvCollar << "\n" <<
" Diff: " << error );
}
/* gearing = a and spread = b
CAPPED coupon - Decomposition of payoff
Payoff
= Nom * Min(a*rate+b,strike) * accrualperiod =
= Nom * [a*rate+b + Min(0,strike-a*rate-b)] * accrualperiod =
= Nom * a*rate+b * accrualperiod + Nom * Min(strike-b-a*rate,0) * accrualperiod
--> If a>0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg - Call(a*rate+b,strike)
--> If a<0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg + Nom * Min(strike-b+|a|*rate+,0) * accrualperiod =
= VanillaFloatingLeg + Put(|a|*rate+b,strike)
*/
// Positive gearing
Leg cappedLeg_p =
makeCapFlooredLeg(startDate_,length_,caps,floors0,
volatility_,gearing_p,spread_p);
Swap capLeg_p(fixedLeg,cappedLeg_p);
capLeg_p.setPricingEngine(engine);
Cap cap_p(floatLeg_p,std::vector<Rate>(1,capstrike));
cap_p.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_p.NPV();
npvCappedLeg = capLeg_p.NPV();
npvCap = cap_p.NPV();
error = std::abs(npvCappedLeg - (npvVanilla-npvCap));
if (error>tolerance) {
BOOST_ERROR("\nCapped Leg: gearing=" << gearing_p << ", " <<
"spread= " << spread_p *100 <<
"%, strike=" << capstrike*100 << "%, " <<
"effective strike= " << (capstrike-spread_p)/gearing_p*100 <<
"%\n" <<
" Capped Floating Leg NPV: " << npvCappedLeg << "\n" <<
" Vanilla Leg NPV: " << npvVanilla << "\n" <<
" Cap NPV: " << npvCap << "\n" <<
" Floating Leg NPV - Cap NPV: " << npvVanilla - npvCap << "\n" <<
" Diff: " << error );
}
// Negative gearing
Leg cappedLeg_n =
makeCapFlooredLeg(startDate_,length_,caps,floors0,
volatility_,gearing_n,spread_n);
Swap capLeg_n(fixedLeg,cappedLeg_n);
capLeg_n.setPricingEngine(engine);
Floor floor_n(floatLeg,std::vector<Rate>(1,(capstrike-spread_n)/gearing_n));
floor_n.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_n.NPV();
npvCappedLeg = capLeg_n.NPV();
npvFloor = floor_n.NPV();
error = std::abs(npvCappedLeg - (npvVanilla+ gearing_n*npvFloor));
if (error>tolerance) {
BOOST_ERROR("\nCapped Leg: gearing=" << gearing_n << ", " <<
"spread= " << spread_n *100 <<
"%, strike=" << capstrike*100 << "%, " <<
"effective strike= " << (capstrike-spread_n)/gearing_n*100 <<
"%\n" <<
" Capped Floating Leg NPV: " << npvCappedLeg << "\n" <<
" npv Vanilla: " << npvVanilla << "\n" <<
" npvFloor: " << npvFloor << "\n" <<
" Floating Leg NPV - Cap NPV: " << npvVanilla + gearing_n*npvFloor << "\n" <<
" Diff: " << error );
}
/* gearing = a and spread = b
FLOORED coupon - Decomposition of payoff
Payoff
= Nom * Max(a*rate+b,strike) * accrualperiod =
= Nom * [a*rate+b + Max(0,strike-a*rate-b)] * accrualperiod =
= Nom * a*rate+b * accrualperiod + Nom * Max(strike-b-a*rate,0) * accrualperiod
--> If a>0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg + Put(a*rate+b,strike)
--> If a<0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg + Nom * Max(strike-b+|a|*rate+,0) * accrualperiod =
= VanillaFloatingLeg - Call(|a|*rate+b,strike)
*/
// Positive gearing
Leg flooredLeg_p1 =
makeCapFlooredLeg(startDate_,length_,caps0,floors,
volatility_,gearing_p,spread_p);
Swap floorLeg_p1(fixedLeg,flooredLeg_p1);
floorLeg_p1.setPricingEngine(engine);
Floor floor_p1(floatLeg_p,std::vector<Rate>(1,floorstrike));
floor_p1.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_p.NPV();
npvFlooredLeg = floorLeg_p1.NPV();
npvFloor = floor_p1.NPV();
error = std::abs(npvFlooredLeg - (npvVanilla+npvFloor));
if (error>tolerance) {
BOOST_ERROR("\nFloored Leg: gearing=" << gearing_p << ", "
<< "spread= " << spread_p *100<< "%, strike=" << floorstrike *100 << "%, "
<< "effective strike= " << (floorstrike-spread_p)/gearing_p*100
<< "%\n" <<
" Floored Floating Leg NPV: " << npvFlooredLeg
<< "\n" <<
" Floating Leg NPV + Floor NPV: " << npvVanilla + npvFloor
<< "\n" <<
" Diff: " << error );
}
// Negative gearing
Leg flooredLeg_n =
makeCapFlooredLeg(startDate_,length_,caps0,floors,
volatility_,gearing_n,spread_n);
Swap floorLeg_n(fixedLeg,flooredLeg_n);
floorLeg_n.setPricingEngine(engine);
Cap cap_n(floatLeg,std::vector<Rate>(1,(floorstrike-spread_n)/gearing_n));
cap_n.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_n.NPV();
npvFlooredLeg = floorLeg_n.NPV();
npvCap = cap_n.NPV();
error = std::abs(npvFlooredLeg - (npvVanilla - gearing_n*npvCap));
if (error>tolerance) {
BOOST_ERROR("\nCapped Leg: gearing=" << gearing_n << ", " <<
"spread= " << spread_n *100 <<
"%, strike=" << floorstrike*100 << "%, " <<
"effective strike= " << (floorstrike-spread_n)/gearing_n*100 <<
"%\n" <<
" Capped Floating Leg NPV: " << npvFlooredLeg << "\n" <<
" Floating Leg NPV - Cap NPV: " << npvVanilla - gearing_n*npvCap << "\n" <<
" Diff: " << error );
}
/* gearing = a and spread = b
COLLARED coupon - Decomposition of payoff
Payoff = Nom * Min(caprate,Max(a*rate+b,floorrate)) * accrualperiod
--> If a>0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg - Collar(a*rate+b, floorrate, caprate)
--> If a<0 (assuming positive effective strike):
Payoff = VanillaFloatingLeg + Collar(|a|*rate+b, caprate, floorrate)
*/
// Positive gearing
Leg collaredLeg_p =
makeCapFlooredLeg(startDate_,length_,caps,floors,
volatility_,gearing_p,spread_p);
Swap collarLeg_p1(fixedLeg,collaredLeg_p);
collarLeg_p1.setPricingEngine(engine);
Collar collar_p(floatLeg_p,
std::vector<Rate>(1,capstrike),
std::vector<Rate>(1,floorstrike));
collar_p.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_p.NPV();
npvCollaredLeg = collarLeg_p1.NPV();
npvCollar = collar_p.NPV();
error = std::abs(npvCollaredLeg - (npvVanilla - npvCollar));
if (error>tolerance) {
BOOST_ERROR("\nCollared Leg: gearing=" << gearing_p << ", "
<< "spread= " << spread_p*100 << "%, strike="
<< floorstrike*100 << "% and " << capstrike*100
<< "%, "
<< "effective strike=" << (floorstrike-spread_p)/gearing_p*100
<< "% and " << (capstrike-spread_p)/gearing_p*100
<< "%\n" <<
" Collared Floating Leg NPV: " << npvCollaredLeg
<< "\n" <<
" Floating Leg NPV - Collar NPV: " << npvVanilla - npvCollar
<< "\n" <<
" Diff: " << error );
}
// Negative gearing
Leg collaredLeg_n =
makeCapFlooredLeg(startDate_,length_,caps,floors,
volatility_,gearing_n,spread_n);
Swap collarLeg_n1(fixedLeg,collaredLeg_n);
collarLeg_n1.setPricingEngine(engine);
Collar collar_n(floatLeg,
std::vector<Rate>(1,(floorstrike-spread_n)/gearing_n),
std::vector<Rate>(1,(capstrike-spread_n)/gearing_n));
collar_n.setPricingEngine(makeEngine(volatility_));
npvVanilla = vanillaLeg_n.NPV();
npvCollaredLeg = collarLeg_n1.NPV();
npvCollar = collar_n.NPV();
error = std::abs(npvCollaredLeg - (npvVanilla - gearing_n*npvCollar));
if (error>tolerance) {
BOOST_ERROR("\nCollared Leg: gearing=" << gearing_n << ", "
<< "spread= " << spread_n*100 << "%, strike="
<< floorstrike*100 << "% and " << capstrike*100
<< "%, "
<< "effective strike=" << (floorstrike-spread_n)/gearing_n*100
<< "% and " << (capstrike-spread_n)/gearing_n*100
<< "%\n" <<
" Collared Floating Leg NPV: " << npvCollaredLeg
<< "\n" <<
" Floating Leg NPV - Collar NPV: " << npvVanilla - gearing_n*npvCollar
<< "\n" <<
" Diff: " << error );
}
}
test_suite* CapFlooredCouponTest::suite() {
test_suite* suite = BOOST_TEST_SUITE("Capped/floored coupon tests");
suite->add(BOOST_TEST_CASE(&CapFlooredCouponTest::testLargeRates));
suite->add(BOOST_TEST_CASE(&CapFlooredCouponTest::testDecomposition));
return suite;
}
|