Skip to content

Commit

Permalink
removed check for increasing notionals as there are bonds with draw d…
Browse files Browse the repository at this point in the history
…own (#1437)
  • Loading branch information
lballabio committed Nov 22, 2022
2 parents f271efd + 32cf78c commit 13cc9e9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
3 changes: 1 addition & 2 deletions ql/instruments/bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Copyright (C) 2007, 2008, 2009 Ferdinando Ametrano
Copyright (C) 2007 Chiara Fornarola
Copyright (C) 2008 Simon Ibbotson
Copyright (C) 2022 Oleg Kulkov
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
Expand Down Expand Up @@ -379,8 +380,6 @@ namespace QuantLib {
lastPaymentDate = coupon->date();
} else if (!close(notional, notionals_.back())) {
// ...or if it has changed.
QL_REQUIRE(notional < notionals_.back(),
"increasing coupon notionals");
notionals_.push_back(coupon->nominal());
// in this case, we also add the last valid date for
// the previous one...
Expand Down
63 changes: 63 additions & 0 deletions test-suite/amortizingbond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/settings.hpp>
#include <ql/time/calendars/brazil.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/business252.hpp>
#include <iostream>

Expand Down Expand Up @@ -211,9 +213,70 @@ void AmortizingBondTest::testBrazilianAmortizingFixedRateBond() {

}

void AmortizingBondTest::testAmortizingFixedRateBondWithDrawDown() {
BOOST_TEST_MESSAGE("Testing amortizing fixed rate bond with draw-down...");

Date issueDate = Date(19, May, 2012);
Date maturityDate = Date(25, May, 2017);
Calendar calendar = UnitedStates(UnitedStates::GovernmentBond);
Natural settlementDays = 3;

Schedule schedule(issueDate, maturityDate, Period(Semiannual), calendar,
Unadjusted, Unadjusted, DateGeneration::Backward, false);

std::vector<double> nominals = { 100.0, 100.0, 100.5, 100.5, 101.5, 101.5, 90.0, 80.0, 70.0, 60.0 };
std::vector<double> rates = { 0.042 };

Leg leg = FixedRateLeg(schedule)
.withNotionals(nominals)
.withCouponRates(rates, Actual360())
.withPaymentAdjustment(Unadjusted)
.withPaymentCalendar(calendar);

Bond bond(settlementDays, calendar, issueDate, leg);

const auto& cfs = bond.cashflows();

// first draw-down
Real calculated = cfs.at(2)->amount();
Real expected = nominals[1] - nominals[2];
Real error = std::fabs(calculated - expected);
Real tolerance = 1e-8;

if(error > tolerance) {
BOOST_ERROR("Failed to calculate first draw down: "
<< "\n expected: " << expected
<< "\n calculated: " << calculated);
}

// second draw-down
calculated = cfs.at(5)->amount();
expected = nominals[3] - nominals[4];
error = std::fabs(calculated - expected);

if(error > tolerance) {
BOOST_ERROR("Failed to calculate second draw down: "
<< "\n expected: " << expected
<< "\n calculated: " << calculated);
}

// first amortization
calculated = cfs.at(8)->amount();
expected = nominals[5] - nominals[6];
error = std::fabs(calculated - expected);

if(error > tolerance) {
BOOST_ERROR("Failed to calculate fist amortization: "
<< "\n expected: " << expected
<< "\n calculated: " << calculated);
}

}

test_suite* AmortizingBondTest::suite() {
auto* suite = BOOST_TEST_SUITE("Amortizing Bond tests");
suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testAmortizingFixedRateBond));
suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testBrazilianAmortizingFixedRateBond));
suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testAmortizingFixedRateBondWithDrawDown));
return suite;
}
4 changes: 2 additions & 2 deletions test-suite/amortizingbond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class AmortizingBondTest {
public:
static void testAmortizingFixedRateBond();
static void testBrazilianAmortizingFixedRateBond();
static boost::unit_test_framework::test_suite* suite();

static void testAmortizingFixedRateBondWithDrawDown();
static boost::unit_test_framework::test_suite* suite();
};

#endif

0 comments on commit 13cc9e9

Please sign in to comment.