Skip to content

Commit

Permalink
Apply fixes by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 21, 2020
1 parent 66e48ed commit 532cd34
Show file tree
Hide file tree
Showing 277 changed files with 2,177 additions and 2,369 deletions.
6 changes: 3 additions & 3 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -162,7 +162,7 @@ class TestFunction : public CostFunction {
int test(OptimizationMethod& method, CostFunction& f, const EndCriteria& endCriteria,
const Array& start, const Constraint& constraint = Constraint(),
const Array& optimum = Array()) {
QL_REQUIRE(start.size() > 0, "Input size needs to be at least 1");
QL_REQUIRE(!start.empty(), "Input size needs to be at least 1");
std::cout << "Starting point: ";
Constraint c;
if (!constraint.empty())
Expand All @@ -177,9 +177,9 @@ int test(OptimizationMethod& method, CostFunction& f, const EndCriteria& endCrit
std::cout << "Global optimum: ";
Real optimVal = printFunction(p, optimum);
if(std::abs(optimVal) < 1e-13)
return std::abs(val-optimVal) < 1e-6;
return static_cast<int>(std::abs(val - optimVal) < 1e-6);
else
return std::abs((val-optimVal)/optimVal) < 1e-6;
return static_cast<int>(std::abs((val - optimVal) / optimVal) < 1e-6);
}
return 1;
}
Expand Down
3 changes: 1 addition & 2 deletions ql/cashflow.cpp
Expand Up @@ -42,7 +42,7 @@ namespace QuantLib {
// specified in the settings (if any)
boost::optional<bool> includeToday =
Settings::instance().includeTodaysCashFlows();
if (includeToday)
if (includeToday) // NOLINT(readability-implicit-bool-conversion)
includeRefDate = *includeToday;
}
return Event::hasOccurred(refDate, includeRefDate);
Expand All @@ -69,4 +69,3 @@ namespace QuantLib {
}

}

