Skip to content

Commit

Permalink
Automated fixes by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and lballabio committed Nov 18, 2024
1 parent 5bf7c0d commit bb4b781
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions ql/methods/finitedifferences/operators/fdmwienerop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace QuantLib {
const ext::shared_ptr<FdmMesher>& mesher,
ext::shared_ptr<YieldTermStructure> rTS,
const Array& lambdas)
: rTS_(std::move(rTS)),
r_(0.0) {
: rTS_(std::move(rTS)) {

QL_REQUIRE(mesher->layout()->dim().size() == lambdas.size(),
"mesher and lambdas need to be of the same dimension");
Expand Down Expand Up @@ -86,6 +85,7 @@ namespace QuantLib {
std::vector<SparseMatrix> FdmWienerOp::toMatrixDecomp() const {
std::vector<SparseMatrix> retVal;

retVal.reserve(ops_.size());
for (const auto& op: ops_)
retVal.push_back(op->toMatrix());

Expand Down
2 changes: 1 addition & 1 deletion ql/methods/finitedifferences/operators/fdmwienerop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace QuantLib {
private:
const ext::shared_ptr<YieldTermStructure> rTS_;
std::vector<ext::shared_ptr<TripleBandLinearOp> > ops_;
Rate r_;
Rate r_ = 0.0;
};
}
#endif
3 changes: 2 additions & 1 deletion ql/pricingengines/basket/bjerksundstenslandspreadengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

#include <ql/pricingengines/basket/bjerksundstenslandspreadengine.hpp>
#include <ql/math/distributions/normaldistribution.hpp>
#include <utility>

namespace QuantLib {

BjerksundStenslandSpreadEngine::BjerksundStenslandSpreadEngine(
ext::shared_ptr<GeneralizedBlackScholesProcess> process1,
ext::shared_ptr<GeneralizedBlackScholesProcess> process2,
Real correlation)
: SpreadBlackScholesVanillaEngine(process1, process2, correlation) {
: SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation) {
}

Real BjerksundStenslandSpreadEngine::calculate(
Expand Down
4 changes: 2 additions & 2 deletions ql/pricingengines/basket/choibasketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ namespace QuantLib {
std::copy(R.row_begin(i)+1, R.row_end(i), R_2_n.row_begin(i));

const SVD svd(C*R_2_n);
const Matrix U = svd.U();
const Array sv = svd.singularValues();
const Matrix& U = svd.U();
const Array& sv = svd.singularValues();

Matrix v(n_, n_-1);
for (Size i=0; i < n_-1; ++i)
Expand Down
4 changes: 2 additions & 2 deletions ql/pricingengines/basket/denglizhoubasketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ namespace QuantLib {
p.reserve(n_);

for (Size i=0; i < n_; ++i)
p.emplace_back(std::make_tuple(weights[i], i, s[i], dq[i], v[i]));
p.emplace_back(weights[i], i, s[i], dq[i], v[i]);

const ext::shared_ptr<PlainVanillaPayoff> payoff =
ext::dynamic_pointer_cast<PlainVanillaPayoff>(avgPayoff->basePayoff());
QL_REQUIRE(payoff, "non-plain vanilla payoff given");

Matrix rho;
if (payoff->strike() < 0.0) {
p.emplace_back(std::make_tuple(1.0, n_, -payoff->strike(), dr0, 0.0));
p.emplace_back(1.0, n_, -payoff->strike(), dr0, 0.0);
rho = Matrix(n_+1, n_+1);
for (Size i=0; i < n_; ++i) {
std::copy(rho_.row_begin(i), rho_.row_end(i), rho.row_begin(i));
Expand Down
10 changes: 5 additions & 5 deletions ql/pricingengines/basket/fdndimblackscholesvanillaengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
#include <ql/pricingengines/basket/fdndimblackscholesvanillaengine.hpp>
#include <ql/pricingengines/basket/vectorbsmprocessextractor.hpp>

#include <boost/preprocessor/iteration/local.hpp>
#include <utility>

namespace QuantLib {

Expand All @@ -41,7 +41,7 @@ namespace QuantLib {
FdmPCABasketInnerValue(
ext::shared_ptr<BasketPayoff> payoff,
ext::shared_ptr<FdmMesher> mesher,
Array logS0, Array vols,
Array logS0, const Array& vols,
std::vector<ext::shared_ptr<YieldTermStructure>> qTS,
ext::shared_ptr<YieldTermStructure> rTS,
Matrix Q, Array l)
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace QuantLib {
Matrix rho, Size xGrid, Size tGrid, Size dampingSteps,
const FdmSchemeDesc& schemeDesc)
: FdndimBlackScholesVanillaEngine(
processes, rho, std::vector<Size>(1, xGrid), tGrid, dampingSteps, schemeDesc)
std::move(processes), std::move(rho), std::vector<Size>(1, xGrid), tGrid, dampingSteps, schemeDesc)
{}


Expand All @@ -143,8 +143,8 @@ namespace QuantLib {

const SymmetricSchurDecomposition schur(
getCovariance(vols.begin(), vols.end(), rho_));
const Matrix Q = schur.eigenvectors();
const Array l = schur.eigenvalues();
const Matrix& Q = schur.eigenvectors();
const Array& l = schur.eigenvalues();

const Real eps = 1e-4;
std::vector<ext::shared_ptr<Fdm1dMesher> > meshers;
Expand Down
3 changes: 2 additions & 1 deletion ql/pricingengines/basket/kirkengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
#include <ql/math/functional.hpp>
#include <ql/pricingengines/basket/kirkengine.hpp>
#include <ql/pricingengines/blackcalculator.hpp>
#include <utility>

namespace QuantLib {

KirkEngine::KirkEngine(ext::shared_ptr<GeneralizedBlackScholesProcess> process1,
ext::shared_ptr<GeneralizedBlackScholesProcess> process2,
Real correlation)
: SpreadBlackScholesVanillaEngine(process1, process2, correlation) {
: SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation) {
}

Real KirkEngine::calculate(
Expand Down
3 changes: 2 additions & 1 deletion ql/pricingengines/basket/operatorsplittingspreadengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <ql/math/functional.hpp>
#include <ql/math/distributions/normaldistribution.hpp>
#include <utility>

namespace QuantLib {

Expand All @@ -29,7 +30,7 @@ namespace QuantLib {
ext::shared_ptr<GeneralizedBlackScholesProcess> process2,
Real correlation,
Order order)
: SpreadBlackScholesVanillaEngine(process1, process2, correlation),
: SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation),
order_(order) {
}

Expand Down
3 changes: 1 addition & 2 deletions ql/pricingengines/basket/singlefactorbsmbasketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace QuantLib {
namespace detail {
SumExponentialsRootSolver::SumExponentialsRootSolver(
Array a, Array sig, Real K)
: a_(std::move(a)), sig_(std::move(sig)), K_(K),
fCtr_(0), fPrimeCtr_(0), fDoublePrimeCtr_(0) {
: a_(std::move(a)), sig_(std::move(sig)), K_(K) {
QL_REQUIRE(a_.size() == sig_.size(),
"Arrays must have the same size");
}
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/basket/singlefactorbsmbasketengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace QuantLib {
private:
const Array a_, sig_;
const Real K_;
mutable Size fCtr_, fPrimeCtr_, fDoublePrimeCtr_;
mutable Size fCtr_ = 0, fPrimeCtr_ = 0, fDoublePrimeCtr_ = 0;
};
}
}
Expand Down
7 changes: 4 additions & 3 deletions ql/pricingengines/basket/vectorbsmprocessextractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include <ql/pricingengines/basket/vectorbsmprocessextractor.hpp>

namespace QuantLib {
namespace detail {
namespace QuantLib::detail {

VectorBsmProcessExtractor::VectorBsmProcessExtractor(
std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > p)
: processes_(std::move(p)) {
Expand Down Expand Up @@ -91,5 +91,6 @@ namespace QuantLib {
}
);
}
}

}

7 changes: 4 additions & 3 deletions ql/pricingengines/basket/vectorbsmprocessextractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <ql/processes/blackscholesprocess.hpp>
#include <functional>

namespace QuantLib {
namespace detail {
namespace QuantLib::detail {

class VectorBsmProcessExtractor {
public:
explicit VectorBsmProcessExtractor(
Expand All @@ -46,7 +46,8 @@ namespace QuantLib {

const std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > processes_;
};
}

}


#endif
14 changes: 7 additions & 7 deletions test-suite/basketoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,9 @@ BOOST_AUTO_TEST_CASE(testOperatorSplittingSpreadEngine) {
{ 0.7, 9.0863, 9.0862},
{ 0.9, 6.9148, 6.9134}
};
for (Size i = 0; i < std::size(testData); ++i) {
const Real rho = testData[i][0];
Real expected = testData[i][1];
for (const auto & i : testData) {
const Real rho = i[0];
Real expected = i[1];

option.setPricingEngine(
ext::make_shared<OperatorSplittingSpreadEngine>(
Expand All @@ -1220,7 +1220,7 @@ BOOST_AUTO_TEST_CASE(testOperatorSplittingSpreadEngine) {
p1, p2, rho, OperatorSplittingSpreadEngine::Second)
);

expected = testData[i][2];
expected = i[2];
diff = std::abs(option.NPV() - expected);
tol = 0.0005;

Expand Down Expand Up @@ -2259,7 +2259,7 @@ BOOST_AUTO_TEST_CASE(testSpreadAndBasketBenchmarks) {
)
.withSteps(1)
.withSamples(4096-1)
.withSeed(12345ul);
.withSeed(12345UL);
};

typedef std::function<ext::shared_ptr<PricingEngine>(
Expand Down Expand Up @@ -2358,15 +2358,15 @@ BOOST_AUTO_TEST_CASE(testSpreadAndBasketBenchmarks) {
}
}

if (calculated.size() > 0) {
if (!calculated.empty()) {
for (Size i=0; i < calculated.size(); ++i) {
diff.push_back(b.referenceNPVs[i] - calculated[i]);
relDiff.push_back(diff.back()/b.referenceNPVs[i]);
}
}
}

if (diff.size() > 0) {
if (!diff.empty()) {
const Real calculatedRmse = std::sqrt(
DotProduct(Array(diff.begin(), diff.end()),
Array(diff.begin(), diff.end()) ) /diff.size());
Expand Down
2 changes: 1 addition & 1 deletion test-suite/matrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ namespace {
void QL_CHECK_CLOSE_ARRAY_TOL(
const Array& actual, const Array& expected, Real tol) {
BOOST_REQUIRE(actual.size() == expected.size());
for (auto i = 0u; i < actual.size(); i++) {
for (auto i = 0U; i < actual.size(); i++) {
BOOST_CHECK_SMALL(actual[i] - expected[i], tol);
}
}
Expand Down

0 comments on commit bb4b781

Please sign in to comment.