Skip to content

Commit

Permalink
Merge f88827c into 992cec2
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed May 24, 2020
2 parents 992cec2 + f88827c commit e5bc55b
Show file tree
Hide file tree
Showing 414 changed files with 3,582 additions and 3,773 deletions.
7 changes: 7 additions & 0 deletions .clang-tidy
@@ -0,0 +1,7 @@
---
Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-misc-macro-parentheses,-misc-incorrect-roundings,-misc-unused-parameters'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
...
27 changes: 27 additions & 0 deletions .github/workflows/tidy.yml
@@ -0,0 +1,27 @@
name: Apply clang-tidy fixes
on:
push:
branches:
- '**'
jobs:
check:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Setup
run: |
sudo apt-get install -y clang-tidy libboost-dev
- name: Check
run: |
find . -name *.[hc]pp -not -name config.*.hpp -not -name all.hpp -not -name quantlib.hpp -not -name paralleltestrunner.hpp | sort | xargs -n 1 ./tools/run_tidy.sh
- uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: clang-tidy-fixes-${{ github.ref }}
commit-message: 'Automated fixes by clang-tidy'
title: 'Automated fixes by clang-tidy'
body: |
This is an automated PR generated by the [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action.
Please review the changes before merging.
2 changes: 1 addition & 1 deletion Examples/Gaussian1dModels/Gaussian1dModels.cpp
Expand Up @@ -579,7 +579,7 @@ int main(int argc, char *argv[]) {

std::vector<Date> markovStepDates(exerciseDates.begin(),
exerciseDates.end());
std::vector<Date> cmsFixingDates(markovStepDates);
const std::vector<Date>& cmsFixingDates(markovStepDates);
std::vector<Real> markovSigmas(markovStepDates.size() + 1, 0.01);
std::vector<Period> tenors(cmsFixingDates.size(), 10 * Years);
ext::shared_ptr<MarkovFunctional> markov =
Expand Down
20 changes: 13 additions & 7 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 Expand Up @@ -251,12 +251,18 @@ void testSimulatedAnnealing(Size dimension, Size maxSteps, Size staticSteps){
std::cout << "================================================================" << std::endl;
}

void testGaussianSA(Size dimension, Size maxSteps, Size staticSteps, Real initialTemp,
void testGaussianSA(Size dimension,
Size maxSteps,
Size staticSteps,
Real initialTemp,
Real finalTemp,
GaussianSimulatedAnnealing::ResetScheme resetScheme = GaussianSimulatedAnnealing::ResetToBestPoint,
GaussianSimulatedAnnealing::ResetScheme resetScheme =
GaussianSimulatedAnnealing::ResetToBestPoint,
Size resetSteps = 150,
GaussianSimulatedAnnealing::LocalOptimizeScheme optimizeScheme = GaussianSimulatedAnnealing::EveryBestPoint,
ext::shared_ptr<OptimizationMethod> localOptimizer = ext::make_shared<LevenbergMarquardt>()){
GaussianSimulatedAnnealing::LocalOptimizeScheme optimizeScheme =
GaussianSimulatedAnnealing::EveryBestPoint,
const ext::shared_ptr<OptimizationMethod>& localOptimizer =
ext::make_shared<LevenbergMarquardt>()) {

/*The ackley function has a large amount of local minima, but the
* structure is symmetric, so if one could simply just ignore the
Expand Down
10 changes: 4 additions & 6 deletions Examples/MarketModels/MarketModels.cpp
Expand Up @@ -79,10 +79,8 @@ namespace QuantLib {
#endif


std::vector<std::vector<Matrix> > theVegaBumps(bool factorwiseBumping,
ext::shared_ptr<MarketModel> marketModel,
bool doCaps)
{
std::vector<std::vector<Matrix> >
theVegaBumps(bool factorwiseBumping, const ext::shared_ptr<MarketModel>& marketModel, bool doCaps) {
Real multiplierCutOff = 50.0;
Real projectionTolerance = 1E-4;
Size numberRates= marketModel->numberOfRates();
Expand Down Expand Up @@ -196,7 +194,7 @@ int Bermudan()
CallSpecifiedMultiProduct(receiverSwap, naifStrategy,
ExerciseAdapter(nullRebate));

EvolutionDescription evolution = dummyProduct.evolution();
const EvolutionDescription& evolution = dummyProduct.evolution();


// parameters for models
Expand Down Expand Up @@ -537,7 +535,7 @@ int InverseFloater(Real rateLevel)
CallSpecifiedMultiProduct(inverseFloater, naifStrategy,
ExerciseAdapter(nullRebate));

EvolutionDescription evolution = dummyProduct.evolution();
const EvolutionDescription& evolution = dummyProduct.evolution();


// parameters for models
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
30 changes: 15 additions & 15 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 @@ -577,15 +577,15 @@ namespace QuantLib {
}

// helper fucntion used to calculate Time-To-Discount for each stage when calculating discount factor stepwisely
Time getStepwiseDiscountTime(const ext::shared_ptr<QuantLib::CashFlow> cashFlow,
Time getStepwiseDiscountTime(const ext::shared_ptr<QuantLib::CashFlow>& cashFlow,
const DayCounter& dc,
Date npvDate,
Date lastDate) {
Date cashFlowDate = cashFlow->date();
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/cashflowvectors.hpp
Expand Up @@ -100,8 +100,8 @@ namespace QuantLib {
Leg leg; leg.reserve(n);

// the following is not always correct
Calendar calendar = schedule.calendar();
const Calendar& calendar = schedule.calendar();

if (paymentCalendar.empty()) {
paymentCalendar = calendar;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace QuantLib {
Leg leg; leg.reserve(n);

// the following is not always correct
Calendar calendar = schedule.calendar();
const Calendar& calendar = schedule.calendar();

Date refStart, start, refEnd, end;
Date paymentDate;
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/conundrumpricer.cpp
Expand Up @@ -226,7 +226,7 @@ namespace QuantLib {

class Spy {
public:
explicit Spy(ext::function<Real (Real)> f) : f_(f) {}
explicit Spy(const ext::function<Real(Real)>& f) : f_(f) {}
Real value(Real x){
abscissas.push_back(x);
Real value = f_(x);
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
8 changes: 3 additions & 5 deletions ql/cashflows/couponpricer.hpp
Expand Up @@ -94,13 +94,11 @@ namespace QuantLib {
public:
enum TimingAdjustment { Black76, BivariateLognormal };
BlackIborCouponPricer(
const Handle<OptionletVolatilityStructure>& v =
Handle<OptionletVolatilityStructure>(),
const Handle<OptionletVolatilityStructure>& v = Handle<OptionletVolatilityStructure>(),
const TimingAdjustment timingAdjustment = Black76,
const Handle<Quote> correlation =
const Handle<Quote>& correlation =
Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(1.0))))
: IborCouponPricer(v), timingAdjustment_(timingAdjustment),
correlation_(correlation) {
: IborCouponPricer(v), timingAdjustment_(timingAdjustment), correlation_(correlation) {
QL_REQUIRE(timingAdjustment_ == Black76 ||
timingAdjustment_ == BivariateLognormal,
"unknown timing adjustment (code " << timingAdjustment_
Expand Down

0 comments on commit e5bc55b

Please sign in to comment.