2 changes: 1 addition & 1 deletion ql/cashflows/averagebmacoupon.cpp
Expand Up @@ -45,7 +45,7 @@ namespace QuantLib {
d1 = startDate,
d2 = startDate;

QL_REQUIRE (fixingDates.size() > 0, "fixing date list empty");
QL_REQUIRE(!fixingDates.empty(), "fixing date list empty");
QL_REQUIRE (index->valueDate(fixingDates.front()) <= startDate,
"first fixing date valid after period start");
QL_REQUIRE (index->valueDate(fixingDates.back()) >= endDate,
Expand Down
22 changes: 9 additions & 13 deletions ql/cashflows/capflooredinflationcoupon.cpp
Expand Up @@ -80,15 +80,16 @@ namespace QuantLib {
const ext::shared_ptr<YoYInflationCouponPricer>& pricer) {

YoYInflationCoupon::setPricer(pricer);
if (underlying_) underlying_->setPricer(pricer);
if (underlying_ != 0)
underlying_->setPricer(pricer);
}


Rate CappedFlooredYoYInflationCoupon::rate() const {
Rate swapletRate = underlying_ ? underlying_->rate() : YoYInflationCoupon::rate();
Rate swapletRate = underlying_ != 0 ? underlying_->rate() : YoYInflationCoupon::rate();

if(isFloored_ || isCapped_) {
if (underlying_) {
if (underlying_ != 0) {
QL_REQUIRE(underlying_->pricer(), "pricer not set");
} else {
QL_REQUIRE(pricer_, "pricer not set");
Expand All @@ -97,19 +98,14 @@ namespace QuantLib {

Rate floorletRate = 0.;
if(isFloored_) {
floorletRate =
underlying_ ?
underlying_->pricer()->floorletRate(effectiveFloor()) :
pricer()->floorletRate(effectiveFloor())
;
floorletRate = underlying_ != 0 ?
underlying_->pricer()->floorletRate(effectiveFloor()) :
pricer()->floorletRate(effectiveFloor());
}
Rate capletRate = 0.;
if(isCapped_) {
capletRate =
underlying_ ?
underlying_->pricer()->capletRate(effectiveCap()) :
pricer()->capletRate(effectiveCap())
;
capletRate = underlying_ != 0 ? underlying_->pricer()->capletRate(effectiveCap()) :
pricer()->capletRate(effectiveCap());
}

return swapletRate + floorletRate - capletRate;
Expand Down
28 changes: 14 additions & 14 deletions ql/cashflows/cashflows.cpp
Expand Up @@ -40,7 +40,7 @@ namespace QuantLib {
Date d = Date::maxDate();
for (Size i=0; i<leg.size(); ++i) {
ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(leg[i]);
if (c)
if (c != 0)
d = std::min(d, c->accrualStartDate());
else
d = std::min(d, leg[i]->date());
Expand All @@ -54,7 +54,7 @@ namespace QuantLib {
Date d = Date::minDate();
for (Size i=0; i<leg.size(); ++i) {
ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(leg[i]);
if (c)
if (c != 0)
d = std::max(d, c->accrualEndDate());
else
d = std::max(d, leg[i]->date());
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->nominal();
}
return 0.0;
Expand All @@ -256,7 +256,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accrualStartDate();
}
return Date();
Expand All @@ -273,7 +273,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accrualEndDate();
}
return Date();
Expand All @@ -290,7 +290,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->referencePeriodStart();
}
return Date();
Expand All @@ -307,7 +307,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->referencePeriodEnd();
}
return Date();
Expand All @@ -324,7 +324,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accrualPeriod();
}
return 0;
Expand All @@ -341,7 +341,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accrualDays();
}
return 0;
Expand All @@ -361,7 +361,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accruedPeriod(settlementDate);
}
return 0;
Expand All @@ -381,7 +381,7 @@ namespace QuantLib {
Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
return cp->accruedDays(settlementDate);
}
return 0;
Expand All @@ -402,7 +402,7 @@ namespace QuantLib {
Real result = 0.0;
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp)
if (cp != 0)
result += cp->accruedAmount(settlementDate);
}
return result;
Expand Down Expand Up @@ -585,7 +585,7 @@ namespace QuantLib {
Date refStartDate, refEndDate;
ext::shared_ptr<Coupon> coupon =
ext::dynamic_pointer_cast<Coupon>(cashFlow);
if (coupon) {
if (coupon != 0) {
refStartDate = coupon->referencePeriodStart();
refEndDate = coupon->referencePeriodEnd();
} else {
Expand All @@ -599,7 +599,7 @@ namespace QuantLib {
refEndDate = cashFlowDate;
}

if (coupon && lastDate!=coupon->accrualStartDate()) {
if ((coupon != 0) && lastDate != coupon->accrualStartDate()) {
Time couponPeriod = dc.yearFraction(coupon->accrualStartDate(),
cashFlowDate, refStartDate, refEndDate);
Time accruedPeriod = dc.yearFraction(coupon->accrualStartDate(),
Expand Down
6 changes: 3 additions & 3 deletions ql/cashflows/conundrumpricer.hpp
Expand Up @@ -284,9 +284,9 @@ namespace QuantLib {
Option::Type optionType);
Real operator()(Real x) const;
protected:
Real functionF(const Real x) const;
Real firstDerivativeOfF(const Real x) const;
Real secondDerivativeOfF(const Real x) const;
Real functionF(Real x) const;
Real firstDerivativeOfF(Real x) const;
Real secondDerivativeOfF(Real x) const;

Real strike() const;
Real annuity() const;
Expand Down
6 changes: 3 additions & 3 deletions ql/cashflows/couponpricer.cpp
Expand Up @@ -225,13 +225,13 @@ namespace QuantLib {
// we might end up here because a CappedFlooredCoupon
// was directly constructed; we should then check
// the underlying for consistency with the pricer
if (ext::dynamic_pointer_cast<IborCoupon>(c.underlying())) {
if (ext::dynamic_pointer_cast<IborCoupon>(c.underlying()) != 0) {
QL_REQUIRE(ext::dynamic_pointer_cast<IborCouponPricer>(pricer_),
"pricer not compatible with Ibor Coupon");
} else if (ext::dynamic_pointer_cast<CmsCoupon>(c.underlying())) {
} else if (ext::dynamic_pointer_cast<CmsCoupon>(c.underlying()) != 0) {
QL_REQUIRE(ext::dynamic_pointer_cast<CmsCouponPricer>(pricer_),
"pricer not compatible with CMS Coupon");
} else if (ext::dynamic_pointer_cast<CmsSpreadCoupon>(c.underlying())) {
} else if (ext::dynamic_pointer_cast<CmsSpreadCoupon>(c.underlying()) != 0) {
QL_REQUIRE(ext::dynamic_pointer_cast<CmsSpreadCouponPricer>(pricer_),
"pricer not compatible with CMS spread Coupon");
}
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/cpicoupon.hpp
Expand Up @@ -179,7 +179,7 @@ namespace QuantLib {
public:
CPILeg(const Schedule& schedule,
const ext::shared_ptr<ZeroInflationIndex>& index,
const Real baseCPI,
Real baseCPI,
const Period& observationLag);
CPILeg& withNotionals(Real notional);
CPILeg& withNotionals(const std::vector<Real>& notionals);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/digitalcoupon.hpp
Expand Up @@ -132,10 +132,10 @@ namespace QuantLib {

void setPricer(
const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
if (pricer_)
if (pricer_ != 0)
unregisterWith(pricer_);
pricer_ = pricer;
if (pricer_)
if (pricer_ != 0)
registerWith(pricer_);
update();
underlying_->setPricer(pricer);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/floatingratecoupon.cpp
Expand Up @@ -60,10 +60,10 @@ namespace QuantLib {

void FloatingRateCoupon::setPricer(
const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
if (pricer_)
if (pricer_ != 0)
unregisterWith(pricer_);
pricer_ = pricer;
if (pricer_)
if (pricer_ != 0)
registerWith(pricer_);
update();
}
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/inflationcoupon.cpp
Expand Up @@ -49,10 +49,10 @@ namespace QuantLib {

void InflationCoupon::setPricer(const ext::shared_ptr<InflationCouponPricer>& pricer) {
QL_REQUIRE(checkPricerImpl(pricer),"pricer given is wrong type");
if (pricer_)
if (pricer_ != 0)
unregisterWith(pricer_);
pricer_ = pricer;
if (pricer_)
if (pricer_ != 0)
registerWith(pricer_);
update();
}
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/inflationcouponpricer.cpp
Expand Up @@ -28,7 +28,7 @@ namespace QuantLib {
for (Size i=0; i<leg.size(); ++i) {
ext::shared_ptr<InflationCoupon> c =
ext::dynamic_pointer_cast<InflationCoupon>(leg[i]);
if (c)
if (c != 0)
c->setPricer(p);
}
}
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/lineartsrpricer.hpp
Expand Up @@ -189,8 +189,8 @@ namespace QuantLib {
private:

Real GsrG(const Date &d) const;
Real singularTerms(const Option::Type type, const Real strike) const;
Real integrand(const Real strike) const;
Real singularTerms(Option::Type type, Real strike) const;
Real integrand(Real strike) const;
Real a_, b_;

class integrand_f;
Expand Down
6 changes: 3 additions & 3 deletions ql/event.cpp
Expand Up @@ -28,9 +28,9 @@ namespace QuantLib {
boost::optional<bool> includeRefDate) const {
Date refDate =
d != Date() ? d : Settings::instance().evaluationDate();
bool includeRefDateEvent =
includeRefDate ? *includeRefDate :
Settings::instance().includeReferenceDateEvents();
bool includeRefDateEvent = includeRefDate ? // NOLINT(readability-implicit-bool-conversion)
*includeRefDate :
Settings::instance().includeReferenceDateEvents();
if (includeRefDateEvent)
return date() < refDate;
else
Expand Down
21 changes: 10 additions & 11 deletions ql/experimental/amortizingbonds/amortizingfixedratebond.hpp
Expand Up @@ -47,17 +47,16 @@ namespace QuantLib {
daycount is only used for quoting/settlement purposes -
not for calculating the coupons.
*/
AmortizingFixedRateBond(
Natural settlementDays,
const Calendar& calendar,
Real faceAmount,
const Date& startDate,
const Period& bondTenor,
const Frequency& sinkingFrequency,
const Rate coupon,
const DayCounter& accrualDayCounter,
BusinessDayConvention paymentConvention = Following,
const Date& issueDate = Date());
AmortizingFixedRateBond(Natural settlementDays,
const Calendar& calendar,
Real faceAmount,
const Date& startDate,
const Period& bondTenor,
const Frequency& sinkingFrequency,
Rate coupon,
const DayCounter& accrualDayCounter,
BusinessDayConvention paymentConvention = Following,
const Date& issueDate = Date());
Frequency frequency() const { return frequency_; }
const DayCounter& dayCounter() const { return dayCounter_; }
protected:
Expand Down
Expand Up @@ -64,7 +64,7 @@ namespace QuantLib {
Real c, Real gm);
Real dvv(Real s,Real p,Real tt,Real a,Real b,Real gm);
Real dff(Real s, Real p,Real tt,Real a,Real b,Real gm);
Real tvtl(int jj,Real limit[4],Real sigmarho[4],Real epsi);
Real tvtl(int jj, const Real limit[4], const Real sigmarho[4], Real epsi);

Real BarrierUPD(Real kprice, Real stock, Real hbarr,
Real taumin, Real taumax, int iord, int igm,
Expand Down Expand Up @@ -783,8 +783,7 @@ namespace QuantLib {
Real RUB, Real AR, Real RUC,
int NUC));

Real tvtl(int NU, Real limit[], Real sigmarho[],Real epsi)
{
Real tvtl(int NU, const Real limit[], const Real sigmarho[], Real epsi) {
/*
A function for computing trivariate normal and t-probabilities.
Expand Down Expand Up @@ -886,7 +885,7 @@ namespace QuantLib {
RUB = asin( R13 );
AR = asin( R23);
RUC = SIGN( PT, AR ) - AR;
TVT = TVT + ADONET( ZRO, ONE, EPS, *TVTMFN)/( 4.0*PT );
TVT = TVT + ADONET(ZRO, ONE, EPS, TVTMFN) / (4.0 * PT);
}
result = max( ZRO, min( TVT, ONE ) );

Expand Down Expand Up @@ -941,7 +940,6 @@ namespace QuantLib {
SX = sin(X);
CS = 1 - SX*SX;
}
return;
}
//

Expand Down

0 comments on commit 532cd34

Please sign in to comment.