From ec99354bb3a7a443f93e092bb5b020fd907a1cde Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:13:04 +0000 Subject: [PATCH] Automated fixes by clang-tidy --- .../finitedifferences/operators/fdmwienerop.cpp | 4 ++-- .../finitedifferences/operators/fdmwienerop.hpp | 2 +- .../basket/bjerksundstenslandspreadengine.cpp | 3 ++- ql/pricingengines/basket/choibasketengine.cpp | 4 ++-- .../basket/denglizhoubasketengine.cpp | 4 ++-- .../basket/fdndimblackscholesvanillaengine.cpp | 10 +++++----- ql/pricingengines/basket/kirkengine.cpp | 3 ++- .../basket/operatorsplittingspreadengine.cpp | 3 ++- .../basket/singlefactorbsmbasketengine.cpp | 3 +-- .../basket/singlefactorbsmbasketengine.hpp | 2 +- .../basket/vectorbsmprocessextractor.cpp | 7 ++++--- .../basket/vectorbsmprocessextractor.hpp | 7 ++++--- test-suite/basketoption.cpp | 14 +++++++------- test-suite/matrices.cpp | 2 +- 14 files changed, 36 insertions(+), 32 deletions(-) diff --git a/ql/methods/finitedifferences/operators/fdmwienerop.cpp b/ql/methods/finitedifferences/operators/fdmwienerop.cpp index e5d263d9d9..bcfba86404 100644 --- a/ql/methods/finitedifferences/operators/fdmwienerop.cpp +++ b/ql/methods/finitedifferences/operators/fdmwienerop.cpp @@ -35,8 +35,7 @@ namespace QuantLib { const ext::shared_ptr& mesher, ext::shared_ptr 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"); @@ -86,6 +85,7 @@ namespace QuantLib { std::vector FdmWienerOp::toMatrixDecomp() const { std::vector retVal; + retVal.reserve(ops_.size()); for (const auto& op: ops_) retVal.push_back(op->toMatrix()); diff --git a/ql/methods/finitedifferences/operators/fdmwienerop.hpp b/ql/methods/finitedifferences/operators/fdmwienerop.hpp index 39f1c20018..1b759c2dba 100644 --- a/ql/methods/finitedifferences/operators/fdmwienerop.hpp +++ b/ql/methods/finitedifferences/operators/fdmwienerop.hpp @@ -54,7 +54,7 @@ namespace QuantLib { private: const ext::shared_ptr rTS_; std::vector > ops_; - Rate r_; + Rate r_ = 0.0; }; } #endif diff --git a/ql/pricingengines/basket/bjerksundstenslandspreadengine.cpp b/ql/pricingengines/basket/bjerksundstenslandspreadengine.cpp index fe9715a5e0..2bd641280d 100644 --- a/ql/pricingengines/basket/bjerksundstenslandspreadengine.cpp +++ b/ql/pricingengines/basket/bjerksundstenslandspreadengine.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace QuantLib { @@ -26,7 +27,7 @@ namespace QuantLib { ext::shared_ptr process1, ext::shared_ptr process2, Real correlation) - : SpreadBlackScholesVanillaEngine(process1, process2, correlation) { + : SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation) { } Real BjerksundStenslandSpreadEngine::calculate( diff --git a/ql/pricingengines/basket/choibasketengine.cpp b/ql/pricingengines/basket/choibasketengine.cpp index 84e8d24869..b14ebd7cb2 100644 --- a/ql/pricingengines/basket/choibasketengine.cpp +++ b/ql/pricingengines/basket/choibasketengine.cpp @@ -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) diff --git a/ql/pricingengines/basket/denglizhoubasketengine.cpp b/ql/pricingengines/basket/denglizhoubasketengine.cpp index bfcc7be699..8846a7e451 100644 --- a/ql/pricingengines/basket/denglizhoubasketengine.cpp +++ b/ql/pricingengines/basket/denglizhoubasketengine.cpp @@ -76,7 +76,7 @@ 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 payoff = ext::dynamic_pointer_cast(avgPayoff->basePayoff()); @@ -84,7 +84,7 @@ namespace QuantLib { 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)); diff --git a/ql/pricingengines/basket/fdndimblackscholesvanillaengine.cpp b/ql/pricingengines/basket/fdndimblackscholesvanillaengine.cpp index fa254c03a8..99e7f43117 100644 --- a/ql/pricingengines/basket/fdndimblackscholesvanillaengine.cpp +++ b/ql/pricingengines/basket/fdndimblackscholesvanillaengine.cpp @@ -30,8 +30,8 @@ #include #include #include - #include +#include namespace QuantLib { @@ -41,7 +41,7 @@ namespace QuantLib { FdmPCABasketInnerValue( ext::shared_ptr payoff, ext::shared_ptr mesher, - Array logS0, Array vols, + Array logS0, const Array& vols, std::vector> qTS, ext::shared_ptr rTS, Matrix Q, Array l) @@ -117,7 +117,7 @@ namespace QuantLib { Matrix rho, Size xGrid, Size tGrid, Size dampingSteps, const FdmSchemeDesc& schemeDesc) : FdndimBlackScholesVanillaEngine( - processes, rho, std::vector(1, xGrid), tGrid, dampingSteps, schemeDesc) + std::move(processes), std::move(rho), std::vector(1, xGrid), tGrid, dampingSteps, schemeDesc) {} @@ -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 > meshers; diff --git a/ql/pricingengines/basket/kirkengine.cpp b/ql/pricingengines/basket/kirkengine.cpp index d00b09b375..bbeb1b42c6 100644 --- a/ql/pricingengines/basket/kirkengine.cpp +++ b/ql/pricingengines/basket/kirkengine.cpp @@ -20,13 +20,14 @@ #include #include #include +#include namespace QuantLib { KirkEngine::KirkEngine(ext::shared_ptr process1, ext::shared_ptr process2, Real correlation) - : SpreadBlackScholesVanillaEngine(process1, process2, correlation) { + : SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation) { } Real KirkEngine::calculate( diff --git a/ql/pricingengines/basket/operatorsplittingspreadengine.cpp b/ql/pricingengines/basket/operatorsplittingspreadengine.cpp index cddbb96017..a7bfc9dea1 100644 --- a/ql/pricingengines/basket/operatorsplittingspreadengine.cpp +++ b/ql/pricingengines/basket/operatorsplittingspreadengine.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace QuantLib { @@ -29,7 +30,7 @@ namespace QuantLib { ext::shared_ptr process2, Real correlation, Order order) - : SpreadBlackScholesVanillaEngine(process1, process2, correlation), + : SpreadBlackScholesVanillaEngine(std::move(process1), std::move(process2), correlation), order_(order) { } diff --git a/ql/pricingengines/basket/singlefactorbsmbasketengine.cpp b/ql/pricingengines/basket/singlefactorbsmbasketengine.cpp index ebc10550a5..4308624d35 100644 --- a/ql/pricingengines/basket/singlefactorbsmbasketengine.cpp +++ b/ql/pricingengines/basket/singlefactorbsmbasketengine.cpp @@ -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"); } diff --git a/ql/pricingengines/basket/singlefactorbsmbasketengine.hpp b/ql/pricingengines/basket/singlefactorbsmbasketengine.hpp index 3e571cb373..1828bf2dfa 100644 --- a/ql/pricingengines/basket/singlefactorbsmbasketengine.hpp +++ b/ql/pricingengines/basket/singlefactorbsmbasketengine.hpp @@ -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; }; } } diff --git a/ql/pricingengines/basket/vectorbsmprocessextractor.cpp b/ql/pricingengines/basket/vectorbsmprocessextractor.cpp index 04b9adb4dd..703991b5db 100644 --- a/ql/pricingengines/basket/vectorbsmprocessextractor.cpp +++ b/ql/pricingengines/basket/vectorbsmprocessextractor.cpp @@ -24,8 +24,8 @@ #include -namespace QuantLib { - namespace detail { +namespace QuantLib::detail { + VectorBsmProcessExtractor::VectorBsmProcessExtractor( std::vector > p) : processes_(std::move(p)) { @@ -91,5 +91,6 @@ namespace QuantLib { } ); } - } + } + diff --git a/ql/pricingengines/basket/vectorbsmprocessextractor.hpp b/ql/pricingengines/basket/vectorbsmprocessextractor.hpp index 649f3cd57e..c9efcde3d8 100644 --- a/ql/pricingengines/basket/vectorbsmprocessextractor.hpp +++ b/ql/pricingengines/basket/vectorbsmprocessextractor.hpp @@ -27,8 +27,8 @@ #include #include -namespace QuantLib { - namespace detail { +namespace QuantLib::detail { + class VectorBsmProcessExtractor { public: explicit VectorBsmProcessExtractor( @@ -46,7 +46,8 @@ namespace QuantLib { const std::vector > processes_; }; - } + } + #endif diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index a5772f4b57..29f9c73510 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -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( @@ -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; @@ -2259,7 +2259,7 @@ BOOST_AUTO_TEST_CASE(testSpreadAndBasketBenchmarks) { ) .withSteps(1) .withSamples(4096-1) - .withSeed(12345ul); + .withSeed(12345UL); }; typedef std::function( @@ -2358,7 +2358,7 @@ 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]); @@ -2366,7 +2366,7 @@ BOOST_AUTO_TEST_CASE(testSpreadAndBasketBenchmarks) { } } - 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()); diff --git a/test-suite/matrices.cpp b/test-suite/matrices.cpp index 6e42e4accd..e056ceb514 100644 --- a/test-suite/matrices.cpp +++ b/test-suite/matrices.cpp @@ -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); } }