Skip to content

Commit

Permalink
Merge pull request #882.
Browse files Browse the repository at this point in the history
Add or improve a few checks.
  • Loading branch information
lballabio committed Aug 10, 2020
2 parents ddf98f4 + 5152e29 commit afc6f02
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ql/cashflows/cashflows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ namespace QuantLib {
Date settlementDate,
Date npvDate,
Real targetNpv) {
if (leg.empty())
return 0.0;

if (settlementDate == Date())
settlementDate = Settings::instance().evaluationDate();
Expand Down
1 change: 1 addition & 0 deletions ql/cashflows/yoyinflationcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ namespace QuantLib {
yoyInflationLeg::operator Leg() const {

Size n = schedule_.size()-1;
QL_REQUIRE(!paymentDayCounter_.empty(), "no payment daycounter given");
QL_REQUIRE(!notionals_.empty(), "no notional given");
QL_REQUIRE(notionals_.size() <= n,
"too many nominals (" << notionals_.size() <<
Expand Down
2 changes: 2 additions & 0 deletions ql/methods/lattices/trinomialtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace QuantLib {
x0_ = process->x0();

Size nTimeSteps = timeGrid.size() - 1;
QL_REQUIRE(nTimeSteps > 0, "null time steps for trinomial tree");

Integer jMin = 0;
Integer jMax = 0;

Expand Down
5 changes: 2 additions & 3 deletions ql/pricingengines/bond/bondfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ namespace QuantLib {
if (settlement == Date())
settlement = bond.settlementDate();

QL_REQUIRE(BondFunctions::isTradable(bond, settlement),
"non tradable at " << settlement <<
" (maturity being " << bond.maturityDate() << ")");
if (!BondFunctions::isTradable(bond, settlement))
return 0.0;

return CashFlows::accruedAmount(bond.cashflows(),
false, settlement) *
Expand Down
2 changes: 1 addition & 1 deletion ql/termstructures/inflationtermstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace QuantLib {
void InflationTermStructure::checkRange(const Date& d,
bool extrapolate) const {
QL_REQUIRE(d >= baseDate(),
"date (" << d << ") is before base date");
"date (" << d << ") is before base date (" << baseDate() << ")");
QL_REQUIRE(extrapolate || allowsExtrapolation() || d <= maxDate(),
"date (" << d << ") is past max curve date ("
<< maxDate() << ")");
Expand Down

0 comments on commit afc6f02

Please sign in to comment.