From 283a28fda99afcc5f6ad0c702217f74f5d726351 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 23 Sep 2024 19:10:51 +0200 Subject: [PATCH] Replace LENGTH macro with std::size --- .../ConvertibleBonds/ConvertibleBonds.cpp | 6 ++-- Examples/FRA/FRA.cpp | 6 ++-- Examples/FittedBondCurve/FittedBondCurve.cpp | 6 ++-- test-suite/americanoption.cpp | 6 ++-- test-suite/amortizingbond.cpp | 2 +- test-suite/andreasenhugevolatilityinterpl.cpp | 10 +++--- test-suite/asianoptions.cpp | 14 ++++---- test-suite/barrieroption.cpp | 10 +++--- test-suite/blackdeltacalculator.cpp | 4 +-- test-suite/cdo.cpp | 6 ++-- test-suite/digitalcoupon.cpp | 2 +- test-suite/digitaloption.cpp | 2 +- test-suite/distributions.cpp | 12 +++---- test-suite/fdheston.cpp | 2 +- test-suite/fdsabr.cpp | 8 ++--- test-suite/forwardoption.cpp | 12 +++---- test-suite/hestonmodel.cpp | 30 ++++++++--------- test-suite/hestonslvmodel.cpp | 12 +++---- test-suite/hybridhestonhullwhiteprocess.cpp | 12 +++---- test-suite/inflation.cpp | 14 ++++---- test-suite/inflationcpibond.cpp | 2 +- test-suite/inflationvolatility.cpp | 6 ++-- test-suite/integrals.cpp | 2 +- test-suite/interpolations.cpp | 14 ++++---- test-suite/margrabeoption.cpp | 6 ++-- test-suite/marketmodel.cpp | 32 +++++++++---------- test-suite/marketmodel_cms.cpp | 2 +- test-suite/marketmodel_smm.cpp | 2 +- test-suite/matrices.cpp | 2 +- test-suite/mclongstaffschwartzengine.cpp | 2 +- test-suite/nthtodefault.cpp | 20 ++++++------ test-suite/overnightindexedswap.cpp | 2 +- test-suite/piecewiseyieldcurve.cpp | 18 +++++------ test-suite/riskneutraldensitycalculator.cpp | 2 +- test-suite/riskstats.cpp | 4 +-- test-suite/shortratemodels.cpp | 4 +-- test-suite/squarerootclvmodel.cpp | 12 +++---- test-suite/stats.cpp | 24 +++++++------- test-suite/swaption.cpp | 8 ++--- test-suite/swingoption.cpp | 4 +-- test-suite/termstructures.cpp | 14 ++++---- test-suite/ultimateforwardtermstructure.cpp | 8 ++--- test-suite/utilities.hpp | 4 --- test-suite/variancegamma.cpp | 8 ++--- test-suite/varianceswaps.cpp | 2 +- test-suite/vpp.cpp | 2 +- 46 files changed, 186 insertions(+), 196 deletions(-) diff --git a/Examples/ConvertibleBonds/ConvertibleBonds.cpp b/Examples/ConvertibleBonds/ConvertibleBonds.cpp index 81553205578..22e32f4a6ce 100644 --- a/Examples/ConvertibleBonds/ConvertibleBonds.cpp +++ b/Examples/ConvertibleBonds/ConvertibleBonds.cpp @@ -31,8 +31,6 @@ #include #include -#define LENGTH(a) (sizeof(a)/sizeof(a[0])) - using namespace QuantLib; int main(int, char* []) { @@ -86,7 +84,7 @@ int main(int, char* []) { Real putPrices[]= { 105.0 }; // Load call schedules - for (Size i=0; i(Bond::Price(callPrices[i], Bond::Price::Clean), @@ -94,7 +92,7 @@ int main(int, char* []) { 1.20)); } - for (Size j=0; j(Bond::Price(putPrices[j], Bond::Price::Clean), diff --git a/Examples/FRA/FRA.cpp b/Examples/FRA/FRA.cpp index 57b60a4cd88..5835d3e94b2 100644 --- a/Examples/FRA/FRA.cpp +++ b/Examples/FRA/FRA.cpp @@ -33,8 +33,6 @@ #include -#define LENGTH(a) (sizeof(a)/sizeof(a[0])) - using namespace std; using namespace QuantLib; @@ -171,7 +169,7 @@ int main(int, char* []) { << endl; Size i; - for (i=0; isetValue(threeMonthFraQuote[9]); - for (i=0; i #include -#define LENGTH(a) (sizeof(a)/sizeof(a[0])) - using namespace std; using namespace QuantLib; @@ -129,7 +127,7 @@ int main(int, char* []) { std::vector> instrumentsA; std::vector> instrumentsB; - for (Size j=0; jquote()->value(); const Bond& b = *instrumentsA[k]->bond(); diff --git a/test-suite/americanoption.cpp b/test-suite/americanoption.cpp index c026fc31f35..c3603a43692 100644 --- a/test-suite/americanoption.cpp +++ b/test-suite/americanoption.cpp @@ -1289,7 +1289,7 @@ BOOST_AUTO_TEST_CASE(testQdAmericanEngines) { 17.05087,26.89157,64.64923,0,390.87453,124.55406,0.01018,94.23963}; std::vector testCaseSpecs; - testCaseSpecs.reserve(LENGTH(pde_values) + LENGTH(edgeTestCases)); + testCaseSpecs.reserve(std::size(pde_values) + std::size(edgeTestCases)); PseudoRandom::rng_type rng(PseudoRandom::urng_type(12345UL)); @@ -1467,7 +1467,7 @@ BOOST_AUTO_TEST_CASE(testAndersenLakeHighPrecisionExample) { QdFpAmericanEngine::FP_A, QdFpAmericanEngine::FP_B }; - for (Size i=0; i < LENGTH(schemes); ++i) { + for (Size i=0; i < std::size(schemes); ++i) { americanOption.setPricingEngine( ext::make_shared( @@ -1533,7 +1533,7 @@ BOOST_AUTO_TEST_CASE(testQdEngineStandardExample) { }; const Real expected[] = { 0.2386475283369327, 0.2386596962737606 }; - for (Size i=0; i < LENGTH(schemes); ++i) { + for (Size i=0; i < std::size(schemes); ++i) { americanOption.setPricingEngine( ext::make_shared( bsProcess, diff --git a/test-suite/amortizingbond.cpp b/test-suite/amortizingbond.cpp index 7665d31cbea..ee0f39dd34f 100644 --- a/test-suite/amortizingbond.cpp +++ b/test-suite/amortizingbond.cpp @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(testAmortizingFixedRateBond) { const Real tolerance = 1.0e-6; - for (Size i=0; i rTS(flatRate(today, 0.0, dc)); const Handle qTS(flatRate(today, 0.0, dc)); - const Size nStrikes = LENGTH(raw); - const Size nMaturities = LENGTH(maturityTimes); + const Size nStrikes = std::size(raw); + const Size nMaturities = std::size(maturityTimes); - static_assert(nMaturities == LENGTH(raw[1])-1, "check raw data"); + static_assert(nMaturities == std::size(raw[1])-1, "check raw data"); AndreasenHugeVolatilityInterpl::CalibrationSet calibrationSet; @@ -127,7 +127,7 @@ CalibrationData AndreasenHugeExampleData() { for (const auto & i : raw) { const Real strike = spot->value()*i[0]; - for (Size j=1; j < LENGTH(i); ++j) { + for (Size j=1; j < std::size(i); ++j) { if (i[j] > QL_EPSILON) { const Date maturity = today + Period(Size(365*maturityTimes[j-1]), Days); @@ -328,7 +328,7 @@ CalibrationData arbitrageData() { const Volatility vols[] = { 0.25, 0.35, 0.05, 0.35 }; AndreasenHugeVolatilityInterpl::CalibrationSet calibrationSet; - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { const Real strike = strikes[i]; const Date maturityDate = today + Period(maturities[i], Months); const Volatility vol = vols[i]; diff --git a/test-suite/asianoptions.cpp b/test-suite/asianoptions.cpp index 81522b54f5e..d3c61355039 100644 --- a/test-suite/asianoptions.cpp +++ b/test-suite/asianoptions.cpp @@ -596,7 +596,7 @@ void testDiscreteGeometricAveragePriceHeston(const ext::shared_ptr exercise(new EuropeanExercise(fixingDates[119])); - for (Size i=0; i engine(new AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess)); - for (Size i=0; i engine_2(new AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_2)); - for (Size i=0; i engine_3(new AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_3)); - for (Size i=0; i(Option::Put, strike); auto exercise = ext::make_shared(maturity); - for (Size i=0; i < LENGTH(barriers); ++i) { - for (Size j=0; j < LENGTH(engines); ++j) { + for (Size i=0; i < std::size(barriers); ++i) { + for (Size j=0; j < std::size(engines); ++j) { Real barrier = barriers[i]; Barrier::Type barrierType = barrierTypes[i]; @@ -1062,7 +1062,7 @@ BOOST_AUTO_TEST_CASE(testImpliedVolatility) { Real targetWithDividends[] = { 8.0, 12.0, 9.0, 8.0 }; Real tolerance = 1e-5; - for (Size i=0; i < LENGTH(barriers); ++i) { + for (Size i=0; i < std::size(barriers); ++i) { Real barrier = barriers[i]; Barrier::Type barrierType = barrierTypes[i]; diff --git a/test-suite/blackdeltacalculator.cpp b/test-suite/blackdeltacalculator.cpp index 629e74d65aa..4fc10b67e9b 100644 --- a/test-suite/blackdeltacalculator.cpp +++ b/test-suite/blackdeltacalculator.cpp @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(testDeltaValues){ Real error; Real tolerance; - for (Size i=0; i correlation(new SimpleQuote(0.0)); Handle hCorrelation(correlation); - QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwDetachment), "data length does not match"); + QL_REQUIRE(std::size(hwAttachment) == std::size(hwDetachment), "data length does not match"); ext::shared_ptr midPCDOEngine(new MidPointCDOEngine(yieldHandle)); ext::shared_ptr integralCDOEngine(new IntegralCDOEngine(yieldHandle)); const Size i = dataSet; correlation->setValue(hwData7[i].correlation); - QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwData7[i].trancheSpread), + QL_REQUIRE(std::size(hwAttachment) == std::size(hwData7[i].trancheSpread), "data length does not match"); std::vector> basketModels; std::vector modelNames; @@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(testHW, T, dataSets) { return; } - for (Size j = 0; j < LENGTH(hwAttachment); j++) { + for (Size j = 0; j < std::size(hwAttachment); j++) { ext::shared_ptr basketPtr( new Basket(asofDate, names, nominals, pool, hwAttachment[j], hwDetachment[j])); std::ostringstream trancheId; diff --git a/test-suite/digitalcoupon.cpp b/test-suite/digitalcoupon.cpp index 6dcd8c35c85..02651bd6065 100644 --- a/test-suite/digitalcoupon.cpp +++ b/test-suite/digitalcoupon.cpp @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(testAssetOrNothing) { Date endDate = vars.calendar.advance(vars.settlement,(k+2)*Years); Rate nullstrike = Null(); Date paymentDate = endDate; - for (Size h=0; h engines[] = { euroEngine, amEngine }; bool knockin=true; - for (Size j=0; j payoff( diff --git a/test-suite/distributions.cpp b/test-suite/distributions.cpp index 32a16cd3c26..b9e1adcb843 100644 --- a/test-suite/distributions.cpp +++ b/test-suite/distributions.cpp @@ -124,7 +124,7 @@ void checkBivariate(const char* tag) { { -30, 1.0, 1.0, 0.000000 } }; - for (Size i=0; i(i))) { BOOST_ERROR(std::setprecision(8) << "failed to reproduce known value for x = " @@ -490,14 +490,14 @@ BOOST_AUTO_TEST_CASE(testBivariateCumulativeStudent) { }; Real tolerance = 1.0e-5; - for (Size i=0; i < LENGTH(ns); ++i) { + for (Size i=0; i < std::size(ns); ++i) { BivariateCumulativeStudentDistribution f1(ns[i], 0.5); BivariateCumulativeStudentDistribution f2(ns[i], -0.5); - for (Size j=0; j < LENGTH(xs); ++j) { + for (Size j=0; j < std::size(xs); ++j) { Real calculated1 = f1(xs[j], xs[j]); - Real reference1 = expected1[i*LENGTH(xs)+j]; + Real reference1 = expected1[i*std::size(xs)+j]; Real calculated2 = f2(xs[j], xs[j]); - Real reference2 = expected2[i*LENGTH(xs)+j]; + Real reference2 = expected2[i*std::size(xs)+j]; if (std::fabs(calculated1 - reference1) > tolerance) BOOST_ERROR("Failed to reproduce CDF value at " << xs[j] << "\n calculated: " << calculated1 << diff --git a/test-suite/fdheston.cpp b/test-suite/fdheston.cpp index 280dc13a744..e51abef301e 100644 --- a/test-suite/fdheston.cpp +++ b/test-suite/fdheston.cpp @@ -473,7 +473,7 @@ BOOST_AUTO_TEST_CASE(testFdmHestonIkonenToivanen) { Real expected[] = { 2.00000, 1.10763, 0.520038, 0.213681, 0.082046 }; const Real tol = 0.001; - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { Handle s0(ext::shared_ptr(new SimpleQuote(strikes[i]))); ext::shared_ptr hestonProcess( new HestonProcess(rTS, qTS, s0, 0.0625, 5, 0.16, 0.9, 0.1)); diff --git a/test-suite/fdsabr.cpp b/test-suite/fdsabr.cpp index d1dccad781e..cccccd9fca8 100644 --- a/test-suite/fdsabr.cpp +++ b/test-suite/fdsabr.cpp @@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE(testOosterleeTestCaseIV) { const Real strikes[] = { 0.4*f0, f0, 1.6*f0 }; const Real tol = 0.00035; - for (Size i=0; i < LENGTH(maturities); ++i) { + for (Size i=0; i < std::size(maturities); ++i) { const Date maturityDate = today + maturities[i]; const Time maturityTime = dc.yearFraction(today, maturityDate); @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(testOosterleeTestCaseIV) { const ext::shared_ptr exercise = ext::make_shared(maturityDate); - for (Size j=0; j < LENGTH(strikes); ++j) { + for (Size j=0; j < std::size(strikes); ++j) { const ext::shared_ptr payoff = ext::make_shared(Option::Call, strikes[j]); @@ -462,7 +462,7 @@ BOOST_AUTO_TEST_CASE(testBenchOpSabrCase) { const Real tol = 2e-4; - for (Size i=0; i < LENGTH(f0s); ++i) { + for (Size i=0; i < std::size(f0s); ++i) { const Date maturity = today + Period(maturityInYears[i]*365, Days); const Time T = dc.yearFraction(today, maturity); @@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE(testBenchOpSabrCase) { f0*std::exp(-0.1*std::sqrt(T)), f0, f0*std::exp(0.1*std::sqrt(T)) }; - for (Size j=0; j < LENGTH(strikes); ++j) { + for (Size j=0; j < std::size(strikes); ++j) { const Real strike = strikes[j]; VanillaOption option( diff --git a/test-suite/forwardoption.cpp b/test-suite/forwardoption.cpp index 28f5361acf5..6597d76f3fc 100644 --- a/test-suite/forwardoption.cpp +++ b/test-suite/forwardoption.cpp @@ -520,7 +520,7 @@ BOOST_AUTO_TEST_CASE(testMCPrices) { Real moneyness[] = { 0.8, 0.9, 1.0, 1.1, 1.2 }; - for (Size moneyness_index = 0; moneyness_index < LENGTH(moneyness); ++moneyness_index) { + for (Size moneyness_index = 0; moneyness_index < std::size(moneyness); ++moneyness_index) { ForwardVanillaOption option(moneyness[moneyness_index], reset, payoff, exercise); @@ -564,7 +564,7 @@ BOOST_AUTO_TEST_CASE(testHestonMCPrices) { 0.002, // Put, moneyness=1.1 0.002}}; // Put, moneyness=1.2 - for (Size type_index = 0; type_index < LENGTH(optionTypes); ++type_index) { + for (Size type_index = 0; type_index < std::size(optionTypes); ++type_index) { Real analyticTolerance = 5e-4; @@ -617,7 +617,7 @@ BOOST_AUTO_TEST_CASE(testHestonMCPrices) { Real moneyness[] = {0.8, 0.9, 1.0, 1.1, 1.2}; - for (Size moneyness_index = 0; moneyness_index < LENGTH(moneyness); ++moneyness_index) { + for (Size moneyness_index = 0; moneyness_index < std::size(moneyness); ++moneyness_index) { ForwardVanillaOption option(moneyness[moneyness_index], reset, payoff, exercise); @@ -662,7 +662,7 @@ BOOST_AUTO_TEST_CASE(testHestonMCPrices) { ext::shared_ptr analyticForwardHestonEngine( new AnalyticHestonForwardEuropeanEngine(hestonProcessSmile)); - for (Size moneyness_index = 0; moneyness_index < LENGTH(moneyness); ++moneyness_index) { + for (Size moneyness_index = 0; moneyness_index < std::size(moneyness); ++moneyness_index) { Real strike = s * moneyness[moneyness_index]; ext::shared_ptr vanillaPayoff(new PlainVanillaPayoff(optionTypes[type_index], strike)); @@ -716,7 +716,7 @@ BOOST_AUTO_TEST_CASE(testHestonAnalyticalVsMCPrices, *precondition(if_speed(Fast 0.003, // Put, moneyness=1.2, CV:false 0.003}}; // Put, moneyness=1.2, CV:true - for (Size option_type_index = 0; option_type_index < LENGTH(optionTypes); ++option_type_index) { + for (Size option_type_index = 0; option_type_index < std::size(optionTypes); ++option_type_index) { Size timeSteps = 50; Size numberOfSamples = 5000; @@ -768,7 +768,7 @@ BOOST_AUTO_TEST_CASE(testHestonAnalyticalVsMCPrices, *precondition(if_speed(Fast Real moneyness[] = { 0.8, 1.0, 1.2 }; - for (Size tol_2nd_index = 0; tol_2nd_index < LENGTH(moneyness); ++tol_2nd_index) { + for (Size tol_2nd_index = 0; tol_2nd_index < std::size(moneyness); ++tol_2nd_index) { auto m = moneyness[tol_2nd_index]; ForwardVanillaOption option(m, reset, payoff, exercise); diff --git a/test-suite/hestonmodel.cpp b/test-suite/hestonmodel.cpp index aa29a02f31e..53dc4bb056b 100644 --- a/test-suite/hestonmodel.cpp +++ b/test-suite/hestonmodel.cpp @@ -1379,13 +1379,13 @@ BOOST_AUTO_TEST_CASE(testAlanLewisReferencePrices) { const Real tol = 1e-12; // 3e-15 works on linux/ia32, // but keep some buffer for other platforms - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { const Real strike = strikes[i]; - for (Size j=0; j < LENGTH(types); ++j) { + for (Size j=0; j < std::size(types); ++j) { const Option::Type type = types[j]; - for (Size k=0; k < LENGTH(engines); ++k) { + for (Size k=0; k < std::size(engines); ++k) { const ext::shared_ptr engine = engines[k]; const ext::shared_ptr payoff( @@ -1467,13 +1467,13 @@ BOOST_AUTO_TEST_CASE(testExpansionOnAlanLewisReference) { const Real tol[2] = {1.003e-2, 3.645e-3}; - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { const Real strike = strikes[i]; - for (Size j=0; j < LENGTH(types); ++j) { + for (Size j=0; j < std::size(types); ++j) { const Option::Type type = types[j]; - for (Size k=0; k < LENGTH(engines); ++k) { + for (Size k=0; k < std::size(engines); ++k) { const ext::shared_ptr engine = engines[k]; const ext::shared_ptr payoff = @@ -1530,7 +1530,7 @@ BOOST_AUTO_TEST_CASE(testExpansionOnFordeReference) { {7e-6, 4e-4, 9e-4, 4e-4}, {4e-4, 3e-2, 0.28, 1.0} }; - for (Size j=0; j < LENGTH(terms); ++j) { + for (Size j=0; j < std::size(terms); ++j) { const Real term = terms[j]; const ext::shared_ptr lpp2 = ext::make_shared(kappa, theta, sigma, @@ -1542,9 +1542,9 @@ BOOST_AUTO_TEST_CASE(testExpansionOnFordeReference) { ext::make_shared(kappa, theta, sigma, v0, rho, term); const ext::shared_ptr expansions[] = { lpp2, lpp3, forde }; - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { const Real strike = strikes[i]; - for (Size k=0; k < LENGTH(expansions); ++k) { + for (Size k=0; k < std::size(expansions); ++k) { const ext::shared_ptr expansion = expansions[k]; const Real expected = referenceVols[j][i]; @@ -1922,7 +1922,7 @@ BOOST_AUTO_TEST_CASE(testCosHestonEngine) { const Real tol = 1e-10; - for (Size i=0; i < LENGTH(payoffs); ++i) { + for (Size i=0; i < std::size(payoffs); ++i) { VanillaOption option(payoffs[i], exercise); option.setPricingEngine(cosEngine); @@ -2141,7 +2141,7 @@ BOOST_AUTO_TEST_CASE(testAndersenPiterbargPricing) { option.setPricingEngine(analyticEngine); const Real expected = option.NPV(); - for (Size k=0; k < LENGTH(engines); ++k) { + for (Size k=0; k < std::size(engines); ++k) { option.setPricingEngine(engines[k]); const Real calculated = option.NPV(); @@ -2261,7 +2261,7 @@ BOOST_AUTO_TEST_CASE(testAndersenPiterbargControlVariateIntegrand) { -8.0*std::log(engine->chF(std::complex(0, -0.5), maturity).real()) }; - for (Size i=0; i < LENGTH(variances); ++i) { + for (Size i=0; i < std::size(variances); ++i) { const Real sigmaBS = std::sqrt(variances[i]/maturity); for (Real u =0.001; u < 15; u*=1.05) { @@ -2957,7 +2957,7 @@ BOOST_AUTO_TEST_CASE(testExponentialFitting4StrikesAndMaturities) { const DiscountFactor df = rTS->discount(t); const Real fwd = s0->value()*qTS->discount(t)/df; - for (Size j=0; j < LENGTH(moneyness); ++j, ++idx) { + for (Size j=0; j < std::size(moneyness); ++j, ++idx) { const Real strike = std::exp(-moneyness[j]*std::sqrt(theta*t))*fwd; @@ -3104,8 +3104,8 @@ BOOST_AUTO_TEST_CASE(testAsymptoticControlVariate) { ext::make_shared(model) }; - for (Size j=0; j < LENGTH(engines); ++j) { - for (Size i=0; i < LENGTH(moneynesses); ++i) { + for (Size j=0; j < std::size(engines); ++j) { + for (Size i=0; i < std::size(moneynesses); ++i) { const Real moneyness = moneynesses[i]; const Real strike = std::exp(-moneyness*std::sqrt(theta*t)); diff --git a/test-suite/hestonslvmodel.cpp b/test-suite/hestonslvmodel.cpp index a3fe62ea2cf..8b9e6a6ac1e 100644 --- a/test-suite/hestonslvmodel.cpp +++ b/test-suite/hestonslvmodel.cpp @@ -432,7 +432,7 @@ void hestonFokkerPlanckFwdEquationTest(const FokkerPlanckFwdTestCase& testCase) } } - avg/=LENGTH(strikes); // NOLINT(bugprone-integer-division) + avg/=std::size(strikes); // NOLINT(bugprone-integer-division) if (avg > testCase.avgEps) { BOOST_FAIL("failed to reproduce Heston SLV prices" @@ -1532,7 +1532,7 @@ BOOST_AUTO_TEST_CASE(testBlackScholesFokkerPlanckFwdEquationLocalVol, *precondit // }; // // -// for (Size i=0; i < LENGTH(testCases); ++i) { +// for (Size i=0; i < std::size(testCases); ++i) { // BOOST_TEST_MESSAGE("Testing stochastic local volatility calibration case " << i << " ..."); // lsvCalibrationTest(testCases[i]); // } @@ -1826,7 +1826,7 @@ BOOST_AUTO_TEST_CASE(testBarrierPricingViaHestonLocalVol) { // -0.390616, -0.380888, -0.371156, -0.361425, // -0.351699, -0.341995 }; // -// for (Size i=0; i < LENGTH(eta); ++i) { +// for (Size i=0; i < std::size(eta); ++i) { // const Handle modHestonModel( // ext::make_shared( // ext::make_shared( @@ -2175,7 +2175,7 @@ BOOST_AUTO_TEST_CASE(testMonteCarloCalibration, *precondition(if_speed(Fast))) { // }; // // std::vector > -// stats(2, std::vector(LENGTH(strikes))); +// stats(2, std::vector(std::size(strikes))); // // for (Size i=0; i < 5*nSim; ++i) { // for (Size k= 0; k < 2; ++k) { @@ -2188,7 +2188,7 @@ BOOST_AUTO_TEST_CASE(testMonteCarloCalibration, *precondition(if_speed(Fast))) { // const Real S_t2 = antiPath.value[0][resetIndex-1]; // const Real S_T2 = antiPath.value[0][tSteps-1]; // -// for (Size j=0; j < LENGTH(strikes); ++j) { +// for (Size j=0; j < std::size(strikes); ++j) { // const Real strike = strikes[j]; // if (strike < 1.0) // stats[k][j].add(0.5*( @@ -2223,7 +2223,7 @@ BOOST_AUTO_TEST_CASE(testMonteCarloCalibration, *precondition(if_speed(Fast))) { // // const DiscountFactor df = rTS->discount(grid.back()); // -// for (Size j=0; j < LENGTH(strikes); ++j) { +// for (Size j=0; j < std::size(strikes); ++j) { // for (Size k= 0; k < 2; ++k) { // const Real strike = strikes[j]; // const Real npv = stats[k][j].mean() * df; diff --git a/test-suite/hybridhestonhullwhiteprocess.cpp b/test-suite/hybridhestonhullwhiteprocess.cpp index dacbd1dcb23..05cc999a722 100644 --- a/test-suite/hybridhestonhullwhiteprocess.cpp +++ b/test-suite/hybridhestonhullwhiteprocess.cpp @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(testBsmHullWhiteEngine) { const Volatility expectedVol[] = { 0.217064577, 0.243995801, 0.256402830, 0.268236596, 0.290461343 }; - for (Size i=0; i < LENGTH(corr); ++i) { + for (Size i=0; i < std::size(corr); ++i) { ext::shared_ptr bsmhwEngine( new AnalyticBSMHullWhiteEngine(corr[i], stochProcess, hullWhiteModel)); @@ -1011,7 +1011,7 @@ BOOST_AUTO_TEST_CASE(testBsmHullWhitePricing) { Real tolWithCV[] = { 2e-4, 2e-4, 2e-4, 2e-4, 0.01 }; Real tolWithOutCV[] = { 5e-3, 5e-3, 5e-3, 5e-3, 0.02 }; - for (Size l=0; l < LENGTH(schemes); ++l) { + for (Size l=0; l < std::size(schemes); ++l) { SchemeData scheme = schemes[l]; for (bool i : controlVariate) { for (unsigned long u : listOfTimeStepsPerYear) { @@ -1066,7 +1066,7 @@ BOOST_AUTO_TEST_CASE(testSpatialDiscretizatinError, *precondition(if_speed(Fast) const Real tol[] = { 0.02, 0.02, 0.02, 0.02, 0.05 }; for (unsigned long u : listOfTimeStepsPerYear) { - for (Size i=0; i < LENGTH(schemes); ++i) { + for (Size i=0; i < std::size(schemes); ++i) { for (auto& j : hestonModels) { Real avgPriceDiff = 0; ext::shared_ptr hestonProcess(makeHestonProcess(j)); @@ -1378,18 +1378,18 @@ BOOST_AUTO_TEST_CASE(testH1HWPricingEngine) { const Real tol = 0.0001; const Real strikes[] = {40, 80, 100, 120, 180 }; - const Real expected[LENGTH(sigma_v)][LENGTH(strikes)] + const Real expected[std::size(sigma_v)][std::size(strikes)] = { { 0.267503, 0.235742, 0.228223, 0.223461, 0.217855 }, { 0.263626, 0.211625, 0.199907, 0.193502, 0.190025 } }; - for (Size j=0; j < LENGTH(sigma_v); ++j) { + for (Size j=0; j < std::size(sigma_v); ++j) { const ext::shared_ptr hestonProcess( new HestonProcess(rTS, qTS, s0, v0, kappa_v, theta, sigma_v[j], rho_sv)); const ext::shared_ptr hestonModel( new HestonModel(hestonProcess)); - for (Size i=0; i < LENGTH(strikes); ++i) { + for (Size i=0; i < std::size(strikes); ++i) { const ext::shared_ptr payoff( new PlainVanillaPayoff(Option::Call, strikes[i])); diff --git a/test-suite/inflation.cpp b/test-suite/inflation.cpp index 4401bde2222..fafc97a51d3 100644 --- a/test-suite/inflation.cpp +++ b/test-suite/inflation.cpp @@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(testZeroIndex) { }; auto iir = ext::make_shared(); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(testZeroTermStructure) { RelinkableHandle hz; auto ii = ext::make_shared(hz); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -509,7 +509,7 @@ BOOST_AUTO_TEST_CASE(testZeroTermStructureWithLag) { RelinkableHandle hz; auto ii = ext::make_shared(hz); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -677,7 +677,7 @@ BOOST_AUTO_TEST_CASE(testSeasonalityCorrection) { RelinkableHandle hz; auto ii = ext::make_shared(hz); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -955,7 +955,7 @@ BOOST_AUTO_TEST_CASE(testRatioYYIndex) { 202.7, 201.6, 203.1, 204.4, 205.4, 206.2, 207.3 }; - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -1090,7 +1090,7 @@ BOOST_AUTO_TEST_CASE(testYYTermStructure) { bool interp = false; auto rpi = ext::make_shared(); auto iir = ext::make_shared(rpi, interp, hy); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } @@ -1247,7 +1247,7 @@ BOOST_AUTO_TEST_CASE(testYYTermStructureWithLag) { bool interp = false; auto rpi = ext::make_shared(); auto iir = ext::make_shared(rpi, interp, hy); - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } diff --git a/test-suite/inflationcpibond.cpp b/test-suite/inflationcpibond.cpp index 96074b3168f..fbec3771756 100644 --- a/test-suite/inflationcpibond.cpp +++ b/test-suite/inflationcpibond.cpp @@ -112,7 +112,7 @@ struct CommonVars { // NOLINT(cppcoreguidelines-special-member-functions) 210.1, 211.4, 211.3, 211.5, 212.8, 213.4, 213.4, 213.4, 214.4 }; - for (Size i=0; iaddFixing(rpiSchedule[i], fixData[i]); } diff --git a/test-suite/inflationvolatility.cpp b/test-suite/inflationvolatility.cpp index 52f07f2589a..19a57636b73 100644 --- a/test-suite/inflationvolatility.cpp +++ b/test-suite/inflationvolatility.cpp @@ -124,8 +124,8 @@ void setup() { std::vector r; std::vector d; - Size nTimesEUR = LENGTH(timesEUR); - Size nTimesGBP = LENGTH(timesGBP); + Size nTimesEUR = std::size(timesEUR); + Size nTimesGBP = std::size(timesGBP); for (Size i = 0; i < nTimesEUR; i++) { r.push_back(ratesEUR[i]); Size ys = (Size)floor(timesEUR[i]); @@ -172,7 +172,7 @@ void setup() { d.clear(); r.clear(); Date baseDate = TARGET().advance(eval, -2, Months, ModifiedFollowing); - for (Size i = 0; i < LENGTH(yoyEUrates); i++) { + for (Size i = 0; i < std::size(yoyEUrates); i++) { Date dd = TARGET().advance(baseDate, i, Years, ModifiedFollowing); d.push_back(dd); r.push_back(yoyEUrates[i]); diff --git a/test-suite/integrals.cpp b/test-suite/integrals.cpp index 7be5d7ddbe9..1dffce9a0f2 100644 --- a/test-suite/integrals.cpp +++ b/test-suite/integrals.cpp @@ -280,7 +280,7 @@ BOOST_AUTO_TEST_CASE(testFolinIntegration) { const Real tol = 1e-12; - for (Size i=0; i < LENGTH(nr); ++i) { + for (Size i=0; i < std::size(nr); ++i) { const Size n = nr[i]; const Real calculatedCosine = FilonIntegral(FilonIntegral::Cosine, t, n)(cosineF(),0,2*M_PI); diff --git a/test-suite/interpolations.cpp b/test-suite/interpolations.cpp index 58fbfdf5144..1fb2ba2c710 100644 --- a/test-suite/interpolations.cpp +++ b/test-suite/interpolations.cpp @@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(testSplineErrorOnGaussianValues) { // results from the paper Real scaleFactor = 1.9; - for (Size i=0; i x = xRange(-1.7, 1.9, n); std::vector y = gaussian(x); @@ -538,7 +538,7 @@ BOOST_AUTO_TEST_CASE(testSplineOnGenericValues) { const Real generic_natural_y2[] = { 0.0, 1.5, -1.5, 0.0 }; Real interpolated, error; - Size i, n = LENGTH(generic_x); + Size i, n = std::size(generic_x); std::vector x35(3); // Natural spline @@ -939,7 +939,7 @@ BOOST_AUTO_TEST_CASE(testAsFunctor) { f.update(); const Real x2[] = { -2.0, -1.0, 0.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; - Size N = LENGTH(x2); + Size N = std::size(x2); std::vector y2(N); Real tolerance = 1.0e-12; @@ -1017,7 +1017,7 @@ BOOST_AUTO_TEST_CASE(testBackwardFlat) { Interpolation f = BackwardFlatInterpolation(std::begin(x), std::end(x), std::begin(y)); f.update(); - Size N = LENGTH(x); + Size N = std::size(x); Size i; Real tolerance = 1.0e-12; @@ -1135,7 +1135,7 @@ BOOST_AUTO_TEST_CASE(testForwardFlat) { Interpolation f = ForwardFlatInterpolation(std::begin(x), std::end(x), std::begin(y)); f.update(); - Size N = LENGTH(x); + Size N = std::size(x); Size i; Real tolerance = 1.0e-12; @@ -1881,7 +1881,7 @@ BOOST_AUTO_TEST_CASE(testNoArbSabrInterpolation, *precondition(if_speed(Fast))){ for (Size j=1; j(todaysForwards.size()); blackVols = std::vector(todaysForwards.size()); normalVols = std::vector(todaysForwards.size()); - for (Size i=0; i evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i = 0; i < LENGTH(evolvers) - stop; i++) { + for (Size i = 0; i < std::size(evolvers) - stop; i++) { for (Size n = 0; n < 1; n++) { MTBrownianGeneratorFactory generatorFactory(seed_); @@ -835,7 +835,7 @@ BOOST_AUTO_TEST_CASE(testOneStepNormalForwardsAndOptionlets) { EvolverType evolvers[] = {NormalPc}; ext::shared_ptr evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i = 0; i < LENGTH(evolvers) - stop; i++) { + for (Size i = 0; i < std::size(evolvers) - stop; i++) { for (Size n = 0; n < 1; n++) { MTBrownianGeneratorFactory generatorFactory(seed_); @@ -1034,7 +1034,7 @@ void testMultiProductComposite(const MarketModelMultiProduct& product, Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i = 0; i < LENGTH(evolvers) - stop; i++) { + for (Size i = 0; i < std::size(evolvers) - stop; i++) { for (Size n = 0; n < 1; n++) { // MTBrownianGeneratorFactory @@ -1445,7 +1445,7 @@ BOOST_AUTO_TEST_CASE(testCallableSwapNaif, *precondition(if_speed(Slow))) { EvolverType evolvers[] = {Pc, Balland, Ipc}; ext::shared_ptr evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i = 0; i < LENGTH(evolvers) - stop; i++) { + for (Size i = 0; i < std::size(evolvers) - stop; i++) { for (Size n = 0; n < 1; n++) { // MTBrownianGeneratorFactory generatorFactory(seed_); @@ -1598,7 +1598,7 @@ BOOST_AUTO_TEST_CASE(testCallableSwapLS, *precondition(if_speed(Slow))) { EvolverType evolvers[] = {Pc, Balland, Ipc}; ext::shared_ptr evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i = 0; i < LENGTH(evolvers) - stop; i++) { + for (Size i = 0; i < std::size(evolvers) - stop; i++) { for (Size n = 0; n < 1; n++) { // MTBrownianGeneratorFactory generatorFactory(seed_); @@ -1774,7 +1774,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(testCallableSwapAnderson, T, slices) { ext::shared_ptr evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i=0; i evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i=0; i evolver; Size stop = isInTerminalMeasure(evolution, numeraires) ? 0 : 1; - for (Size i=0; i tol) BOOST_FAIL("determinant calculation failed " diff --git a/test-suite/mclongstaffschwartzengine.cpp b/test-suite/mclongstaffschwartzengine.cpp index 2553cf587fc..a7805d774d4 100644 --- a/test-suite/mclongstaffschwartzengine.cpp +++ b/test-suite/mclongstaffschwartzengine.cpp @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(testAmericanOption, *precondition(if_speed(Fast))) { .withAbsoluteTolerance(0.02) .withSeed(42) .withPolynomialOrder(3) - .withBasisSystem(polynomialTypes[0*(i*3+j)%LENGTH(polynomialTypes)]); + .withBasisSystem(polynomialTypes[0*(i*3+j)%std::size(polynomialTypes)]); americanOption.setPricingEngine(mcengine); const Real calculated = americanOption.NPV(); diff --git a/test-suite/nthtodefault.cpp b/test-suite/nthtodefault.cpp index 54f2a8c559a..ea2f35c3f09 100644 --- a/test-suite/nthtodefault.cpp +++ b/test-suite/nthtodefault.cpp @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(testGauss, *precondition(if_speed(Slow))) { Period timeUnit = 1*Weeks; // required to reach accuracy Size names = 10; - QL_REQUIRE (LENGTH(hwData) == names, "hwData length does not match"); + QL_REQUIRE (std::size(hwData) == names, "hwData length does not match"); Real rate = 0.05; DayCounter dc = Actual365Fixed(); @@ -211,19 +211,19 @@ BOOST_AUTO_TEST_CASE(testGauss, *precondition(if_speed(Slow))) { ntd.back().setPricingEngine(engine); } - static_assert(LENGTH(hwCorrelation) == 3, + static_assert(std::size(hwCorrelation) == 3, "correlation length does not match"); Real diff, maxDiff = 0; basket->setLossModel(copula); - for (Size j = 0; j < LENGTH(hwCorrelation); j++) { + for (Size j = 0; j < std::size(hwCorrelation); j++) { simpleQuote->setValue (hwCorrelation[j]); for (Size i = 0; i < ntd.size(); i++) { - QL_REQUIRE (ntd[i].rank() == hwData[i].rank, "rank does not match"); - static_assert(LENGTH(hwCorrelation) == LENGTH(hwData[i].spread), - "vector length does not match"); + QL_REQUIRE(ntd[i].rank() == hwData[i].rank, "rank does not match"); + QL_REQUIRE(std::size(hwCorrelation) == std::size(hwData[i].spread), + "vector length does not match"); diff = 1e4 * ntd[i].fairPremium() - hwData[i].spread[j]; maxDiff = std::max(maxDiff, fabs (diff)); BOOST_CHECK_MESSAGE (fabs(diff/hwData[i].spread[j]) < relTolerance @@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(testStudent, *precondition(if_speed(Slow))) { Period timeUnit = 1*Weeks; // required to reach accuracy Size names = 10; - QL_REQUIRE (LENGTH(hwDataDist) == names, "hwDataDist length does not match"); + QL_REQUIRE (std::size(hwDataDist) == names, "hwDataDist length does not match"); Real rate = 0.05; DayCounter dc = Actual365Fixed(); @@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(testStudent, *precondition(if_speed(Slow))) { ntd.back().setPricingEngine(engine); } - static_assert(LENGTH(hwCorrelation) == 3, + static_assert(std::size(hwCorrelation) == 3, "correlation length does not match"); Real maxDiff = 0; @@ -343,11 +343,11 @@ BOOST_AUTO_TEST_CASE(testStudent, *precondition(if_speed(Slow))) { // This is the necessary code, but a proper hwData for the t copula is needed. // Real diff; - // for (Size j = 0; j < LENGTH(hwCorrelation); j++) { + // for (Size j = 0; j < std::size(hwCorrelation); j++) { // simpleQuote->setValue (hwCorrelation[j]); // for (Size i = 0; i < ntd.size(); i++) { // QL_REQUIRE (ntd[i].rank() == hwData[i].rank, "rank does not match"); - // static_assert(LENGTH(hwCorrelation) == LENGTH(hwData[i].spread), + // static_assert(std::size(hwCorrelation) == std::size(hwData[i].spread), // "vector length does not match"); // diff = 1e4 * ntd[i].fairPremium() - hwData[i].spread[j]; // maxDiff = std::max(maxDiff, fabs (diff)); diff --git a/test-suite/overnightindexedswap.cpp b/test-suite/overnightindexedswap.cpp index 843adb1157a..0b7ad1da542 100644 --- a/test-suite/overnightindexedswap.cpp +++ b/test-suite/overnightindexedswap.cpp @@ -680,7 +680,7 @@ BOOST_AUTO_TEST_CASE(testBootstrapRegression) { index->endOfMonth(), index->dayCounter())); - for (Size i=1; i( data[i].settlementDays, diff --git a/test-suite/piecewiseyieldcurve.cpp b/test-suite/piecewiseyieldcurve.cpp index d71f4428085..0ff7a287250 100644 --- a/test-suite/piecewiseyieldcurve.cpp +++ b/test-suite/piecewiseyieldcurve.cpp @@ -218,13 +218,13 @@ struct CommonVars { bmaConvention = Following; bmaDayCounter = ActualActual(ActualActual::ISDA); - deposits = LENGTH(depositData); - fras = LENGTH(fraData); - immFuts = LENGTH(immFutData); - asxFuts = LENGTH(asxFutData); - swaps = LENGTH(swapData); - bonds = LENGTH(bondData); - bmas = LENGTH(bmaData); + deposits = std::size(depositData); + fras = std::size(fraData); + immFuts = std::size(immFutData); + asxFuts = std::size(asxFutData); + swaps = std::size(swapData); + bonds = std::size(bondData); + bmas = std::size(bmaData); // market elements rates = std::vector >(deposits+swaps); @@ -1353,12 +1353,12 @@ BOOST_AUTO_TEST_CASE(testGlobalBootstrap, *precondition(usingAtParCoupons())) { curve->enableExtrapolation(); // check expected pillar dates - for (Size i = 0; i < LENGTH(refDate); ++i) { + for (Size i = 0; i < std::size(refDate); ++i) { BOOST_CHECK_EQUAL(refDate[i], helpers[i]->pillarDate()); } // check expected zero rates - for (Size i = 0; i < LENGTH(refZeroRate); ++i) { + for (Size i = 0; i < std::size(refZeroRate); ++i) { // 0.01 basis points tolerance QL_CHECK_SMALL(std::fabs(refZeroRate[i] - curve->zeroRate(refDate[i], Actual360(), Continuous).rate()), 1E-6); diff --git a/test-suite/riskneutraldensitycalculator.cpp b/test-suite/riskneutraldensitycalculator.cpp index 9d38c838f1a..700b2d158db 100644 --- a/test-suite/riskneutraldensitycalculator.cpp +++ b/test-suite/riskneutraldensitycalculator.cpp @@ -756,7 +756,7 @@ BOOST_AUTO_TEST_CASE(testCEVCDF) { const Real betas[] = { 0.45, 1.25 }; const Real tol = 1e-6; - for (Size i = 1; i < LENGTH(betas); ++i) { + for (Size i = 1; i < std::size(betas); ++i) { const Real beta = betas[i]; const ext::shared_ptr calculator = ext::make_shared(f0, alpha, beta); diff --git a/test-suite/riskstats.cpp b/test-suite/riskstats.cpp index 0a4d7a6aa17..bc980c26f78 100644 --- a/test-suite/riskstats.cpp +++ b/test-suite/riskstats.cpp @@ -47,8 +47,8 @@ BOOST_AUTO_TEST_CASE(testResults) { Real dataMin, dataMax; std::vector data(N), weights(N); - for (i=0; i > slvStats( // calibrationDates.size()-2, -// std::vector(LENGTH(strikes))); +// std::vector(std::size(strikes))); // // typedef SobolBrownianBridgeRsg rsg_type; // typedef MultiPathGenerator::sample_type sample_type; @@ -602,7 +602,7 @@ class NonZeroConstraint : public Constraint { // const Real S_t1 = path.value[0][resetIndices[i]]; // const Real S_T1 = path.value[0][maturityIndices[i]]; // -// for (Size j=0; j < LENGTH(strikes); ++j) { +// for (Size j=0; j < std::size(strikes); ++j) { // const Real strike = strikes[j]; // slvStats[i][j].add((strike < 1.0) // ? Real(S_t1 * std::max(0.0, strike - S_T1/S_t1)) @@ -620,7 +620,7 @@ class NonZeroConstraint : public Constraint { // const ext::shared_ptr exercise( // ext::make_shared(maturityDate)); // -// for (Size j=0; j < LENGTH(strikes); ++j) { +// for (Size j=0; j < std::size(strikes); ++j) { // const Real strike = strikes[j]; // const Real npv = slvStats[i][j].mean()*df; // @@ -636,13 +636,13 @@ class NonZeroConstraint : public Constraint { // QuantLib::detail::ImpliedVolatilityHelper::calculate( // *fwdOption, *fwdEngine, *vol, npv, 1e-8, 200, 1e-4, 2.0); // -// const Size idx = j + i*LENGTH(strikes); +// const Size idx = j + i*std::size(strikes); // refVols[idx] = implVol; // } // } // // SquareRootCLVCalibrationFunction costFunction( -// Array(strikes, strikes+LENGTH(strikes)), +// Array(strikes, strikes+std::size(strikes)), // resetDates, // maturityDates, // bsProcess, diff --git a/test-suite/stats.cpp b/test-suite/stats.cpp index 060a4f3a758..0d42c6cc34d 100644 --- a/test-suite/stats.cpp +++ b/test-suite/stats.cpp @@ -47,32 +47,32 @@ template void check(const std::string& name) { S s; - for (Size i=0; i ss(dimension); Size i; - for (i = 0; i temp(dimension, data[i]); ss.add(temp, weights[i]); } @@ -129,20 +129,20 @@ void checkSequence(const std::string& name, Size dimension) { std::vector calculated; Real expected, tolerance; - if (ss.samples() != LENGTH(data)) + if (ss.samples() != std::size(data)) BOOST_FAIL("SequenceStatistics<" << name << ">: " << "wrong number of samples\n" << " calculated: " << ss.samples() << "\n" - << " expected: " << LENGTH(data)); + << " expected: " << std::size(data)); - expected = std::accumulate(weights,weights+LENGTH(weights),Real(0.0)); + expected = std::accumulate(weights,weights+std::size(weights),Real(0.0)); if (ss.weightSum() != expected) BOOST_FAIL("SequenceStatistics<" << name << ">: " << "wrong sum of weights\n" << " calculated: " << ss.weightSum() << "\n" << " expected: " << expected); - expected = *std::min_element(data,data+LENGTH(data)); + expected = *std::min_element(data,data+std::size(data)); calculated = ss.min(); for (i=0; i swap = MakeVanillaSwap(length, vars.index, strike) .withEffectiveDate(startDate) @@ -851,7 +851,7 @@ BOOST_AUTO_TEST_CASE(testImpliedVolatility, *precondition(if_speed(Faster))) { .withFixedLegDayCount(vars.fixedDayCount) .withFloatingLegSpread(0.0) .withType(k); - for (Size h=0; h swaption = @@ -948,7 +948,7 @@ BOOST_AUTO_TEST_CASE(testImpliedVolatilityOis, *precondition(if_speed(Fast))) { .withPaymentFrequency(Annual) .withFixedLegDayCount(vars.fixedDayCount) .withType(k); - for (Size h=0; h swaption = @@ -1061,7 +1061,7 @@ void checkSwaptionDelta(bool useBachelierVol) for (auto exercise : exercises) { for (auto& length : lengths) { for (Real& strike : strikes) { - for (Size h=0; h swaptionEngine = makeConstVolEngine( discountHandle, volatility); diff --git a/test-suite/swingoption.cpp b/test-suite/swingoption.cpp index d8b955a0b45..9c1d5b96048 100644 --- a/test-suite/swingoption.cpp +++ b/test-suite/swingoption.cpp @@ -123,12 +123,12 @@ BOOST_AUTO_TEST_CASE(testExtendedOrnsteinUhlenbeckProcess) { [ ](Real x) -> Real { return x + 1.0; }, [ ](Real x) -> Real { return std::sin(x); }}; - for (Size n=0; n < LENGTH(f); ++n) { + for (Size n=0; n < std::size(f); ++n) { ExtendedOrnsteinUhlenbeckProcess refProcess( speed, vol, 0.0, f[n], ExtendedOrnsteinUhlenbeckProcess::GaussLobatto, 1e-6); - for (Size i=0; i < LENGTH(discr)-1; ++i) { + for (Size i=0; i < std::size(discr)-1; ++i) { ExtendedOrnsteinUhlenbeckProcess eouProcess( speed, vol, 0.0, f[n], discr[i]); diff --git a/test-suite/termstructures.cpp b/test-suite/termstructures.cpp index 496a924c703..e2207c1c5b2 100644 --- a/test-suite/termstructures.cpp +++ b/test-suite/termstructures.cpp @@ -76,8 +76,8 @@ struct CommonVars { { 20, Years, 5.89 }, { 30, Years, 5.96 } }; - Size deposits = LENGTH(depositData), - swaps = LENGTH(swapData); + Size deposits = std::size(depositData), + swaps = std::size(swapData); std::vector > instruments(deposits+swaps); for (Size i=0; i expected(LENGTH(days)); - for (i=0; i expected(std::size(days)); + for (i=0; idiscount(today+days[i]); Settings::instance().evaluationDate() = today+30; - std::vector calculated(LENGTH(days)); - for (i=0; i calculated(std::size(days)); + for (i=0; idiscount(today+30+days[i]); - for (i=0; i > instruments(nInstruments); for (Size i = 0; i < nInstruments; i++) { instruments[i] = ext::shared_ptr(new SwapRateHelper( @@ -122,7 +122,7 @@ ext::shared_ptr calculateLLFR(const Handle& ts, const Time cutOff = ts->timeFromReference(ts->referenceDate() + fsp); LLFRWeight llfrWeights[] = {{25.0, 1.0}, {30.0, 0.5}, {40.0, 0.25}, {50.0, 0.125}}; - Size nWeights = LENGTH(llfrWeights); + Size nWeights = std::size(llfrWeights); Rate llfr = 0.0; for (Size j = 0; j < nWeights; j++) { LLFRWeight w = llfrWeights[j]; @@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(testDutchCentralBankRates) { {100, Years, 0.01939}}; Real tolerance = 1.0e-4; - Size nRates = LENGTH(expectedZeroes); + Size nRates = std::size(expectedZeroes); for (Size i = 0; i < nRates; ++i) { Period p = expectedZeroes[i].n * expectedZeroes[i].units; @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(testExtrapolatedForward) { 70 * Years, 80 * Years, 90 * Years, 100 * Years, }; - Size nTenors = LENGTH(tenors); + Size nTenors = std::size(tenors); for (Size i = 0; i < nTenors; ++i) { Date maturity = vars.settlement + tenors[i]; diff --git a/test-suite/utilities.hpp b/test-suite/utilities.hpp index 3d1892527a9..130483a672a 100644 --- a/test-suite/utilities.hpp +++ b/test-suite/utilities.hpp @@ -62,10 +62,6 @@ using QuantLib::value; #define QL_CHECK_CLOSE(L, R, T) BOOST_CHECK_CLOSE(value(L), value(R), value(T)) #define QL_CHECK_CLOSE_FRACTION(L, R, T) BOOST_CHECK_CLOSE_FRACTION(value(L), value(R), value(T)) - -// This makes it easier to use array literals (for new code, use std::vector though) -#define LENGTH(a) (sizeof(a)/sizeof(a[0])) - namespace QuantLib { std::string payoffTypeToString(const ext::shared_ptr&); diff --git a/test-suite/variancegamma.cpp b/test-suite/variancegamma.cpp index 4dea146e032..22ebe0b1d7c 100644 --- a/test-suite/variancegamma.cpp +++ b/test-suite/variancegamma.cpp @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(testVarianceGamma) { { Option::Put, 5550, 1.0} }; - Real results[LENGTH(processes)][LENGTH(options)] = { + Real results[std::size(processes)][std::size(options)] = { { 955.1637, 922.7529, 890.9872, 859.8739, 829.4197, 799.6303, 770.5104, 742.0640, 714.2943, 687.2032, 660.7921, 635.0613, 610.0103, 585.6379, 561.9416, 538.9186, @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(testVarianceGamma) { DayCounter dc = Actual360(); Date today = Date::todaysDate(); - for (Size i=0; i spot(new SimpleQuote(processes[i].s)); ext::shared_ptr qRate(new SimpleQuote(processes[i].q)); ext::shared_ptr qTS = flatRate(today, qRate, dc); @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(testVarianceGamma) { std::vector > optionList; std::vector > payoffs; - for (Size j=0; j exercise(new EuropeanExercise(exDate)); @@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE(testVarianceGamma) { // Test FFT engine // FFT engine is extremely efficient when sent a list of options to calculate first fftEngine->precalculate(optionList); - for (Size j=0; j option = ext::static_pointer_cast(optionList[j]); option->setPricingEngine(fftEngine); diff --git a/test-suite/varianceswaps.cpp b/test-suite/varianceswaps.cpp index 190bd43506f..9858fbef084 100644 --- a/test-suite/varianceswaps.cpp +++ b/test-suite/varianceswaps.cpp @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(testReplicatingVarianceSwap) { qRate->setValue(value.q); rRate->setValue(value.r); - Size options = LENGTH(replicatingOptionData); + Size options = std::size(replicatingOptionData); std::vector callStrikes, putStrikes, callVols, putVols; // Assumes ascending strikes and same min call and max put strikes diff --git a/test-suite/vpp.cpp b/test-suite/vpp.cpp index c1a4d607b24..47cff539dab 100644 --- a/test-suite/vpp.cpp +++ b/test-suite/vpp.cpp @@ -511,7 +511,7 @@ BOOST_AUTO_TEST_CASE(testVPPIntrinsicValue) { const Real expected[] = { 0.0, 2056.04, 11145.577778, 26452.04, 44512.461818, 62000.626667, 137591.911111}; - for (Size i=0; i < LENGTH(efficiency); ++i) { + for (Size i=0; i < std::size(efficiency); ++i) { const Real heatRate = 1.0/efficiency[i]; VanillaVPPOption option(heatRate, pMin, pMax, tMinUp, tMinDown,