Skip to content

Commit

Permalink
Small fixes to callable bonds; add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 10, 2020
1 parent afc6f02 commit a8de45a
Show file tree
Hide file tree
Showing 6 changed files with 645 additions and 17 deletions.
Expand Up @@ -52,14 +52,14 @@ namespace QuantLib {
dayCounter.yearFraction(referenceDate,
args.callabilityDates[i]);

// similar to the tree swaption engine, we collapse similar coupon
// and exercise dates to avoid mispricing. Delete if unnecessary.

// To avoid mispricing, we snap exercise dates to the closest coupon date.
for (Size i=0; i<callabilityTimes_.size(); i++) {
Time exerciseTime = callabilityTimes_[i];
Time& exerciseTime = callabilityTimes_[i];
for (Size j=0; j<couponTimes_.size(); j++) {
if (withinNextWeek(exerciseTime, couponTimes_[j]))
couponTimes_[j] = exerciseTime;
if (withinNextWeek(exerciseTime, couponTimes_[j])) {
exerciseTime = couponTimes_[j];
break;
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions ql/experimental/callablebonds/treecallablebondengine.cpp
Expand Up @@ -50,18 +50,13 @@ namespace QuantLib {
void TreeCallableFixedRateBondEngine::calculateWithSpread(Spread s) const {
QL_REQUIRE(!model_.empty(), "no model specified");

Date referenceDate;
DayCounter dayCounter;

ext::shared_ptr<TermStructureConsistentModel> tsmodel =
ext::dynamic_pointer_cast<TermStructureConsistentModel>(*model_);
if (tsmodel != 0) {
referenceDate = tsmodel->termStructure()->referenceDate();
dayCounter = tsmodel->termStructure()->dayCounter();
} else {
referenceDate = termStructure_->referenceDate();
dayCounter = termStructure_->dayCounter();
}
Handle<YieldTermStructure> discountCurve =
tsmodel != 0 ? tsmodel->termStructure() : termStructure_;

Date referenceDate = discountCurve->referenceDate();
DayCounter dayCounter = discountCurve->dayCounter();

DiscretizedCallableFixedRateBond callableBond(arguments_,
referenceDate,
Expand Down Expand Up @@ -89,7 +84,10 @@ namespace QuantLib {
arguments_.redemptionDate);
callableBond.initialize(lattice, redemptionTime);
callableBond.rollback(0.0);
results_.value = results_.settlementValue = callableBond.presentValue();
results_.value = callableBond.presentValue();

DiscountFactor d = discountCurve->discount(arguments_.settlementDate);
results_.settlementValue = results_.value / d;
}

}
Expand Down
2 changes: 2 additions & 0 deletions test-suite/Makefile.am
Expand Up @@ -20,6 +20,7 @@ QL_TEST_SRCS = \
brownianbridge.cpp \
businessdayconventions.cpp \
calendars.cpp \
callablebonds.cpp \
capfloor.cpp \
capflooredcoupon.cpp \
cashflows.cpp \
Expand Down Expand Up @@ -176,6 +177,7 @@ QL_TEST_HDRS = \
brownianbridge.hpp \
businessdayconventions.hpp \
calendars.hpp \
callablebonds.hpp \
capfloor.hpp \
capflooredcoupon.hpp \
cashflows.hpp \
Expand Down

0 comments on commit a8de45a

Please sign in to comment.