From 292aea8849805628c067171bf67f547136a2cf68 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Tue, 7 Nov 2023 17:40:26 +0800 Subject: [PATCH 001/102] Migrated margrabeoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/margrabeoption.cpp | 23 ++++++++----------- test-suite/margrabeoption.hpp | 34 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 55 deletions(-) delete mode 100644 test-suite/margrabeoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 3d9a1050d39..d1ceacd970e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - margrabeoption.hpp marketmodel.hpp marketmodel_cms.hpp marketmodel_smm.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 03f366045df..4d3f5e40785 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - margrabeoption.hpp \ marketmodel.hpp \ marketmodel_cms.hpp \ marketmodel_smm.hpp \ diff --git a/test-suite/margrabeoption.cpp b/test-suite/margrabeoption.cpp index f8c7eae87b4..4b7ad956bee 100644 --- a/test-suite/margrabeoption.cpp +++ b/test-suite/margrabeoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "margrabeoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -117,7 +117,11 @@ namespace { } -void MargrabeOptionTest::testEuroExchangeTwoAssets() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(MargrabeOptionTest) + +BOOST_AUTO_TEST_CASE(testEuroExchangeTwoAssets) { BOOST_TEST_MESSAGE("Testing European one-asset-for-another option..."); @@ -284,7 +288,7 @@ void MargrabeOptionTest::testEuroExchangeTwoAssets() { } } -void MargrabeOptionTest::testGreeks() { +BOOST_AUTO_TEST_CASE(testGreeks) { BOOST_TEST_MESSAGE("Testing analytic European exchange option greeks..."); @@ -444,7 +448,7 @@ void MargrabeOptionTest::testGreeks() { } } -void MargrabeOptionTest::testAmericanExchangeTwoAssets() { +BOOST_AUTO_TEST_CASE(testAmericanExchangeTwoAssets) { BOOST_TEST_MESSAGE("Testing American one-asset-for-another option..."); @@ -547,13 +551,6 @@ void MargrabeOptionTest::testAmericanExchangeTwoAssets() { } } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* MargrabeOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Exchange option tests"); - suite->add( - QUANTLIB_TEST_CASE(&MargrabeOptionTest::testEuroExchangeTwoAssets)); - suite->add( - QUANTLIB_TEST_CASE(&MargrabeOptionTest::testAmericanExchangeTwoAssets)); - suite->add(QUANTLIB_TEST_CASE(&MargrabeOptionTest::testGreeks)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/margrabeoption.hpp b/test-suite/margrabeoption.hpp deleted file mode 100644 index 661dc1cbc0c..00000000000 --- a/test-suite/margrabeoption.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2010 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_margrabe_option_hpp -#define quantlib_test_margrabe_option_hpp - -#include - -class MargrabeOptionTest { - public: - static void testEuroExchangeTwoAssets(); - static void testAmericanExchangeTwoAssets(); - static void testGreeks(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index e4325835cda..d29f2dea1c4 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "margrabeoption.hpp" #include "marketmodel.hpp" #include "marketmodel_cms.hpp" #include "marketmodel_smm.hpp" @@ -138,7 +137,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MargrabeOptionTest::suite()); test->add(MarketModelTest::suite(speed)); test->add(MarketModelCmsTest::suite(speed)); test->add(MarketModelSmmTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 9e7bd99060d..d503a3d4053 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 8b822d4a34b..4dac4525cbb 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 6fed27833da813eae39d5289ebe44e19777c26b3 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:15:55 +0800 Subject: [PATCH 002/102] Migrated marketmodel.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/marketmodel.cpp | 189 ++++++++++++--------------- test-suite/marketmodel.hpp | 61 --------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 86 insertions(+), 172 deletions(-) delete mode 100644 test-suite/marketmodel.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d1ceacd970e..5b313cb6d14 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel.hpp marketmodel_cms.hpp marketmodel_smm.hpp marketmodel_smmcapletalphacalibration.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 4d3f5e40785..7b15af5e279 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel.hpp \ marketmodel_cms.hpp \ marketmodel_smm.hpp \ marketmodel_smmcapletalphacalibration.hpp \ diff --git a/test-suite/marketmodel.cpp b/test-suite/marketmodel.cpp index 861e6e1404b..f8c5df45983 100644 --- a/test-suite/marketmodel.cpp +++ b/test-suite/marketmodel.cpp @@ -22,7 +22,8 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -118,6 +119,10 @@ using std::sqrt; namespace market_model_test { + enum MarketModelType { ExponentialCorrelationFlatVolatility, + ExponentialCorrelationAbcdVolatility/*, CalibratedMM*/ + }; + Date todaysDate, startDate, endDate; Schedule dates; std::vector - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 4dac4525cbb..ca7c79412a9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 7f307673db861c42e8d7a3afd68876c31a0811bc Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:23:14 +0800 Subject: [PATCH 003/102] Migrated marketmodel_cms.cpp --- test-suite/CMakeLists.txt | 3 +-- test-suite/Makefile.am | 2 -- test-suite/marketmodel_cms.cpp | 22 ++++++----------- test-suite/marketmodel_cms.hpp | 37 ---------------------------- test-suite/quantlibbenchmark.cpp | 8 +++++- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 16 insertions(+), 62 deletions(-) delete mode 100644 test-suite/marketmodel_cms.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 5b313cb6d14..a9cde7ed465 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel_cms.hpp marketmodel_smm.hpp marketmodel_smmcapletalphacalibration.hpp marketmodel_smmcapletcalibration.hpp @@ -268,7 +267,7 @@ set(QL_BENCHMARK_SOURCES interpolations.cpp jumpdiffusion.cpp lowdiscrepancysequences.cpp - marketmodel_cms.cpp marketmodel_cms.hpp + marketmodel_cms.cpp marketmodel_smm.cpp marketmodel_smm.hpp quantooption.cpp quantooption.hpp quantlibglobalfixture.cpp quantlibglobalfixture.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7b15af5e279..e452a310437 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel_cms.hpp \ marketmodel_smm.hpp \ marketmodel_smmcapletalphacalibration.hpp \ marketmodel_smmcapletcalibration.hpp \ @@ -278,7 +277,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - marketmodel_cms.hpp \ marketmodel_smm.hpp \ quantlibglobalfixture.hpp \ quantooption.hpp \ diff --git a/test-suite/marketmodel_cms.cpp b/test-suite/marketmodel_cms.cpp index 0e950b6b510..d6d53956dc5 100644 --- a/test-suite/marketmodel_cms.cpp +++ b/test-suite/marketmodel_cms.cpp @@ -20,7 +20,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel_cms.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -424,8 +425,11 @@ namespace market_model_cms_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions() { +BOOST_AUTO_TEST_SUITE(MarketModelCmsTest) + +BOOST_AUTO_TEST_CASE(testMultiStepCmSwapsAndSwaptions, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE("Testing exact repricing of " "multi-step constant maturity swaps and swaptions " @@ -520,16 +524,6 @@ void MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions() { } } +BOOST_AUTO_TEST_SUITE_END() - -// --- Call the desired tests -test_suite* MarketModelCmsTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("CMS Market-model tests"); - - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE( - &MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/marketmodel_cms.hpp b/test-suite/marketmodel_cms.hpp deleted file mode 100644 index 3297adcc53c..00000000000 --- a/test-suite/marketmodel_cms.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006 Ferdinando Ametrano - Copyright (C) 2006 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_market_cms_model_hpp -#define quantlib_test_market_cms_model_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarketModelCmsTest { - public: - static void testMultiStepCmSwapsAndSwaptions(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 96b827edae9..04e703c90b8 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -228,6 +228,12 @@ namespace QuantLibTest { struct testMersenneTwisterDiscrepancy: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace MarketModelCmsTest { + struct testMultiStepCmSwapsAndSwaptions: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } + } namespace { @@ -277,7 +283,7 @@ namespace { Benchmark("HestonModel::DAXCalibration", [] { QuantLibTest::HestonModelTest::testDAXCalibration().test_method(); }, 555.19), Benchmark("InterpolationTest::testSabrInterpolation", [] { QuantLibTest::InterpolationTest::testSabrInterpolation().test_method(); }, 2266.06), Benchmark("JumpDiffusion::Greeks", [] { QuantLibTest::JumpDiffusionTest::testGreeks().test_method(); }, 433.77), - Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", &MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions, 11497.73), + Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", [] { QuantLibTest::MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions().test_method(), 11497.73), Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", &MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions, 11244.95), Benchmark("QuantoOption::ForwardGreeks", &QuantoOptionTest::testForwardGreeks, 90.98), Benchmark("RandomNumber::MersenneTwisterDescrepancy", [] { QuantLibTest::LowDiscrepancyTest::testMersenneTwisterDiscrepancy().test_method(); }, 951.98), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 22bf0b76133..627b84f690e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "marketmodel_cms.hpp" #include "marketmodel_smm.hpp" #include "marketmodel_smmcapletalphacalibration.hpp" #include "marketmodel_smmcapletcalibration.hpp" @@ -136,7 +135,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarketModelCmsTest::suite(speed)); test->add(MarketModelSmmTest::suite(speed)); test->add(MarketModelSmmCapletAlphaCalibrationTest::suite()); test->add(MarketModelSmmCapletCalibrationTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 4fa3433eecf..f56dc065b56 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index ca7c79412a9..003ecff32d9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d25e4805788eb10a0e8918db41680a0728a56984 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:30:35 +0800 Subject: [PATCH 004/102] Migrated marketmodel_smm.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 2 -- test-suite/marketmodel_smm.cpp | 22 +++++------- test-suite/marketmodel_smm.hpp | 50 ---------------------------- test-suite/quantlibbenchmark.cpp | 13 ++++---- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 16 insertions(+), 80 deletions(-) delete mode 100644 test-suite/marketmodel_smm.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a9cde7ed465..0b49abcb20a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel_smm.hpp marketmodel_smmcapletalphacalibration.hpp marketmodel_smmcapletcalibration.hpp marketmodel_smmcaplethomocalibration.hpp @@ -268,7 +267,7 @@ set(QL_BENCHMARK_SOURCES jumpdiffusion.cpp lowdiscrepancysequences.cpp marketmodel_cms.cpp - marketmodel_smm.cpp marketmodel_smm.hpp + marketmodel_smm.cpp quantooption.cpp quantooption.hpp quantlibglobalfixture.cpp quantlibglobalfixture.hpp riskstats.cpp riskstats.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e452a310437..7ae32529000 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel_smm.hpp \ marketmodel_smmcapletalphacalibration.hpp \ marketmodel_smmcapletcalibration.hpp \ marketmodel_smmcaplethomocalibration.hpp \ @@ -277,7 +276,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - marketmodel_smm.hpp \ quantlibglobalfixture.hpp \ quantooption.hpp \ riskstats.hpp \ diff --git a/test-suite/marketmodel_smm.cpp b/test-suite/marketmodel_smm.cpp index aa4807a591a..ab752360461 100644 --- a/test-suite/marketmodel_smm.cpp +++ b/test-suite/marketmodel_smm.cpp @@ -18,7 +18,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel_smm.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -418,8 +419,11 @@ namespace market_model_smm_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions() { +BOOST_AUTO_TEST_SUITE(MarketModelSmmTest) + +BOOST_AUTO_TEST_CASE(testMultiStepCoterminalSwapsAndSwaptions, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE("Testing exact repricing of " "multi-step coterminal swaps and swaptions " @@ -503,16 +507,6 @@ void MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions() { } } +BOOST_AUTO_TEST_SUITE_END() - -// --- Call the desired tests -test_suite* MarketModelSmmTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("SMM Market-model tests"); - - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE( - &MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/marketmodel_smm.hpp b/test-suite/marketmodel_smm.hpp deleted file mode 100644 index 05cd607ccb1..00000000000 --- a/test-suite/marketmodel_smm.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Marco Bianchetti - Copyright (C) 2007 Cristina Duminuco - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_market_model_smm_hpp -#define quantlib_test_market_model_smm_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarketModelSmmTest { - public: - /* static void testMultiStepForwardsAndOptionlets(); - static void testOneStepForwardsAndOptionlets(); - static void testOneStepNormalForwardsAndOptionlets(); - static void testMultiStepCoterminalSwapsAndSwaptions(); - static void testMultiStepCoinitialSwaps(); - static void testCallableSwapNaif(); - static void testCallableSwapLS(); - static void testCallableSwapAnderson(); - static void testGreeks(); - static void testAbcdVolatilityIntegration(); - static void testAbcdVolatilityCompare(); - static void testAbcdVolatilityFit(); - static void testDriftCalculator(); - static void testIsInSubset();*/ - static void testMultiStepCoterminalSwapsAndSwaptions(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 04e703c90b8..19e4bfe65d4 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,10 +137,6 @@ #endif #include "utilities.hpp" -#include "marketmodel_smm.hpp" -#include "marketmodel_cms.hpp" -#include "quantooption.hpp" -#include "riskstats.hpp" #include "shortratemodels.hpp" namespace QuantLibTest { @@ -234,6 +230,11 @@ namespace QuantLibTest { public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace MarketModelSmmTest { + struct testMultiStepCoterminalSwapsAndSwaptions: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } + } namespace { @@ -283,8 +284,8 @@ namespace { Benchmark("HestonModel::DAXCalibration", [] { QuantLibTest::HestonModelTest::testDAXCalibration().test_method(); }, 555.19), Benchmark("InterpolationTest::testSabrInterpolation", [] { QuantLibTest::InterpolationTest::testSabrInterpolation().test_method(); }, 2266.06), Benchmark("JumpDiffusion::Greeks", [] { QuantLibTest::JumpDiffusionTest::testGreeks().test_method(); }, 433.77), - Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", [] { QuantLibTest::MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions().test_method(), 11497.73), - Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", &MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions, 11244.95), + Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", [] { QuantLibTest::MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions().test_method(); }, 11497.73), + Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", [] { QuantLibTest::MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions().test_method(); }, 11244.95), Benchmark("QuantoOption::ForwardGreeks", &QuantoOptionTest::testForwardGreeks, 90.98), Benchmark("RandomNumber::MersenneTwisterDescrepancy", [] { QuantLibTest::LowDiscrepancyTest::testMersenneTwisterDiscrepancy().test_method(); }, 951.98), Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 627b84f690e..d7d0ae51ff6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "marketmodel_smm.hpp" #include "marketmodel_smmcapletalphacalibration.hpp" #include "marketmodel_smmcapletcalibration.hpp" #include "marketmodel_smmcaplethomocalibration.hpp" @@ -135,7 +134,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarketModelSmmTest::suite(speed)); test->add(MarketModelSmmCapletAlphaCalibrationTest::suite()); test->add(MarketModelSmmCapletCalibrationTest::suite()); test->add(MarketModelSmmCapletHomoCalibrationTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f56dc065b56..663b34b65a1 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 003ecff32d9..03f0a2170b9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 0ac5f2bd563efa7232314cae7ca25a6129b3ca50 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:35:13 +0800 Subject: [PATCH 005/102] Migrated marketmodel_smmcapletalphacalibration.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - .../marketmodel_smmcapletalphacalibration.cpp | 17 ++++------ .../marketmodel_smmcapletalphacalibration.hpp | 34 ------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 7 insertions(+), 52 deletions(-) delete mode 100644 test-suite/marketmodel_smmcapletalphacalibration.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 0b49abcb20a..ad84357b4b4 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel_smmcapletalphacalibration.hpp marketmodel_smmcapletcalibration.hpp marketmodel_smmcaplethomocalibration.hpp markovfunctional.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7ae32529000..59f92a826b7 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel_smmcapletalphacalibration.hpp \ marketmodel_smmcapletcalibration.hpp \ marketmodel_smmcaplethomocalibration.hpp \ markovfunctional.hpp \ diff --git a/test-suite/marketmodel_smmcapletalphacalibration.cpp b/test-suite/marketmodel_smmcapletalphacalibration.cpp index dde7ba2464f..00020647042 100644 --- a/test-suite/marketmodel_smmcapletalphacalibration.cpp +++ b/test-suite/marketmodel_smmcapletalphacalibration.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel_smmcapletalphacalibration.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -211,8 +211,11 @@ namespace market_model_smm_caplet_alpha_calibration_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void MarketModelSmmCapletAlphaCalibrationTest::testFunction() { +BOOST_AUTO_TEST_SUITE(MarketModelSmmCapletAlphaCalibrationTest) + +BOOST_AUTO_TEST_CASE(testFunction) { BOOST_TEST_MESSAGE("Testing alpha caplet calibration " "in a lognormal coterminal swap market model..."); @@ -343,12 +346,6 @@ void MarketModelSmmCapletAlphaCalibrationTest::testFunction() { } } +BOOST_AUTO_TEST_SUITE_END() -// --- Call the desired tests -test_suite* MarketModelSmmCapletAlphaCalibrationTest::suite() { - auto* suite = BOOST_TEST_SUITE("SMM Caplet alpha calibration test"); - - suite->add(QUANTLIB_TEST_CASE(&MarketModelSmmCapletAlphaCalibrationTest::testFunction)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/marketmodel_smmcapletalphacalibration.hpp b/test-suite/marketmodel_smmcapletalphacalibration.hpp deleted file mode 100644 index 264659f1d17..00000000000 --- a/test-suite/marketmodel_smmcapletalphacalibration.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Mark Joshi - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_market_model_smm_caplet_alpha_calibration_hpp -#define quantlib_test_market_model_smm_caplet_alpha_calibration_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarketModelSmmCapletAlphaCalibrationTest { - public: - static void testFunction(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index d7d0ae51ff6..5c9a5fa4d39 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "marketmodel_smmcapletalphacalibration.hpp" #include "marketmodel_smmcapletcalibration.hpp" #include "marketmodel_smmcaplethomocalibration.hpp" #include "markovfunctional.hpp" @@ -134,7 +133,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarketModelSmmCapletAlphaCalibrationTest::suite()); test->add(MarketModelSmmCapletCalibrationTest::suite()); test->add(MarketModelSmmCapletHomoCalibrationTest::suite()); test->add(MarkovFunctionalTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 663b34b65a1..9b8f00bda56 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 03f0a2170b9..ead05ea83aa 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 466e1802813c860cc27b610167049b940e5ae6c3 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:38:15 +0800 Subject: [PATCH 006/102] Migrated marketmodel_smmcapletcalibration.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - .../marketmodel_smmcapletcalibration.cpp | 16 ++++----- .../marketmodel_smmcapletcalibration.hpp | 34 ------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 test-suite/marketmodel_smmcapletcalibration.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index ad84357b4b4..201b6ca812c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel_smmcapletcalibration.hpp marketmodel_smmcaplethomocalibration.hpp markovfunctional.hpp matrices.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 59f92a826b7..69460dcaba0 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel_smmcapletcalibration.hpp \ marketmodel_smmcaplethomocalibration.hpp \ markovfunctional.hpp \ matrices.hpp \ diff --git a/test-suite/marketmodel_smmcapletcalibration.cpp b/test-suite/marketmodel_smmcapletcalibration.cpp index c046fba8850..f53b9babc98 100644 --- a/test-suite/marketmodel_smmcapletcalibration.cpp +++ b/test-suite/marketmodel_smmcapletcalibration.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel_smmcapletcalibration.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -209,9 +209,11 @@ namespace market_model_smm_caplet_calibration_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) +BOOST_AUTO_TEST_SUITE(MarketModelSmmCapletCalibrationTest) -void MarketModelSmmCapletCalibrationTest::testFunction() { +BOOST_AUTO_TEST_CASE(testFunction) { BOOST_TEST_MESSAGE("Testing GHLS caplet calibration " "in a lognormal coterminal swap market model..."); @@ -335,12 +337,6 @@ void MarketModelSmmCapletCalibrationTest::testFunction() { } } +BOOST_AUTO_TEST_SUITE_END() -// --- Call the desired tests -test_suite* MarketModelSmmCapletCalibrationTest::suite() { - auto* suite = BOOST_TEST_SUITE("SMM Caplet calibration test"); - - suite->add(QUANTLIB_TEST_CASE(&MarketModelSmmCapletCalibrationTest::testFunction)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/marketmodel_smmcapletcalibration.hpp b/test-suite/marketmodel_smmcapletcalibration.hpp deleted file mode 100644 index e3ff1edcd69..00000000000 --- a/test-suite/marketmodel_smmcapletcalibration.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Mark Joshi - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_market_model_smm_caplet_calibration_hpp -#define quantlib_test_market_model_smm_caplet_calibration_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarketModelSmmCapletCalibrationTest { - public: - static void testFunction(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 5c9a5fa4d39..cca44577088 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "marketmodel_smmcapletcalibration.hpp" #include "marketmodel_smmcaplethomocalibration.hpp" #include "markovfunctional.hpp" #include "matrices.hpp" @@ -133,7 +132,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarketModelSmmCapletCalibrationTest::suite()); test->add(MarketModelSmmCapletHomoCalibrationTest::suite()); test->add(MarkovFunctionalTest::suite(speed)); test->add(MatricesTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 9b8f00bda56..f954da31399 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index ead05ea83aa..93278478b83 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 2dd13f8838333aafda5e3276e951da2904d623d3 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:44:15 +0800 Subject: [PATCH 007/102] Migrated marketmodel_smmcaplethomocalibration.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - .../marketmodel_smmcaplethomocalibration.cpp | 42 ++++--------------- .../marketmodel_smmcaplethomocalibration.hpp | 36 ---------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 8 insertions(+), 78 deletions(-) delete mode 100644 test-suite/marketmodel_smmcaplethomocalibration.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 201b6ca812c..aed8bab0d87 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - marketmodel_smmcaplethomocalibration.hpp markovfunctional.hpp matrices.hpp mclongstaffschwartzengine.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 69460dcaba0..424ed18f0d1 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - marketmodel_smmcaplethomocalibration.hpp \ markovfunctional.hpp \ matrices.hpp \ mclongstaffschwartzengine.hpp \ diff --git a/test-suite/marketmodel_smmcaplethomocalibration.cpp b/test-suite/marketmodel_smmcaplethomocalibration.cpp index c3f31232636..0e5ebf6f7f0 100644 --- a/test-suite/marketmodel_smmcaplethomocalibration.cpp +++ b/test-suite/marketmodel_smmcaplethomocalibration.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "marketmodel_smmcaplethomocalibration.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -221,9 +221,11 @@ namespace market_model_smm_caplet_homo_calibration_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) +BOOST_AUTO_TEST_SUITE(MarketModelSmmCapletHomoCalibrationTest) -void MarketModelSmmCapletHomoCalibrationTest::testFunction() { +BOOST_AUTO_TEST_CASE(testFunction) { BOOST_TEST_MESSAGE("Testing max homogeneity caplet calibration " "in a lognormal coterminal swap market model..."); @@ -350,18 +352,9 @@ void MarketModelSmmCapletHomoCalibrationTest::testFunction() { // for (Size i=0; i < newSwapMM.numberOfRates(); ++i) // BOOST_TEST_MESSAGE("swap MM time dependent vols: "<< i << std::fixed << // std::setprecision(6) << Array(newSwapMM.timeDependentVolatility(i))); - - - - - - } - - -void MarketModelSmmCapletHomoCalibrationTest::testPeriodFunction() -{ +BOOST_AUTO_TEST_CASE(testPeriodFunction) { BOOST_TEST_MESSAGE("Testing max homogeneity periodic caplet calibration " "in a lognormal coterminal swap market model..."); @@ -520,16 +513,9 @@ void MarketModelSmmCapletHomoCalibrationTest::testPeriodFunction() "\n error: " << error << "\n tolerance: " << swapTolerance); } - - - - - - } - -void MarketModelSmmCapletHomoCalibrationTest::testSphereCylinder() { +BOOST_AUTO_TEST_CASE(testSphereCylinder) { BOOST_TEST_MESSAGE("Testing sphere-cylinder optimization..."); @@ -623,18 +609,6 @@ void MarketModelSmmCapletHomoCalibrationTest::testSphereCylinder() { } } +BOOST_AUTO_TEST_SUITE_END() -// --- Call the desired tests -test_suite* MarketModelSmmCapletHomoCalibrationTest::suite() { - auto* suite = BOOST_TEST_SUITE("SMM Caplet homogeneous calibration test"); - - suite->add(QUANTLIB_TEST_CASE( - &MarketModelSmmCapletHomoCalibrationTest::testFunction)); - suite->add(QUANTLIB_TEST_CASE( - &MarketModelSmmCapletHomoCalibrationTest::testPeriodFunction)); - - suite->add(QUANTLIB_TEST_CASE( - &MarketModelSmmCapletHomoCalibrationTest::testSphereCylinder)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/marketmodel_smmcaplethomocalibration.hpp b/test-suite/marketmodel_smmcaplethomocalibration.hpp deleted file mode 100644 index 75ac5c8f8f2..00000000000 --- a/test-suite/marketmodel_smmcaplethomocalibration.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Mark Joshi - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_market_model_smm_caplet_homo_calibration_hpp -#define quantlib_test_market_model_smm_caplet_homo_calibration_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarketModelSmmCapletHomoCalibrationTest { - public: - static void testFunction(); - static void testPeriodFunction(); - static void testSphereCylinder(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index cca44577088..aa2fce2b167 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "marketmodel_smmcaplethomocalibration.hpp" #include "markovfunctional.hpp" #include "matrices.hpp" #include "mclongstaffschwartzengine.hpp" @@ -132,7 +131,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarketModelSmmCapletHomoCalibrationTest::suite()); test->add(MarkovFunctionalTest::suite(speed)); test->add(MatricesTest::suite()); test->add(MCLongstaffSchwartzEngineTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f954da31399..ba5abe34b71 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 93278478b83..736236aefb1 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From bf46253891d11cd4b09f2b1a23733d6ddd48784a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 13:51:02 +0800 Subject: [PATCH 008/102] Migrated matrices.cpp and markovfunctional.cpp --- test-suite/CMakeLists.txt | 2 - test-suite/Makefile.am | 2 - test-suite/markovfunctional.cpp | 270 +++++++++++++-------------- test-suite/markovfunctional.hpp | 40 ---- test-suite/matrices.cpp | 89 ++++----- test-suite/matrices.hpp | 52 ------ test-suite/quantlibtestsuite.cpp | 4 - test-suite/testsuite.vcxproj | 2 - test-suite/testsuite.vcxproj.filters | 6 - 9 files changed, 165 insertions(+), 302 deletions(-) delete mode 100644 test-suite/markovfunctional.hpp delete mode 100644 test-suite/matrices.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index aed8bab0d87..d16ff5a581c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,8 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - markovfunctional.hpp - matrices.hpp mclongstaffschwartzengine.hpp mersennetwister.hpp money.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 424ed18f0d1..c5037e25880 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,8 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - markovfunctional.hpp \ - matrices.hpp \ mclongstaffschwartzengine.hpp \ mersennetwister.hpp \ money.hpp \ diff --git a/test-suite/markovfunctional.cpp b/test-suite/markovfunctional.cpp index 7d857d8e447..e82b49f14cc 100644 --- a/test-suite/markovfunctional.cpp +++ b/test-suite/markovfunctional.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "markovfunctional.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -56,123 +57,6 @@ using namespace boost::unit_test_framework; using std::fabs; -void MarkovFunctionalTest::testMfStateProcess() { - - const Real tolerance = 1E-10; - BOOST_TEST_MESSAGE("Testing Markov functional state process..."); - - Array times1(0), vols1(1, 1.0); - MfStateProcess sp1(0.00, times1, vols1); - Real var11 = sp1.variance(0.0, 0.0, 1.0); - Real var12 = sp1.variance(0.0, 0.0, 2.0); - if (std::fabs(var11 - 1.0) > tolerance) - BOOST_ERROR("process 1 has not variance 1.0 for dt = 1.0 but " - << var11); - if (std::fabs(var12 - 2.0) > tolerance) - BOOST_ERROR("process 1 has not variance 1.0 for dt = 1.0 but " - << var12); - - Array times2(2), vols2(3); - times2[0] = 1.0; - times2[1] = 2.0; - vols2[0] = 1.0; - vols2[1] = 2.0; - vols2[2] = 3.0; - MfStateProcess sp2(0.00, times2, vols2); - Real dif21 = sp2.diffusion(0.0, 0.0); - Real dif22 = sp2.diffusion(0.99, 0.0); - Real dif23 = sp2.diffusion(1.0, 0.0); - Real dif24 = sp2.diffusion(1.9, 0.0); - Real dif25 = sp2.diffusion(2.0, 0.0); - Real dif26 = sp2.diffusion(3.0, 0.0); - Real dif27 = sp2.diffusion(5.0, 0.0); - if (std::fabs(dif21 - 1.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 0.0, should be 1.0 but is " - << dif21); - if (std::fabs(dif22 - 1.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 0.99, should be 1.0 but is " - << dif22); - if (std::fabs(dif23 - 2.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 1.0, should be 2.0 but is " - << dif23); - if (std::fabs(dif24 - 2.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 1.9, should be 2.0 but is " - << dif24); - if (std::fabs(dif25 - 3.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 2.0, should be 3.0 but is " - << dif25); - if (std::fabs(dif26 - 3.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 3.0, should be 3.0 but is " - << dif26); - if (std::fabs(dif27 - 3.0) > tolerance) - BOOST_ERROR("process 2 has wrong drift at 5.0, should be 3.0 but is " - << dif27); - Real var21 = sp2.variance(0.0, 0.0, 0.0); - Real var22 = sp2.variance(0.0, 0.0, 0.5); - Real var23 = sp2.variance(0.0, 0.0, 1.0); - Real var24 = sp2.variance(0.0, 0.0, 1.5); - Real var25 = sp2.variance(0.0, 0.0, 3.0); - Real var26 = sp2.variance(0.0, 0.0, 5.0); - Real var27 = sp2.variance(1.2, 0.0, 1.0); - if (std::fabs(var21 - 0.0) > tolerance) - BOOST_ERROR("process 2 has wrong variance at 0.0, should be 0.0 but is " - << var21); - if (std::fabs(var22 - 0.5) > tolerance) - BOOST_ERROR("process 2 has wrong variance at 0.5, should be 0.5 but is " - << var22); - if (std::fabs(var23 - 1.0) > tolerance) - BOOST_ERROR("process 2 has wrong variance at 1.0, should be 1.0 but is " - << var23); - if (std::fabs(var24 - 3.0) > tolerance) - BOOST_ERROR("process 2 has wrong variance at 1.5, should be 3.0 but is " - << var24); - if (std::fabs(var25 - 14.0) > tolerance) - BOOST_ERROR( - "process 2 has wrong variance at 3.0, should be 14.0 but is " - << var25); - if (std::fabs(var26 - 32.0) > tolerance) - BOOST_ERROR( - "process 2 has wrong variance at 5.0, should be 32.0 but is " - << var26); - if (std::fabs(var27 - 5.0) > tolerance) - BOOST_ERROR("process 2 has wrong variance between 1.2 and 2.2, should " - "be 5.0 but is " - << var27); - - MfStateProcess sp3(0.01, times2, vols2); - Real var31 = sp3.variance(0.0, 0.0, 0.0); - Real var32 = sp3.variance(0.0, 0.0, 0.5); - Real var33 = sp3.variance(0.0, 0.0, 1.0); - Real var34 = sp3.variance(0.0, 0.0, 1.5); - Real var35 = sp3.variance(0.0, 0.0, 3.0); - Real var36 = sp3.variance(0.0, 0.0, 5.0); - Real var37 = sp3.variance(1.2, 0.0, 1.0); - if (std::fabs(var31 - 0.0) > tolerance) - BOOST_ERROR("process 3 has wrong variance at 0.0, should be 0.0 but is " - << std::setprecision(12) << var31); - if (std::fabs(var32 - 0.502508354208) > tolerance) - BOOST_ERROR("process 3 has wrong variance at 0.5, should be 0.5 but it " - << std::setprecision(12) << var32); - if (std::fabs(var33 - 1.01006700134) > tolerance) - BOOST_ERROR("process 3 has wrong variance at 1.0, should be 1.0 but it " - << std::setprecision(12) << var33); - if (std::fabs(var34 - 3.06070578669) > tolerance) - BOOST_ERROR("process 3 has wrong variance at 1.5, should be 3.0 but it " - << std::setprecision(12) << var34); - if (std::fabs(var35 - 14.5935513933) > tolerance) - BOOST_ERROR( - "process 3 has wrong variance at 3.0, should be 14.0 but it " - << std::setprecision(12) << var35); - if (std::fabs(var36 - 34.0940185819) > tolerance) - BOOST_ERROR( - "process 3 has wrong variance at 5.0, should be 32.0 but it " - << std::setprecision(12) << var36); - if (std::fabs(var37 - 5.18130257358) > tolerance) - BOOST_ERROR("process 3 has wrong variance between 1.2 and 2.2, should " - "be 5.0 but it " - << std::setprecision(12) << var37); -} - namespace { // Flat yield term structure at 3% @@ -632,7 +516,128 @@ namespace { } } -void MarkovFunctionalTest::testKahaleSmileSection() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(MarkovFunctionalTest) + +BOOST_AUTO_TEST_CASE(testMfStateProcess) { + + const Real tolerance = 1E-10; + BOOST_TEST_MESSAGE("Testing Markov functional state process..."); + + Array times1(0), vols1(1, 1.0); + MfStateProcess sp1(0.00, times1, vols1); + Real var11 = sp1.variance(0.0, 0.0, 1.0); + Real var12 = sp1.variance(0.0, 0.0, 2.0); + if (std::fabs(var11 - 1.0) > tolerance) + BOOST_ERROR("process 1 has not variance 1.0 for dt = 1.0 but " + << var11); + if (std::fabs(var12 - 2.0) > tolerance) + BOOST_ERROR("process 1 has not variance 1.0 for dt = 1.0 but " + << var12); + + Array times2(2), vols2(3); + times2[0] = 1.0; + times2[1] = 2.0; + vols2[0] = 1.0; + vols2[1] = 2.0; + vols2[2] = 3.0; + MfStateProcess sp2(0.00, times2, vols2); + Real dif21 = sp2.diffusion(0.0, 0.0); + Real dif22 = sp2.diffusion(0.99, 0.0); + Real dif23 = sp2.diffusion(1.0, 0.0); + Real dif24 = sp2.diffusion(1.9, 0.0); + Real dif25 = sp2.diffusion(2.0, 0.0); + Real dif26 = sp2.diffusion(3.0, 0.0); + Real dif27 = sp2.diffusion(5.0, 0.0); + if (std::fabs(dif21 - 1.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 0.0, should be 1.0 but is " + << dif21); + if (std::fabs(dif22 - 1.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 0.99, should be 1.0 but is " + << dif22); + if (std::fabs(dif23 - 2.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 1.0, should be 2.0 but is " + << dif23); + if (std::fabs(dif24 - 2.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 1.9, should be 2.0 but is " + << dif24); + if (std::fabs(dif25 - 3.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 2.0, should be 3.0 but is " + << dif25); + if (std::fabs(dif26 - 3.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 3.0, should be 3.0 but is " + << dif26); + if (std::fabs(dif27 - 3.0) > tolerance) + BOOST_ERROR("process 2 has wrong drift at 5.0, should be 3.0 but is " + << dif27); + Real var21 = sp2.variance(0.0, 0.0, 0.0); + Real var22 = sp2.variance(0.0, 0.0, 0.5); + Real var23 = sp2.variance(0.0, 0.0, 1.0); + Real var24 = sp2.variance(0.0, 0.0, 1.5); + Real var25 = sp2.variance(0.0, 0.0, 3.0); + Real var26 = sp2.variance(0.0, 0.0, 5.0); + Real var27 = sp2.variance(1.2, 0.0, 1.0); + if (std::fabs(var21 - 0.0) > tolerance) + BOOST_ERROR("process 2 has wrong variance at 0.0, should be 0.0 but is " + << var21); + if (std::fabs(var22 - 0.5) > tolerance) + BOOST_ERROR("process 2 has wrong variance at 0.5, should be 0.5 but is " + << var22); + if (std::fabs(var23 - 1.0) > tolerance) + BOOST_ERROR("process 2 has wrong variance at 1.0, should be 1.0 but is " + << var23); + if (std::fabs(var24 - 3.0) > tolerance) + BOOST_ERROR("process 2 has wrong variance at 1.5, should be 3.0 but is " + << var24); + if (std::fabs(var25 - 14.0) > tolerance) + BOOST_ERROR( + "process 2 has wrong variance at 3.0, should be 14.0 but is " + << var25); + if (std::fabs(var26 - 32.0) > tolerance) + BOOST_ERROR( + "process 2 has wrong variance at 5.0, should be 32.0 but is " + << var26); + if (std::fabs(var27 - 5.0) > tolerance) + BOOST_ERROR("process 2 has wrong variance between 1.2 and 2.2, should " + "be 5.0 but is " + << var27); + + MfStateProcess sp3(0.01, times2, vols2); + Real var31 = sp3.variance(0.0, 0.0, 0.0); + Real var32 = sp3.variance(0.0, 0.0, 0.5); + Real var33 = sp3.variance(0.0, 0.0, 1.0); + Real var34 = sp3.variance(0.0, 0.0, 1.5); + Real var35 = sp3.variance(0.0, 0.0, 3.0); + Real var36 = sp3.variance(0.0, 0.0, 5.0); + Real var37 = sp3.variance(1.2, 0.0, 1.0); + if (std::fabs(var31 - 0.0) > tolerance) + BOOST_ERROR("process 3 has wrong variance at 0.0, should be 0.0 but is " + << std::setprecision(12) << var31); + if (std::fabs(var32 - 0.502508354208) > tolerance) + BOOST_ERROR("process 3 has wrong variance at 0.5, should be 0.5 but it " + << std::setprecision(12) << var32); + if (std::fabs(var33 - 1.01006700134) > tolerance) + BOOST_ERROR("process 3 has wrong variance at 1.0, should be 1.0 but it " + << std::setprecision(12) << var33); + if (std::fabs(var34 - 3.06070578669) > tolerance) + BOOST_ERROR("process 3 has wrong variance at 1.5, should be 3.0 but it " + << std::setprecision(12) << var34); + if (std::fabs(var35 - 14.5935513933) > tolerance) + BOOST_ERROR( + "process 3 has wrong variance at 3.0, should be 14.0 but it " + << std::setprecision(12) << var35); + if (std::fabs(var36 - 34.0940185819) > tolerance) + BOOST_ERROR( + "process 3 has wrong variance at 5.0, should be 32.0 but it " + << std::setprecision(12) << var36); + if (std::fabs(var37 - 5.18130257358) > tolerance) + BOOST_ERROR("process 3 has wrong variance between 1.2 and 2.2, should " + "be 5.0 but it " + << std::setprecision(12) << var37); +} + +BOOST_AUTO_TEST_CASE(testKahaleSmileSection) { BOOST_TEST_MESSAGE("Testing Kahale smile section..."); @@ -837,7 +842,7 @@ void MarkovFunctionalTest::testKahaleSmileSection() { } } -void MarkovFunctionalTest::testCalibrationOneInstrumentSet() { +BOOST_AUTO_TEST_CASE(testCalibrationOneInstrumentSet, *precondition(if_speed(Slow))) { const Real tol0 = 0.0001; // 1bp tolerance for model zero rates vs. market // zero rates (note that model zero rates are @@ -1068,7 +1073,7 @@ void MarkovFunctionalTest::testCalibrationOneInstrumentSet() { Settings::instance().evaluationDate() = savedEvalDate; } -void MarkovFunctionalTest::testVanillaEngines() { +BOOST_AUTO_TEST_CASE(testVanillaEngines, *precondition(if_speed(Slow))) { const Real tol1 = 0.0001; // 1bp tolerance for model engine call put premia // vs. black premia @@ -1352,7 +1357,7 @@ void MarkovFunctionalTest::testVanillaEngines() { Settings::instance().evaluationDate() = savedEvalDate; } -void MarkovFunctionalTest::testCalibrationTwoInstrumentSets() { +BOOST_AUTO_TEST_CASE(testCalibrationTwoInstrumentSets, *precondition(if_speed(Fast))) { const Real tol1 = 0.1; // 0.1 times vega tolerance for model vs. market in // second instrument set @@ -1595,7 +1600,7 @@ void MarkovFunctionalTest::testCalibrationTwoInstrumentSets() { Settings::instance().evaluationDate() = savedEvalDate; } -void MarkovFunctionalTest::testBermudanSwaption() { +BOOST_AUTO_TEST_CASE(testBermudanSwaption) { Real tol0 = 0.0001; // 1bp tolerance against cached values @@ -1678,21 +1683,6 @@ void MarkovFunctionalTest::testBermudanSwaption() { Settings::instance().evaluationDate() = savedEvalDate; } -test_suite *MarkovFunctionalTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Markov functional model tests"); - - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testMfStateProcess)); - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testKahaleSmileSection)); - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testBermudanSwaption)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testCalibrationTwoInstrumentSets)); - } +BOOST_AUTO_TEST_SUITE_END() - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testCalibrationOneInstrumentSet)); - suite->add(QUANTLIB_TEST_CASE(&MarkovFunctionalTest::testVanillaEngines)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/markovfunctional.hpp b/test-suite/markovfunctional.hpp deleted file mode 100644 index 586223bb3fc..00000000000 --- a/test-suite/markovfunctional.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2012 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_markovfunctional_hpp -#define quantlib_test_markovfunctional_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MarkovFunctionalTest { - public: - static void testMfStateProcess(); - static void testKahaleSmileSection(); - static void testCalibrationOneInstrumentSet(); - static void testCalibrationTwoInstrumentSets(); - static void testVanillaEngines(); - static void testBermudanSwaption(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/matrices.cpp b/test-suite/matrices.cpp index dbcea2dab6b..4b40c534249 100644 --- a/test-suite/matrices.cpp +++ b/test-suite/matrices.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "matrices.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -114,10 +114,27 @@ namespace matrices_test { M7[0][1] = 0.3; M7[0][2] = 0.2; M7[2][1] = 1.2; } + class MatrixMult { + public: + explicit MatrixMult(Matrix m) : m_(std::move(m)) {} + Array operator()(const Array& x) const { + return m_ * x; + } + + private: + const Matrix m_; + }; + + Real norm2(const Array& x) { + return std::sqrt(DotProduct(x,x)); + } } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(MatricesTest) -void MatricesTest::testEigenvectors() { +BOOST_AUTO_TEST_CASE(testEigenvectors) { BOOST_TEST_MESSAGE("Testing eigenvalues and eigenvectors calculation..."); @@ -157,7 +174,7 @@ void MatricesTest::testEigenvectors() { } } -void MatricesTest::testSqrt() { +BOOST_AUTO_TEST_CASE(testSqrt) { BOOST_TEST_MESSAGE("Testing matricial square root..."); @@ -179,7 +196,7 @@ void MatricesTest::testSqrt() { } } -void MatricesTest::testHighamSqrt() { +BOOST_AUTO_TEST_CASE(testHighamSqrt) { BOOST_TEST_MESSAGE("Testing Higham matricial square root..."); using namespace matrices_test; @@ -200,7 +217,7 @@ void MatricesTest::testHighamSqrt() { } } -void MatricesTest::testSVD() { +BOOST_AUTO_TEST_CASE(testSVD) { BOOST_TEST_MESSAGE("Testing singular value decomposition..."); @@ -246,7 +263,7 @@ void MatricesTest::testSVD() { } } -void MatricesTest::testQRDecomposition() { +BOOST_AUTO_TEST_CASE(testQRDecomposition) { BOOST_TEST_MESSAGE("Testing QR decomposition..."); @@ -283,7 +300,7 @@ void MatricesTest::testQRDecomposition() { } } -void MatricesTest::testQRSolve() { +BOOST_AUTO_TEST_CASE(testQRSolve) { BOOST_TEST_MESSAGE("Testing QR solve..."); @@ -355,7 +372,7 @@ void MatricesTest::testQRSolve() { } } -void MatricesTest::testInverse() { +BOOST_AUTO_TEST_CASE(testInverse) { BOOST_TEST_MESSAGE("Testing LU inverse calculation..."); @@ -385,7 +402,7 @@ void MatricesTest::testInverse() { } } -void MatricesTest::testDeterminant() { +BOOST_AUTO_TEST_CASE(testDeterminant) { BOOST_TEST_MESSAGE("Testing LU determinant calculation..."); @@ -440,7 +457,7 @@ void MatricesTest::testDeterminant() { } } -void MatricesTest::testOrthogonalProjection() { +BOOST_AUTO_TEST_CASE(testOrthogonalProjection) { BOOST_TEST_MESSAGE("Testing orthogonal projections..."); Size dimension = 1000; @@ -506,7 +523,7 @@ void MatricesTest::testOrthogonalProjection() { } -void MatricesTest::testCholeskyDecomposition() { +BOOST_AUTO_TEST_CASE(testCholeskyDecomposition) { BOOST_TEST_MESSAGE("Testing Cholesky Decomposition..."); @@ -577,7 +594,7 @@ void MatricesTest::testCholeskyDecomposition() { } } -void MatricesTest::testMoorePenroseInverse() { +BOOST_AUTO_TEST_CASE(testMoorePenroseInverse) { BOOST_TEST_MESSAGE("Testing Moore-Penrose inverse..."); @@ -626,25 +643,7 @@ void MatricesTest::testMoorePenroseInverse() { } - -namespace matrices_test { - class MatrixMult { - public: - explicit MatrixMult(Matrix m) : m_(std::move(m)) {} - Array operator()(const Array& x) const { - return m_ * x; - } - - private: - const Matrix m_; - }; - - Real norm2(const Array& x) { - return std::sqrt(DotProduct(x,x)); - } -} - -void MatricesTest::testIterativeSolvers() { +BOOST_AUTO_TEST_CASE(testIterativeSolvers) { BOOST_TEST_MESSAGE("Testing iterative solvers..."); using namespace matrices_test; @@ -703,7 +702,7 @@ void MatricesTest::testIterativeSolvers() { } } -void MatricesTest::testInitializers() { +BOOST_AUTO_TEST_CASE(testInitializers) { BOOST_TEST_MESSAGE("Testing matrix initializers..."); Matrix m1 = {}; @@ -745,7 +744,7 @@ namespace { } -void MatricesTest::testSparseMatrixMemory() { +BOOST_AUTO_TEST_CASE(testSparseMatrixMemory) { BOOST_TEST_MESSAGE("Testing sparse matrix memory layout..."); @@ -808,7 +807,7 @@ void MatricesTest::testSparseMatrixMemory() { } \ } \ -void MatricesTest::testOperators() { +BOOST_AUTO_TEST_CASE(testOperators) { BOOST_TEST_MESSAGE("Testing matrix operators..."); @@ -866,24 +865,6 @@ void MatricesTest::testOperators() { QL_CHECK_CLOSE_MATRIX(rvalue_real_quotient, scalar_quotient); } -test_suite* MatricesTest::suite() { - auto* suite = BOOST_TEST_SUITE("Matrix tests"); - - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testOrthogonalProjection)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testEigenvectors)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testSqrt)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testSVD)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testHighamSqrt)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testQRDecomposition)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testQRSolve)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testInverse)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testDeterminant)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testSparseMatrixMemory)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testCholeskyDecomposition)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testMoorePenroseInverse)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testIterativeSolvers)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testInitializers)); - suite->add(QUANTLIB_TEST_CASE(&MatricesTest::testOperators)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/matrices.hpp b/test-suite/matrices.hpp deleted file mode 100644 index 16bf168003c..00000000000 --- a/test-suite/matrices.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Ferdinando Ametrano - Copyright (C) 2004, 2007 Neil Firth - Copyright (C) 2016 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_matrices_hpp -#define quantlib_test_matrices_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MatricesTest { - public: - static void testEigenvectors(); - static void testSqrt(); - static void testHighamSqrt(); - static void testSVD(); - static void testQRDecomposition(); - static void testQRSolve(); - static void testInverse(); - static void testDeterminant(); - static void testOrthogonalProjection(); - static void testCholeskyDecomposition(); - static void testMoorePenroseInverse(); - static void testIterativeSolvers(); - static void testInitializers(); - static void testSparseMatrixMemory(); - static void testOperators(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index aa2fce2b167..a1b841a17b8 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,8 +34,6 @@ # include #endif -#include "markovfunctional.hpp" -#include "matrices.hpp" #include "mclongstaffschwartzengine.hpp" #include "mersennetwister.hpp" #include "money.hpp" @@ -131,8 +129,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MarkovFunctionalTest::suite(speed)); - test->add(MatricesTest::suite()); test->add(MCLongstaffSchwartzEngineTest::suite(speed)); test->add(MersenneTwisterTest::suite()); test->add(MoneyTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ba5abe34b71..3f8841561a9 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,8 +810,6 @@ - - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 736236aefb1..de1f62ea837 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,12 +527,6 @@ - - Header Files - - - Header Files - Header Files From 0baf421d8b3fb9a767ff8479449101fce5c1fce2 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:18:29 +0800 Subject: [PATCH 009/102] Migrated mclongstaffschwartzengine.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/mclongstaffschwartzengine.cpp | 23 ++++++--------- test-suite/mclongstaffschwartzengine.hpp | 37 ------------------------ test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 test-suite/mclongstaffschwartzengine.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d16ff5a581c..864ee69fd2e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - mclongstaffschwartzengine.hpp mersennetwister.hpp money.hpp noarbsabr.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c5037e25880..34f4c4683b6 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - mclongstaffschwartzengine.hpp \ mersennetwister.hpp \ money.hpp \ noarbsabr.hpp \ diff --git a/test-suite/mclongstaffschwartzengine.cpp b/test-suite/mclongstaffschwartzengine.cpp index a452e5b9f24..898486d5a3b 100644 --- a/test-suite/mclongstaffschwartzengine.cpp +++ b/test-suite/mclongstaffschwartzengine.cpp @@ -19,7 +19,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "mclongstaffschwartzengine.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -120,8 +121,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void MCLongstaffSchwartzEngineTest::testAmericanOption() { +BOOST_AUTO_TEST_SUITE(MCLongstaffSchwartzEngineTest) + +BOOST_AUTO_TEST_CASE(testAmericanOption, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing Monte-Carlo pricing of American options..."); // most of the example taken from the EquityOption.cpp @@ -222,7 +226,7 @@ void MCLongstaffSchwartzEngineTest::testAmericanOption() { } } -void MCLongstaffSchwartzEngineTest::testAmericanMaxOption() { +BOOST_AUTO_TEST_CASE(testAmericanMaxOption) { // reference values taken from // "Monte Carlo Methods in Financial Engineering", @@ -307,15 +311,6 @@ void MCLongstaffSchwartzEngineTest::testAmericanMaxOption() { } } -test_suite* MCLongstaffSchwartzEngineTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Longstaff Schwartz MC engine tests"); - - suite->add(QUANTLIB_TEST_CASE(&MCLongstaffSchwartzEngineTest::testAmericanMaxOption)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&MCLongstaffSchwartzEngineTest::testAmericanOption)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/mclongstaffschwartzengine.hpp b/test-suite/mclongstaffschwartzengine.hpp deleted file mode 100644 index e729d6efbd0..00000000000 --- a/test-suite/mclongstaffschwartzengine.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_mc_longstaff_schwartz_engine_hpp -#define quantlib_test_mc_longstaff_schwartz_engine_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MCLongstaffSchwartzEngineTest { - public: - static void testAmericanOption(); - static void testAmericanMaxOption(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index a1b841a17b8..fe4669408bf 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "mclongstaffschwartzengine.hpp" #include "mersennetwister.hpp" #include "money.hpp" #include "noarbsabr.hpp" @@ -129,7 +128,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MCLongstaffSchwartzEngineTest::suite(speed)); test->add(MersenneTwisterTest::suite()); test->add(MoneyTest::suite()); test->add(NumericalDifferentiationTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 3f8841561a9..95bc399e667 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index de1f62ea837..181ebaa9783 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 8097320ecc35003fdecd03587ed7612431abb7ca Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:21:20 +0800 Subject: [PATCH 010/102] Migrated mersennetwister.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/mersennetwister.cpp | 16 ++++++------- test-suite/mersennetwister.hpp | 35 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 51 deletions(-) delete mode 100644 test-suite/mersennetwister.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 864ee69fd2e..45d6f111191 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - mersennetwister.hpp money.hpp noarbsabr.hpp normalclvmodel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 34f4c4683b6..3b38f5e4c54 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - mersennetwister.hpp \ money.hpp \ noarbsabr.hpp \ normalclvmodel.hpp \ diff --git a/test-suite/mersennetwister.cpp b/test-suite/mersennetwister.cpp index d90e1d82133..49d54ca3e9c 100644 --- a/test-suite/mersennetwister.cpp +++ b/test-suite/mersennetwister.cpp @@ -17,14 +17,18 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "mersennetwister.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include using namespace QuantLib; using namespace boost::unit_test_framework; -void MersenneTwisterTest::testValues() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(MersenneTwisterTest) + +BOOST_AUTO_TEST_CASE(testValues) { BOOST_TEST_MESSAGE("Testing Mersenne twister..."); @@ -481,10 +485,6 @@ void MersenneTwisterTest::testValues() { "during parallel computation"); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* MersenneTwisterTest::suite() { - auto* suite = BOOST_TEST_SUITE("Mersenne twister tests"); - suite->add(QUANTLIB_TEST_CASE(&MersenneTwisterTest::testValues)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/mersennetwister.hpp b/test-suite/mersennetwister.hpp deleted file mode 100644 index 20587b00acf..00000000000 --- a/test-suite/mersennetwister.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Ferdinando Ametrano - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_mt19937_hpp -#define quantlib_test_mt19937_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MersenneTwisterTest { - public: - static void testValues(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index fe4669408bf..0eaa667697f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "mersennetwister.hpp" #include "money.hpp" #include "noarbsabr.hpp" #include "normalclvmodel.hpp" @@ -128,7 +127,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MersenneTwisterTest::suite()); test->add(MoneyTest::suite()); test->add(NumericalDifferentiationTest::suite()); test->add(NthOrderDerivativeOpTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 95bc399e667..0ee8d011b13 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 181ebaa9783..a3fd5afbe90 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 808c87befaed2c37d19f5687ebca9113ab54d251 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:23:36 +0800 Subject: [PATCH 011/102] Migrated money.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/money.cpp | 23 ++++++++--------- test-suite/money.hpp | 37 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 58 deletions(-) delete mode 100644 test-suite/money.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 45d6f111191..914609ec168 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - money.hpp noarbsabr.hpp normalclvmodel.hpp nthorderderivativeop.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 3b38f5e4c54..f64dd6381bb 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - money.hpp \ noarbsabr.hpp \ normalclvmodel.hpp \ nthorderderivativeop.hpp \ diff --git a/test-suite/money.cpp b/test-suite/money.cpp index 4fc91296770..9a131ec5f8b 100644 --- a/test-suite/money.cpp +++ b/test-suite/money.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "money.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -27,7 +27,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void MoneyTest::testNone() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(MoneyTest) + +BOOST_AUTO_TEST_CASE(testNone) { BOOST_TEST_MESSAGE("Testing money arithmetic without conversions..."); @@ -50,8 +54,7 @@ void MoneyTest::testNone() { } } - -void MoneyTest::testBaseCurrency() { +BOOST_AUTO_TEST_CASE(testBaseCurrency) { BOOST_TEST_MESSAGE("Testing money arithmetic with conversion " "to base currency..."); @@ -88,8 +91,7 @@ void MoneyTest::testBaseCurrency() { } } - -void MoneyTest::testAutomated() { +BOOST_AUTO_TEST_CASE(testAutomated) { BOOST_TEST_MESSAGE("Testing money arithmetic with automated conversion..."); @@ -124,11 +126,6 @@ void MoneyTest::testAutomated() { } } -test_suite* MoneyTest::suite() { - auto* suite = BOOST_TEST_SUITE("Money tests"); - suite->add(QUANTLIB_TEST_CASE(&MoneyTest::testNone)); - suite->add(QUANTLIB_TEST_CASE(&MoneyTest::testBaseCurrency)); - suite->add(QUANTLIB_TEST_CASE(&MoneyTest::testAutomated)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/money.hpp b/test-suite/money.hpp deleted file mode 100644 index 7ce5b7da696..00000000000 --- a/test-suite/money.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_money_hpp -#define quantlib_test_money_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class MoneyTest { - public: - static void testNone(); - static void testBaseCurrency(); - static void testAutomated(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 0eaa667697f..8615179a553 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "money.hpp" #include "noarbsabr.hpp" #include "normalclvmodel.hpp" #include "nthorderderivativeop.hpp" @@ -127,7 +126,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(MoneyTest::suite()); test->add(NumericalDifferentiationTest::suite()); test->add(NthOrderDerivativeOpTest::suite(speed)); test->add(ObservableTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0ee8d011b13..796d8aa6361 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index a3fd5afbe90..84ba60279aa 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From c33f85bd7c2762045428a13005748a8598549fb7 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:25:56 +0800 Subject: [PATCH 012/102] Migrated noarbsabr.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/noarbsabr.cpp | 18 +++++++------- test-suite/noarbsabr.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 53 deletions(-) delete mode 100644 test-suite/noarbsabr.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 914609ec168..a72b19178cc 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - noarbsabr.hpp normalclvmodel.hpp nthorderderivativeop.hpp nthtodefault.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index f64dd6381bb..1caf14ee818 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - noarbsabr.hpp \ normalclvmodel.hpp \ nthorderderivativeop.hpp \ nthtodefault.hpp \ diff --git a/test-suite/noarbsabr.cpp b/test-suite/noarbsabr.cpp index d2a17962174..ab007c20aea 100644 --- a/test-suite/noarbsabr.cpp +++ b/test-suite/noarbsabr.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "noarbsabr.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -43,7 +43,11 @@ void checkD0(const Real sigmaI, const Real beta, const Real rho, const Real nu, } } -void NoArbSabrTest::testAbsorptionMatrix() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(NoArbSabrExperimentalTest) + +BOOST_AUTO_TEST_CASE(testAbsorptionMatrix) { BOOST_TEST_MESSAGE("Testing no-arbitrage Sabr absorption matrix..."); @@ -69,7 +73,7 @@ void NoArbSabrTest::testAbsorptionMatrix() { } -void NoArbSabrTest::testConsistencyWithHagan() { +BOOST_AUTO_TEST_CASE(testConsistencyWithHagan) { BOOST_TEST_MESSAGE("Testing consistency of noarb-sabr with Hagan et al (2002)"); @@ -117,10 +121,6 @@ void NoArbSabrTest::testConsistencyWithHagan() { } +BOOST_AUTO_TEST_SUITE_END() -test_suite* NoArbSabrTest::suite() { - auto* suite = BOOST_TEST_SUITE("NoArbSabrModel tests"); - suite->add(QUANTLIB_TEST_CASE(&NoArbSabrTest::testAbsorptionMatrix)); - suite->add(QUANTLIB_TEST_CASE(&NoArbSabrTest::testConsistencyWithHagan)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/noarbsabr.hpp b/test-suite/noarbsabr.hpp deleted file mode 100644 index dc23cc2b93e..00000000000 --- a/test-suite/noarbsabr.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_noarbsabr_hpp -#define quantlib_test_noarbsabr_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class NoArbSabrTest { - public: - static void testAbsorptionMatrix(); - static void testConsistencyWithHagan(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8615179a553..0b63ac85d78 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "noarbsabr.hpp" #include "normalclvmodel.hpp" #include "nthorderderivativeop.hpp" #include "nthtodefault.hpp" @@ -171,7 +170,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(NoArbSabrTest::suite()); test->add(NormalCLVModelTest::experimental(speed)); test->add(NthToDefaultTest::suite(speed)); test->add(PagodaOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 796d8aa6361..9695b64cca8 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 84ba60279aa..4c9d9b27878 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 2237aebcabb9b7d791126d97c95bdaf621654940 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:29:22 +0800 Subject: [PATCH 013/102] Migrated normalclvmodel.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/normalclvmodel.cpp | 41 +++++++++------------------- test-suite/normalclvmodel.hpp | 37 ------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 13 insertions(+), 73 deletions(-) delete mode 100644 test-suite/normalclvmodel.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a72b19178cc..eb75319c294 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - normalclvmodel.hpp nthorderderivativeop.hpp nthtodefault.hpp numericaldifferentiation.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1caf14ee818..7d8986666e5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - normalclvmodel.hpp \ nthorderderivativeop.hpp \ nthtodefault.hpp \ numericaldifferentiation.hpp \ diff --git a/test-suite/normalclvmodel.cpp b/test-suite/normalclvmodel.cpp index e003fe7d384..f584c7a1038 100644 --- a/test-suite/normalclvmodel.cpp +++ b/test-suite/normalclvmodel.cpp @@ -17,8 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ - -#include "normalclvmodel.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -51,7 +51,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void NormalCLVModelTest::testBSCumlativeDistributionFunction() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(NormalCLVModelExperimentalTest) + +BOOST_AUTO_TEST_CASE(testBSCumlativeDistributionFunction) { BOOST_TEST_MESSAGE("Testing Black-Scholes cumulative distribution function" " with constant volatility..."); @@ -94,7 +98,7 @@ void NormalCLVModelTest::testBSCumlativeDistributionFunction() { } } -void NormalCLVModelTest::testHestonCumlativeDistributionFunction() { +BOOST_AUTO_TEST_CASE(testHestonCumlativeDistributionFunction) { BOOST_TEST_MESSAGE("Testing Heston cumulative distribution function..."); const DayCounter dc = Actual365Fixed(); @@ -145,9 +149,7 @@ void NormalCLVModelTest::testHestonCumlativeDistributionFunction() { } } - - -void NormalCLVModelTest::testIllustrative1DExample() { +BOOST_AUTO_TEST_CASE(testIllustrative1DExample) { BOOST_TEST_MESSAGE( "Testing illustrative 1D example of normal CLV model..."); @@ -276,7 +278,7 @@ namespace normal_clv_model_test { }; } -void NormalCLVModelTest::testMonteCarloBSOptionPricing() { +BOOST_AUTO_TEST_CASE(testMonteCarloBSOptionPricing) { BOOST_TEST_MESSAGE("Testing Monte Carlo BS option pricing..."); using namespace normal_clv_model_test; @@ -370,8 +372,7 @@ void NormalCLVModelTest::testMonteCarloBSOptionPricing() { << "\n expected: " << expected); } } - -void NormalCLVModelTest::testMoustacheGraph() { +BOOST_AUTO_TEST_CASE(testMoustacheGraph, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE( "Testing double no-touch pricing with normal CLV model..."); @@ -536,22 +537,6 @@ void NormalCLVModelTest::testMoustacheGraph() { } } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* NormalCLVModelTest::experimental(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("NormalCLVModel tests"); - - suite->add(QUANTLIB_TEST_CASE( - &NormalCLVModelTest::testBSCumlativeDistributionFunction)); - suite->add(QUANTLIB_TEST_CASE( - &NormalCLVModelTest::testHestonCumlativeDistributionFunction)); - suite->add(QUANTLIB_TEST_CASE( - &NormalCLVModelTest::testIllustrative1DExample)); - suite->add(QUANTLIB_TEST_CASE( - &NormalCLVModelTest::testMonteCarloBSOptionPricing)); - - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE( - &NormalCLVModelTest::testMoustacheGraph)); - } - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/normalclvmodel.hpp b/test-suite/normalclvmodel.hpp deleted file mode 100644 index 2b70ffd6914..00000000000 --- a/test-suite/normalclvmodel.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2016 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_normal_clv_model_hpp -#define quantlib_test_normal_clv_model_hpp - -#include -#include "speedlevel.hpp" - -class NormalCLVModelTest { - public: - static void testBSCumlativeDistributionFunction(); - static void testHestonCumlativeDistributionFunction(); - static void testIllustrative1DExample(); - static void testMonteCarloBSOptionPricing(); - static void testMoustacheGraph(); - static boost::unit_test_framework::test_suite* experimental(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 0b63ac85d78..4d280bd8219 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "normalclvmodel.hpp" #include "nthorderderivativeop.hpp" #include "nthtodefault.hpp" #include "numericaldifferentiation.hpp" @@ -170,7 +169,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(NormalCLVModelTest::experimental(speed)); test->add(NthToDefaultTest::suite(speed)); test->add(PagodaOptionTest::suite()); test->add(PartialTimeBarrierOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 9695b64cca8..e0a9db318a3 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 4c9d9b27878..bfbef74dc47 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -704,9 +704,6 @@ Header Files - - Header Files - Header Files From a04f2305d35bf9d9f39ab96a8cb8e0a81bcc17b5 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:34:18 +0800 Subject: [PATCH 014/102] Migrated nthorderderivativeop.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/nthorderderivativeop.cpp | 76 ++++++++-------------------- test-suite/nthorderderivativeop.hpp | 47 ----------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 22 insertions(+), 109 deletions(-) delete mode 100644 test-suite/nthorderderivativeop.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index eb75319c294..3a4b18081d8 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - nthorderderivativeop.hpp nthtodefault.hpp numericaldifferentiation.hpp observable.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7d8986666e5..8dfcbf1083c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - nthorderderivativeop.hpp \ nthtodefault.hpp \ numericaldifferentiation.hpp \ observable.hpp \ diff --git a/test-suite/nthorderderivativeop.cpp b/test-suite/nthorderderivativeop.cpp index 3d6f9f5a5ef..54ed42d6454 100644 --- a/test-suite/nthorderderivativeop.cpp +++ b/test-suite/nthorderderivativeop.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "nthorderderivativeop.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -53,7 +54,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void NthOrderDerivativeOpTest::testSparseMatrixApply() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(NthOrderDerivativeOpTest) + +BOOST_AUTO_TEST_CASE(testSparseMatrixApply) { BOOST_TEST_MESSAGE("Testing sparse matrix apply..."); SparseMatrix sm(5,7); @@ -73,7 +78,7 @@ void NthOrderDerivativeOpTest::testSparseMatrixApply() { BOOST_CHECK(close_enough(y[4], 0.0)); } -void NthOrderDerivativeOpTest::testFirstOrder2PointsApply() { +BOOST_AUTO_TEST_CASE(testFirstOrder2PointsApply) { BOOST_TEST_MESSAGE("Testing two points first order " "derivative operator apply on an uniform grid..."); @@ -90,7 +95,7 @@ void NthOrderDerivativeOpTest::testFirstOrder2PointsApply() { BOOST_CHECK(close_enough(y[i], 1/dx)); } -void NthOrderDerivativeOpTest::testFirstOrder3PointsOnUniformGrid() { +BOOST_AUTO_TEST_CASE(testFirstOrder3PointsOnUniformGrid) { BOOST_TEST_MESSAGE("Testing three points first order " "derivative operator on an uniform grid..."); @@ -126,7 +131,7 @@ void NthOrderDerivativeOpTest::testFirstOrder3PointsOnUniformGrid() { BOOST_CHECK(close_enough(m(5,5), 3.0/2.0*ddx)); } -void NthOrderDerivativeOpTest::testFirstOrder5PointsOnUniformGrid() { +BOOST_AUTO_TEST_CASE(testFirstOrder5PointsOnUniformGrid) { BOOST_TEST_MESSAGE("Testing five points first order " "derivative operator on an uniform grid..."); @@ -173,7 +178,7 @@ void NthOrderDerivativeOpTest::testFirstOrder5PointsOnUniformGrid() { BOOST_CHECK(close_enough(m(5,5), 25.0/12.0*ddx)); } -void NthOrderDerivativeOpTest::testFirstOrder2PointsOnUniformGrid() { +BOOST_AUTO_TEST_CASE(testFirstOrder2PointsOnUniformGrid) { BOOST_TEST_MESSAGE("Testing two points first order " "derivative operator on an uniform grid..."); @@ -205,7 +210,7 @@ void NthOrderDerivativeOpTest::testFirstOrder2PointsOnUniformGrid() { BOOST_CHECK(close_enough(m(3,3), ddx)); } -void NthOrderDerivativeOpTest::testFirstOrder4PointsOnUniformGrid() { +BOOST_AUTO_TEST_CASE(testFirstOrder4PointsOnUniformGrid) { BOOST_TEST_MESSAGE("Testing four points first order " "derivative operator on an uniform grid..."); @@ -237,7 +242,7 @@ void NthOrderDerivativeOpTest::testFirstOrder4PointsOnUniformGrid() { BOOST_CHECK(close_enough(m(3,3), 11.0/6.0*ddx)); } -void NthOrderDerivativeOpTest::testFirstOrder2PointsOn2DimUniformGrid() { +BOOST_AUTO_TEST_CASE(testFirstOrder2PointsOn2DimUniformGrid) { BOOST_TEST_MESSAGE("Testing two points first order " "derivative operator on a 2 dimensional uniform grid..."); @@ -277,7 +282,7 @@ void NthOrderDerivativeOpTest::testFirstOrder2PointsOn2DimUniformGrid() { } } -void NthOrderDerivativeOpTest::testSecondOrder3PointsNonUniformGrid() { +BOOST_AUTO_TEST_CASE(testSecondOrder3PointsNonUniformGrid) { BOOST_TEST_MESSAGE("Testing three points second order " "derivative operator on a non-uniform grid..."); @@ -313,7 +318,7 @@ void NthOrderDerivativeOpTest::testSecondOrder3PointsNonUniformGrid() { BOOST_CHECK(close_enough(m(3,3), 1.0/3.0)); } -void NthOrderDerivativeOpTest::testSecondOrder4PointsNonUniformGrid() { +BOOST_AUTO_TEST_CASE(testSecondOrder4PointsNonUniformGrid) { BOOST_TEST_MESSAGE("Testing four points second order " "derivative operator on a non-uniform grid..."); @@ -360,7 +365,7 @@ void NthOrderDerivativeOpTest::testSecondOrder4PointsNonUniformGrid() { BOOST_CHECK(close_enough(m(4,4), 17.0/84.0)); } -void NthOrderDerivativeOpTest::testThirdOrder4PointsUniformGrid() { +BOOST_AUTO_TEST_CASE(testThirdOrder4PointsUniformGrid) { BOOST_TEST_MESSAGE("Testing four points third order " "derivative operator on a uniform grid..."); @@ -704,7 +709,7 @@ namespace { }; } -void NthOrderDerivativeOpTest::testHigherOrderHestonOptionPricing() { +BOOST_AUTO_TEST_CASE(testHigherOrderHestonOptionPricing, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing Heston model option pricing convergence with " "higher order finite difference operators..."); @@ -769,7 +774,7 @@ namespace { } } -void NthOrderDerivativeOpTest::testHigherOrderAndRichardsonExtrapolation() { +BOOST_AUTO_TEST_CASE(testHigherOrderAndRichardsonExtrapolation) { BOOST_TEST_MESSAGE( "Testing Heston option pricing convergence with " "higher order FDM operators and Richardson Extrapolation..."); @@ -815,7 +820,7 @@ void NthOrderDerivativeOpTest::testCompareFirstDerivativeOpNonUniformGrid() { BOOST_CHECK(std::fabs(fm(i, j)- dm(i, j)) < 1e-12); } -void NthOrderDerivativeOpTest::testCompareFirstDerivativeOp2dUniformGrid() { +BOOST_AUTO_TEST_CASE(testCompareFirstDerivativeOp2dUniformGrid) { BOOST_TEST_MESSAGE( "Testing with FirstDerivativeOp on a 2d uniform grid..."); @@ -848,7 +853,7 @@ void NthOrderDerivativeOpTest::testCompareFirstDerivativeOp2dUniformGrid() { BOOST_CHECK(std::fabs(Real(fm(i, j)) - Real(dm(i, j))) < 1e-12); } -void NthOrderDerivativeOpTest::testMixedSecondOrder9PointsOnUniformGrid() { +BOOST_AUTO_TEST_CASE(testMixedSecondOrder9PointsOnUniformGrid) { BOOST_TEST_MESSAGE( "Testing nine points mixed second order " "derivative operator on a uniform grid..."); @@ -878,43 +883,6 @@ void NthOrderDerivativeOpTest::testMixedSecondOrder9PointsOnUniformGrid() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* NthOrderDerivativeOpTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("NthOrderDerivativeOp tests"); - - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testSparseMatrixApply)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder2PointsApply)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder3PointsOnUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder5PointsOnUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder2PointsOnUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder4PointsOnUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testFirstOrder2PointsOn2DimUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testSecondOrder3PointsNonUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testSecondOrder4PointsNonUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testThirdOrder4PointsUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testHigherOrderAndRichardsonExtrapolation)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testCompareFirstDerivativeOpNonUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testCompareFirstDerivativeOp2dUniformGrid)); - suite->add(QUANTLIB_TEST_CASE( - &NthOrderDerivativeOpTest::testMixedSecondOrder9PointsOnUniformGrid)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&NthOrderDerivativeOpTest::testHigherOrderHestonOptionPricing)); - } - - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/nthorderderivativeop.hpp b/test-suite/nthorderderivativeop.hpp deleted file mode 100644 index c4bd530b607..00000000000 --- a/test-suite/nthorderderivativeop.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2018 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_nth_order_derivative_op_hpp -#define quantlib_test_nth_order_derivative_op_hpp - -#include -#include "speedlevel.hpp" - -class NthOrderDerivativeOpTest { - public: - static void testSparseMatrixApply(); - static void testFirstOrder2PointsApply(); - static void testFirstOrder3PointsOnUniformGrid(); - static void testFirstOrder5PointsOnUniformGrid(); - static void testFirstOrder2PointsOnUniformGrid(); - static void testFirstOrder4PointsOnUniformGrid(); - static void testFirstOrder2PointsOn2DimUniformGrid(); - static void testSecondOrder3PointsNonUniformGrid(); - static void testSecondOrder4PointsNonUniformGrid(); - static void testThirdOrder4PointsUniformGrid(); - static void testHigherOrderHestonOptionPricing(); - static void testHigherOrderAndRichardsonExtrapolation(); - static void testCompareFirstDerivativeOpNonUniformGrid(); - static void testCompareFirstDerivativeOp2dUniformGrid(); - static void testMixedSecondOrder9PointsOnUniformGrid(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 4d280bd8219..3faaed9cb29 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "nthorderderivativeop.hpp" #include "nthtodefault.hpp" #include "numericaldifferentiation.hpp" #include "observable.hpp" @@ -125,7 +124,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(NumericalDifferentiationTest::suite()); - test->add(NthOrderDerivativeOpTest::suite(speed)); test->add(ObservableTest::suite()); test->add(OdeTest::suite()); test->add(OperatorTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index e0a9db318a3..ca877017e45 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -812,7 +812,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index bfbef74dc47..61c2dcbbcca 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From d3d75ed9f70cff3400b051fe7d178e121bb0009a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:41:04 +0800 Subject: [PATCH 015/102] Migrated nthtodefault.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/nthtodefault.cpp | 33 ++++++++++++------------- test-suite/nthtodefault.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 15 insertions(+), 62 deletions(-) delete mode 100644 test-suite/nthtodefault.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 3a4b18081d8..92574a23fa7 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - nthtodefault.hpp numericaldifferentiation.hpp observable.hpp ode.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 8dfcbf1083c..d8ebc5348af 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - nthtodefault.hpp \ numericaldifferentiation.hpp \ observable.hpp \ ode.hpp \ diff --git a/test-suite/nthtodefault.cpp b/test-suite/nthtodefault.cpp index 43f3b61cb55..ddf6109ec0d 100644 --- a/test-suite/nthtodefault.cpp +++ b/test-suite/nthtodefault.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "nthtodefault.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -96,8 +97,13 @@ namespace nth_to_default_test { #endif -void NthToDefaultTest::testGauss() { - #ifndef QL_PATCH_SOLARIS +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(NthToDefaultExperimentalTest) + +#ifndef QL_PATCH_SOLARIS + +BOOST_AUTO_TEST_CASE(testGauss, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE("Testing nth-to-default against Hull-White values " "with Gaussian copula..."); @@ -235,12 +241,9 @@ void NthToDefaultTest::testGauss() { << absTolerance << " exceeded"); } } - #endif } +BOOST_AUTO_TEST_CASE(testStudent, *precondition(if_speed(Slow))) { - -void NthToDefaultTest::testStudent() { - #ifndef QL_PATCH_SOLARIS BOOST_TEST_MESSAGE("Testing nth-to-default against Hull-White values " "with Student copula..."); @@ -381,16 +384,10 @@ void NthToDefaultTest::testStudent() { << abs(diff) << "|" << hwDataDist[i].spread[3]); } //END - #endif } -test_suite* NthToDefaultTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Nth-to-default tests"); -#ifndef QL_PATCH_SOLARIS - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&NthToDefaultTest::testGauss)); - suite->add(QUANTLIB_TEST_CASE(&NthToDefaultTest::testStudent)); - } - #endif - return suite; -} +#endif + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/nthtodefault.hpp b/test-suite/nthtodefault.hpp deleted file mode 100644 index e1099fdc950..00000000000 --- a/test-suite/nthtodefault.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008 Roland Lichters - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_nth_to_default_hpp -#define quantlib_test_nth_to_default_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class NthToDefaultTest { - public: - static void testGauss(); - static void testStudent(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 3faaed9cb29..7cd9753b232 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "nthtodefault.hpp" #include "numericaldifferentiation.hpp" #include "observable.hpp" #include "ode.hpp" @@ -167,7 +166,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(NthToDefaultTest::suite(speed)); test->add(PagodaOptionTest::suite()); test->add(PartialTimeBarrierOptionTest::suite()); test->add(QuantoOptionTest::experimental()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ca877017e45..5e0fff07fc5 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 61c2dcbbcca..4d88b83baa0 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 54394ab21037fb0373e3fdb5f4b681519a779996 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:48:10 +0800 Subject: [PATCH 016/102] Migrated numericaldifferentiation.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/numericaldifferentiation.cpp | 48 ++++++++----------------- test-suite/numericaldifferentiation.hpp | 38 -------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 14 insertions(+), 80 deletions(-) delete mode 100644 test-suite/numericaldifferentiation.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 92574a23fa7..2f9588a4252 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - numericaldifferentiation.hpp observable.hpp ode.hpp operators.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index d8ebc5348af..e164819d324 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - numericaldifferentiation.hpp \ observable.hpp \ ode.hpp \ operators.hpp \ diff --git a/test-suite/numericaldifferentiation.cpp b/test-suite/numericaldifferentiation.cpp index 4a934dcbdcd..da671653a32 100644 --- a/test-suite/numericaldifferentiation.cpp +++ b/test-suite/numericaldifferentiation.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "numericaldifferentiation.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -66,7 +66,11 @@ namespace { } } -void NumericalDifferentiationTest::testTabulatedCentralScheme() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(NumericalDifferentiationTest) + +BOOST_AUTO_TEST_CASE(testTabulatedCentralScheme) { BOOST_TEST_MESSAGE("Testing numerical differentiation " "using the central scheme..."); const ext::function f; @@ -96,7 +100,7 @@ void NumericalDifferentiationTest::testTabulatedCentralScheme() { {-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5}); } -void NumericalDifferentiationTest::testTabulatedBackwardScheme() { +BOOST_AUTO_TEST_CASE(testTabulatedBackwardScheme) { BOOST_TEST_MESSAGE("Testing numerical differentiation " "using the backward scheme..."); const ext::function f; @@ -122,8 +126,7 @@ void NumericalDifferentiationTest::testTabulatedBackwardScheme() { {0.0, -0.5, -1.0, -1.5}); } - -void NumericalDifferentiationTest::testTabulatedForwardScheme() { +BOOST_AUTO_TEST_CASE(testTabulatedForwardScheme) { BOOST_TEST_MESSAGE("Testing numerical differentiation " "using the Forward scheme..."); const ext::function f; @@ -149,8 +152,7 @@ void NumericalDifferentiationTest::testTabulatedForwardScheme() { {0.0, 0.5, 1.0, 1.5}); } - -void NumericalDifferentiationTest::testIrregularSchemeFirstOrder() { +BOOST_AUTO_TEST_CASE(testIrregularSchemeFirstOrder) { BOOST_TEST_MESSAGE("Testing numerical differentiation " "of first order using an irregular scheme..."); const ext::function f; @@ -169,7 +171,7 @@ void NumericalDifferentiationTest::testIrregularSchemeFirstOrder() { { alpha, beta, gamma }); } -void NumericalDifferentiationTest::testIrregularSchemeSecondOrder() { +BOOST_AUTO_TEST_CASE(testIrregularSchemeSecondOrder) { BOOST_TEST_MESSAGE("Testing numerical differentiation " "of second order using an irregular scheme..."); const ext::function f; @@ -188,8 +190,7 @@ void NumericalDifferentiationTest::testIrregularSchemeSecondOrder() { {alpha, beta, gamma}); } - -void NumericalDifferentiationTest::testDerivativesOfSineFunction() { +BOOST_AUTO_TEST_CASE(testDerivativesOfSineFunction) { BOOST_TEST_MESSAGE("Testing numerical differentiation" " of sin function..."); @@ -272,7 +273,7 @@ namespace { } } -void NumericalDifferentiationTest::testCoefficientBasedOnVandermonde() { +BOOST_AUTO_TEST_CASE(testCoefficientBasedOnVandermonde) { BOOST_TEST_MESSAGE("Testing coefficients from numerical differentiation" " by comparison with results from" " Vandermonde matrix inversion..."); @@ -299,27 +300,6 @@ void NumericalDifferentiationTest::testCoefficientBasedOnVandermonde() { } } +BOOST_AUTO_TEST_SUITE_END() - -test_suite* NumericalDifferentiationTest::suite() { - auto* suite = BOOST_TEST_SUITE("NumericalDifferentiation tests"); - - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testTabulatedCentralScheme)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testTabulatedBackwardScheme)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testTabulatedForwardScheme)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testIrregularSchemeFirstOrder)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testIrregularSchemeSecondOrder)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testDerivativesOfSineFunction)); - suite->add(QUANTLIB_TEST_CASE( - &NumericalDifferentiationTest::testCoefficientBasedOnVandermonde)); - - return suite; -} - - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/numericaldifferentiation.hpp b/test-suite/numericaldifferentiation.hpp deleted file mode 100644 index 3cf4cbd8aef..00000000000 --- a/test-suite/numericaldifferentiation.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2015 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_numerical_differentiation_hpp -#define quantlib_test_numerical_differentiation_hpp - -#include - -class NumericalDifferentiationTest { - public: - static void testTabulatedCentralScheme(); - static void testTabulatedBackwardScheme(); - static void testTabulatedForwardScheme(); - static void testIrregularSchemeFirstOrder(); - static void testIrregularSchemeSecondOrder(); - static void testDerivativesOfSineFunction(); - static void testCoefficientBasedOnVandermonde(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 7cd9753b232..a6646a25d3f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "numericaldifferentiation.hpp" #include "observable.hpp" #include "ode.hpp" #include "operators.hpp" @@ -122,7 +121,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(NumericalDifferentiationTest::suite()); test->add(ObservableTest::suite()); test->add(OdeTest::suite()); test->add(OperatorTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 5e0fff07fc5..b0964289f2f 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 4d88b83baa0..40bde19448d 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From ef72eb0d2d3a3aa0205e014ff29a39b02dc2ab72 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:52:18 +0800 Subject: [PATCH 017/102] Migrated observable.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/observable.cpp | 39 +++++++++----------------- test-suite/observable.hpp | 41 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 13 insertions(+), 75 deletions(-) delete mode 100644 test-suite/observable.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 2f9588a4252..70eff079b67 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - observable.hpp ode.hpp operators.hpp optimizers.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e164819d324..d219fd8731e 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - observable.hpp \ ode.hpp \ operators.hpp \ optimizers.hpp \ diff --git a/test-suite/observable.cpp b/test-suite/observable.cpp index f55f4375472..277de8e9803 100644 --- a/test-suite/observable.cpp +++ b/test-suite/observable.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "observable.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -55,7 +55,11 @@ namespace { } -void ObservableTest::testObservableSettings() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ObservableTest) + +BOOST_AUTO_TEST_CASE(testObservableSettings) { BOOST_TEST_MESSAGE("Testing observable settings..."); @@ -182,7 +186,7 @@ namespace { }; } -void ObservableTest::testAsyncGarbagCollector() { +BOOST_AUTO_TEST_CASE(testAsyncGarbagCollector) { BOOST_TEST_MESSAGE("Testing observer pattern with an asynchronous " "garbage collector (JVM/.NET use case)..."); @@ -213,8 +217,7 @@ void ObservableTest::testAsyncGarbagCollector() { } } - -void ObservableTest::testMultiThreadingGlobalSettings() { +BOOST_AUTO_TEST_CASE(testMultiThreadingGlobalSettings) { BOOST_TEST_MESSAGE("Testing observer global settings in a " "multithreading environment..."); @@ -265,7 +268,7 @@ void ObservableTest::testMultiThreadingGlobalSettings() { } #endif -void ObservableTest::testDeepUpdate() { +BOOST_AUTO_TEST_CASE(testDeepUpdate) { BOOST_TEST_MESSAGE("Testing deep update of observers..."); RestoreUpdates guard; @@ -311,14 +314,14 @@ namespace { }; } -void ObservableTest::testEmptyObserverList() { +BOOST_AUTO_TEST_CASE(testEmptyObserverList) { BOOST_TEST_MESSAGE("Testing unregisterWith call on empty observer..."); const ext::shared_ptr dummyObserver=ext::make_shared(); dummyObserver->unregisterWith(ext::make_shared(10.0)); } -void ObservableTest::testAddAndDeleteObserverDuringNotifyObservers() { +BOOST_AUTO_TEST_CASE(testAddAndDeleteObserverDuringNotifyObservers) { BOOST_TEST_MESSAGE("Testing addition and deletion of observers during notifyObserver..."); const ext::shared_ptr rng @@ -395,22 +398,6 @@ void ObservableTest::testAddAndDeleteObserverDuringNotifyObservers() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* ObservableTest::suite() { - auto* suite = BOOST_TEST_SUITE("Observer tests"); - - suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testObservableSettings)); - -#ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN - suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testAsyncGarbagCollector)); - suite->add(QUANTLIB_TEST_CASE( - &ObservableTest::testMultiThreadingGlobalSettings)); -#endif - - suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testDeepUpdate)); - suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testEmptyObserverList)); - suite->add(QUANTLIB_TEST_CASE( - &ObservableTest::testAddAndDeleteObserverDuringNotifyObservers)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/observable.hpp b/test-suite/observable.hpp deleted file mode 100644 index aaea4adf11a..00000000000 --- a/test-suite/observable.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2015 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_observer_hpp -#define quantlib_test_observer_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ObservableTest { - public: - static void testObservableSettings(); - static void testAsyncGarbagCollector(); - static void testMultiThreadingGlobalSettings(); - static void testDeepUpdate(); - static void testEmptyObserverList(); - static void testAddAndDeleteObserverDuringNotifyObservers(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index a6646a25d3f..eae789ddcb4 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "observable.hpp" #include "ode.hpp" #include "operators.hpp" #include "optimizers.hpp" @@ -121,7 +120,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(ObservableTest::suite()); test->add(OdeTest::suite()); test->add(OperatorTest::suite()); test->add(OptimizersTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b0964289f2f..6236f945e95 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 40bde19448d..28a479c944e 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -692,9 +692,6 @@ Header Files - - Header Files - Header Files From 1b5862db33e07a1dad7e06eb36945438d34d844b Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:54:58 +0800 Subject: [PATCH 018/102] Migrated ode.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/ode.cpp | 23 ++++++++--------- test-suite/ode.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 11 insertions(+), 58 deletions(-) delete mode 100644 test-suite/ode.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 70eff079b67..4e48057dae9 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - ode.hpp operators.hpp optimizers.hpp optionletstripper.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index d219fd8731e..7ade111b430 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - ode.hpp \ operators.hpp \ optimizers.hpp \ optionletstripper.hpp \ diff --git a/test-suite/ode.cpp b/test-suite/ode.cpp index e01300e53cd..28148997b29 100644 --- a/test-suite/ode.cpp +++ b/test-suite/ode.cpp @@ -18,13 +18,12 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "ode.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include #include - using namespace QuantLib; using namespace boost::unit_test_framework; @@ -64,7 +63,11 @@ namespace { } -void OdeTest::testAdaptiveRungeKutta() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(OdeTest) + +BOOST_AUTO_TEST_CASE(testAdaptiveRungeKutta) { BOOST_TEST_MESSAGE("Testing adaptive Runge Kutta..."); @@ -142,7 +145,7 @@ namespace { } } -void OdeTest::testMatrixExponential() { +BOOST_AUTO_TEST_CASE(testMatrixExponential) { BOOST_TEST_MESSAGE("Testing matrix exponential based on ode..."); // Reference results are taken from @@ -191,7 +194,7 @@ void OdeTest::testMatrixExponential() { } } -void OdeTest::testMatrixExponentialOfZero() { +BOOST_AUTO_TEST_CASE(testMatrixExponentialOfZero) { BOOST_TEST_MESSAGE("Testing matrix exponential of a zero matrix " "based on ode..."); @@ -212,10 +215,6 @@ void OdeTest::testMatrixExponentialOfZero() { } } -test_suite* OdeTest::suite() { - auto* suite = BOOST_TEST_SUITE("ode tests"); - suite->add(QUANTLIB_TEST_CASE(&OdeTest::testAdaptiveRungeKutta)); - suite->add(QUANTLIB_TEST_CASE(&OdeTest::testMatrixExponential)); - suite->add(QUANTLIB_TEST_CASE(&OdeTest::testMatrixExponentialOfZero)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/ode.hpp b/test-suite/ode.hpp deleted file mode 100644 index 08d5f3a9125..00000000000 --- a/test-suite/ode.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2012 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_ode_hpp -#define quantlib_test_ode_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class OdeTest { - public: - static void testAdaptiveRungeKutta(); - static void testMatrixExponential(); - static void testMatrixExponentialOfZero(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index eae789ddcb4..396dbf8516e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "ode.hpp" #include "operators.hpp" #include "optimizers.hpp" #include "optionletstripper.hpp" @@ -120,7 +119,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OdeTest::suite()); test->add(OperatorTest::suite()); test->add(OptimizersTest::suite(speed)); test->add(OptionletStripperTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 6236f945e95..75b61c613de 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 28a479c944e..68e941ea8c9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 7e1345c61ba69770d67fdbfb4f4242c3f34075ef Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 15:57:05 +0800 Subject: [PATCH 019/102] Migrated operators.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/operators.cpp | 21 +++++++-------- test-suite/operators.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 58 deletions(-) delete mode 100644 test-suite/operators.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 4e48057dae9..064025da925 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - operators.hpp optimizers.hpp optionletstripper.hpp overnightindexedcoupon.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7ade111b430..04e9734e0d3 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - operators.hpp \ optimizers.hpp \ optionletstripper.hpp \ overnightindexedcoupon.hpp \ diff --git a/test-suite/operators.cpp b/test-suite/operators.cpp index 6bcc3c2823b..2e24a3bbbeb 100644 --- a/test-suite/operators.cpp +++ b/test-suite/operators.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "operators.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -32,8 +32,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void OperatorTest::testTridiagonal() { +BOOST_AUTO_TEST_SUITE(OperatorTest) + +BOOST_AUTO_TEST_CASE(testTridiagonal) { BOOST_TEST_MESSAGE("Testing tridiagonal operator..."); @@ -115,7 +118,7 @@ void OperatorTest::testTridiagonal() { "\n tolerance: " << tolerance); } -void OperatorTest::testConsistency() { +BOOST_AUTO_TEST_CASE(testConsistency) { BOOST_TEST_MESSAGE("Testing differential operators..."); @@ -162,7 +165,7 @@ void OperatorTest::testConsistency() { } } -void OperatorTest::testBSMOperatorConsistency() { +BOOST_AUTO_TEST_CASE(testBSMOperatorConsistency) { BOOST_TEST_MESSAGE("Testing consistency of BSM operators..."); Array grid(10); @@ -221,12 +224,6 @@ void OperatorTest::testBSMOperatorConsistency() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* OperatorTest::suite() { - auto* suite = BOOST_TEST_SUITE("Operator tests"); - suite->add(QUANTLIB_TEST_CASE(&OperatorTest::testTridiagonal)); - suite->add(QUANTLIB_TEST_CASE(&OperatorTest::testConsistency)); - suite->add(QUANTLIB_TEST_CASE(&OperatorTest::testBSMOperatorConsistency)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/operators.hpp b/test-suite/operators.hpp deleted file mode 100644 index 51c5f306853..00000000000 --- a/test-suite/operators.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - Copyright (C) 2011 Ferdinando Ametrano - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_operators_hpp -#define quantlib_test_operators_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class OperatorTest { - public: - static void testTridiagonal(); - static void testConsistency(); - static void testBSMOperatorConsistency(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 396dbf8516e..ca9186f460f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "operators.hpp" #include "optimizers.hpp" #include "optionletstripper.hpp" #include "overnightindexedcoupon.hpp" @@ -119,7 +118,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OperatorTest::suite()); test->add(OptimizersTest::suite(speed)); test->add(OptionletStripperTest::suite()); test->add(OvernightIndexedCouponTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 75b61c613de..274c4610ee6 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 68e941ea8c9..7c1e31b395f 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 0449cd225f9b4f2608756a3d05402cde93dcbf5f Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 16:02:23 +0800 Subject: [PATCH 020/102] Migrated optimizers.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/optimizers.cpp | 28 ++++++++-------------- test-suite/optimizers.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 62 deletions(-) delete mode 100644 test-suite/optimizers.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 064025da925..a2ca64b1597 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - optimizers.hpp optionletstripper.hpp overnightindexedcoupon.hpp overnightindexedswap.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 04e9734e0d3..b5f1bf888ea 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - optimizers.hpp \ optionletstripper.hpp \ overnightindexedcoupon.hpp \ overnightindexedswap.hpp \ diff --git a/test-suite/optimizers.cpp b/test-suite/optimizers.cpp index 8944aca42fe..6e34484c1f4 100644 --- a/test-suite/optimizers.cpp +++ b/test-suite/optimizers.cpp @@ -21,7 +21,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "optimizers.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -261,8 +262,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void OptimizersTest::test() { +BOOST_AUTO_TEST_SUITE(OptimizersTest) + +BOOST_AUTO_TEST_CASE(test) { BOOST_TEST_MESSAGE("Testing optimizers..."); setup(); @@ -343,8 +347,7 @@ void OptimizersTest::test() { } } - -void OptimizersTest::nestedOptimizationTest() { +BOOST_AUTO_TEST_CASE(nestedOptimizationTest) { BOOST_TEST_MESSAGE("Testing nested optimizations..."); OptimizationBasedCostFunction optimizationBasedCostFunction; NoConstraint constraint; @@ -432,7 +435,7 @@ namespace { }; } -void OptimizersTest::testDifferentialEvolution() { +BOOST_AUTO_TEST_CASE(testDifferentialEvolution, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing differential evolution..."); /* Note: @@ -541,17 +544,6 @@ void OptimizersTest::testDifferentialEvolution() { } } -test_suite* OptimizersTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Optimizers tests"); - - suite->add(QUANTLIB_TEST_CASE(&OptimizersTest::test)); - suite->add(QUANTLIB_TEST_CASE(&OptimizersTest::nestedOptimizationTest)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE( - &OptimizersTest::testDifferentialEvolution)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/optimizers.hpp b/test-suite/optimizers.hpp deleted file mode 100644 index b642d4e9210..00000000000 --- a/test-suite/optimizers.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Marco Bianchetti - Copyright (C) 2007 Giorgio Facchinetti - Copyright (C) 2012 Ralph Schreyer - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_optimizers_hpp -#define quantlib_test_optimizers_hpp - -#include -#include "speedlevel.hpp" - -class OptimizersTest { - public: - static void test(); - static void nestedOptimizationTest(); - static void testDifferentialEvolution(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index ca9186f460f..604a2b53d22 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "optimizers.hpp" #include "optionletstripper.hpp" #include "overnightindexedcoupon.hpp" #include "overnightindexedswap.hpp" @@ -118,7 +117,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OptimizersTest::suite(speed)); test->add(OptionletStripperTest::suite()); test->add(OvernightIndexedCouponTest::suite()); test->add(OvernightIndexedSwapTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 274c4610ee6..1ef0757d242 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 7c1e31b395f..c9a71a90b66 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 5ba4269e8709ef93615fef0554e1a1c27298d735 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 16:06:38 +0800 Subject: [PATCH 021/102] Migrated optionletstripper.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/optionletstripper.cpp | 35 ++++++++++------------- test-suite/optionletstripper.hpp | 42 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 15 insertions(+), 70 deletions(-) delete mode 100644 test-suite/optionletstripper.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a2ca64b1597..6280f81bf57 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - optionletstripper.hpp overnightindexedcoupon.hpp overnightindexedswap.hpp pagodaoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index b5f1bf888ea..3df08115f4d 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - optionletstripper.hpp \ overnightindexedcoupon.hpp \ overnightindexedswap.hpp \ pagodaoption.hpp \ diff --git a/test-suite/optionletstripper.cpp b/test-suite/optionletstripper.cpp index daa346bb9bd..d9c18f7e287 100644 --- a/test-suite/optionletstripper.cpp +++ b/test-suite/optionletstripper.cpp @@ -19,7 +19,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "optionletstripper.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -381,7 +382,11 @@ namespace optionlet_stripper_test { }; } -void OptionletStripperTest::testFlatTermVolatilityStripping1() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(OptionletStripperTest) + +BOOST_AUTO_TEST_CASE(testFlatTermVolatilityStripping1) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from flat term vol " @@ -444,7 +449,7 @@ void OptionletStripperTest::testFlatTermVolatilityStripping1() { } } -void OptionletStripperTest::testTermVolatilityStripping1() { +BOOST_AUTO_TEST_CASE(testTermVolatilityStripping1) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from non-flat term " @@ -507,7 +512,7 @@ void OptionletStripperTest::testTermVolatilityStripping1() { } } -void OptionletStripperTest::testTermVolatilityStrippingNormalVol() { +BOOST_AUTO_TEST_CASE(testTermVolatilityStrippingNormalVol) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from non-flat normal vol term " @@ -575,7 +580,7 @@ void OptionletStripperTest::testTermVolatilityStrippingNormalVol() { } } -void OptionletStripperTest::testTermVolatilityStrippingShiftedLogNormalVol() { +BOOST_AUTO_TEST_CASE(testTermVolatilityStrippingShiftedLogNormalVol) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from non-flat normal vol term " @@ -644,7 +649,7 @@ void OptionletStripperTest::testTermVolatilityStrippingShiftedLogNormalVol() { } } -void OptionletStripperTest::testFlatTermVolatilityStripping2() { +BOOST_AUTO_TEST_CASE(testFlatTermVolatilityStripping2) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from flat term vol " @@ -713,7 +718,7 @@ void OptionletStripperTest::testFlatTermVolatilityStripping2() { } -void OptionletStripperTest::testTermVolatilityStripping2() { +BOOST_AUTO_TEST_CASE(testTermVolatilityStripping2) { BOOST_TEST_MESSAGE( "Testing forward/forward vol stripping from non-flat term vol " @@ -780,7 +785,7 @@ void OptionletStripperTest::testTermVolatilityStripping2() { } } -void OptionletStripperTest::testSwitchStrike() { +BOOST_AUTO_TEST_CASE(testSwitchStrike) { BOOST_TEST_MESSAGE("Testing switch strike level and recalibration of level " "in case of curve relinking..."); @@ -827,16 +832,6 @@ void OptionletStripperTest::testSwitchStrike() { << "\nerror: " << io::rate(error) << "\ntolerance: " << io::rate(vars.tolerance)); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* OptionletStripperTest::suite() { - auto* suite = BOOST_TEST_SUITE("OptionletStripper Tests"); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testFlatTermVolatilityStripping1)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testTermVolatilityStripping1)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testFlatTermVolatilityStripping2)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testTermVolatilityStripping2)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testSwitchStrike)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testTermVolatilityStrippingNormalVol)); - suite->add(QUANTLIB_TEST_CASE(&OptionletStripperTest::testTermVolatilityStrippingShiftedLogNormalVol)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/optionletstripper.hpp b/test-suite/optionletstripper.hpp deleted file mode 100644 index baf6f87ab80..00000000000 --- a/test-suite/optionletstripper.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008 Ferdinando Ametrano - Copyright (C) 2007, 2008 Laurent Hoffmann - Copyright (C) 2015, 2016 Michael von den Driesch - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_optionletstripper_hpp -#define quantlib_test_optionletstripper_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class OptionletStripperTest { - public: - static void testFlatTermVolatilityStripping1(); - static void testTermVolatilityStripping1(); - static void testTermVolatilityStrippingNormalVol(); - static void testTermVolatilityStrippingShiftedLogNormalVol(); - static void testFlatTermVolatilityStripping2(); - static void testTermVolatilityStripping2(); - static void testSwitchStrike(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 604a2b53d22..9af43a8801d 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "optionletstripper.hpp" #include "overnightindexedcoupon.hpp" #include "overnightindexedswap.hpp" #include "pagodaoption.hpp" @@ -117,7 +116,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OptionletStripperTest::suite()); test->add(OvernightIndexedCouponTest::suite()); test->add(OvernightIndexedSwapTest::suite()); test->add(PathGeneratorTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 1ef0757d242..19f5633286a 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index c9a71a90b66..f60d97bb15c 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From a86f85d5ed3e1b3318fc91db189071321e38d41b Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 16:11:26 +0800 Subject: [PATCH 022/102] Migrated overnightindexedcoupon.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/overnightindexedcoupon.cpp | 48 +++++++++++---------------- test-suite/overnightindexedcoupon.hpp | 40 ---------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 20 insertions(+), 76 deletions(-) delete mode 100644 test-suite/overnightindexedcoupon.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 6280f81bf57..e7fac69627f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - overnightindexedcoupon.hpp overnightindexedswap.hpp pagodaoption.hpp paralleltestrunner.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 3df08115f4d..1a3b1289b7c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - overnightindexedcoupon.hpp \ overnightindexedswap.hpp \ pagodaoption.hpp \ partialtimebarrieroption.hpp \ diff --git a/test-suite/overnightindexedcoupon.cpp b/test-suite/overnightindexedcoupon.cpp index f0974cbda6d..f3d776028b2 100644 --- a/test-suite/overnightindexedcoupon.cpp +++ b/test-suite/overnightindexedcoupon.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "overnightindexedcoupon.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -83,8 +83,12 @@ namespace overnight_indexed_coupon_tests { << "\n calculated: " << std::setprecision(12) << calculated \ << "\n error: " << std::setprecision(12) << std::fabs(calculated-expected)); \ } - -void OvernightIndexedCouponTest::testPastCouponRate() { + +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(OvernightIndexedCouponTest) + +BOOST_AUTO_TEST_CASE(testPastCouponRate) { BOOST_TEST_MESSAGE("Testing rate for past overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -103,7 +107,7 @@ void OvernightIndexedCouponTest::testPastCouponRate() { CHECK_OIS_COUPON_RESULT("coupon amount", pastCoupon->amount(), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testCurrentCouponRate() { +BOOST_AUTO_TEST_CASE(testCurrentCouponRate) { BOOST_TEST_MESSAGE("Testing rate for current overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -132,7 +136,7 @@ void OvernightIndexedCouponTest::testCurrentCouponRate() { CHECK_OIS_COUPON_RESULT("coupon amount", currentCoupon->amount(), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testFutureCouponRate() { +BOOST_AUTO_TEST_CASE(testFutureCouponRate) { BOOST_TEST_MESSAGE("Testing rate for future overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -152,7 +156,7 @@ void OvernightIndexedCouponTest::testFutureCouponRate() { CHECK_OIS_COUPON_RESULT("coupon amount", futureCoupon->amount(), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testRateWhenTodayIsHoliday() { +BOOST_AUTO_TEST_CASE(testRateWhenTodayIsHoliday) { BOOST_TEST_MESSAGE("Testing rate for overnight-indexed coupon when today is a holiday..."); using namespace overnight_indexed_coupon_tests; @@ -171,8 +175,8 @@ void OvernightIndexedCouponTest::testRateWhenTodayIsHoliday() { CHECK_OIS_COUPON_RESULT("coupon rate", coupon->rate(), expectedRate, 1e-12); CHECK_OIS_COUPON_RESULT("coupon amount", coupon->amount(), expectedAmount, 1e-8); } - -void OvernightIndexedCouponTest::testAccruedAmountInThePast() { + +BOOST_AUTO_TEST_CASE(testAccruedAmountInThePast) { BOOST_TEST_MESSAGE("Testing accrued amount in the past for overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -186,7 +190,7 @@ void OvernightIndexedCouponTest::testAccruedAmountInThePast() { CHECK_OIS_COUPON_RESULT("coupon amount", coupon->accruedAmount(Date(18, November, 2021)), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testAccruedAmountSpanningToday() { +BOOST_AUTO_TEST_CASE(testAccruedAmountSpanningToday) { BOOST_TEST_MESSAGE("Testing accrued amount spanning today for current overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -211,7 +215,7 @@ void OvernightIndexedCouponTest::testAccruedAmountSpanningToday() { CHECK_OIS_COUPON_RESULT("coupon amount", coupon->accruedAmount(Date(10, December, 2021)), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testAccruedAmountInTheFuture() { +BOOST_AUTO_TEST_CASE(testAccruedAmountInTheFuture) { BOOST_TEST_MESSAGE("Testing accrued amount in the future for overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -231,7 +235,7 @@ void OvernightIndexedCouponTest::testAccruedAmountInTheFuture() { CHECK_OIS_COUPON_RESULT("coupon amount", coupon->accruedAmount(accrualDate), expectedAmount, 1e-8); } -void OvernightIndexedCouponTest::testAccruedAmountOnPastHoliday() { +BOOST_AUTO_TEST_CASE(testAccruedAmountOnPastHoliday) { BOOST_TEST_MESSAGE("Testing accrued amount on a past holiday for overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -247,8 +251,7 @@ void OvernightIndexedCouponTest::testAccruedAmountOnPastHoliday() { Real expectedAmount = vars.notional * 0.000074724810; CHECK_OIS_COUPON_RESULT("coupon amount", coupon->accruedAmount(accrualDate), expectedAmount, 1e-8); } - -void OvernightIndexedCouponTest::testAccruedAmountOnFutureHoliday() { +BOOST_AUTO_TEST_CASE(testAccruedAmountOnFutureHoliday) { BOOST_TEST_MESSAGE("Testing accrued amount on a future holiday for overnight-indexed coupon..."); using namespace overnight_indexed_coupon_tests; @@ -266,18 +269,7 @@ void OvernightIndexedCouponTest::testAccruedAmountOnFutureHoliday() { Real expectedAmount = vars.notional * 0.000100005012; CHECK_OIS_COUPON_RESULT("coupon amount", coupon->accruedAmount(accrualDate), expectedAmount, 1e-8); } - -test_suite* OvernightIndexedCouponTest::suite() { - auto* suite = BOOST_TEST_SUITE("Overnight-indexed coupon tests"); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testPastCouponRate)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testCurrentCouponRate)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testFutureCouponRate)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testRateWhenTodayIsHoliday)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testAccruedAmountInThePast)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testAccruedAmountSpanningToday)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testAccruedAmountInTheFuture)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testAccruedAmountOnPastHoliday)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedCouponTest::testAccruedAmountOnFutureHoliday)); - - return suite; -} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/overnightindexedcoupon.hpp b/test-suite/overnightindexedcoupon.hpp deleted file mode 100644 index c88e4fe25e7..00000000000 --- a/test-suite/overnightindexedcoupon.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2021 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_overnight_indexed_coupon_hpp -#define quantlib_test_overnight_indexed_coupon_hpp - -#include - -class OvernightIndexedCouponTest { - public: - static void testPastCouponRate(); - static void testCurrentCouponRate(); - static void testFutureCouponRate(); - static void testRateWhenTodayIsHoliday(); - static void testAccruedAmountInThePast(); - static void testAccruedAmountSpanningToday(); - static void testAccruedAmountInTheFuture(); - static void testAccruedAmountOnPastHoliday(); - static void testAccruedAmountOnFutureHoliday(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 9af43a8801d..e4120c93e2e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "overnightindexedcoupon.hpp" #include "overnightindexedswap.hpp" #include "pagodaoption.hpp" #include "partialtimebarrieroption.hpp" @@ -116,7 +115,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OvernightIndexedCouponTest::suite()); test->add(OvernightIndexedSwapTest::suite()); test->add(PathGeneratorTest::suite()); test->add(PeriodTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 19f5633286a..bc97a4636a1 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index f60d97bb15c..898dadc406a 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 33d30c8aec6bcaae6781edb6a1cfa76cb475abf0 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 16:16:41 +0800 Subject: [PATCH 023/102] Migrated overnightindexedswap.cpp + bug fix --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/nthorderderivativeop.cpp | 2 +- test-suite/overnightindexedswap.cpp | 196 ++++++++++++--------------- test-suite/overnightindexedswap.hpp | 46 ------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 8 files changed, 91 insertions(+), 161 deletions(-) delete mode 100644 test-suite/overnightindexedswap.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index e7fac69627f..97af8b6f340 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - overnightindexedswap.hpp pagodaoption.hpp paralleltestrunner.hpp partialtimebarrieroption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1a3b1289b7c..7221ed75df3 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - overnightindexedswap.hpp \ pagodaoption.hpp \ partialtimebarrieroption.hpp \ pathgenerator.hpp \ diff --git a/test-suite/nthorderderivativeop.cpp b/test-suite/nthorderderivativeop.cpp index 54ed42d6454..f457e15688c 100644 --- a/test-suite/nthorderderivativeop.cpp +++ b/test-suite/nthorderderivativeop.cpp @@ -793,7 +793,7 @@ BOOST_AUTO_TEST_CASE(testHigherOrderAndRichardsonExtrapolation) { } } -void NthOrderDerivativeOpTest::testCompareFirstDerivativeOpNonUniformGrid() { +BOOST_AUTO_TEST_CASE(testCompareFirstDerivativeOpNonUniformGrid) { BOOST_TEST_MESSAGE( "Testing with FirstDerivativeOp on a non-uniform grid..."); diff --git a/test-suite/overnightindexedswap.cpp b/test-suite/overnightindexedswap.cpp index 83d8de9f8fd..850c46a2d76 100644 --- a/test-suite/overnightindexedswap.cpp +++ b/test-suite/overnightindexedswap.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "overnightindexedswap.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -172,10 +172,86 @@ namespace overnight_indexed_swap_test { } }; + void testBootstrap(bool telescopicValueDates, + RateAveraging::Type averagingMethod, + Real tolerance = 1.0e-8) { + + CommonVars vars; + + Natural paymentLag = 2; + + std::vector > eoniaHelpers; + + ext::shared_ptr euribor3m(new Euribor3M); + ext::shared_ptr eonia(new Eonia); + + for (auto& i : depositData) { + Real rate = 0.01 * i.rate; + ext::shared_ptr simple = ext::make_shared(rate); + ext::shared_ptr quote (simple); + Period term = i.n * i.unit; + ext::shared_ptr helper(new DepositRateHelper( + Handle(quote), term, i.settlementDays, euribor3m->fixingCalendar(), + euribor3m->businessDayConvention(), euribor3m->endOfMonth(), euribor3m->dayCounter())); + + if (term <= 2*Days) + eoniaHelpers.push_back(helper); + } + + for (auto& i : eoniaSwapData) { + Real rate = 0.01 * i.rate; + ext::shared_ptr simple = ext::make_shared(rate); + ext::shared_ptr quote (simple); + Period term = i.n * i.unit; + ext::shared_ptr helper(new + OISRateHelper(i.settlementDays, + term, + Handle(quote), + eonia, + Handle(), + telescopicValueDates, + paymentLag, + Following, + Annual, + Calendar(), + 0 * Days, + 0.0, + Pillar::LastRelevantDate, + Date(), + averagingMethod)); + eoniaHelpers.push_back(helper); + } + + auto eoniaTS = ext::make_shared>(vars.today, eoniaHelpers, Actual365Fixed()); + + vars.eoniaTermStructure.linkTo(eoniaTS); + + // test curve consistency + for (auto& i : eoniaSwapData) { + Rate expected = i.rate / 100; + Period term = i.n * i.unit; + // test telescopic value dates (in bootstrap) against non telescopic value dates (swap here) + ext::shared_ptr swap = + vars.makeSwap(term, 0.0, 0.0, false, Null(), paymentLag, averagingMethod); + Rate calculated = swap->fairRate(); + Rate error = std::fabs(expected-calculated); + + if (error>tolerance) + BOOST_FAIL("curve inconsistency:" << std::setprecision(10) << + "\n swap length: " << term << + "\n quoted rate: " << expected << + "\n calculated rate: " << calculated << + "\n error: " << error << + "\n tolerance: " << tolerance); + } + } // testBootstrap(telescopicValueDates) } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(OvernightIndexedSwapTest) -void OvernightIndexedSwapTest::testFairRate() { +BOOST_AUTO_TEST_CASE(testFairRate) { BOOST_TEST_MESSAGE("Testing Eonia-swap calculation of fair fixed rate..."); @@ -218,8 +294,7 @@ void OvernightIndexedSwapTest::testFairRate() { } } - -void OvernightIndexedSwapTest::testFairSpread() { +BOOST_AUTO_TEST_CASE(testFairSpread) { BOOST_TEST_MESSAGE("Testing Eonia-swap calculation of " "fair floating spread..."); @@ -264,7 +339,7 @@ void OvernightIndexedSwapTest::testFairSpread() { } } -void OvernightIndexedSwapTest::testCachedValue() { +BOOST_AUTO_TEST_CASE(testCachedValue) { BOOST_TEST_MESSAGE("Testing Eonia-swap calculation against cached value..."); @@ -296,99 +371,23 @@ void OvernightIndexedSwapTest::testCachedValue() { "\n tolerance:" << tolerance); } -namespace overnight_indexed_swap_test { - void testBootstrap(bool telescopicValueDates, - RateAveraging::Type averagingMethod, - Real tolerance = 1.0e-8) { - - CommonVars vars; - - Integer paymentLag = 2; - - std::vector > eoniaHelpers; - - ext::shared_ptr euribor3m(new Euribor3M); - ext::shared_ptr eonia(new Eonia); - - for (auto& i : depositData) { - Real rate = 0.01 * i.rate; - ext::shared_ptr simple = ext::make_shared(rate); - ext::shared_ptr quote (simple); - Period term = i.n * i.unit; - ext::shared_ptr helper(new DepositRateHelper( - Handle(quote), term, i.settlementDays, euribor3m->fixingCalendar(), - euribor3m->businessDayConvention(), euribor3m->endOfMonth(), euribor3m->dayCounter())); - - if (term <= 2*Days) - eoniaHelpers.push_back(helper); - } - - for (auto& i : eoniaSwapData) { - Real rate = 0.01 * i.rate; - ext::shared_ptr simple = ext::make_shared(rate); - ext::shared_ptr quote (simple); - Period term = i.n * i.unit; - ext::shared_ptr helper(new - OISRateHelper(i.settlementDays, - term, - Handle(quote), - eonia, - Handle(), - telescopicValueDates, - paymentLag, - Following, - Annual, - Calendar(), - 0 * Days, - 0.0, - Pillar::LastRelevantDate, - Date(), - averagingMethod)); - eoniaHelpers.push_back(helper); - } - - auto eoniaTS = ext::make_shared>(vars.today, eoniaHelpers, Actual365Fixed()); - - vars.eoniaTermStructure.linkTo(eoniaTS); - - // test curve consistency - for (auto& i : eoniaSwapData) { - Rate expected = i.rate / 100; - Period term = i.n * i.unit; - // test telescopic value dates (in bootstrap) against non telescopic value dates (swap here) - ext::shared_ptr swap = - vars.makeSwap(term, 0.0, 0.0, false, Null(), paymentLag, averagingMethod); - Rate calculated = swap->fairRate(); - Rate error = std::fabs(expected-calculated); - - if (error>tolerance) - BOOST_FAIL("curve inconsistency:" << std::setprecision(10) << - "\n swap length: " << term << - "\n quoted rate: " << expected << - "\n calculated rate: " << calculated << - "\n error: " << error << - "\n tolerance: " << tolerance); - } -} // testBootstrap(telescopicValueDates) -} // anonymous namespace - -void OvernightIndexedSwapTest::testBootstrap() { +BOOST_AUTO_TEST_CASE(testBootstrap) { BOOST_TEST_MESSAGE("Testing Eonia-swap curve building with daily compounded ON rates..."); overnight_indexed_swap_test::testBootstrap(false, RateAveraging::Compound); } -void OvernightIndexedSwapTest::testBootstrapWithArithmeticAverage() { +BOOST_AUTO_TEST_CASE(testBootstrapWithArithmeticAverage) { BOOST_TEST_MESSAGE("Testing Eonia-swap curve building with arithmetic average ON rates..."); overnight_indexed_swap_test::testBootstrap(false, RateAveraging::Simple); } -void OvernightIndexedSwapTest::testBootstrapWithTelescopicDates() { +BOOST_AUTO_TEST_CASE(testBootstrapWithTelescopicDates) { BOOST_TEST_MESSAGE( "Testing Eonia-swap curve building with telescopic value dates and DCON rates..."); overnight_indexed_swap_test::testBootstrap(true, RateAveraging::Compound); } -void OvernightIndexedSwapTest::testBootstrapWithTelescopicDatesAndArithmeticAverage() { +BOOST_AUTO_TEST_CASE(testBootstrapWithTelescopicDatesAndArithmeticAverage) { BOOST_TEST_MESSAGE( "Testing Eonia-swap curve building with telescopic value dates and AAON rates..."); // Given that we are using an approximation that omits @@ -397,7 +396,7 @@ void OvernightIndexedSwapTest::testBootstrapWithTelescopicDatesAndArithmeticAver overnight_indexed_swap_test::testBootstrap(true, RateAveraging::Simple, 1.0e-5); } -void OvernightIndexedSwapTest::testSeasonedSwaps() { +BOOST_AUTO_TEST_CASE(testSeasonedSwaps) { BOOST_TEST_MESSAGE("Testing seasoned Eonia-swap calculation..."); @@ -433,8 +432,7 @@ void OvernightIndexedSwapTest::testSeasonedSwaps() { } } - -void OvernightIndexedSwapTest::testBootstrapRegression() { +BOOST_AUTO_TEST_CASE(testBootstrapRegression) { BOOST_TEST_MESSAGE("Testing 1.16 regression with OIS bootstrap..."); using namespace overnight_indexed_swap_test; @@ -499,8 +497,7 @@ void OvernightIndexedSwapTest::testBootstrapRegression() { BOOST_CHECK_NO_THROW(curve.discount(1.0)); } - -void OvernightIndexedSwapTest::test131BootstrapRegression() { +BOOST_AUTO_TEST_CASE(test131BootstrapRegression) { BOOST_TEST_MESSAGE("Testing 1.31 regression with OIS bootstrap..."); Date today(11, December, 2012); @@ -516,7 +513,7 @@ void OvernightIndexedSwapTest::test131BootstrapRegression() { BOOST_CHECK_NO_THROW(curve.nodes()); } -void OvernightIndexedSwapTest::testConstructorsAndNominals() { +BOOST_AUTO_TEST_CASE(testConstructorsAndNominals) { BOOST_TEST_MESSAGE("Testing different constructors for OIS..."); using namespace overnight_indexed_swap_test; @@ -648,19 +645,6 @@ void OvernightIndexedSwapTest::testConstructorsAndNominals() { BOOST_CHECK_EQUAL(ois_4.overnightNominals()[3], nominal/2); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* OvernightIndexedSwapTest::suite() { - auto* suite = BOOST_TEST_SUITE("Overnight-indexed swap tests"); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testFairRate)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testFairSpread)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testCachedValue)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testBootstrap)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testBootstrapWithArithmeticAverage)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testBootstrapWithTelescopicDates)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testBootstrapWithTelescopicDatesAndArithmeticAverage)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testSeasonedSwaps)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testBootstrapRegression)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::test131BootstrapRegression)); - suite->add(QUANTLIB_TEST_CASE(&OvernightIndexedSwapTest::testConstructorsAndNominals)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/overnightindexedswap.hpp b/test-suite/overnightindexedswap.hpp deleted file mode 100644 index 5c84c5d1c2f..00000000000 --- a/test-suite/overnightindexedswap.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2009 Roland Lichters - Copyright (C) 2014 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_overnight_indexed_swap_hpp -#define quantlib_test_overnight_indexed_swap_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class OvernightIndexedSwapTest { - public: - static void testFairRate(); - static void testFairSpread(); - static void testCachedValue(); - static void testBootstrap(); - static void testBootstrapWithArithmeticAverage(); - static void testBootstrapWithTelescopicDates(); - static void testBootstrapWithTelescopicDatesAndArithmeticAverage(); - static void testSeasonedSwaps(); - static void testBootstrapRegression(); - static void test131BootstrapRegression(); - static void testConstructorsAndNominals(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index e4120c93e2e..977ea5f4a5a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -34,7 +34,6 @@ # include #endif -#include "overnightindexedswap.hpp" #include "pagodaoption.hpp" #include "partialtimebarrieroption.hpp" #include "pathgenerator.hpp" @@ -115,7 +114,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(OvernightIndexedSwapTest::suite()); test->add(PathGeneratorTest::suite()); test->add(PeriodTest::suite()); test->add(PiecewiseYieldCurveTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index bc97a4636a1..4eb57a79954 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,7 +810,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 898dadc406a..1b6606e39d4 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 32355174624b49a82ee04a29ade52864284a47ab Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 8 Nov 2023 17:14:30 +0800 Subject: [PATCH 024/102] Revert "Migrated marketmodel.cpp" This reverts commit 0e012fe1 --- test-suite/CMakeLists.txt | 1 + test-suite/Makefile.am | 1 + test-suite/marketmodel.cpp | 189 +++++++++++++++------------ test-suite/marketmodel.hpp | 61 +++++++++ test-suite/quantlibtestsuite.cpp | 2 + test-suite/testsuite.vcxproj | 1 + test-suite/testsuite.vcxproj.filters | 3 + 7 files changed, 172 insertions(+), 86 deletions(-) create mode 100644 test-suite/marketmodel.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 97af8b6f340..fd3bbd0a549 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,6 +174,7 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS + marketmodel.hpp pagodaoption.hpp paralleltestrunner.hpp partialtimebarrieroption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7221ed75df3..a364fc6f1eb 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,6 +174,7 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ + marketmodel.hpp \ pagodaoption.hpp \ partialtimebarrieroption.hpp \ pathgenerator.hpp \ diff --git a/test-suite/marketmodel.cpp b/test-suite/marketmodel.cpp index f8c5df45983..861e6e1404b 100644 --- a/test-suite/marketmodel.cpp +++ b/test-suite/marketmodel.cpp @@ -22,8 +22,7 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" -#include "toplevelfixture.hpp" +#include "marketmodel.hpp" #include "utilities.hpp" #include #include @@ -119,10 +118,6 @@ using std::sqrt; namespace market_model_test { - enum MarketModelType { ExponentialCorrelationFlatVolatility, - ExponentialCorrelationAbcdVolatility/*, CalibratedMM*/ - }; - Date todaysDate, startDate, endDate; Schedule dates; std::vector + diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 1b6606e39d4..1b41de89750 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,6 +527,9 @@ + + Header Files + Header Files From c867824c684eaec5a6a820f29bd83d89fbdc743e Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Mon, 13 Nov 2023 11:35:57 +0800 Subject: [PATCH 025/102] Fixed namespace errors --- test-suite/observable.cpp | 137 +++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/test-suite/observable.cpp b/test-suite/observable.cpp index 277de8e9803..9f9cbf96bf6 100644 --- a/test-suite/observable.cpp +++ b/test-suite/observable.cpp @@ -31,6 +31,14 @@ #include #include +#ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN +#include +#include +#include +#include +#include +#endif + using namespace QuantLib; using namespace boost::unit_test_framework; @@ -53,76 +61,7 @@ namespace { } }; -} - -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) - -BOOST_AUTO_TEST_SUITE(ObservableTest) - -BOOST_AUTO_TEST_CASE(testObservableSettings) { - - BOOST_TEST_MESSAGE("Testing observable settings..."); - - const ext::shared_ptr quote(new SimpleQuote(100.0)); - UpdateCounter updateCounter; - - updateCounter.registerWith(quote); - if (updateCounter.counter() != 0) { - BOOST_FAIL("update counter value is not zero"); - } - - quote->setValue(1.0); - if (updateCounter.counter() != 1) { - BOOST_FAIL("update counter value is not one"); - } - - ObservableSettings::instance().disableUpdates(false); - quote->setValue(2.0); - if (updateCounter.counter() != 1) { - BOOST_FAIL("update counter value is not one"); - } - ObservableSettings::instance().enableUpdates(); - if (updateCounter.counter() != 1) { - BOOST_FAIL("update counter value is not one"); - } - - ObservableSettings::instance().disableUpdates(true); - quote->setValue(3.0); - if (updateCounter.counter() != 1) { - BOOST_FAIL("update counter value is not one"); - } - ObservableSettings::instance().enableUpdates(); - if (updateCounter.counter() != 2) { - BOOST_FAIL("update counter value is not two"); - } - - UpdateCounter updateCounter2; - updateCounter2.registerWith(quote); - ObservableSettings::instance().disableUpdates(true); - for (Size i=0; i < 10; ++i) { - quote->setValue(Real(i)); - } - if (updateCounter.counter() != 2) { - BOOST_FAIL("update counter value is not two"); - } - ObservableSettings::instance().enableUpdates(); - if (updateCounter.counter() != 3 || updateCounter2.counter() != 1) { - BOOST_FAIL("update counter values are not correct"); - } -} - - #ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN - -#include -#include -#include -#include - -#include - -namespace { - class MTUpdateCounter : public Observer { public: MTUpdateCounter() : counter_(0) { @@ -184,8 +123,68 @@ namespace { std::list > objList; }; +#endif +} + +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ObservableTest) + +BOOST_AUTO_TEST_CASE(testObservableSettings) { + + BOOST_TEST_MESSAGE("Testing observable settings..."); + + const ext::shared_ptr quote(new SimpleQuote(100.0)); + UpdateCounter updateCounter; + + updateCounter.registerWith(quote); + if (updateCounter.counter() != 0) { + BOOST_FAIL("update counter value is not zero"); + } + + quote->setValue(1.0); + if (updateCounter.counter() != 1) { + BOOST_FAIL("update counter value is not one"); + } + + ObservableSettings::instance().disableUpdates(false); + quote->setValue(2.0); + if (updateCounter.counter() != 1) { + BOOST_FAIL("update counter value is not one"); + } + ObservableSettings::instance().enableUpdates(); + if (updateCounter.counter() != 1) { + BOOST_FAIL("update counter value is not one"); + } + + ObservableSettings::instance().disableUpdates(true); + quote->setValue(3.0); + if (updateCounter.counter() != 1) { + BOOST_FAIL("update counter value is not one"); + } + ObservableSettings::instance().enableUpdates(); + if (updateCounter.counter() != 2) { + BOOST_FAIL("update counter value is not two"); + } + + UpdateCounter updateCounter2; + updateCounter2.registerWith(quote); + ObservableSettings::instance().disableUpdates(true); + for (Size i=0; i < 10; ++i) { + quote->setValue(Real(i)); + } + if (updateCounter.counter() != 2) { + BOOST_FAIL("update counter value is not two"); + } + ObservableSettings::instance().enableUpdates(); + if (updateCounter.counter() != 3 || updateCounter2.counter() != 1) { + BOOST_FAIL("update counter values are not correct"); + } } + +#ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN + BOOST_AUTO_TEST_CASE(testAsyncGarbagCollector) { BOOST_TEST_MESSAGE("Testing observer pattern with an asynchronous " From 138413ed526f2a3bc03d8f6ddfd1011c1dcb4c53 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Mon, 13 Nov 2023 13:39:11 +0800 Subject: [PATCH 026/102] Migrated pagodaoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/pagodaoption.cpp | 16 +++++++------- test-suite/pagodaoption.hpp | 32 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 test-suite/pagodaoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index fd3bbd0a549..ca7b406a43d 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -175,7 +175,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp - pagodaoption.hpp paralleltestrunner.hpp partialtimebarrieroption.hpp pathgenerator.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index a364fc6f1eb..7cf83a8a3d2 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - pagodaoption.hpp \ partialtimebarrieroption.hpp \ pathgenerator.hpp \ period.hpp \ diff --git a/test-suite/pagodaoption.cpp b/test-suite/pagodaoption.cpp index ba7951ccf72..25ec77ae8e7 100644 --- a/test-suite/pagodaoption.cpp +++ b/test-suite/pagodaoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "pagodaoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -28,7 +28,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void PagodaOptionTest::testCached() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(PagodaOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testCached) { BOOST_TEST_MESSAGE("Testing pagoda option against cached values..."); @@ -125,10 +129,6 @@ void PagodaOptionTest::testCached() { << " expected: " << tolerance); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* PagodaOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Pagoda-option tests"); - suite->add(QUANTLIB_TEST_CASE(&PagodaOptionTest::testCached)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/pagodaoption.hpp b/test-suite/pagodaoption.hpp deleted file mode 100644 index ab32b8d08ba..00000000000 --- a/test-suite/pagodaoption.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_pagoda_option_hpp -#define quantlib_test_pagoda_option_hpp - -#include - -class PagodaOptionTest { - public: - static void testCached(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f07c4cc03fa..e9b9b2da2ee 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "pagodaoption.hpp" #include "partialtimebarrieroption.hpp" #include "pathgenerator.hpp" #include "period.hpp" @@ -152,7 +151,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(PagodaOptionTest::suite()); test->add(PartialTimeBarrierOptionTest::suite()); test->add(QuantoOptionTest::experimental()); test->add(RiskNeutralDensityCalculatorTest::experimental(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 44fc92fd7a9..6fdd98c238d 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -811,7 +811,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 1b41de89750..494b3393178 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -530,9 +530,6 @@ Header Files - - Header Files - Header Files From e4e8216d7a2a8260b8acf5b19af0d220e4e7c78a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Mon, 13 Nov 2023 13:42:00 +0800 Subject: [PATCH 027/102] Migrated partialtimebarrieroption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/partialtimebarrieroption.cpp | 18 ++++++------- test-suite/partialtimebarrieroption.hpp | 35 ------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 test-suite/partialtimebarrieroption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index ca7b406a43d..9c9e125ea05 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp - partialtimebarrieroption.hpp pathgenerator.hpp period.hpp piecewiseyieldcurve.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7cf83a8a3d2..925efcf8424 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - partialtimebarrieroption.hpp \ pathgenerator.hpp \ period.hpp \ piecewiseyieldcurve.hpp \ diff --git a/test-suite/partialtimebarrieroption.cpp b/test-suite/partialtimebarrieroption.cpp index 710b9f4055a..daaa57a677e 100644 --- a/test-suite/partialtimebarrieroption.cpp +++ b/test-suite/partialtimebarrieroption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "partialtimebarrieroption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -40,7 +40,11 @@ namespace partial_time_barrier_option_test { } -void PartialTimeBarrierOptionTest::testAnalyticEngine() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(PartialTimeBarrierOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testAnalyticEngine) { BOOST_TEST_MESSAGE( "Testing analytic engine for partial-time barrier option..."); @@ -125,12 +129,6 @@ void PartialTimeBarrierOptionTest::testAnalyticEngine() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* PartialTimeBarrierOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Partial-time barrier option tests"); - - suite->add(QUANTLIB_TEST_CASE( - &PartialTimeBarrierOptionTest::testAnalyticEngine)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/partialtimebarrieroption.hpp b/test-suite/partialtimebarrieroption.hpp deleted file mode 100644 index acb5f9047bf..00000000000 --- a/test-suite/partialtimebarrieroption.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_partial_time_barrier_options_hpp -#define quantlib_test_partial_time_barrier_options_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class PartialTimeBarrierOptionTest { - public: - static void testAnalyticEngine(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index e9b9b2da2ee..9563d95fa55 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "partialtimebarrieroption.hpp" #include "pathgenerator.hpp" #include "period.hpp" #include "piecewiseyieldcurve.hpp" @@ -151,7 +150,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(PartialTimeBarrierOptionTest::suite()); test->add(QuantoOptionTest::experimental()); test->add(RiskNeutralDensityCalculatorTest::experimental(speed)); test->add(SpreadOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 6fdd98c238d..fbb5b9315a7 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -811,7 +811,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 494b3393178..76249b1d6cb 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From abfb7663ccd2de2504c16b4634e38fd2807ee3dc Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Mon, 13 Nov 2023 14:02:05 +0800 Subject: [PATCH 028/102] refactored speed_level function into speedlevel.cpp --- test-suite/quantlibglobalfixture.cpp | 20 -------------------- test-suite/quantlibglobalfixture.hpp | 1 - test-suite/quantlibtestsuite.cpp | 21 --------------------- test-suite/speedlevel.cpp | 20 ++++++++++++++++++++ test-suite/speedlevel.hpp | 3 ++- 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 5ffd2a0f187..6494e02f4f7 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -144,26 +144,6 @@ SpeedLevel QuantLibGlobalFixture::get_speed() { return speed; } -SpeedLevel QuantLibGlobalFixture::speed_level(int argc, char** argv) { - /*! Again, dead simple parser: - - passing --slow causes all tests to be run; - - passing --fast causes most tests to be run, except the slowest; - - passing --faster causes only the faster tests to be run; - - passing nothing is the same as --slow - */ - - for (int i=1; i Date: Mon, 13 Nov 2023 22:27:47 +0800 Subject: [PATCH 029/102] Migrated pathgenerator.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/pathgenerator.cpp | 19 +++++++-------- test-suite/pathgenerator.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 test-suite/pathgenerator.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9c9e125ea05..1ff917bcf9f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp - pathgenerator.hpp period.hpp piecewiseyieldcurve.hpp piecewisezerospreadedtermstructure.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 925efcf8424..f4fa7b3320e 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - pathgenerator.hpp \ period.hpp \ piecewiseyieldcurve.hpp \ piecewisezerospreadedtermstructure.hpp \ diff --git a/test-suite/pathgenerator.cpp b/test-suite/pathgenerator.cpp index 227406f31ce..0c351f3b828 100644 --- a/test-suite/pathgenerator.cpp +++ b/test-suite/pathgenerator.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "pathgenerator.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -140,8 +140,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void PathGeneratorTest::testPathGenerator() { +BOOST_AUTO_TEST_SUITE(PathGeneratorTest) + +BOOST_AUTO_TEST_CASE(testPathGenerator) { BOOST_TEST_MESSAGE("Testing 1-D path generation against cached values..."); @@ -175,8 +178,7 @@ void PathGeneratorTest::testPathGenerator() { "square-root", false, 1.70608664108, 6.024200546031); } - -void PathGeneratorTest::testMultiPathGenerator() { +BOOST_AUTO_TEST_CASE(testMultiPathGenerator) { BOOST_TEST_MESSAGE("Testing n-D path generation against cached values..."); @@ -285,11 +287,6 @@ void PathGeneratorTest::testMultiPathGenerator() { testMultiple(process, "square-root", result4, result4a); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* PathGeneratorTest::suite() { - auto* suite = BOOST_TEST_SUITE("Path generation tests"); - suite->add(QUANTLIB_TEST_CASE(&PathGeneratorTest::testPathGenerator)); - suite->add(QUANTLIB_TEST_CASE(&PathGeneratorTest::testMultiPathGenerator)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/pathgenerator.hpp b/test-suite/pathgenerator.hpp deleted file mode 100644 index 5f4edfa86f1..00000000000 --- a/test-suite/pathgenerator.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_path_generator_hpp -#define quantlib_test_path_generator_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class PathGeneratorTest { - public: - static void testPathGenerator(); - static void testMultiPathGenerator(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 525cc582bd9..14ec2269047 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "pathgenerator.hpp" #include "period.hpp" #include "piecewiseyieldcurve.hpp" #include "piecewisezerospreadedtermstructure.hpp" @@ -93,7 +92,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(PathGeneratorTest::suite()); test->add(PeriodTest::suite()); test->add(PiecewiseYieldCurveTest::suite()); test->add(PiecewiseZeroSpreadedTermStructureTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index fbb5b9315a7..81a0aad481f 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -811,7 +811,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 76249b1d6cb..5230717be85 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From ba8dc3f166aa329f4dd8c5ca39a419323452f801 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Mon, 13 Nov 2023 22:30:36 +0800 Subject: [PATCH 030/102] Migrated period.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/period.cpp | 21 ++++++++-------- test-suite/period.hpp | 37 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 56 deletions(-) delete mode 100644 test-suite/period.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 1ff917bcf9f..2339460db5a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp - period.hpp piecewiseyieldcurve.hpp piecewisezerospreadedtermstructure.hpp quantlibglobalfixture.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index f4fa7b3320e..c4e24856a90 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - period.hpp \ piecewiseyieldcurve.hpp \ piecewisezerospreadedtermstructure.hpp \ quantlibglobalfixture.hpp \ diff --git a/test-suite/period.cpp b/test-suite/period.cpp index c9f4eeace95..6a90d30bb1c 100644 --- a/test-suite/period.cpp +++ b/test-suite/period.cpp @@ -17,14 +17,18 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "period.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include "ql/time/period.hpp" using namespace QuantLib; using namespace boost::unit_test_framework; -void PeriodTest::testYearsMonthsAlgebra() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(PeriodTest) + +BOOST_AUTO_TEST_CASE(testYearsMonthsAlgebra) { BOOST_TEST_MESSAGE("Testing period algebra on years/months..."); @@ -77,7 +81,7 @@ void PeriodTest::testYearsMonthsAlgebra() { " instead of " << Years); } -void PeriodTest::testWeeksDaysAlgebra() { +BOOST_AUTO_TEST_CASE(testWeeksDaysAlgebra) { BOOST_TEST_MESSAGE("Testing period algebra on weeks/days..."); @@ -120,7 +124,7 @@ void PeriodTest::testWeeksDaysAlgebra() { " instead of " << Days); } -void PeriodTest::testNormalization() { +BOOST_AUTO_TEST_CASE(testNormalization) { BOOST_TEST_MESSAGE("Testing period normalization..."); @@ -185,11 +189,6 @@ void PeriodTest::testNormalization() { } -test_suite* PeriodTest::suite() { - auto* suite = BOOST_TEST_SUITE("Period tests"); - suite->add(QUANTLIB_TEST_CASE(&PeriodTest::testYearsMonthsAlgebra)); - suite->add(QUANTLIB_TEST_CASE(&PeriodTest::testWeeksDaysAlgebra)); - suite->add(QUANTLIB_TEST_CASE(&PeriodTest::testNormalization)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/period.hpp b/test-suite/period.hpp deleted file mode 100644 index 042b6eef081..00000000000 --- a/test-suite/period.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Ferdinando Ametrano - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_period_hpp -#define quantlib_test_period_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class PeriodTest { - public: - static void testYearsMonthsAlgebra(); - static void testWeeksDaysAlgebra(); - static void testNormalization(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 14ec2269047..83df81d4a5a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "period.hpp" #include "piecewiseyieldcurve.hpp" #include "piecewisezerospreadedtermstructure.hpp" #include "quantooption.hpp" @@ -92,7 +91,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(PeriodTest::suite()); test->add(PiecewiseYieldCurveTest::suite()); test->add(PiecewiseZeroSpreadedTermStructureTest::suite()); test->add(QuantoOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 81a0aad481f..c369db83e5c 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -812,7 +812,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 5230717be85..bf9c351d084 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From bd35efc876c829c4064c96f05ad45f5a5dc375d0 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Tue, 14 Nov 2023 18:11:24 +0800 Subject: [PATCH 031/102] Migrated piecewiseyieldcurve.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/piecewiseyieldcurve.cpp | 181 +++++++++++---------------- test-suite/piecewiseyieldcurve.hpp | 69 ---------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 75 insertions(+), 183 deletions(-) delete mode 100644 test-suite/piecewiseyieldcurve.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 2339460db5a..7b4198c2fd8 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp - piecewiseyieldcurve.hpp piecewisezerospreadedtermstructure.hpp quantlibglobalfixture.hpp quantooption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c4e24856a90..56b996a549c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - piecewiseyieldcurve.hpp \ piecewisezerospreadedtermstructure.hpp \ quantlibglobalfixture.hpp \ quantooption.hpp \ diff --git a/test-suite/piecewiseyieldcurve.cpp b/test-suite/piecewiseyieldcurve.cpp index 41d789219de..60eff290d92 100644 --- a/test-suite/piecewiseyieldcurve.cpp +++ b/test-suite/piecewiseyieldcurve.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "piecewiseyieldcurve.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -651,25 +651,39 @@ namespace piecewise_yield_curve_test { } +namespace { + namespace tt = boost::test_tools; -void PiecewiseYieldCurveTest::testLogCubicDiscountConsistency() { - - BOOST_TEST_MESSAGE( - "Testing consistency of piecewise-log-cubic discount curve..."); - - using namespace piecewise_yield_curve_test; - - CommonVars vars; - - testCurveConsistency( - vars, - MonotonicLogCubic()); - testBMACurveConsistency( - vars, - MonotonicLogCubic()); + struct usingAtParCoupons { + tt::assertion_result operator()(test_unit_id) { + return tt::assertion_result(IborCoupon::Settings::instance().usingAtParCoupons()); + } + }; } -void PiecewiseYieldCurveTest::testLogLinearDiscountConsistency() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(PiecewiseYieldCurveTest) + +//Unstable +//BOOST_AUTO_TEST_CASE(testLogCubicDiscountConsistency) { +// +// BOOST_TEST_MESSAGE( +// "Testing consistency of piecewise-log-cubic discount curve..."); +// +// using namespace piecewise_yield_curve_test; +// +// CommonVars vars; +// +// testCurveConsistency( +// vars, +// MonotonicLogCubic()); +// testBMACurveConsistency( +// vars, +// MonotonicLogCubic()); +//} + +BOOST_AUTO_TEST_CASE(testLogLinearDiscountConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-log-linear discount curve..."); @@ -682,7 +696,7 @@ void PiecewiseYieldCurveTest::testLogLinearDiscountConsistency() { testBMACurveConsistency(vars); } -void PiecewiseYieldCurveTest::testLinearDiscountConsistency() { +BOOST_AUTO_TEST_CASE(testLinearDiscountConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-linear discount curve..."); @@ -695,7 +709,7 @@ void PiecewiseYieldCurveTest::testLinearDiscountConsistency() { testBMACurveConsistency(vars); } -void PiecewiseYieldCurveTest::testLinearZeroConsistency() { +BOOST_AUTO_TEST_CASE(testLinearZeroConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-linear zero-yield curve..."); @@ -708,7 +722,7 @@ void PiecewiseYieldCurveTest::testLinearZeroConsistency() { testBMACurveConsistency(vars); } -void PiecewiseYieldCurveTest::testSplineZeroConsistency() { +BOOST_AUTO_TEST_CASE(testSplineZeroConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-cubic zero-yield curve..."); @@ -729,7 +743,7 @@ void PiecewiseYieldCurveTest::testSplineZeroConsistency() { CubicInterpolation::SecondDerivative, 0.0)); } -void PiecewiseYieldCurveTest::testLinearForwardConsistency() { +BOOST_AUTO_TEST_CASE(testLinearForwardConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-linear forward-rate curve..."); @@ -742,7 +756,7 @@ void PiecewiseYieldCurveTest::testLinearForwardConsistency() { testBMACurveConsistency(vars); } -void PiecewiseYieldCurveTest::testFlatForwardConsistency() { +BOOST_AUTO_TEST_CASE(testFlatForwardConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of piecewise-flat forward-rate curve..."); @@ -755,28 +769,29 @@ void PiecewiseYieldCurveTest::testFlatForwardConsistency() { testBMACurveConsistency(vars); } -void PiecewiseYieldCurveTest::testSplineForwardConsistency() { - - BOOST_TEST_MESSAGE( - "Testing consistency of piecewise-cubic forward-rate curve..."); - - using namespace piecewise_yield_curve_test; - - CommonVars vars; - - testCurveConsistency( - vars, - Cubic(CubicInterpolation::Spline, true, - CubicInterpolation::SecondDerivative, 0.0, - CubicInterpolation::SecondDerivative, 0.0)); - testBMACurveConsistency( - vars, - Cubic(CubicInterpolation::Spline, true, - CubicInterpolation::SecondDerivative, 0.0, - CubicInterpolation::SecondDerivative, 0.0)); -} - -void PiecewiseYieldCurveTest::testConvexMonotoneForwardConsistency() { +//Unstable +//BOOST_AUTO_TEST_CASE(testSplineForwardConsistency) { +// +// BOOST_TEST_MESSAGE( +// "Testing consistency of piecewise-cubic forward-rate curve..."); +// +// using namespace piecewise_yield_curve_test; +// +// CommonVars vars; +// +// testCurveConsistency( +// vars, +// Cubic(CubicInterpolation::Spline, true, +// CubicInterpolation::SecondDerivative, 0.0, +// CubicInterpolation::SecondDerivative, 0.0)); +// testBMACurveConsistency( +// vars, +// Cubic(CubicInterpolation::Spline, true, +// CubicInterpolation::SecondDerivative, 0.0, +// CubicInterpolation::SecondDerivative, 0.0)); +//} + +BOOST_AUTO_TEST_CASE(testConvexMonotoneForwardConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of convex monotone forward-rate curve..."); @@ -789,8 +804,7 @@ void PiecewiseYieldCurveTest::testConvexMonotoneForwardConsistency() { IterativeBootstrap>(vars); } - -void PiecewiseYieldCurveTest::testLocalBootstrapConsistency() { +BOOST_AUTO_TEST_CASE(testLocalBootstrapConsistency) { BOOST_TEST_MESSAGE( "Testing consistency of local-bootstrap algorithm..."); @@ -803,7 +817,7 @@ void PiecewiseYieldCurveTest::testLocalBootstrapConsistency() { vars, ConvexMonotone(), 1.0e-7); } -void PiecewiseYieldCurveTest::testParFraRegression() { +BOOST_AUTO_TEST_CASE(testParFraRegression) { BOOST_TEST_MESSAGE("Testing regression for at-par FRA..."); using namespace piecewise_yield_curve_test; @@ -843,7 +857,7 @@ void PiecewiseYieldCurveTest::testParFraRegression() { } } -void PiecewiseYieldCurveTest::testObservability() { +BOOST_AUTO_TEST_CASE(testObservability) { BOOST_TEST_MESSAGE("Testing observability of piecewise yield curve..."); @@ -890,8 +904,7 @@ void PiecewiseYieldCurveTest::testObservability() { " without an intervening recalculation"); } - -void PiecewiseYieldCurveTest::testLiborFixing() { +BOOST_AUTO_TEST_CASE(testLiborFixing) { BOOST_TEST_MESSAGE( "Testing use of today's LIBOR fixings in swap curve..."); @@ -979,7 +992,7 @@ void PiecewiseYieldCurveTest::testLiborFixing() { } } -void PiecewiseYieldCurveTest::testJpyLibor() { +BOOST_AUTO_TEST_CASE(testJpyLibor) { BOOST_TEST_MESSAGE( "Testing bootstrap over JPY LIBOR swaps..."); @@ -1052,7 +1065,7 @@ void PiecewiseYieldCurveTest::testJpyLibor() { } } -void PiecewiseYieldCurveTest::testDefaultInstantiation() { +BOOST_AUTO_TEST_CASE(testDefaultInstantiation) { BOOST_TEST_MESSAGE("Testing instantiation of curves without passing an interpolator..."); @@ -1072,7 +1085,7 @@ void PiecewiseYieldCurveTest::testDefaultInstantiation() { PiecewiseYieldCurve convex(vars.settlement, vars.instruments, Actual360()); } -void PiecewiseYieldCurveTest::testSwapRateHelperLastRelevantDate() { +BOOST_AUTO_TEST_CASE(testSwapRateHelperLastRelevantDate) { BOOST_TEST_MESSAGE("Testing SwapRateHelper last relevant date..."); Settings::instance().evaluationDate() = Date(22, Dec, 2016); @@ -1093,7 +1106,7 @@ void PiecewiseYieldCurveTest::testSwapRateHelperLastRelevantDate() { BOOST_CHECK_NO_THROW(curve.discount(1.0)); } -void PiecewiseYieldCurveTest::testSwapRateHelperSpotDate() { +BOOST_AUTO_TEST_CASE(testSwapRateHelperSpotDate) { BOOST_TEST_MESSAGE("Testing SwapRateHelper spot date..."); ext::shared_ptr usdLibor3m = ext::make_shared(3 * Months); @@ -1124,7 +1137,8 @@ void PiecewiseYieldCurveTest::testSwapRateHelperSpotDate() { // "calculated: " << calculated); } -void PiecewiseYieldCurveTest::testBadPreviousCurve() { +// This regression test didn't work with indexed coupons anyway. +BOOST_AUTO_TEST_CASE(testBadPreviousCurve, *precondition(usingAtParCoupons())) { BOOST_TEST_MESSAGE("Testing bootstrap starting from bad guess..."); using namespace piecewise_yield_curve_test; @@ -1188,7 +1202,7 @@ void PiecewiseYieldCurveTest::testBadPreviousCurve() { } } -void PiecewiseYieldCurveTest::testConstructionWithExplicitBootstrap() { +BOOST_AUTO_TEST_CASE(testConstructionWithExplicitBootstrap) { BOOST_TEST_MESSAGE("Testing that construction with an explicit bootstrap succeeds..."); @@ -1215,7 +1229,7 @@ void PiecewiseYieldCurveTest::testConstructionWithExplicitBootstrap() { BOOST_CHECK_NO_THROW(yts->discount(1.0, true)); } -void PiecewiseYieldCurveTest::testLargeRates() { +BOOST_AUTO_TEST_CASE(testLargeRates) { BOOST_TEST_MESSAGE("Testing bootstrap with large input rates..."); using namespace piecewise_yield_curve_test; @@ -1285,7 +1299,7 @@ namespace piecewise_yield_curve_test { }; } -void PiecewiseYieldCurveTest::testGlobalBootstrap() { +BOOST_AUTO_TEST_CASE(testGlobalBootstrap, *precondition(usingAtParCoupons())) { BOOST_TEST_MESSAGE("Testing global bootstrap..."); @@ -1372,7 +1386,7 @@ void PiecewiseYieldCurveTest::testGlobalBootstrap() { IterativeBootstrap with no retries, the yield curve building fails. Allowing retries, it expands the min and max bounds and passes. */ -void PiecewiseYieldCurveTest::testIterativeBootstrapRetries() { +BOOST_AUTO_TEST_CASE(testIterativeBootstrapRetries) { BOOST_TEST_MESSAGE("Testing iterative bootstrap with retries..."); @@ -1474,51 +1488,6 @@ void PiecewiseYieldCurveTest::testIterativeBootstrapRetries() { QL_CHECK_SMALL(calcFwd - expFwd, 1e-10); } -test_suite* PiecewiseYieldCurveTest::suite() { - - auto* suite = BOOST_TEST_SUITE("Piecewise yield curve tests"); - - // unstable - // suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLogCubicDiscountConsistency)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLogLinearDiscountConsistency)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLinearDiscountConsistency)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLinearZeroConsistency)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testSplineZeroConsistency)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLinearForwardConsistency)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testFlatForwardConsistency)); - // unstable - // suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testSplineForwardConsistency)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testConvexMonotoneForwardConsistency)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLocalBootstrapConsistency)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testParFraRegression)); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testObservability)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLiborFixing)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testDefaultInstantiation)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testJpyLibor)); - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testSwapRateHelperLastRelevantDate)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testSwapRateHelperSpotDate)); - - if (IborCoupon::Settings::instance().usingAtParCoupons()) { - // This regression test didn't work with indexed coupons anyway. - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testBadPreviousCurve)); - } - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testConstructionWithExplicitBootstrap)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testLargeRates)); - - if (IborCoupon::Settings::instance().usingAtParCoupons()) { - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testGlobalBootstrap)); - } - - suite->add(QUANTLIB_TEST_CASE(&PiecewiseYieldCurveTest::testIterativeBootstrapRetries)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/piecewiseyieldcurve.hpp b/test-suite/piecewiseyieldcurve.hpp deleted file mode 100644 index c300eb5bdd8..00000000000 --- a/test-suite/piecewiseyieldcurve.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005, 2006, 2008, 2009, 2017 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_piecewise_yield_curve_hpp -#define quantlib_test_piecewise_yield_curve_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class PiecewiseYieldCurveTest { - public: - static void testLogCubicDiscountConsistency(); - static void testLogLinearDiscountConsistency(); - static void testLinearDiscountConsistency(); - - static void testLinearZeroConsistency(); - static void testSplineZeroConsistency(); - - static void testLinearForwardConsistency(); - static void testFlatForwardConsistency(); - static void testSplineForwardConsistency(); - - static void testConvexMonotoneForwardConsistency(); - static void testLocalBootstrapConsistency(); - - static void testParFraRegression(); - - static void testDefaultInstantiation(); - - static void testObservability(); - static void testLiborFixing(); - - static void testJpyLibor(); - - static void testSwapRateHelperLastRelevantDate(); - static void testSwapRateHelperSpotDate(); - - static void testBadPreviousCurve(); - - static void testConstructionWithExplicitBootstrap(); - static void testLargeRates(); - - static void testGlobalBootstrap(); - - static void testIterativeBootstrapRetries(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 83df81d4a5a..10d447e4cc8 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "piecewiseyieldcurve.hpp" #include "piecewisezerospreadedtermstructure.hpp" #include "quantooption.hpp" #include "quotes.hpp" @@ -91,7 +90,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(PiecewiseYieldCurveTest::suite()); test->add(PiecewiseZeroSpreadedTermStructureTest::suite()); test->add(QuantoOptionTest::suite()); test->add(QuoteTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index c369db83e5c..c70be5860e5 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -812,7 +812,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index bf9c351d084..b8c4b630251 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From 893234b5e2940f5db2eb47693fc85d60b4b65bbb Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Tue, 14 Nov 2023 18:15:06 +0800 Subject: [PATCH 032/102] Migrated piecewisezerospreadedtermstructure.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - .../piecewisezerospreadedtermstructure.cpp | 50 +++++++------------ .../piecewisezerospreadedtermstructure.hpp | 43 ---------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 17 insertions(+), 84 deletions(-) delete mode 100644 test-suite/piecewisezerospreadedtermstructure.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 7b4198c2fd8..6196ff35325 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp - piecewisezerospreadedtermstructure.hpp quantlibglobalfixture.hpp quantooption.hpp quotes.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 56b996a549c..916d1251ff7 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ - piecewisezerospreadedtermstructure.hpp \ quantlibglobalfixture.hpp \ quantooption.hpp \ quotes.hpp \ diff --git a/test-suite/piecewisezerospreadedtermstructure.cpp b/test-suite/piecewisezerospreadedtermstructure.cpp index cff591cecd4..efb05933d60 100644 --- a/test-suite/piecewisezerospreadedtermstructure.cpp +++ b/test-suite/piecewisezerospreadedtermstructure.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "piecewisezerospreadedtermstructure.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -75,7 +75,11 @@ namespace piecewise_zero_spreaded_term_structure_test { } -void PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationLeft() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(PiecewiseZeroSpreadedTermStructureTest) + +BOOST_AUTO_TEST_CASE(testFlatInterpolationLeft) { BOOST_TEST_MESSAGE("Testing flat interpolation before the first spreaded date..."); @@ -113,7 +117,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationLeft() { } -void PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationRight() { +BOOST_AUTO_TEST_CASE(testFlatInterpolationRight) { BOOST_TEST_MESSAGE("Testing flat interpolation after the last spreaded date..."); @@ -152,7 +156,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationRight() { } -void PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolationMultipleSpreads() { +BOOST_AUTO_TEST_CASE(testLinearInterpolationMultipleSpreads) { BOOST_TEST_MESSAGE("Testing linear interpolation with more than two spreaded dates..."); @@ -197,7 +201,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolationMultipleSpre } -void PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolation() { +BOOST_AUTO_TEST_CASE(testLinearInterpolation) { BOOST_TEST_MESSAGE("Testing linear interpolation between two dates..."); @@ -240,7 +244,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolation() { } -void PiecewiseZeroSpreadedTermStructureTest::testForwardFlatInterpolation() { +BOOST_AUTO_TEST_CASE(testForwardFlatInterpolation) { BOOST_TEST_MESSAGE("Testing forward flat interpolation between two dates..."); @@ -278,7 +282,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testForwardFlatInterpolation() { } -void PiecewiseZeroSpreadedTermStructureTest::testBackwardFlatInterpolation() { +BOOST_AUTO_TEST_CASE(testBackwardFlatInterpolation) { BOOST_TEST_MESSAGE("Testing backward flat interpolation between two dates..."); @@ -320,7 +324,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testBackwardFlatInterpolation() { } -void PiecewiseZeroSpreadedTermStructureTest::testDefaultInterpolation() { +BOOST_AUTO_TEST_CASE(testDefaultInterpolation) { BOOST_TEST_MESSAGE("Testing default interpolation between two dates..."); @@ -358,7 +362,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testDefaultInterpolation() { } -void PiecewiseZeroSpreadedTermStructureTest::testSetInterpolationFactory() { +BOOST_AUTO_TEST_CASE(testSetInterpolationFactory) { BOOST_TEST_MESSAGE("Testing factory constructor with additional parameters..."); @@ -408,7 +412,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testSetInterpolationFactory() { } -void PiecewiseZeroSpreadedTermStructureTest::testMaxDate() { +BOOST_AUTO_TEST_CASE(testMaxDate) { BOOST_TEST_MESSAGE("Testing term structure max date..."); @@ -441,7 +445,7 @@ void PiecewiseZeroSpreadedTermStructureTest::testMaxDate() { } -void PiecewiseZeroSpreadedTermStructureTest::testQuoteChanging() { +BOOST_AUTO_TEST_CASE(testQuoteChanging) { BOOST_TEST_MESSAGE("Testing quote update..."); @@ -491,26 +495,6 @@ void PiecewiseZeroSpreadedTermStructureTest::testQuoteChanging() { } -test_suite* PiecewiseZeroSpreadedTermStructureTest::suite() { - auto* suite = BOOST_TEST_SUITE("Interpolated piecewise zero spreaded yield curve tests"); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationLeft)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testFlatInterpolationRight)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolationMultipleSpreads)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testLinearInterpolation)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testBackwardFlatInterpolation)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testForwardFlatInterpolation)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testDefaultInterpolation)); - suite->add(QUANTLIB_TEST_CASE( - &PiecewiseZeroSpreadedTermStructureTest::testSetInterpolationFactory)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseZeroSpreadedTermStructureTest::testMaxDate)); - suite->add(QUANTLIB_TEST_CASE(&PiecewiseZeroSpreadedTermStructureTest::testQuoteChanging)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/piecewisezerospreadedtermstructure.hpp b/test-suite/piecewisezerospreadedtermstructure.hpp deleted file mode 100644 index 7f31990ae4d..00000000000 --- a/test-suite/piecewisezerospreadedtermstructure.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_piecewise_zero_spreaded_term_structure_hpp -#define quantlib_test_piecewise_zero_spreaded_term_structure_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class PiecewiseZeroSpreadedTermStructureTest { - public: - static void testFlatInterpolationLeft(); - static void testFlatInterpolationRight(); - static void testLinearInterpolationMultipleSpreads(); - static void testLinearInterpolation(); - static void testForwardFlatInterpolation(); - static void testBackwardFlatInterpolation(); - static void testDefaultInterpolation(); - static void testSetInterpolationFactory(); - static void testMaxDate(); - static void testQuoteChanging(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 10d447e4cc8..544ca3cd895 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "piecewisezerospreadedtermstructure.hpp" #include "quantooption.hpp" #include "quotes.hpp" #include "rangeaccrual.hpp" @@ -90,7 +89,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(PiecewiseZeroSpreadedTermStructureTest::suite()); test->add(QuantoOptionTest::suite()); test->add(QuoteTest::suite()); test->add(RangeAccrualTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index c70be5860e5..b53ad47c6b1 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -812,7 +812,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index b8c4b630251..d3b6960a16d 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From 75cdbfd81b2734234e8fb071038076d305802404 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Tue, 14 Nov 2023 18:27:54 +0800 Subject: [PATCH 033/102] Migrated quantooption.cpp --- test-suite/CMakeLists.txt | 5 +- test-suite/Makefile.am | 1 - test-suite/quantlibbenchmark.cpp | 8 +- test-suite/quantlibtestsuite.cpp | 3 - test-suite/quantooption.cpp | 201 ++++++++++++--------------- test-suite/quantooption.hpp | 48 ------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 8 files changed, 100 insertions(+), 170 deletions(-) delete mode 100644 test-suite/quantooption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 6196ff35325..9631372f115 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -177,7 +177,6 @@ set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp quantlibglobalfixture.hpp - quantooption.hpp quotes.hpp rangeaccrual.hpp riskneutraldensitycalculator.hpp @@ -243,8 +242,8 @@ set(QL_BENCHMARK_SOURCES lowdiscrepancysequences.cpp marketmodel_cms.cpp marketmodel_smm.cpp - quantooption.cpp quantooption.hpp - quantlibglobalfixture.cpp quantlibglobalfixture.hpp + quantooption.cpp + quantlibglobalfixture.cpp quantlibglobalfixture.hpp riskstats.cpp riskstats.hpp shortratemodels.cpp shortratemodels.hpp speedlevel.cpp speedlevel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 916d1251ff7..3f3bd61616c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -176,7 +176,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ quantlibglobalfixture.hpp \ - quantooption.hpp \ quotes.hpp \ rangeaccrual.hpp \ riskneutraldensitycalculator.hpp \ diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 19e4bfe65d4..b5f6578cabf 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -235,6 +235,10 @@ namespace QuantLibTest { public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace QuantoOptionTest { + struct testForwardGreeks: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -286,9 +290,9 @@ namespace { Benchmark("JumpDiffusion::Greeks", [] { QuantLibTest::JumpDiffusionTest::testGreeks().test_method(); }, 433.77), Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", [] { QuantLibTest::MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions().test_method(); }, 11497.73), Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", [] { QuantLibTest::MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions().test_method(); }, 11244.95), - Benchmark("QuantoOption::ForwardGreeks", &QuantoOptionTest::testForwardGreeks, 90.98), + Benchmark("QuantoOption::ForwardGreeks", [] { QuantLibTest::QuantoOptionTest::testForwardGreeks().test_method(); }, 90.98), Benchmark("RandomNumber::MersenneTwisterDescrepancy", [] { QuantLibTest::LowDiscrepancyTest::testMersenneTwisterDiscrepancy().test_method(); }, 951.98), - Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), + Benchmark("RiskStatistics::Results", [] { QuantLibTest::RisktestResults, 300.28), Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) }; diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 544ca3cd895..8faa8355b4b 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,7 +35,6 @@ #endif #include "marketmodel.hpp" -#include "quantooption.hpp" #include "quotes.hpp" #include "rangeaccrual.hpp" #include "riskneutraldensitycalculator.hpp" @@ -89,7 +88,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(QuantoOptionTest::suite()); test->add(QuoteTest::suite()); test->add(RangeAccrualTest::suite()); test->add(RiskStatisticsTest::suite()); @@ -121,7 +119,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(QuantoOptionTest::experimental()); test->add(RiskNeutralDensityCalculatorTest::experimental(speed)); test->add(SpreadOptionTest::suite()); test->add(SquareRootCLVModelTest::experimental()); diff --git a/test-suite/quantooption.cpp b/test-suite/quantooption.cpp index 1b78c08329a..12f2975846e 100644 --- a/test-suite/quantooption.cpp +++ b/test-suite/quantooption.cpp @@ -21,7 +21,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "quantooption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -219,8 +219,11 @@ namespace { }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void QuantoOptionTest::testValues() { +BOOST_AUTO_TEST_SUITE(QuantoOptionTest) + +BOOST_AUTO_TEST_CASE(testValues) { BOOST_TEST_MESSAGE("Testing quanto option values..."); @@ -291,8 +294,7 @@ void QuantoOptionTest::testValues() { } } - -void QuantoOptionTest::testGreeks() { +BOOST_AUTO_TEST_CASE(testGreeks) { BOOST_TEST_MESSAGE("Testing quanto option greeks..."); @@ -487,9 +489,7 @@ void QuantoOptionTest::testGreeks() { } } - - -void QuantoOptionTest::testForwardValues() { +BOOST_AUTO_TEST_CASE(testForwardValues) { BOOST_TEST_MESSAGE("Testing quanto-forward option values..."); @@ -563,8 +563,7 @@ void QuantoOptionTest::testForwardValues() { } } - -void QuantoOptionTest::testForwardGreeks() { +BOOST_AUTO_TEST_CASE(testForwardGreeks) { BOOST_TEST_MESSAGE("Testing quanto-forward option greeks..."); @@ -773,8 +772,7 @@ void QuantoOptionTest::testForwardGreeks() { } } - -void QuantoOptionTest::testForwardPerformanceValues() { +BOOST_AUTO_TEST_CASE(testForwardPerformanceValues) { BOOST_TEST_MESSAGE("Testing quanto-forward-performance option values..."); @@ -852,7 +850,7 @@ void QuantoOptionTest::testForwardPerformanceValues() { } } -void QuantoOptionTest::testBarrierValues() { +BOOST_AUTO_TEST_CASE(testBarrierValues) { BOOST_TEST_MESSAGE("Testing quanto-barrier option values..."); @@ -930,82 +928,7 @@ void QuantoOptionTest::testBarrierValues() { } } -void QuantoOptionTest::testDoubleBarrierValues() { - - BOOST_TEST_MESSAGE("Testing quanto-double-barrier option values..."); - - QuantoDoubleBarrierOptionData values[] = { - // barrierType, bar.lo, bar.hi, rebate, type, spot, strk, q, r, T, vol, fx rate, fx vol, corr, result, tol - { DoubleBarrier::KnockOut, 50.0, 150.0, 0, Option::Call, 100, 100.0, 0.00, 0.1, 0.25, 0.15, 0.05, 0.2, 0.3, 3.4623, 1.0e-4}, - { DoubleBarrier::KnockOut, 90.0, 110.0, 0, Option::Call, 100, 100.0, 0.00, 0.1, 0.50, 0.15, 0.05, 0.2, 0.3, 0.5236, 1.0e-4}, - { DoubleBarrier::KnockOut, 90.0, 110.0, 0, Option::Put, 100, 100.0, 0.00, 0.1, 0.25, 0.15, 0.05, 0.2, 0.3, 1.1320, 1.0e-4}, - { DoubleBarrier::KnockIn, 80.0, 120.0, 0, Option::Call, 100, 102.0, 0.00, 0.1, 0.25, 0.25, 0.05, 0.2, 0.3, 2.6313, 1.0e-4}, - { DoubleBarrier::KnockIn, 80.0, 120.0, 0, Option::Call, 100, 102.0, 0.00, 0.1, 0.50, 0.15, 0.05, 0.2, 0.3, 1.9305, 1.0e-4}, - }; - - DayCounter dc = Actual360(); - Date today = Date::todaysDate(); - - ext::shared_ptr spot(new SimpleQuote(0.0)); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - Handle qTS(flatRate(today, qRate, dc)); - ext::shared_ptr rRate(new SimpleQuote(0.0)); - Handle rTS(flatRate(today, rRate, dc)); - ext::shared_ptr vol(new SimpleQuote(0.0)); - Handle volTS(flatVol(today, vol, dc)); - - ext::shared_ptr fxRate(new SimpleQuote(0.0)); - Handle fxrTS(flatRate(today, fxRate, dc)); - ext::shared_ptr fxVol(new SimpleQuote(0.0)); - Handle fxVolTS(flatVol(today, fxVol, dc)); - ext::shared_ptr correlation(new SimpleQuote(0.0)); - - ext::shared_ptr stochProcess( - new BlackScholesMertonProcess(Handle(spot), - Handle(qTS), - Handle(rTS), - Handle(volTS))); - - ext::shared_ptr engine( - new QuantoEngine( - stochProcess, fxrTS, fxVolTS, - Handle(correlation))); - - for (auto& value : values) { - - ext::shared_ptr payoff(new PlainVanillaPayoff(value.type, value.strike)); - - Date exDate = today + timeToDays(value.t); - ext::shared_ptr exercise(new EuropeanExercise(exDate)); - - spot->setValue(value.s); - qRate->setValue(value.q); - rRate->setValue(value.r); - vol->setValue(value.v); - - fxRate->setValue(value.fxr); - fxVol->setValue(value.fxv); - correlation->setValue(value.corr); - - QuantoDoubleBarrierOption option(value.barrierType, value.barrier_lo, value.barrier_hi, - value.rebate, payoff, exercise); - - option.setPricingEngine(engine); - - Real calculated = option.NPV(); - Real error = std::fabs(calculated - value.result); - Real tolerance = value.tol; - - if (error>tolerance) { - QUANTO_DOUBLE_BARRIER_REPORT_FAILURE( - "value", payoff, value.barrierType, value.barrier_lo, value.barrier_hi, - value.rebate, exercise, value.s, value.q, value.r, today, value.v, value.fxr, - value.fxv, value.corr, value.result, calculated, error, tolerance); - } - } -} - -void QuantoOptionTest::testFDMQuantoHelper() { +BOOST_AUTO_TEST_CASE(testFDMQuantoHelper) { BOOST_TEST_MESSAGE("Testing FDM quanto helper..."); @@ -1098,7 +1021,7 @@ void QuantoOptionTest::testFDMQuantoHelper() { } } -void QuantoOptionTest::testPDEOptionValues() { +BOOST_AUTO_TEST_CASE(testPDEOptionValues) { BOOST_TEST_MESSAGE("Testing quanto-option values with PDEs..."); @@ -1201,7 +1124,7 @@ void QuantoOptionTest::testPDEOptionValues() { } } -void QuantoOptionTest::testAmericanQuantoOption() { +BOOST_AUTO_TEST_CASE(testAmericanQuantoOption) { BOOST_TEST_MESSAGE("Testing American quanto-option values with PDEs..."); @@ -1344,25 +1267,85 @@ void QuantoOptionTest::testAmericanQuantoOption() { } } -test_suite* QuantoOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Quanto option tests"); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testValues)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testGreeks)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testForwardValues)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testForwardGreeks)); - suite->add(QUANTLIB_TEST_CASE( - &QuantoOptionTest::testForwardPerformanceValues)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testBarrierValues)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testFDMQuantoHelper)); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testPDEOptionValues)); - - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testAmericanQuantoOption)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(QuantoOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testDoubleBarrierValues) { + + BOOST_TEST_MESSAGE("Testing quanto-double-barrier option values..."); + + QuantoDoubleBarrierOptionData values[] = { + // barrierType, bar.lo, bar.hi, rebate, type, spot, strk, q, r, T, vol, fx rate, fx vol, corr, result, tol + { DoubleBarrier::KnockOut, 50.0, 150.0, 0, Option::Call, 100, 100.0, 0.00, 0.1, 0.25, 0.15, 0.05, 0.2, 0.3, 3.4623, 1.0e-4}, + { DoubleBarrier::KnockOut, 90.0, 110.0, 0, Option::Call, 100, 100.0, 0.00, 0.1, 0.50, 0.15, 0.05, 0.2, 0.3, 0.5236, 1.0e-4}, + { DoubleBarrier::KnockOut, 90.0, 110.0, 0, Option::Put, 100, 100.0, 0.00, 0.1, 0.25, 0.15, 0.05, 0.2, 0.3, 1.1320, 1.0e-4}, + { DoubleBarrier::KnockIn, 80.0, 120.0, 0, Option::Call, 100, 102.0, 0.00, 0.1, 0.25, 0.25, 0.05, 0.2, 0.3, 2.6313, 1.0e-4}, + { DoubleBarrier::KnockIn, 80.0, 120.0, 0, Option::Call, 100, 102.0, 0.00, 0.1, 0.50, 0.15, 0.05, 0.2, 0.3, 1.9305, 1.0e-4}, + }; + + DayCounter dc = Actual360(); + Date today = Date::todaysDate(); + + ext::shared_ptr spot(new SimpleQuote(0.0)); + ext::shared_ptr qRate(new SimpleQuote(0.0)); + Handle qTS(flatRate(today, qRate, dc)); + ext::shared_ptr rRate(new SimpleQuote(0.0)); + Handle rTS(flatRate(today, rRate, dc)); + ext::shared_ptr vol(new SimpleQuote(0.0)); + Handle volTS(flatVol(today, vol, dc)); + + ext::shared_ptr fxRate(new SimpleQuote(0.0)); + Handle fxrTS(flatRate(today, fxRate, dc)); + ext::shared_ptr fxVol(new SimpleQuote(0.0)); + Handle fxVolTS(flatVol(today, fxVol, dc)); + ext::shared_ptr correlation(new SimpleQuote(0.0)); + + ext::shared_ptr stochProcess( + new BlackScholesMertonProcess(Handle(spot), + Handle(qTS), + Handle(rTS), + Handle(volTS))); -test_suite* QuantoOptionTest::experimental() { - auto* suite = BOOST_TEST_SUITE("Experimental quanto option tests"); - suite->add(QUANTLIB_TEST_CASE(&QuantoOptionTest::testDoubleBarrierValues)); - return suite; + ext::shared_ptr engine( + new QuantoEngine( + stochProcess, fxrTS, fxVolTS, + Handle(correlation))); + + for (auto& value : values) { + + ext::shared_ptr payoff(new PlainVanillaPayoff(value.type, value.strike)); + + Date exDate = today + timeToDays(value.t); + ext::shared_ptr exercise(new EuropeanExercise(exDate)); + + spot->setValue(value.s); + qRate->setValue(value.q); + rRate->setValue(value.r); + vol->setValue(value.v); + + fxRate->setValue(value.fxr); + fxVol->setValue(value.fxv); + correlation->setValue(value.corr); + + QuantoDoubleBarrierOption option(value.barrierType, value.barrier_lo, value.barrier_hi, + value.rebate, payoff, exercise); + + option.setPricingEngine(engine); + + Real calculated = option.NPV(); + Real error = std::fabs(calculated - value.result); + Real tolerance = value.tol; + + if (error>tolerance) { + QUANTO_DOUBLE_BARRIER_REPORT_FAILURE( + "value", payoff, value.barrierType, value.barrier_lo, value.barrier_hi, + value.rebate, exercise, value.s, value.q, value.r, today, value.v, value.fxr, + value.fxv, value.corr, value.result, calculated, error, tolerance); + } + } } +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/quantooption.hpp b/test-suite/quantooption.hpp deleted file mode 100644 index 8f1a520f339..00000000000 --- a/test-suite/quantooption.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004 Ferdinando Ametrano - Copyright (C) 2004 StatPro Italia srl - Copyright (C) 2008 Paul Farrington - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_quanto_option_hpp -#define quantlib_test_quanto_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class QuantoOptionTest { - public: - static void testValues(); - static void testGreeks(); - static void testForwardValues(); - static void testForwardGreeks(); - static void testForwardPerformanceValues(); - static void testBarrierValues(); - static void testDoubleBarrierValues(); - static void testFDMQuantoHelper(); - static void testPDEOptionValues(); - static void testAmericanQuantoOption(); - - static boost::unit_test_framework::test_suite* suite(); - static boost::unit_test_framework::test_suite* experimental(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b53ad47c6b1..133365f4fa1 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -813,7 +813,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index d3b6960a16d..dfeca960a40 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -536,9 +536,6 @@ Header Files - - Header Files - Header Files From 480538b57cff87ee6f42f4fd50dcb8e72e3a2e6d Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 10:22:35 +0800 Subject: [PATCH 034/102] Refactored speedlevel.cpp to preconditions.cpp to group preconditions --- test-suite/CMakeLists.txt | 8 +- test-suite/Makefile.am | 8 +- test-suite/americanoption.cpp | 19 ++-- test-suite/andreasenhugevolatilityinterpl.cpp | 20 ++--- test-suite/asianoptions.cpp | 24 ++--- test-suite/basketoption.cpp | 16 ++-- test-suite/bermudanswaption.cpp | 2 +- test-suite/cashflows.cpp | 11 +-- test-suite/cdo.cpp | 16 ++-- test-suite/dividendoption.cpp | 2 +- test-suite/doublebarrieroption.cpp | 30 +++---- test-suite/fdheston.cpp | 30 +++---- test-suite/fdmlinearop.cpp | 76 ++++++++-------- test-suite/fdsabr.cpp | 4 +- test-suite/forwardoption.cpp | 16 ++-- test-suite/gjrgarchmodel.cpp | 18 ++-- test-suite/hestonmodel.cpp | 4 +- test-suite/hestonslvmodel.cpp | 88 +++++++++---------- test-suite/hybridhestonhullwhiteprocess.cpp | 36 ++++---- test-suite/interpolations.cpp | 2 +- test-suite/libormarketmodel.cpp | 33 ++++--- test-suite/libormarketmodelprocess.cpp | 16 ++-- test-suite/lookbackoptions.cpp | 12 +-- test-suite/marketmodel.hpp | 2 +- test-suite/marketmodel_cms.cpp | 30 +++---- test-suite/marketmodel_smm.cpp | 42 ++++----- test-suite/markovfunctional.cpp | 48 +++++----- test-suite/mclongstaffschwartzengine.cpp | 2 +- test-suite/normalclvmodel.cpp | 6 +- test-suite/nthorderderivativeop.cpp | 15 ++-- test-suite/nthtodefault.cpp | 12 +-- test-suite/optimizers.cpp | 12 +-- test-suite/optionletstripper.cpp | 16 ++-- test-suite/piecewiseyieldcurve.cpp | 11 +-- .../{speedlevel.cpp => preconditions.cpp} | 27 ++---- .../{speedlevel.hpp => preconditions.hpp} | 10 ++- test-suite/quantlibglobalfixture.cpp | 20 +++++ test-suite/quantlibglobalfixture.hpp | 4 +- test-suite/quantlibtestsuite.cpp | 2 +- test-suite/riskneutraldensitycalculator.hpp | 2 +- test-suite/shortratemodels.hpp | 2 +- test-suite/swaption.hpp | 2 +- test-suite/swingoption.hpp | 2 +- test-suite/testsuite.vcxproj | 4 +- test-suite/testsuite.vcxproj.filters | 12 +-- test-suite/vpp.hpp | 2 +- test-suite/zabr.hpp | 2 +- 47 files changed, 382 insertions(+), 396 deletions(-) rename test-suite/{speedlevel.cpp => preconditions.cpp} (65%) rename test-suite/{speedlevel.hpp => preconditions.hpp} (82%) diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9631372f115..5c7dfe14069 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -126,6 +126,7 @@ set(QL_TEST_SOURCES period.cpp piecewiseyieldcurve.cpp piecewisezerospreadedtermstructure.cpp + preconditions.cpp quantlibglobalfixture.cpp quantlibtestsuite.cpp quantooption.cpp @@ -141,7 +142,6 @@ set(QL_TEST_SOURCES shortratemodels.cpp sofrfutures.cpp solvers.cpp - speedlevel.cpp spreadoption.cpp squarerootclvmodel.cpp stats.cpp @@ -176,6 +176,7 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS marketmodel.hpp paralleltestrunner.hpp + preconditions.hpp quantlibglobalfixture.hpp quotes.hpp rangeaccrual.hpp @@ -189,7 +190,6 @@ set(QL_TEST_HEADERS shortratemodels.hpp sofrfutures.hpp solvers.hpp - speedlevel.hpp spreadoption.hpp squarerootclvmodel.hpp stats.hpp @@ -242,11 +242,11 @@ set(QL_BENCHMARK_SOURCES lowdiscrepancysequences.cpp marketmodel_cms.cpp marketmodel_smm.cpp + preconditions.cpp preconditions.hpp quantooption.cpp - quantlibglobalfixture.cpp quantlibglobalfixture.hpp + quantlibglobalfixture.cpp quantlibglobalfixture.hpp riskstats.cpp riskstats.hpp shortratemodels.cpp shortratemodels.hpp - speedlevel.cpp speedlevel.hpp utilities.cpp utilities.hpp swaptionvolstructuresutilities.hpp ) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 3f3bd61616c..1b99fb69d05 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -128,6 +128,7 @@ QL_TEST_SRCS = \ period.cpp \ piecewiseyieldcurve.cpp \ piecewisezerospreadedtermstructure.cpp \ + preconditions.cpp \ quantlibglobalfixture.cpp \ quantooption.cpp \ quotes.cpp \ @@ -142,7 +143,6 @@ QL_TEST_SRCS = \ shortratemodels.cpp \ sofrfutures.cpp \ solvers.cpp \ - speedlevel.cpp \ spreadoption.cpp \ squarerootclvmodel.cpp \ stats.cpp \ @@ -175,6 +175,7 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ marketmodel.hpp \ + preconditions.hpp \ quantlibglobalfixture.hpp \ quotes.hpp \ rangeaccrual.hpp \ @@ -188,7 +189,6 @@ QL_TEST_HDRS = \ shortratemodels.hpp \ sofrfutures.hpp \ solvers.hpp \ - speedlevel.hpp \ spreadoption.hpp \ squarerootclvmodel.hpp \ stats.hpp \ @@ -242,11 +242,11 @@ QL_BENCHMARK_SRCS = \ lowdiscrepancysequences.cpp \ marketmodel_cms.cpp \ marketmodel_smm.cpp \ + preconditions.cpp \ quantlibglobalfixture.cpp \ quantooption.cpp \ riskstats.cpp \ shortratemodels.cpp \ - speedlevel.cpp \ utilities.cpp QL_BENCHMARK_HDRS = \ @@ -254,7 +254,7 @@ QL_BENCHMARK_HDRS = \ quantooption.hpp \ riskstats.hpp \ shortratemodels.hpp \ - speedlevel.hpp \ + preconditions.hpp \ utilities.hpp QL_BENCHMARKS = ${QL_BENCHMARK_SRCS} ${QL_BENCHMARK_HDRS} diff --git a/test-suite/americanoption.cpp b/test-suite/americanoption.cpp index 3c2688f8403..29cafb0ba42 100644 --- a/test-suite/americanoption.cpp +++ b/test-suite/americanoption.cpp @@ -19,31 +19,30 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include -#include -#include #include -#include -#include #include -#include +#include #include +#include +#include #include #include #include #include -#include -#include #include +#include +#include #include #include -#include #include +#include +#include +#include #include - #include using namespace QuantLib; diff --git a/test-suite/andreasenhugevolatilityinterpl.cpp b/test-suite/andreasenhugevolatilityinterpl.cpp index 26973bb8710..7504cb975a4 100644 --- a/test-suite/andreasenhugevolatilityinterpl.cpp +++ b/test-suite/andreasenhugevolatilityinterpl.cpp @@ -17,29 +17,29 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" +#include +#include #include #include #include #include #include -#include -#include -#include -#include #include +#include #include -#include #include #include -#include -#include -#include +#include +#include #include -#include #include +#include +#include +#include +#include #include using namespace QuantLib; diff --git a/test-suite/asianoptions.cpp b/test-suite/asianoptions.cpp index 836e7b452e7..6fd7b845ce3 100644 --- a/test-suite/asianoptions.cpp +++ b/test-suite/asianoptions.cpp @@ -22,28 +22,28 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include +#include #include #include #include -#include -#include -#include -#include -#include +#include +#include #include -#include #include +#include +#include +#include #include #include diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index c9a192ff673..a7c4c4ccd81 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -19,23 +19,23 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include #include -#include +#include +#include #include -#include #include +#include +#include #include #include -#include -#include +#include #include #include -#include +#include +#include #include using namespace QuantLib; diff --git a/test-suite/bermudanswaption.cpp b/test-suite/bermudanswaption.cpp index 90ac0756202..3aacba01342 100644 --- a/test-suite/bermudanswaption.cpp +++ b/test-suite/bermudanswaption.cpp @@ -19,7 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include diff --git a/test-suite/cashflows.cpp b/test-suite/cashflows.cpp index f4a915c7c0a..f303d5da669 100644 --- a/test-suite/cashflows.cpp +++ b/test-suite/cashflows.cpp @@ -17,6 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -41,16 +42,6 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -namespace { - namespace tt = boost::test_tools; - - struct usingAtParCoupons { - tt::assertion_result operator()(test_unit_id) { - return tt::assertion_result(IborCoupon::Settings::instance().usingAtParCoupons()); - } - }; -} - BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(CashFlowTest) diff --git a/test-suite/cdo.cpp b/test-suite/cdo.cpp index b0c9a75a940..362b130610e 100644 --- a/test-suite/cdo.cpp +++ b/test-suite/cdo.cpp @@ -17,24 +17,24 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" +#include #include -#include +#include +#include +#include #include #include +#include #include -#include -#include -#include -#include +#include #include +#include #include #include #include -#include -#include #include #include #include diff --git a/test-suite/dividendoption.cpp b/test-suite/dividendoption.cpp index 31cdea9017c..33e4366eaf0 100644 --- a/test-suite/dividendoption.cpp +++ b/test-suite/dividendoption.cpp @@ -20,7 +20,7 @@ // TODO: Figure out why tests for options with both continuous and discrete // dividends fail. -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include diff --git a/test-suite/doublebarrieroption.cpp b/test-suite/doublebarrieroption.cpp index 79537a3645e..a321fb8d94e 100644 --- a/test-suite/doublebarrieroption.cpp +++ b/test-suite/doublebarrieroption.cpp @@ -18,31 +18,31 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include -#include -#include -#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/fdheston.cpp b/test-suite/fdheston.cpp index 0db15c41067..a1734d9c2d8 100644 --- a/test-suite/fdheston.cpp +++ b/test-suite/fdheston.cpp @@ -18,29 +18,29 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include +#include #include +#include #include -#include -#include -#include -#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include using namespace QuantLib; diff --git a/test-suite/fdmlinearop.cpp b/test-suite/fdmlinearop.cpp index 997de4d8cb7..74e28686660 100644 --- a/test-suite/fdmlinearop.cpp +++ b/test-suite/fdmlinearop.cpp @@ -19,62 +19,60 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include #include -#include +#include +#include +#include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include #include #include #include -#include -#include -#include -#include -#include - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include - +#include #include #include diff --git a/test-suite/fdsabr.cpp b/test-suite/fdsabr.cpp index 50b3ed7c119..20694952fe8 100644 --- a/test-suite/fdsabr.cpp +++ b/test-suite/fdsabr.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include #include using namespace QuantLib; diff --git a/test-suite/forwardoption.cpp b/test-suite/forwardoption.cpp index 9ab88635e12..c1745787c82 100644 --- a/test-suite/forwardoption.cpp +++ b/test-suite/forwardoption.cpp @@ -17,23 +17,23 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include +#include #include #include -#include -#include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include #include +#include +#include +#include #include #include diff --git a/test-suite/gjrgarchmodel.cpp b/test-suite/gjrgarchmodel.cpp index 1891f10a5a7..fa83db070b9 100644 --- a/test-suite/gjrgarchmodel.cpp +++ b/test-suite/gjrgarchmodel.cpp @@ -17,26 +17,26 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include #include +#include #include #include +#include #include #include -#include -#include +#include +#include +#include +#include #include -#include +#include #include +#include #include -#include -#include -#include #include -#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/hestonmodel.cpp b/test-suite/hestonmodel.cpp index ac5287740c9..126e2a32905 100644 --- a/test-suite/hestonmodel.cpp +++ b/test-suite/hestonmodel.cpp @@ -18,17 +18,17 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/test-suite/hestonslvmodel.cpp b/test-suite/hestonslvmodel.cpp index 299f65fc47e..8e69f0b4007 100644 --- a/test-suite/hestonslvmodel.cpp +++ b/test-suite/hestonslvmodel.cpp @@ -18,74 +18,74 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include -#include -#include +#include #include +#include #include #include #include #include +#include +#include +#include #include #include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include -#include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/test-suite/hybridhestonhullwhiteprocess.cpp b/test-suite/hybridhestonhullwhiteprocess.cpp index 765267394eb..de36916343a 100644 --- a/test-suite/hybridhestonhullwhiteprocess.cpp +++ b/test-suite/hybridhestonhullwhiteprocess.cpp @@ -17,40 +17,40 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include #include #include -#include -#include #include +#include +#include +#include #include #include -#include -#include #include -#include #include -#include -#include -#include +#include #include -#include -#include #include #include -#include +#include #include #include -#include -#include +#include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include using namespace QuantLib; diff --git a/test-suite/interpolations.cpp b/test-suite/interpolations.cpp index f2516bbe3dd..d6ef11710d1 100644 --- a/test-suite/interpolations.cpp +++ b/test-suite/interpolations.cpp @@ -22,7 +22,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include diff --git a/test-suite/libormarketmodel.cpp b/test-suite/libormarketmodel.cpp index dc2093c89ed..e6e36a337e3 100644 --- a/test-suite/libormarketmodel.cpp +++ b/test-suite/libormarketmodel.cpp @@ -17,34 +17,33 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include #include #include -#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/libormarketmodelprocess.cpp b/test-suite/libormarketmodelprocess.cpp index da9b0b7b025..ae35163f4c1 100644 --- a/test-suite/libormarketmodelprocess.cpp +++ b/test-suite/libormarketmodelprocess.cpp @@ -17,20 +17,20 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include #include +#include +#include #include +#include +#include +#include #include -#include #include -#include -#include -#include +#include +#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/lookbackoptions.cpp b/test-suite/lookbackoptions.cpp index 325aa82b8ea..8a216d5e894 100644 --- a/test-suite/lookbackoptions.cpp +++ b/test-suite/lookbackoptions.cpp @@ -19,20 +19,20 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include #include -#include #include -#include +#include #include +#include #include -#include +#include #include +#include +#include #include -#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/marketmodel.hpp b/test-suite/marketmodel.hpp index e45ec7dc26f..4421f503849 100644 --- a/test-suite/marketmodel.hpp +++ b/test-suite/marketmodel.hpp @@ -22,9 +22,9 @@ #ifndef quantlib_test_market_model_hpp #define quantlib_test_market_model_hpp +#include "preconditions.hpp" #include #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/marketmodel_cms.cpp b/test-suite/marketmodel_cms.cpp index d6d53956dc5..ae18fbe77f0 100644 --- a/test-suite/marketmodel_cms.cpp +++ b/test-suite/marketmodel_cms.cpp @@ -20,32 +20,32 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include -#include -#include +#include #include -#include +#include +#include #include -#include +#include +#include #include #include -#include -#include +#include #include -#include -#include #include #include diff --git a/test-suite/marketmodel_smm.cpp b/test-suite/marketmodel_smm.cpp index ab752360461..12a87990a46 100644 --- a/test-suite/marketmodel_smm.cpp +++ b/test-suite/marketmodel_smm.cpp @@ -18,37 +18,37 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include #include #include -#include -#include +#include #include -#include -#include -#include #include using namespace QuantLib; diff --git a/test-suite/markovfunctional.cpp b/test-suite/markovfunctional.cpp index e82b49f14cc..13bcb629ad2 100644 --- a/test-suite/markovfunctional.cpp +++ b/test-suite/markovfunctional.cpp @@ -17,40 +17,40 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include #include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/mclongstaffschwartzengine.cpp b/test-suite/mclongstaffschwartzengine.cpp index 898486d5a3b..66eb2d97fa3 100644 --- a/test-suite/mclongstaffschwartzengine.cpp +++ b/test-suite/mclongstaffschwartzengine.cpp @@ -19,7 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include diff --git a/test-suite/normalclvmodel.cpp b/test-suite/normalclvmodel.cpp index f584c7a1038..fdf935a72a1 100644 --- a/test-suite/normalclvmodel.cpp +++ b/test-suite/normalclvmodel.cpp @@ -17,15 +17,14 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include #include #include #include #include +#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/test-suite/nthorderderivativeop.cpp b/test-suite/nthorderderivativeop.cpp index f457e15688c..d0db3130e55 100644 --- a/test-suite/nthorderderivativeop.cpp +++ b/test-suite/nthorderderivativeop.cpp @@ -17,37 +17,34 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" - #include -#include #include #include #include #include #include #include -#include #include +#include #include #include #include #include -#include #include +#include #include #include -#include #include #include +#include #include - +#include #include -#include #include - +#include #include #include diff --git a/test-suite/nthtodefault.cpp b/test-suite/nthtodefault.cpp index ddf6109ec0d..f2929e4d8f1 100644 --- a/test-suite/nthtodefault.cpp +++ b/test-suite/nthtodefault.cpp @@ -17,22 +17,22 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include +#include #include -#include #include +#include #include +#include #include #include -#include +#include #include +#include #include #include -#include -#include #include #include diff --git a/test-suite/optimizers.cpp b/test-suite/optimizers.cpp index 6e34484c1f4..5f8654d82cb 100644 --- a/test-suite/optimizers.cpp +++ b/test-suite/optimizers.cpp @@ -21,19 +21,19 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" -#include -#include -#include -#include #include +#include #include #include -#include #include #include +#include +#include +#include +#include using namespace QuantLib; using namespace boost::unit_test_framework; diff --git a/test-suite/optionletstripper.cpp b/test-suite/optionletstripper.cpp index d9c18f7e287..636acc63aec 100644 --- a/test-suite/optionletstripper.cpp +++ b/test-suite/optionletstripper.cpp @@ -19,22 +19,22 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include #include #include #include -#include -#include -#include -#include -#include #include #include diff --git a/test-suite/piecewiseyieldcurve.cpp b/test-suite/piecewiseyieldcurve.cpp index 60eff290d92..882fcef0501 100644 --- a/test-suite/piecewiseyieldcurve.cpp +++ b/test-suite/piecewiseyieldcurve.cpp @@ -17,6 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -651,16 +652,6 @@ namespace piecewise_yield_curve_test { } -namespace { - namespace tt = boost::test_tools; - - struct usingAtParCoupons { - tt::assertion_result operator()(test_unit_id) { - return tt::assertion_result(IborCoupon::Settings::instance().usingAtParCoupons()); - } - }; -} - BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(PiecewiseYieldCurveTest) diff --git a/test-suite/speedlevel.cpp b/test-suite/preconditions.cpp similarity index 65% rename from test-suite/speedlevel.cpp rename to test-suite/preconditions.cpp index 6283be66c72..7de9827b46a 100644 --- a/test-suite/speedlevel.cpp +++ b/test-suite/preconditions.cpp @@ -17,9 +17,11 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "quantlibglobalfixture.hpp" +#include +using namespace QuantLib; namespace utf = boost::unit_test; namespace tt = boost::test_tools; @@ -31,22 +33,7 @@ tt::assertion_result if_speed::operator()(utf::test_unit_id) { return level; } -SpeedLevel speed_level(int argc, char** argv) { - /*! Again, dead simple parser: - - passing --slow causes all tests to be run; - - passing --fast causes most tests to be run, except the slowest; - - passing --faster causes only the faster tests to be run; - - passing nothing is the same as --slow - */ - - for (int i=1; i @@ -36,6 +36,8 @@ struct if_speed { boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id); }; -SpeedLevel speed_level (int argc, char **argv); +struct usingAtParCoupons { + boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id); +}; -#endif \ No newline at end of file +#endif //quantlib_test_preconditions_hpp \ No newline at end of file diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 6494e02f4f7..9c5cdeb3643 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -147,3 +147,23 @@ SpeedLevel QuantLibGlobalFixture::get_speed() { SpeedLevel QuantLibGlobalFixture::speed = Slow; BOOST_TEST_GLOBAL_FIXTURE(QuantLibGlobalFixture); + +SpeedLevel speed_level(int argc, char** argv) { + /*! Again, dead simple parser: + - passing --slow causes all tests to be run; + - passing --fast causes most tests to be run, except the slowest; + - passing --faster causes only the faster tests to be run; + - passing nothing is the same as --slow +*/ + + for (int i=1; i class QuantLibGlobalFixture { // NOLINT(cppcoreguidelines-special-member-functions) @@ -36,4 +36,6 @@ class QuantLibGlobalFixture { // NOLINT(cppcoreguidelines-special-member-functi decltype(std::chrono::steady_clock::now()) stop; }; +SpeedLevel speed_level (int argc, char **argv); + #endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8faa8355b4b..ec771a9f567 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -35,6 +35,7 @@ #endif #include "marketmodel.hpp" +#include "quantlibglobalfixture.hpp" #include "quotes.hpp" #include "rangeaccrual.hpp" #include "riskneutraldensitycalculator.hpp" @@ -47,7 +48,6 @@ #include "shortratemodels.hpp" #include "sofrfutures.hpp" #include "solvers.hpp" -#include "speedlevel.hpp" #include "spreadoption.hpp" #include "squarerootclvmodel.hpp" #include "stats.hpp" diff --git a/test-suite/riskneutraldensitycalculator.hpp b/test-suite/riskneutraldensitycalculator.hpp index e48b71780b6..69a15c8fe4b 100644 --- a/test-suite/riskneutraldensitycalculator.hpp +++ b/test-suite/riskneutraldensitycalculator.hpp @@ -21,8 +21,8 @@ #ifndef quantlib_test_risk_neutral_density_calculator_hpp #define quantlib_test_risk_neutral_density_calculator_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/shortratemodels.hpp b/test-suite/shortratemodels.hpp index 8adeef7911e..8a7ef7664bd 100644 --- a/test-suite/shortratemodels.hpp +++ b/test-suite/shortratemodels.hpp @@ -20,8 +20,8 @@ #ifndef quantlib_test_short_rate_models_hpp #define quantlib_test_short_rate_models_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/swaption.hpp b/test-suite/swaption.hpp index 1f40f2d9162..66c82895a69 100644 --- a/test-suite/swaption.hpp +++ b/test-suite/swaption.hpp @@ -21,8 +21,8 @@ #ifndef quantlib_test_swaption_hpp #define quantlib_test_swaption_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/swingoption.hpp b/test-suite/swingoption.hpp index 59e96a62bb1..57fc129719d 100644 --- a/test-suite/swingoption.hpp +++ b/test-suite/swingoption.hpp @@ -20,8 +20,8 @@ #ifndef quantlib_test_swing_option_hpp #define quantlib_test_swing_option_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 133365f4fa1..3dd523fe418 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -763,6 +763,7 @@ + @@ -777,7 +778,6 @@ - @@ -812,6 +812,7 @@ + @@ -825,7 +826,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index dfeca960a40..58cce1ad6d4 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -335,6 +335,9 @@ Source Files + + Source Files + Source Files @@ -374,9 +377,6 @@ Source Files - - Source Files - Source Files @@ -533,6 +533,9 @@ Header Files + + Header Files + Header Files @@ -569,9 +572,6 @@ Header Files - - Header Files - Header Files diff --git a/test-suite/vpp.hpp b/test-suite/vpp.hpp index ac500af58e6..018dc61ab3f 100644 --- a/test-suite/vpp.hpp +++ b/test-suite/vpp.hpp @@ -20,8 +20,8 @@ #ifndef quantlib_test_vpp_hpp #define quantlib_test_vpp_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ diff --git a/test-suite/zabr.hpp b/test-suite/zabr.hpp index 5b7ebe4085c..d85f249d914 100644 --- a/test-suite/zabr.hpp +++ b/test-suite/zabr.hpp @@ -20,8 +20,8 @@ #ifndef quantlib_test_zabr_hpp #define quantlib_test_zabr_hpp +#include "preconditions.hpp" #include -#include "speedlevel.hpp" /* remember to document new and/or updated tests in the Doxygen comment block of the corresponding class */ From 778b758dc0a95459188e7290982b28935327ffd2 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 11:42:32 +0800 Subject: [PATCH 035/102] Migrated quotes.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 2 -- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/quotes.cpp | 29 ++++++++------------- test-suite/quotes.hpp | 39 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 11 insertions(+), 66 deletions(-) delete mode 100644 test-suite/quotes.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 5c7dfe14069..89939637384 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - quotes.hpp rangeaccrual.hpp riskneutraldensitycalculator.hpp riskstats.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1b99fb69d05..4ac7a09a26e 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - quotes.hpp \ rangeaccrual.hpp \ riskneutraldensitycalculator.hpp \ riskstats.hpp \ @@ -251,7 +250,6 @@ QL_BENCHMARK_SRCS = \ QL_BENCHMARK_HDRS = \ quantlibglobalfixture.hpp \ - quantooption.hpp \ riskstats.hpp \ shortratemodels.hpp \ preconditions.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index ec771a9f567..9f5fbbab63e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "quotes.hpp" #include "rangeaccrual.hpp" #include "riskneutraldensitycalculator.hpp" #include "riskstats.hpp" @@ -88,7 +87,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(QuoteTest::suite()); test->add(RangeAccrualTest::suite()); test->add(RiskStatisticsTest::suite()); test->add(RngTraitsTest::suite()); diff --git a/test-suite/quotes.cpp b/test-suite/quotes.cpp index 29e33474ab3..779c4eaa632 100644 --- a/test-suite/quotes.cpp +++ b/test-suite/quotes.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "quotes.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -45,8 +45,11 @@ namespace quotes_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void QuoteTest::testObservable() { +BOOST_AUTO_TEST_SUITE(QuoteTest) + +BOOST_AUTO_TEST_CASE(testObservable) { BOOST_TEST_MESSAGE("Testing observability of quotes..."); @@ -60,7 +63,7 @@ void QuoteTest::testObservable() { } -void QuoteTest::testObservableHandle() { +BOOST_AUTO_TEST_CASE(testObservableHandle) { BOOST_TEST_MESSAGE("Testing observability of quote handles..."); @@ -81,7 +84,7 @@ void QuoteTest::testObservableHandle() { } -void QuoteTest::testDerived() { +BOOST_AUTO_TEST_CASE(testDerived) { BOOST_TEST_MESSAGE("Testing derived quotes..."); @@ -102,7 +105,7 @@ void QuoteTest::testDerived() { } } -void QuoteTest::testComposite() { +BOOST_AUTO_TEST_CASE(testComposite) { BOOST_TEST_MESSAGE("Testing composite quotes..."); @@ -122,7 +125,7 @@ void QuoteTest::testComposite() { } } -void QuoteTest::testForwardValueQuoteAndImpliedStdevQuote(){ +BOOST_AUTO_TEST_CASE(testForwardValueQuoteAndImpliedStdevQuote){ BOOST_TEST_MESSAGE( "Testing forward-value and implied-standard-deviation quotes..."); Real forwardRate = .05; @@ -194,16 +197,6 @@ void QuoteTest::testForwardValueQuoteAndImpliedStdevQuote(){ BOOST_FAIL("Observer was not notified of quote change"); } +BOOST_AUTO_TEST_SUITE_END() - -test_suite* QuoteTest::suite() { - auto* suite = BOOST_TEST_SUITE("Quote tests"); - suite->add(QUANTLIB_TEST_CASE(&QuoteTest::testObservable)); - suite->add(QUANTLIB_TEST_CASE(&QuoteTest::testObservableHandle)); - suite->add(QUANTLIB_TEST_CASE(&QuoteTest::testDerived)); - suite->add(QUANTLIB_TEST_CASE(&QuoteTest::testComposite)); - suite->add(QUANTLIB_TEST_CASE( - &QuoteTest::testForwardValueQuoteAndImpliedStdevQuote)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/quotes.hpp b/test-suite/quotes.hpp deleted file mode 100644 index 35e67fed240..00000000000 --- a/test-suite/quotes.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_quotes_hpp -#define quantlib_test_quotes_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class QuoteTest { - public: - static void testObservable(); - static void testObservableHandle(); - static void testDerived(); - static void testComposite(); - static void testForwardValueQuoteAndImpliedStdevQuote(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 3dd523fe418..7214cf21390 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 58cce1ad6d4..e8fa426835f 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 737ffecaabedddd8fe77c20d2dfd1010941a0055 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 11:47:03 +0800 Subject: [PATCH 036/102] Migrated rangeaccrual.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/rangeaccrual.cpp | 27 +++++++++------------ test-suite/rangeaccrual.hpp | 36 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 test-suite/rangeaccrual.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 89939637384..2240c23d5eb 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - rangeaccrual.hpp riskneutraldensitycalculator.hpp riskstats.hpp rngtraits.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 4ac7a09a26e..bc7bb5fdb80 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - rangeaccrual.hpp \ riskneutraldensitycalculator.hpp \ riskstats.hpp \ rngtraits.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 9f5fbbab63e..bf2c0ff8dea 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "rangeaccrual.hpp" #include "riskneutraldensitycalculator.hpp" #include "riskstats.hpp" #include "rngtraits.hpp" @@ -87,7 +86,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(RangeAccrualTest::suite()); test->add(RiskStatisticsTest::suite()); test->add(RngTraitsTest::suite()); test->add(RoundingTest::suite()); diff --git a/test-suite/rangeaccrual.cpp b/test-suite/rangeaccrual.cpp index 96225428796..a31e3de9955 100644 --- a/test-suite/rangeaccrual.cpp +++ b/test-suite/rangeaccrual.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "rangeaccrual.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -586,7 +586,12 @@ namespace range_accrual_test { //******************************************************************************************// //******************************************************************************************// -void RangeAccrualTest::testInfiniteRange() { + +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(RangeAccrualTest) + +BOOST_AUTO_TEST_CASE(testInfiniteRange) { BOOST_TEST_MESSAGE("Testing infinite range accrual floaters..."); @@ -640,7 +645,7 @@ void RangeAccrualTest::testInfiniteRange() { } } -void RangeAccrualTest::testPriceMonotonicityWithRespectToLowerStrike() { +BOOST_AUTO_TEST_CASE(testPriceMonotonicityWithRespectToLowerStrike) { BOOST_TEST_MESSAGE( "Testing price monotonicity with respect to the lower strike..."); @@ -697,8 +702,7 @@ void RangeAccrualTest::testPriceMonotonicityWithRespectToLowerStrike() { } } - -void RangeAccrualTest::testPriceMonotonicityWithRespectToUpperStrike() { +BOOST_AUTO_TEST_CASE(testPriceMonotonicityWithRespectToUpperStrike) { BOOST_TEST_MESSAGE( "Testing price monotonicity with respect to the upper strike..."); @@ -754,15 +758,6 @@ void RangeAccrualTest::testPriceMonotonicityWithRespectToUpperStrike() { } } } +BOOST_AUTO_TEST_SUITE_END() - -test_suite* RangeAccrualTest::suite() { - auto* suite = BOOST_TEST_SUITE("Range Accrual tests"); - suite->add(QUANTLIB_TEST_CASE(&RangeAccrualTest::testInfiniteRange)); - suite->add(QUANTLIB_TEST_CASE( - &RangeAccrualTest::testPriceMonotonicityWithRespectToLowerStrike)); - suite->add(QUANTLIB_TEST_CASE( - &RangeAccrualTest::testPriceMonotonicityWithRespectToUpperStrike)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/rangeaccrual.hpp b/test-suite/rangeaccrual.hpp deleted file mode 100644 index ec941ee8a1b..00000000000 --- a/test-suite/rangeaccrual.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Giorgio Facchinetti - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_range_accrual_hpp -#define quantlib_test_range_accrual_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class RangeAccrualTest { - public: - static void testInfiniteRange(); - static void testPriceMonotonicityWithRespectToLowerStrike(); - static void testPriceMonotonicityWithRespectToUpperStrike(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 7214cf21390..a04734a6a00 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index e8fa426835f..f50c47e0fb8 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 8fc0a0059ebf5ff3e19a0034cc0522aba7dcf29d Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 11:56:16 +0800 Subject: [PATCH 037/102] Migrated riskneutraldensitycalculator.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 - test-suite/riskneutraldensitycalculator.cpp | 46 +++++++-------------- test-suite/riskneutraldensitycalculator.hpp | 42 ------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 15 insertions(+), 81 deletions(-) delete mode 100644 test-suite/riskneutraldensitycalculator.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 2240c23d5eb..d73bd3e2958 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - riskneutraldensitycalculator.hpp riskstats.hpp rngtraits.hpp rounding.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index bc7bb5fdb80..71b03fe264a 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - riskneutraldensitycalculator.hpp \ riskstats.hpp \ rngtraits.hpp \ rounding.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index bf2c0ff8dea..afb524985ba 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "riskneutraldensitycalculator.hpp" #include "riskstats.hpp" #include "rngtraits.hpp" #include "rounding.hpp" @@ -115,7 +114,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(RiskNeutralDensityCalculatorTest::experimental(speed)); test->add(SpreadOptionTest::suite()); test->add(SquareRootCLVModelTest::experimental()); test->add(SviVolatilityTest::experimental()); diff --git a/test-suite/riskneutraldensitycalculator.cpp b/test-suite/riskneutraldensitycalculator.cpp index 02ab101afbc..a30300cacb0 100644 --- a/test-suite/riskneutraldensitycalculator.cpp +++ b/test-suite/riskneutraldensitycalculator.cpp @@ -18,7 +18,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "riskneutraldensitycalculator.hpp" +#include "preconditions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -46,7 +47,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void RiskNeutralDensityCalculatorTest::testDensityAgainstOptionPrices() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(RiskNeutralDensityCalculatorExperimentalTest) + +BOOST_AUTO_TEST_CASE(testDensityAgainstOptionPrices) { BOOST_TEST_MESSAGE("Testing density against option prices..."); const DayCounter dayCounter = Actual365Fixed(); @@ -116,7 +121,7 @@ void RiskNeutralDensityCalculatorTest::testDensityAgainstOptionPrices() { } } -void RiskNeutralDensityCalculatorTest::testBSMagainstHestonRND() { +BOOST_AUTO_TEST_CASE(testBSMagainstHestonRND) { BOOST_TEST_MESSAGE("Testing Black-Scholes-Merton and Heston densities..."); const DayCounter dayCounter = Actual365Fixed(); @@ -279,7 +284,7 @@ namespace { } } -void RiskNeutralDensityCalculatorTest::testLocalVolatilityRND() { +BOOST_AUTO_TEST_CASE(testLocalVolatilityRND) { BOOST_TEST_MESSAGE("Testing Fokker-Planck forward equation " "for local volatility process to calculate " "risk neutral densities..."); @@ -460,7 +465,7 @@ void RiskNeutralDensityCalculatorTest::testLocalVolatilityRND() { } } -void RiskNeutralDensityCalculatorTest::testSquareRootProcessRND() { +BOOST_AUTO_TEST_CASE(testSquareRootProcessRND) { BOOST_TEST_MESSAGE("Testing probability density for a square root process..."); struct SquareRootProcessParams { @@ -551,7 +556,7 @@ void RiskNeutralDensityCalculatorTest::testSquareRootProcessRND() { } } -void RiskNeutralDensityCalculatorTest::testBlackScholesWithSkew() { +BOOST_AUTO_TEST_CASE(testBlackScholesWithSkew, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing probability density for a BSM process " "with strike dependent volatility vs local volatility..."); @@ -703,7 +708,7 @@ void RiskNeutralDensityCalculatorTest::testBlackScholesWithSkew() { } } -void RiskNeutralDensityCalculatorTest::testMassAtZeroCEVProcessRND() { +BOOST_AUTO_TEST_CASE(testMassAtZeroCEVProcessRND) { BOOST_TEST_MESSAGE("Testing the mass at zero for a " "constant elasticity of variance (CEV) process..."); @@ -742,7 +747,7 @@ void RiskNeutralDensityCalculatorTest::testMassAtZeroCEVProcessRND() { } } -void RiskNeutralDensityCalculatorTest::testCEVCDF() { +BOOST_AUTO_TEST_CASE(testCEVCDF) { BOOST_TEST_MESSAGE("Testing CDF for a " "constant elasticity of variance (CEV) process..."); @@ -776,27 +781,6 @@ void RiskNeutralDensityCalculatorTest::testCEVCDF() { } } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* RiskNeutralDensityCalculatorTest::experimental(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Risk neutral density calculator tests"); - - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testDensityAgainstOptionPrices)); - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testBSMagainstHestonRND)); - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testLocalVolatilityRND)); - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testSquareRootProcessRND)); - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testMassAtZeroCEVProcessRND)); - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testCEVCDF)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE( - &RiskNeutralDensityCalculatorTest::testBlackScholesWithSkew)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/riskneutraldensitycalculator.hpp b/test-suite/riskneutraldensitycalculator.hpp deleted file mode 100644 index 69a15c8fe4b..00000000000 --- a/test-suite/riskneutraldensitycalculator.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2015 Johannes Göttker-Schnetmann - Copyright (C) 2015 Klaus Spanderen - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_risk_neutral_density_calculator_hpp -#define quantlib_test_risk_neutral_density_calculator_hpp - -#include "preconditions.hpp" -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class RiskNeutralDensityCalculatorTest { - public: - static void testDensityAgainstOptionPrices(); - static void testBSMagainstHestonRND(); - static void testLocalVolatilityRND(); - static void testSquareRootProcessRND(); - static void testMassAtZeroCEVProcessRND(); - static void testCEVCDF(); - static void testBlackScholesWithSkew(); - static boost::unit_test_framework::test_suite* experimental(SpeedLevel); -}; - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index a04734a6a00..73055fe5ca0 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index f50c47e0fb8..fda57daa1e3 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -647,9 +647,6 @@ Header Files - - Header Files - Header Files From 0e51483a97225f00839fba4c28c0a6f67fac3da0 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 12:00:46 +0800 Subject: [PATCH 038/102] Migrated riskstats.cpp --- test-suite/CMakeLists.txt | 3 +-- test-suite/Makefile.am | 2 -- test-suite/quantlibbenchmark.cpp | 7 +++++- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/riskstats.cpp | 16 ++++++------- test-suite/riskstats.hpp | 35 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 15 insertions(+), 54 deletions(-) delete mode 100644 test-suite/riskstats.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d73bd3e2958..446d5bf09e3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - riskstats.hpp rngtraits.hpp rounding.hpp sampledcurve.hpp @@ -242,7 +241,7 @@ set(QL_BENCHMARK_SOURCES preconditions.cpp preconditions.hpp quantooption.cpp quantlibglobalfixture.cpp quantlibglobalfixture.hpp - riskstats.cpp riskstats.hpp + riskstats.cpp shortratemodels.cpp shortratemodels.hpp utilities.cpp utilities.hpp swaptionvolstructuresutilities.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 71b03fe264a..b4e84a48c94 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - riskstats.hpp \ rngtraits.hpp \ rounding.hpp \ sampledcurve.hpp \ @@ -248,7 +247,6 @@ QL_BENCHMARK_SRCS = \ QL_BENCHMARK_HDRS = \ quantlibglobalfixture.hpp \ - riskstats.hpp \ shortratemodels.hpp \ preconditions.hpp \ utilities.hpp diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index b5f6578cabf..b18d720e4e3 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -239,6 +239,11 @@ namespace QuantLibTest { struct testForwardGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace RiskStatisticsTest { + struct testResults: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -292,7 +297,7 @@ namespace { Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", [] { QuantLibTest::MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions().test_method(); }, 11244.95), Benchmark("QuantoOption::ForwardGreeks", [] { QuantLibTest::QuantoOptionTest::testForwardGreeks().test_method(); }, 90.98), Benchmark("RandomNumber::MersenneTwisterDescrepancy", [] { QuantLibTest::LowDiscrepancyTest::testMersenneTwisterDiscrepancy().test_method(); }, 951.98), - Benchmark("RiskStatistics::Results", [] { QuantLibTest::RisktestResults, 300.28), + Benchmark("RiskStatistics::Results", [] { QuantLibTest::RiskStatisticsTest::testResults().test_method(); }, 300.28), Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) }; diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index afb524985ba..c7d9d455d06 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "riskstats.hpp" #include "rngtraits.hpp" #include "rounding.hpp" #include "sampledcurve.hpp" @@ -85,7 +84,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(RiskStatisticsTest::suite()); test->add(RngTraitsTest::suite()); test->add(RoundingTest::suite()); test->add(SampledCurveTest::suite()); diff --git a/test-suite/riskstats.cpp b/test-suite/riskstats.cpp index 39b0de82d21..bd9b401ed55 100644 --- a/test-suite/riskstats.cpp +++ b/test-suite/riskstats.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "riskstats.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -29,7 +29,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void RiskStatisticsTest::testResults() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(RiskStatisticsTest) + +BOOST_AUTO_TEST_CASE(testResults) { BOOST_TEST_MESSAGE("Testing risk measures..."); @@ -603,10 +607,6 @@ void RiskStatisticsTest::testResults() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* RiskStatisticsTest::suite() { - auto* suite = BOOST_TEST_SUITE("Risk statistics tests"); - suite->add(QUANTLIB_TEST_CASE(&RiskStatisticsTest::testResults)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/riskstats.hpp b/test-suite/riskstats.hpp deleted file mode 100644 index 128e27411fa..00000000000 --- a/test-suite/riskstats.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_risk_statistics_hpp -#define quantlib_test_risk_statistics_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class RiskStatisticsTest { - public: - static void testResults(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 73055fe5ca0..f19fc97eb2a 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index fda57daa1e3..622a836522f 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 1dae1e7dade6c063d8c1646f63b4e85c60049efa Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 13:58:39 +0800 Subject: [PATCH 039/102] Update the header from speedlevel.cpp to preconditions.cpp --- test-suite/lowdiscrepancysequences.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suite/lowdiscrepancysequences.cpp b/test-suite/lowdiscrepancysequences.cpp index fe68c19ca49..7aa80404dbd 100644 --- a/test-suite/lowdiscrepancysequences.cpp +++ b/test-suite/lowdiscrepancysequences.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "speedlevel.hpp" +#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include From 78196198f03d7e0b1ade08d43e7ff17bded95806 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:07:17 +0800 Subject: [PATCH 040/102] Migrated rngtraits.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/rngtraits.cpp | 26 ++++++++----------- test-suite/rngtraits.hpp | 39 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 11 insertions(+), 62 deletions(-) delete mode 100644 test-suite/rngtraits.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 446d5bf09e3..e0cb93de2c6 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - rngtraits.hpp rounding.hpp sampledcurve.hpp schedule.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index b4e84a48c94..82cca52b1c7 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - rngtraits.hpp \ rounding.hpp \ sampledcurve.hpp \ schedule.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index c7d9d455d06..baa533c77c4 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "rngtraits.hpp" #include "rounding.hpp" #include "sampledcurve.hpp" #include "schedule.hpp" @@ -84,7 +83,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(RngTraitsTest::suite()); test->add(RoundingTest::suite()); test->add(SampledCurveTest::suite()); test->add(ScheduleTest::suite()); diff --git a/test-suite/rngtraits.cpp b/test-suite/rngtraits.cpp index 46a62e4b82e..beae2cea772 100644 --- a/test-suite/rngtraits.cpp +++ b/test-suite/rngtraits.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "rngtraits.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -27,7 +27,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void RngTraitsTest::testGaussian() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(RngTraitsTest) + +BOOST_AUTO_TEST_CASE(testGaussian) { BOOST_TEST_MESSAGE("Testing Gaussian pseudo-random number generation..."); @@ -47,8 +51,7 @@ void RngTraitsTest::testGaussian() { << " expected: " << stored); } - -void RngTraitsTest::testDefaultPoisson() { +BOOST_AUTO_TEST_CASE(testDefaultPoisson) { BOOST_TEST_MESSAGE("Testing Poisson pseudo-random number generation..."); @@ -69,8 +72,7 @@ void RngTraitsTest::testDefaultPoisson() { << " expected: " << stored); } - -void RngTraitsTest::testCustomPoisson() { +BOOST_AUTO_TEST_CASE(testCustomPoisson) { BOOST_TEST_MESSAGE("Testing custom Poisson pseudo-random number generation..."); @@ -92,7 +94,7 @@ void RngTraitsTest::testCustomPoisson() { << " expected: " << stored); } -void RngTraitsTest::testRanLux() { +BOOST_AUTO_TEST_CASE(testRanLux) { BOOST_TEST_MESSAGE("Testing known RanLux sequence..."); Ranlux3UniformRng ranlux3(2938723U); @@ -126,12 +128,6 @@ void RngTraitsTest::testRanLux() { } } -test_suite* RngTraitsTest::suite() { - auto* suite = BOOST_TEST_SUITE("RNG traits tests"); - suite->add(QUANTLIB_TEST_CASE(&RngTraitsTest::testGaussian)); - suite->add(QUANTLIB_TEST_CASE(&RngTraitsTest::testDefaultPoisson)); - suite->add(QUANTLIB_TEST_CASE(&RngTraitsTest::testCustomPoisson)); - suite->add(QUANTLIB_TEST_CASE(&RngTraitsTest::testRanLux)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/rngtraits.hpp b/test-suite/rngtraits.hpp deleted file mode 100644 index ca27b71d4cb..00000000000 --- a/test-suite/rngtraits.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004 StatPro Italia srl - Copyright (C) 2004 Walter Penschke - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_rng_traits_hpp -#define quantlib_test_rng_traits_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class RngTraitsTest { - public: - static void testGaussian(); - static void testDefaultPoisson(); - static void testCustomPoisson(); - static void testRanLux(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f19fc97eb2a..d24f2b21573 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 622a836522f..2c0119e6818 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From afea3c8ef403fdb06117bc919b0d1119dfa00504 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:09:34 +0800 Subject: [PATCH 041/102] Migrated rounding.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/rounding.cpp | 27 ++++++++----------- test-suite/rounding.hpp | 39 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 11 insertions(+), 63 deletions(-) delete mode 100644 test-suite/rounding.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index e0cb93de2c6..2abbfc33d7e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - rounding.hpp sampledcurve.hpp schedule.hpp settings.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 82cca52b1c7..e115c139cc5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - rounding.hpp \ sampledcurve.hpp \ schedule.hpp \ settings.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index baa533c77c4..2b378499e65 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "rounding.hpp" #include "sampledcurve.hpp" #include "schedule.hpp" #include "settings.hpp" @@ -83,7 +82,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(RoundingTest::suite()); test->add(SampledCurveTest::suite()); test->add(ScheduleTest::suite()); test->add(SettingsTest::suite()); diff --git a/test-suite/rounding.cpp b/test-suite/rounding.cpp index 80afb623b7a..97f318ff65e 100644 --- a/test-suite/rounding.cpp +++ b/test-suite/rounding.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "rounding.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -63,8 +63,11 @@ namespace rounding_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void RoundingTest::testClosest() { +BOOST_AUTO_TEST_SUITE(RoundingTest) + +BOOST_AUTO_TEST_CASE(testClosest) { BOOST_TEST_MESSAGE("Testing closest decimal rounding..."); @@ -83,7 +86,7 @@ void RoundingTest::testClosest() { } } -void RoundingTest::testUp() { +BOOST_AUTO_TEST_CASE(testUp) { BOOST_TEST_MESSAGE("Testing upward decimal rounding..."); @@ -102,7 +105,7 @@ void RoundingTest::testUp() { } } -void RoundingTest::testDown() { +BOOST_AUTO_TEST_CASE(testDown) { BOOST_TEST_MESSAGE("Testing downward decimal rounding..."); @@ -121,7 +124,7 @@ void RoundingTest::testDown() { } } -void RoundingTest::testFloor() { +BOOST_AUTO_TEST_CASE(testFloor) { BOOST_TEST_MESSAGE("Testing floor decimal rounding..."); @@ -140,7 +143,7 @@ void RoundingTest::testFloor() { } } -void RoundingTest::testCeiling() { +BOOST_AUTO_TEST_CASE(testCeiling) { BOOST_TEST_MESSAGE("Testing ceiling decimal rounding..."); @@ -159,14 +162,6 @@ void RoundingTest::testCeiling() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* RoundingTest::suite() { - auto* suite = BOOST_TEST_SUITE("Rounding tests"); - suite->add(QUANTLIB_TEST_CASE(&RoundingTest::testClosest)); - suite->add(QUANTLIB_TEST_CASE(&RoundingTest::testUp)); - suite->add(QUANTLIB_TEST_CASE(&RoundingTest::testDown)); - suite->add(QUANTLIB_TEST_CASE(&RoundingTest::testFloor)); - suite->add(QUANTLIB_TEST_CASE(&RoundingTest::testCeiling)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/rounding.hpp b/test-suite/rounding.hpp deleted file mode 100644 index 5ea218d86ae..00000000000 --- a/test-suite/rounding.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_rounding_hpp -#define quantlib_test_rounding_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class RoundingTest { - public: - static void testClosest(); - static void testUp(); - static void testDown(); - static void testFloor(); - static void testCeiling(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index d24f2b21573..dee4eeca89a 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 2c0119e6818..ced1ae7d215 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From e13073925b1eec895ec5f1a5f22285b806441919 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:37:44 +0800 Subject: [PATCH 042/102] Migrated sampledcurve.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/sampledcurve.cpp | 15 ++++++------ test-suite/sampledcurve.hpp | 35 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 test-suite/sampledcurve.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 2abbfc33d7e..1968a7d7820 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - sampledcurve.hpp schedule.hpp settings.hpp shortratemodels.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e115c139cc5..c32d606e6f7 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - sampledcurve.hpp \ schedule.hpp \ settings.hpp \ shortratemodels.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2b378499e65..3bebdd97d49 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "sampledcurve.hpp" #include "schedule.hpp" #include "settings.hpp" #include "shortratemodels.hpp" @@ -82,7 +81,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(SampledCurveTest::suite()); test->add(ScheduleTest::suite()); test->add(SettingsTest::suite()); test->add(ShortRateModelTest::suite(speed)); // fails with QL_USE_INDEXED_COUPON diff --git a/test-suite/sampledcurve.cpp b/test-suite/sampledcurve.cpp index d87d43f7103..9772740fac6 100644 --- a/test-suite/sampledcurve.cpp +++ b/test-suite/sampledcurve.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "sampledcurve.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -35,7 +35,11 @@ namespace sampled_curve_test { QL_DEPRECATED_DISABLE_WARNING -void SampledCurveTest::testConstruction() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(SampledCurveTest) + +BOOST_AUTO_TEST_CASE(testConstruction) { BOOST_TEST_MESSAGE("Testing sampled curve construction..."); @@ -86,9 +90,6 @@ void SampledCurveTest::testConstruction() { QL_DEPRECATED_ENABLE_WARNING -test_suite* SampledCurveTest::suite() { - auto* suite = BOOST_TEST_SUITE("sampled curve tests"); - suite->add(QUANTLIB_TEST_CASE(&SampledCurveTest::testConstruction)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/sampledcurve.hpp b/test-suite/sampledcurve.hpp deleted file mode 100644 index 50f18b6552f..00000000000 --- a/test-suite/sampledcurve.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_sampled_curve_hpp -#define quantlib_test_sampled_curve_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class SampledCurveTest { - public: - static void testConstruction(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index dee4eeca89a..3eda06e80c4 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index ced1ae7d215..9dc3de7bd51 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 0edee520c9b92df6a594c2dd497f5b327e0853aa Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:43:50 +0800 Subject: [PATCH 043/102] Migrated schedule.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 - test-suite/schedule.cpp | 93 ++++++++++------------------ test-suite/schedule.hpp | 59 ------------------ test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 32 insertions(+), 128 deletions(-) delete mode 100644 test-suite/schedule.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 1968a7d7820..d8d1385e06e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - schedule.hpp settings.hpp shortratemodels.hpp sofrfutures.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c32d606e6f7..da0024604f3 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - schedule.hpp \ settings.hpp \ shortratemodels.hpp \ sofrfutures.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 3bebdd97d49..39922d55d86 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "schedule.hpp" #include "settings.hpp" #include "shortratemodels.hpp" #include "sofrfutures.hpp" @@ -81,7 +80,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(ScheduleTest::suite()); test->add(SettingsTest::suite()); test->add(ShortRateModelTest::suite(speed)); // fails with QL_USE_INDEXED_COUPON test->add(SofrFuturesTest::suite()); diff --git a/test-suite/schedule.cpp b/test-suite/schedule.cpp index ef8b08602f1..4f439473aa7 100644 --- a/test-suite/schedule.cpp +++ b/test-suite/schedule.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "schedule.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -56,8 +56,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void ScheduleTest::testDailySchedule() { +BOOST_AUTO_TEST_SUITE(ScheduleTest) + +BOOST_AUTO_TEST_CASE(testDailySchedule) { BOOST_TEST_MESSAGE("Testing schedule with daily frequency..."); Date startDate = Date(17,January,2012); @@ -82,7 +85,7 @@ void ScheduleTest::testDailySchedule() { check_dates(s, expected); } -void ScheduleTest::testEndDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testEndDateWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing end date for schedule with end-of-month adjustment..."); @@ -108,8 +111,7 @@ void ScheduleTest::testEndDateWithEomAdjustment() { check_dates(s, expected); } - -void ScheduleTest::testDatesPastEndDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testDatesPastEndDateWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing that no dates are past the end date with EOM adjustment..."); @@ -137,7 +139,7 @@ void ScheduleTest::testDatesPastEndDateWithEomAdjustment() { BOOST_ERROR("last period should not be regular"); } -void ScheduleTest::testDatesSameAsEndDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testDatesSameAsEndDateWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing that next-to-last date same as end date is removed..."); @@ -165,7 +167,7 @@ void ScheduleTest::testDatesSameAsEndDateWithEomAdjustment() { BOOST_ERROR("last period should be regular"); } -void ScheduleTest::testForwardDatesWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testForwardDatesWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing that the last date is not adjusted for EOM when " "termination date convention is unadjusted..."); @@ -189,7 +191,7 @@ void ScheduleTest::testForwardDatesWithEomAdjustment() { check_dates(s, expected); } -void ScheduleTest::testBackwardDatesWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testBackwardDatesWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing that the first date is not adjusted for EOM " "going backward when termination date convention is unadjusted..."); @@ -213,7 +215,7 @@ void ScheduleTest::testBackwardDatesWithEomAdjustment() { check_dates(s, expected); } -void ScheduleTest::testDoubleFirstDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testDoubleFirstDateWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing that the first date is not duplicated due to " "EOM convention when going backwards..."); @@ -237,7 +239,7 @@ void ScheduleTest::testDoubleFirstDateWithEomAdjustment() { check_dates(s, expected); } -void ScheduleTest::testFirstDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testFirstDateWithEomAdjustment) { BOOST_TEST_MESSAGE("Testing schedule with first date and EOM adjustments..."); Schedule schedule = MakeSchedule() @@ -261,7 +263,7 @@ void ScheduleTest::testFirstDateWithEomAdjustment() { check_dates(schedule, expected); } -void ScheduleTest::testNextToLastWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testNextToLastWithEomAdjustment) { BOOST_TEST_MESSAGE("Testing schedule with next to last date and EOM adjustments..."); Schedule schedule = MakeSchedule() @@ -286,7 +288,7 @@ void ScheduleTest::testNextToLastWithEomAdjustment() { check_dates(schedule, expected); } -void ScheduleTest::testEffectiveDateWithEomAdjustment() { +BOOST_AUTO_TEST_CASE(testEffectiveDateWithEomAdjustment) { BOOST_TEST_MESSAGE( "Testing forward schedule with EOM adjustment and effective date and first date in the same month..."); @@ -350,7 +352,7 @@ namespace CdsTests { } } -void ScheduleTest::testCDS2015Convention() { +BOOST_AUTO_TEST_CASE(testCDS2015Convention) { using CdsTests::makeCdsSchedule; @@ -407,7 +409,7 @@ void ScheduleTest::testCDS2015Convention() { BOOST_CHECK_EQUAL(s.endDate(), expMaturity); } -void ScheduleTest::testCDS2015ConventionGrid() { +BOOST_AUTO_TEST_CASE(testCDS2015ConventionGrid) { using CdsTests::InputData; @@ -492,7 +494,7 @@ void ScheduleTest::testCDS2015ConventionGrid() { CdsTests::testCDSConventions(inputs, DateGeneration::CDS2015); } -void ScheduleTest::testCDSConventionGrid() { +BOOST_AUTO_TEST_CASE(testCDSConventionGrid) { using CdsTests::InputData; @@ -583,7 +585,7 @@ void ScheduleTest::testCDSConventionGrid() { CdsTests::testCDSConventions(inputs, DateGeneration::CDS); } -void ScheduleTest::testOldCDSConventionGrid() { +BOOST_AUTO_TEST_CASE(testOldCDSConventionGrid) { using CdsTests::InputData; @@ -662,7 +664,7 @@ void ScheduleTest::testOldCDSConventionGrid() { CdsTests::testCDSConventions(inputs, DateGeneration::OldCDS); } -void ScheduleTest::testCDS2015ConventionSampleDates() { +BOOST_AUTO_TEST_CASE(testCDS2015ConventionSampleDates) { BOOST_TEST_MESSAGE("Testing all dates in sample CDS schedule(s) for rule CDS2015..."); @@ -725,7 +727,7 @@ void ScheduleTest::testCDS2015ConventionSampleDates() { check_dates(s, expDates); } -void ScheduleTest::testCDSConventionSampleDates() { +BOOST_AUTO_TEST_CASE(testCDSConventionSampleDates) { BOOST_TEST_MESSAGE("Testing all dates in sample CDS schedule(s) for rule CDS..."); @@ -785,7 +787,7 @@ void ScheduleTest::testCDSConventionSampleDates() { check_dates(s, expDates); } -void ScheduleTest::testOldCDSConventionSampleDates() { +BOOST_AUTO_TEST_CASE(testOldCDSConventionSampleDates) { BOOST_TEST_MESSAGE("Testing all dates in sample CDS schedule(s) for rule OldCDS..."); @@ -847,7 +849,7 @@ void ScheduleTest::testOldCDSConventionSampleDates() { check_dates(s, expDates); } -void ScheduleTest::testCDS2015ZeroMonthsMatured() { +BOOST_AUTO_TEST_CASE(testCDS2015ZeroMonthsMatured) { BOOST_TEST_MESSAGE("Testing 0M tenor for CDS2015 where matured..."); @@ -870,7 +872,7 @@ void ScheduleTest::testCDS2015ZeroMonthsMatured() { } } -void ScheduleTest::testDateConstructor() { +BOOST_AUTO_TEST_CASE(testDateConstructor) { BOOST_TEST_MESSAGE("Testing the constructor taking a vector of dates and " "possibly additional meta information..."); @@ -927,7 +929,7 @@ void ScheduleTest::testDateConstructor() { BOOST_ERROR("schedule2 has end of month flag false, expected true"); } -void ScheduleTest::testFourWeeksTenor() { +BOOST_AUTO_TEST_CASE(testFourWeeksTenor) { BOOST_TEST_MESSAGE( "Testing that a four-weeks tenor works..."); @@ -944,7 +946,7 @@ void ScheduleTest::testFourWeeksTenor() { } } -void ScheduleTest::testScheduleAlwaysHasAStartDate() { +BOOST_AUTO_TEST_CASE(testScheduleAlwaysHasAStartDate) { BOOST_TEST_MESSAGE("Testing that variations of MakeSchedule " "always produce a schedule with a start date..."); // Attempt to establish whether the first coupoun payment date is @@ -980,7 +982,7 @@ void ScheduleTest::testScheduleAlwaysHasAStartDate() { "The first element should always be the start date"); } -void ScheduleTest::testShortEomSchedule() { +BOOST_AUTO_TEST_CASE(testShortEomSchedule) { BOOST_TEST_MESSAGE("Testing short end-of-month schedule..."); Schedule s; // seg-faults in 1.15 @@ -998,7 +1000,7 @@ void ScheduleTest::testShortEomSchedule() { BOOST_CHECK(s[1] == Date(28, Feb, 2019)); } -void ScheduleTest::testFirstDateOnMaturity() { +BOOST_AUTO_TEST_CASE(testFirstDateOnMaturity) { BOOST_TEST_MESSAGE("Testing schedule with first date on maturity..."); Schedule schedule = MakeSchedule() .from(Date(20, September, 2016)) @@ -1027,7 +1029,7 @@ void ScheduleTest::testFirstDateOnMaturity() { check_dates(schedule, expected); } -void ScheduleTest::testNextToLastDateOnStart() { +BOOST_AUTO_TEST_CASE(testNextToLastDateOnStart) { BOOST_TEST_MESSAGE("Testing schedule with next-to-last date on start date..."); Schedule schedule = MakeSchedule() .from(Date(20, September, 2016)) @@ -1056,7 +1058,7 @@ void ScheduleTest::testNextToLastDateOnStart() { check_dates(schedule, expected); } -void ScheduleTest::testTruncation() { +BOOST_AUTO_TEST_CASE(testTruncation) { BOOST_TEST_MESSAGE("Testing schedule truncation..."); Schedule s = MakeSchedule().from(Date(30, September, 2009)) .to(Date(15, June, 2020)) @@ -1134,37 +1136,6 @@ void ScheduleTest::testTruncation() { BOOST_CHECK(t.isRegular().front() == true); } -test_suite* ScheduleTest::suite() { - auto* suite = BOOST_TEST_SUITE("Schedule tests"); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testDailySchedule)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testEndDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE( - &ScheduleTest::testDatesPastEndDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE( - &ScheduleTest::testDatesSameAsEndDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE( - &ScheduleTest::testForwardDatesWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE( - &ScheduleTest::testBackwardDatesWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE( - &ScheduleTest::testDoubleFirstDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testFirstDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testNextToLastWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testEffectiveDateWithEomAdjustment)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDS2015Convention)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDS2015ConventionGrid)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDSConventionGrid)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testOldCDSConventionGrid)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDS2015ConventionSampleDates)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDSConventionSampleDates)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testOldCDSConventionSampleDates)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testCDS2015ZeroMonthsMatured)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testDateConstructor)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testFourWeeksTenor)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testScheduleAlwaysHasAStartDate)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testShortEomSchedule)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testFirstDateOnMaturity)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testNextToLastDateOnStart)); - suite->add(QUANTLIB_TEST_CASE(&ScheduleTest::testTruncation)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/schedule.hpp b/test-suite/schedule.hpp deleted file mode 100644 index acef3da0539..00000000000 --- a/test-suite/schedule.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2012 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_schedule_hpp -#define quantlib_test_schedule_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ScheduleTest { - public: - static void testDailySchedule(); - static void testEndDateWithEomAdjustment(); - static void testDatesPastEndDateWithEomAdjustment(); - static void testDatesSameAsEndDateWithEomAdjustment(); - static void testForwardDatesWithEomAdjustment(); - static void testBackwardDatesWithEomAdjustment(); - static void testDoubleFirstDateWithEomAdjustment(); - static void testFirstDateWithEomAdjustment(); - static void testNextToLastWithEomAdjustment(); - static void testEffectiveDateWithEomAdjustment(); - static void testCDS2015Convention(); - static void testCDS2015ConventionGrid(); - static void testCDSConventionGrid(); - static void testOldCDSConventionGrid(); - static void testCDS2015ConventionSampleDates(); - static void testCDSConventionSampleDates(); - static void testOldCDSConventionSampleDates(); - static void testCDS2015ZeroMonthsMatured(); - static void testDateConstructor(); - static void testFourWeeksTenor(); - static void testScheduleAlwaysHasAStartDate(); - static void testShortEomSchedule(); - static void testFirstDateOnMaturity(); - static void testNextToLastDateOnStart(); - static void testTruncation(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 3eda06e80c4..6dceaa70e73 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 9dc3de7bd51..c123a686873 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From ac1b5599571a29346896e64cc4d9f40ef6e79400 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:48:32 +0800 Subject: [PATCH 044/102] Migrated settings.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/settings.cpp | 15 ++++++------ test-suite/settings.hpp | 35 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 test-suite/settings.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d8d1385e06e..957865a74d6 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - settings.hpp shortratemodels.hpp sofrfutures.hpp solvers.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index da0024604f3..9e25048ac36 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - settings.hpp \ shortratemodels.hpp \ sofrfutures.hpp \ solvers.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 39922d55d86..f4ee7eef4cb 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "settings.hpp" #include "shortratemodels.hpp" #include "sofrfutures.hpp" #include "solvers.hpp" @@ -80,7 +79,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(SettingsTest::suite()); test->add(ShortRateModelTest::suite(speed)); // fails with QL_USE_INDEXED_COUPON test->add(SofrFuturesTest::suite()); test->add(Solver1DTest::suite()); diff --git a/test-suite/settings.cpp b/test-suite/settings.cpp index 433c3f5101d..8a9354724a9 100644 --- a/test-suite/settings.cpp +++ b/test-suite/settings.cpp @@ -17,15 +17,18 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "settings.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include using namespace QuantLib; using namespace boost::unit_test_framework; +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void SettingsTest::testNotificationsOnDateChange() { +BOOST_AUTO_TEST_SUITE(SettingsTest) + +BOOST_AUTO_TEST_CASE(testNotificationsOnDateChange) { BOOST_TEST_MESSAGE("Testing notifications on evaluation-date change..."); #ifdef QL_HIGH_RESOLUTION_DATE @@ -58,8 +61,6 @@ void SettingsTest::testNotificationsOnDateChange() { BOOST_ERROR("missing notification"); } -test_suite* SettingsTest::suite() { - auto* suite = BOOST_TEST_SUITE("SettingsTest tests"); - suite->add(QUANTLIB_TEST_CASE(&SettingsTest::testNotificationsOnDateChange)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/settings.hpp b/test-suite/settings.hpp deleted file mode 100644 index b1543e12e2b..00000000000 --- a/test-suite/settings.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2021 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_settings_hpp -#define quantlib_test_settings_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class SettingsTest { - public: - static void testNotificationsOnDateChange(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 6dceaa70e73..0fe209b3851 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index c123a686873..7c5bad16f5d 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 5040d98edcc52a51f87ebd98fafac5161979981e Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 14:57:05 +0800 Subject: [PATCH 045/102] Migrated shortratemodels.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 2 -- test-suite/quantlibbenchmark.cpp | 8 ++++-- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/shortratemodels.cpp | 34 +++++++++-------------- test-suite/shortratemodels.hpp | 41 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 20 insertions(+), 74 deletions(-) delete mode 100644 test-suite/shortratemodels.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 957865a74d6..b422d8b8fc1 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - shortratemodels.hpp sofrfutures.hpp solvers.hpp spreadoption.hpp @@ -237,7 +236,7 @@ set(QL_BENCHMARK_SOURCES quantooption.cpp quantlibglobalfixture.cpp quantlibglobalfixture.hpp riskstats.cpp - shortratemodels.cpp shortratemodels.hpp + shortratemodels.cpp utilities.cpp utilities.hpp swaptionvolstructuresutilities.hpp ) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 9e25048ac36..f3a6ff76071 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - shortratemodels.hpp \ sofrfutures.hpp \ solvers.hpp \ spreadoption.hpp \ @@ -242,7 +241,6 @@ QL_BENCHMARK_SRCS = \ QL_BENCHMARK_HDRS = \ quantlibglobalfixture.hpp \ - shortratemodels.hpp \ preconditions.hpp \ utilities.hpp diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index b18d720e4e3..a85af77d941 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "shortratemodels.hpp" namespace QuantLibTest { namespace AmericanOptionTest { @@ -244,6 +243,11 @@ namespace QuantLibTest { struct testResults: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace ShortRateModelTest { + struct testSwaps: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -298,7 +302,7 @@ namespace { Benchmark("QuantoOption::ForwardGreeks", [] { QuantLibTest::QuantoOptionTest::testForwardGreeks().test_method(); }, 90.98), Benchmark("RandomNumber::MersenneTwisterDescrepancy", [] { QuantLibTest::LowDiscrepancyTest::testMersenneTwisterDiscrepancy().test_method(); }, 951.98), Benchmark("RiskStatistics::Results", [] { QuantLibTest::RiskStatisticsTest::testResults().test_method(); }, 300.28), - Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) + Benchmark("ShortRateModel::Swaps", [] { QuantLibTest::ShortRateModelTest::testSwaps().test_method(); }, 454.73) }; /* PAPI code diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f4ee7eef4cb..8a225b8c77f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "shortratemodels.hpp" #include "sofrfutures.hpp" #include "solvers.hpp" #include "spreadoption.hpp" @@ -79,7 +78,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(ShortRateModelTest::suite(speed)); // fails with QL_USE_INDEXED_COUPON test->add(SofrFuturesTest::suite()); test->add(Solver1DTest::suite()); test->add(StatisticsTest::suite()); diff --git a/test-suite/shortratemodels.cpp b/test-suite/shortratemodels.cpp index 777170b8100..eb08b567162 100644 --- a/test-suite/shortratemodels.cpp +++ b/test-suite/shortratemodels.cpp @@ -21,7 +21,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "shortratemodels.hpp" +#include "preconditions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -54,8 +55,11 @@ namespace short_rate_models_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void ShortRateModelTest::testCachedHullWhite() { +BOOST_AUTO_TEST_SUITE(ShortRateModelTest) // fails with QL_USE_INDEXED_COUPON + +BOOST_AUTO_TEST_CASE(testCachedHullWhite) { BOOST_TEST_MESSAGE("Testing Hull-White calibration against cached values using swaptions with start delay..."); using namespace short_rate_models_test; @@ -129,7 +133,7 @@ void ShortRateModelTest::testCachedHullWhite() { } } -void ShortRateModelTest::testCachedHullWhiteFixedReversion() { +BOOST_AUTO_TEST_CASE(testCachedHullWhiteFixedReversion) { BOOST_TEST_MESSAGE("Testing Hull-White calibration with fixed reversion against cached values..."); using namespace short_rate_models_test; @@ -205,8 +209,7 @@ void ShortRateModelTest::testCachedHullWhiteFixedReversion() { } } - -void ShortRateModelTest::testCachedHullWhite2() { +BOOST_AUTO_TEST_CASE(testCachedHullWhite2) { BOOST_TEST_MESSAGE("Testing Hull-White calibration against cached " "values using swaptions without start delay..."); @@ -287,7 +290,7 @@ void ShortRateModelTest::testCachedHullWhite2() { } } -void ShortRateModelTest::testSwaps() { +BOOST_AUTO_TEST_CASE(testSwaps) { BOOST_TEST_MESSAGE("Testing Hull-White swap pricing against known values..."); bool usingAtParCoupons = IborCoupon::Settings::instance().usingAtParCoupons(); @@ -389,7 +392,7 @@ void ShortRateModelTest::testSwaps() { } } -void ShortRateModelTest::testFuturesConvexityBias() { +BOOST_AUTO_TEST_CASE(testFuturesConvexityBias) { BOOST_TEST_MESSAGE("Testing Hull-White futures convexity bias..."); // G. Kirikos, D. Novak, "Convexity Conundrums", Risk Magazine, March 1997 @@ -418,7 +421,7 @@ void ShortRateModelTest::testFuturesConvexityBias() { } } -void ShortRateModelTest::testExtendedCoxIngersollRossDiscountFactor() { +BOOST_AUTO_TEST_CASE(testExtendedCoxIngersollRossDiscountFactor) { BOOST_TEST_MESSAGE("Testing zero-bond pricing for extended CIR model..."); const Date today = Settings::instance().evaluationDate(); @@ -447,17 +450,6 @@ void ShortRateModelTest::testExtendedCoxIngersollRossDiscountFactor() { << "\n tolerance : " << tol); } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* ShortRateModelTest::suite(SpeedLevel) { - auto* suite = BOOST_TEST_SUITE("Short-rate model tests"); - - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testCachedHullWhite)); - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testCachedHullWhiteFixedReversion)); - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testCachedHullWhite2)); - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testFuturesConvexityBias)); - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testExtendedCoxIngersollRossDiscountFactor)); - suite->add(QUANTLIB_TEST_CASE(&ShortRateModelTest::testSwaps)); - - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/shortratemodels.hpp b/test-suite/shortratemodels.hpp deleted file mode 100644 index 8a7ef7664bd..00000000000 --- a/test-suite/shortratemodels.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_short_rate_models_hpp -#define quantlib_test_short_rate_models_hpp - -#include "preconditions.hpp" -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ShortRateModelTest { - public: - static void testFuturesConvexityBias(); - static void testCachedHullWhite(); - static void testCachedHullWhiteFixedReversion(); - static void testCachedHullWhite2(); - static void testSwaps(); - static void testExtendedCoxIngersollRossDiscountFactor(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0fe209b3851..cb8fbc39a23 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 7c5bad16f5d..358b2cb69af 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From f3b201d2129afd5b3f7838c4d936423aea20beda Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 15:02:38 +0800 Subject: [PATCH 046/102] Migrated sofrfutures.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/sofrfutures.cpp | 16 ++++++-------- test-suite/sofrfutures.hpp | 32 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 test-suite/sofrfutures.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index b422d8b8fc1..162d63e5d49 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - sofrfutures.hpp solvers.hpp spreadoption.hpp squarerootclvmodel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index f3a6ff76071..cef34431912 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - sofrfutures.hpp \ solvers.hpp \ spreadoption.hpp \ squarerootclvmodel.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8a225b8c77f..fd136fbe8e6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "sofrfutures.hpp" #include "solvers.hpp" #include "spreadoption.hpp" #include "squarerootclvmodel.hpp" @@ -78,7 +77,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(SofrFuturesTest::suite()); test->add(Solver1DTest::suite()); test->add(StatisticsTest::suite()); test->add(SubPeriodsCouponTest::suite()); diff --git a/test-suite/sofrfutures.cpp b/test-suite/sofrfutures.cpp index f38ea985bec..b788f1868e1 100644 --- a/test-suite/sofrfutures.cpp +++ b/test-suite/sofrfutures.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "sofrfutures.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -41,8 +41,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void SofrFuturesTest::testBootstrap() { +BOOST_AUTO_TEST_SUITE(SofrFuturesTest) + +BOOST_AUTO_TEST_CASE(testBootstrap) { BOOST_TEST_MESSAGE("Testing bootstrap over SOFR futures..."); Date today = Date(26, October, 2018); @@ -113,11 +116,6 @@ void SofrFuturesTest::testBootstrap() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* SofrFuturesTest::suite() { - auto* suite = BOOST_TEST_SUITE("SOFR futures tests"); - - suite->add(QUANTLIB_TEST_CASE(&SofrFuturesTest::testBootstrap)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/sofrfutures.hpp b/test-suite/sofrfutures.hpp deleted file mode 100644 index 0e36df00d75..00000000000 --- a/test-suite/sofrfutures.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2018 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_sofr_futures_hpp -#define quantlib_test_sofr_futures_hpp - -#include - -class SofrFuturesTest { - public: - static void testBootstrap(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index cb8fbc39a23..449a2ddfc36 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 358b2cb69af..3aa55cceff5 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 3622f0d03ce200b3004bf168ac6b7c8d20e21e81 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 15:05:18 +0800 Subject: [PATCH 047/102] remove redundant header --- test-suite/shortratemodels.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test-suite/shortratemodels.cpp b/test-suite/shortratemodels.cpp index eb08b567162..4ba368bcebb 100644 --- a/test-suite/shortratemodels.cpp +++ b/test-suite/shortratemodels.cpp @@ -21,7 +21,6 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "preconditions.hpp" #include "toplevelfixture.hpp" #include "utilities.hpp" #include From 1f464d32f6ce918dc1787e008eca78b23b166f55 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 15:10:51 +0800 Subject: [PATCH 048/102] Migrated solvers.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/solvers.cpp | 36 +++++++++-------------- test-suite/solvers.hpp | 43 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 14 insertions(+), 73 deletions(-) delete mode 100644 test-suite/solvers.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 162d63e5d49..710450d4830 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - solvers.hpp spreadoption.hpp squarerootclvmodel.hpp stats.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index cef34431912..4580de5105a 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - solvers.hpp \ spreadoption.hpp \ squarerootclvmodel.hpp \ stats.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index fd136fbe8e6..34571ab7d37 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "solvers.hpp" #include "spreadoption.hpp" #include "squarerootclvmodel.hpp" #include "stats.hpp" @@ -77,7 +76,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(Solver1DTest::suite()); test->add(StatisticsTest::suite()); test->add(SubPeriodsCouponTest::suite()); test->add(SwapTest::suite()); diff --git a/test-suite/solvers.cpp b/test-suite/solvers.cpp index 33031f2885e..92e35253c89 100644 --- a/test-suite/solvers.cpp +++ b/test-suite/solvers.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "solvers.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -168,58 +168,50 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void Solver1DTest::testBrent() { +BOOST_AUTO_TEST_SUITE(Solver1DTest) + +BOOST_AUTO_TEST_CASE(testBrent) { BOOST_TEST_MESSAGE("Testing Brent solver..."); test_solver(Brent(), "Brent", 1.0e-6); } -void Solver1DTest::testBisection() { +BOOST_AUTO_TEST_CASE(testBisection) { BOOST_TEST_MESSAGE("Testing bisection solver..."); test_solver(Bisection(), "Bisection", 1.0e-6); } -void Solver1DTest::testFalsePosition() { +BOOST_AUTO_TEST_CASE(testFalsePosition) { BOOST_TEST_MESSAGE("Testing false-position solver..."); test_solver(FalsePosition(), "FalsePosition", 1.0e-6); } -void Solver1DTest::testNewton() { +BOOST_AUTO_TEST_CASE(testNewton) { BOOST_TEST_MESSAGE("Testing Newton solver..."); test_solver(Newton(), "Newton", 1.0e-12); } -void Solver1DTest::testNewtonSafe() { +BOOST_AUTO_TEST_CASE(testNewtonSafe) { BOOST_TEST_MESSAGE("Testing Newton-safe solver..."); test_solver(NewtonSafe(), "NewtonSafe", 1.0e-9); } -void Solver1DTest::testFiniteDifferenceNewtonSafe() { +BOOST_AUTO_TEST_CASE(testFiniteDifferenceNewtonSafe) { BOOST_TEST_MESSAGE("Testing finite-difference Newton-safe solver..."); test_solver(FiniteDifferenceNewtonSafe(), "FiniteDifferenceNewtonSafe", Null()); } -void Solver1DTest::testRidder() { +BOOST_AUTO_TEST_CASE(testRidder) { BOOST_TEST_MESSAGE("Testing Ridder solver..."); test_solver(Ridder(), "Ridder", 1.0e-6); } -void Solver1DTest::testSecant() { +BOOST_AUTO_TEST_CASE(testSecant) { BOOST_TEST_MESSAGE("Testing secant solver..."); test_solver(Secant(), "Secant", 1.0e-6); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* Solver1DTest::suite() { - auto* suite = BOOST_TEST_SUITE("1-D solver tests"); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testBrent)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testBisection)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testFalsePosition)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testNewton)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testNewtonSafe)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testFiniteDifferenceNewtonSafe)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testRidder)); - suite->add(QUANTLIB_TEST_CASE(&Solver1DTest::testSecant)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/solvers.hpp b/test-suite/solvers.hpp deleted file mode 100644 index 1225b89c846..00000000000 --- a/test-suite/solvers.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - Copyright (C) 2012 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_solvers_hpp -#define quantlib_test_solvers_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class Solver1DTest { - public: - static void testBrent(); - static void testBisection(); - static void testFalsePosition(); - static void testNewton(); - static void testNewtonSafe(); - static void testFiniteDifferenceNewtonSafe(); - static void testRidder(); - static void testSecant(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 449a2ddfc36..58f50196ea5 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 3aa55cceff5..c469aeeaa35 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 966f58c3e510da2bd36b2b992ade7cf0943a552b Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 15:16:35 +0800 Subject: [PATCH 049/102] Migrated spreadoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/spreadoption.cpp | 17 +++++++------- test-suite/spreadoption.hpp | 35 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 52 deletions(-) delete mode 100644 test-suite/spreadoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 710450d4830..128f4b46b75 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - spreadoption.hpp squarerootclvmodel.hpp stats.hpp subperiodcoupons.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 4580de5105a..7fdcdf13a16 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - spreadoption.hpp \ squarerootclvmodel.hpp \ stats.hpp \ subperiodcoupons.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 34571ab7d37..d1ed88667b6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "spreadoption.hpp" #include "squarerootclvmodel.hpp" #include "stats.hpp" #include "subperiodcoupons.hpp" @@ -96,7 +95,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(SpreadOptionTest::suite()); test->add(SquareRootCLVModelTest::experimental()); test->add(SviVolatilityTest::experimental()); test->add(SwingOptionTest::suite(speed)); diff --git a/test-suite/spreadoption.cpp b/test-suite/spreadoption.cpp index bebc7e45a02..7c0f6c4fd12 100644 --- a/test-suite/spreadoption.cpp +++ b/test-suite/spreadoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "spreadoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -60,7 +60,11 @@ struct Case { Real theta; }; -void SpreadOptionTest::testKirkEngine() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(SpreadOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testKirkEngine) { BOOST_TEST_MESSAGE("Testing Kirk approximation for spread options..."); /* The example data below are from "complete guide to option @@ -163,11 +167,6 @@ void SpreadOptionTest::testKirkEngine() { } } -test_suite* SpreadOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Spread option tests"); - - suite->add(QUANTLIB_TEST_CASE(&SpreadOptionTest::testKirkEngine)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/spreadoption.hpp b/test-suite/spreadoption.hpp deleted file mode 100644 index f41c0247ab0..00000000000 --- a/test-suite/spreadoption.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2011 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_spread_option_hpp -#define quantlib_test_spread_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class SpreadOptionTest { - public: - static void testKirkEngine(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 58f50196ea5..06b77e3b197 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index c469aeeaa35..51a3e2d061e 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 3a4cd58ccf826fc8013def384909abc9e531dcf2 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 15 Nov 2023 15:21:37 +0800 Subject: [PATCH 050/102] Migrated squarerootclvmodel.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 - test-suite/squarerootclvmodel.cpp | 756 +++++++++++++-------------- test-suite/squarerootclvmodel.hpp | 34 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 374 insertions(+), 424 deletions(-) delete mode 100644 test-suite/squarerootclvmodel.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 128f4b46b75..cd9922132de 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - squarerootclvmodel.hpp stats.hpp subperiodcoupons.hpp svivolatility.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7fdcdf13a16..ee371e6f65c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - squarerootclvmodel.hpp \ stats.hpp \ subperiodcoupons.hpp \ svivolatility.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index d1ed88667b6..6d0a1f0be25 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "squarerootclvmodel.hpp" #include "stats.hpp" #include "subperiodcoupons.hpp" #include "svivolatility.hpp" @@ -95,7 +94,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(SquareRootCLVModelTest::experimental()); test->add(SviVolatilityTest::experimental()); test->add(SwingOptionTest::suite(speed)); test->add(TwoAssetBarrierOptionTest::suite()); diff --git a/test-suite/squarerootclvmodel.cpp b/test-suite/squarerootclvmodel.cpp index 79c2da9afec..19ae9ffa20a 100644 --- a/test-suite/squarerootclvmodel.cpp +++ b/test-suite/squarerootclvmodel.cpp @@ -18,8 +18,8 @@ */ +#include "toplevelfixture.hpp" #include "utilities.hpp" -#include "squarerootclvmodel.hpp" #include #include #include @@ -73,8 +73,11 @@ namespace square_root_clv_model { chi_squared_type; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void SquareRootCLVModelTest::testSquareRootCLVVanillaPricing() { +BOOST_AUTO_TEST_SUITE(SquareRootCLVModelExperimentalTest) + +BOOST_AUTO_TEST_CASE(testSquareRootCLVVanillaPricing) { BOOST_TEST_MESSAGE( "Testing vanilla option pricing with square-root kernel process..."); @@ -156,7 +159,7 @@ void SquareRootCLVModelTest::testSquareRootCLVVanillaPricing() { } } -void SquareRootCLVModelTest::testSquareRootCLVMappingFunction() { +BOOST_AUTO_TEST_CASE(testSquareRootCLVMappingFunction) { BOOST_TEST_MESSAGE( "Testing mapping function of the square-root kernel process..."); @@ -441,382 +444,371 @@ namespace square_root_clv_model { }; } -void SquareRootCLVModelTest::testForwardSkew() { - BOOST_TEST_MESSAGE( - "Testing forward skew dynamics with square-root kernel process..."); - - using namespace square_root_clv_model; - - const Date todaysDate(16, Oct, 2016); - Settings::instance().evaluationDate() = todaysDate; - const Date endDate = todaysDate + Period(4, Years); - - const DayCounter dc = Actual365Fixed(); - - // Heston model is used to generate an arbitrage free volatility surface - const Real s0 = 100; - const Real r = 0.1; - const Real q = 0.05; - const Real v0 = 0.09; - const Real kappa = 1.0; - const Real theta = 0.09; - const Real sigma = 0.3; - const Real rho = -0.75; - - const Handle spot(ext::make_shared(s0)); - const Handle rTS(flatRate(r, dc)); - const Handle qTS(flatRate(q, dc)); - - const ext::shared_ptr hestonModel( - ext::make_shared( - ext::make_shared( - rTS, qTS, spot, v0, kappa, theta, sigma, rho))); - - const Handle blackVol( - ext::make_shared( - Handle(hestonModel))); - - const Handle localVol( - ext::make_shared( - blackVol, rTS, qTS, spot, std::sqrt(theta))); - - const Real sTheta = 0.389302; - const Real sKappa = 0.1101849; - const Real sSigma = 0.275368; - const Real sX0 = 0.466809; - - const ext::shared_ptr sqrtProcess( - ext::make_shared( - sTheta, sKappa, sSigma, sX0)); - - const ext::shared_ptr bsProcess( - ext::make_shared( - spot, qTS, rTS, blackVol)); - - std::vector calibrationDates(1, todaysDate + Period(6, Months)); - while (calibrationDates.back() < endDate) - calibrationDates.push_back(calibrationDates.back() + Period(3, Months)); - - std::set clvCalibrationDates( - calibrationDates.begin(), calibrationDates.end()); - - Date tmpDate = todaysDate + Period(1, Days); - while (tmpDate < todaysDate + Period(1, Years)) { - clvCalibrationDates.insert(tmpDate); - tmpDate += Period(1, Weeks); - } - - const SquareRootCLVModel clvSqrtModel( - bsProcess, - sqrtProcess, - std::vector( - clvCalibrationDates.begin(), clvCalibrationDates.end()), - 14, 1-1e-14, 1e-14); - - const ext::function gSqrt = clvSqrtModel.g(); - - const ext::shared_ptr vol( - ext::make_shared(0.1)); - - const ext::shared_ptr fwdEngine( - ext::make_shared >( - ext::make_shared( - spot, qTS, rTS, - Handle(flatVol(todaysDate, vol, dc))))); - - - // forward skew of the Heston-SLV model - std::vector From 066c50de2d1d38c434af8981960bf99e4782b407 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 16 Nov 2023 10:34:26 +0800 Subject: [PATCH 055/102] Migrated swap.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 -- test-suite/swap.cpp | 32 +++++++++------------- test-suite/swap.hpp | 41 ---------------------------- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 14 insertions(+), 69 deletions(-) delete mode 100644 test-suite/swap.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 05615b0b7cb..bbb246aa426 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,8 +178,7 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - swap.hpp - swapforwardmappings.hpp + swapforwardmappings.hpp swaption.hpp swaptionvolatilitycube.hpp swaptionvolatilitymatrix.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 614e85a4b51..ea2a059318c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - swap.hpp \ swapforwardmappings.hpp \ swaption.hpp \ swaptionvolatilitycube.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 73d1c765bc4..bf9675f3447 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "swap.hpp" #include "swapforwardmappings.hpp" #include "swaption.hpp" #include "swaptionvolatilitycube.hpp" @@ -71,7 +70,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(SwapTest::suite()); test->add(SwapForwardMappingsTest::suite()); test->add(SwaptionTest::suite(speed)); test->add(SwaptionVolatilityCubeTest::suite()); diff --git a/test-suite/swap.cpp b/test-suite/swap.cpp index 1da351c47d9..1b386336332 100644 --- a/test-suite/swap.cpp +++ b/test-suite/swap.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "swap.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -95,8 +95,11 @@ namespace swap_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void SwapTest::testFairRate() { +BOOST_AUTO_TEST_SUITE(SwapTest) + +BOOST_AUTO_TEST_CASE(testFairRate) { BOOST_TEST_MESSAGE("Testing vanilla-swap calculation of fair fixed rate..."); @@ -122,7 +125,7 @@ void SwapTest::testFairRate() { } } -void SwapTest::testFairSpread() { +BOOST_AUTO_TEST_CASE(testFairSpread) { BOOST_TEST_MESSAGE("Testing vanilla-swap calculation of " "fair floating spread..."); @@ -149,7 +152,7 @@ void SwapTest::testFairSpread() { } } -void SwapTest::testRateDependency() { +BOOST_AUTO_TEST_CASE(testRateDependency) { BOOST_TEST_MESSAGE("Testing vanilla-swap dependency on fixed rate..."); @@ -184,7 +187,7 @@ void SwapTest::testRateDependency() { } } -void SwapTest::testSpreadDependency() { +BOOST_AUTO_TEST_CASE(testSpreadDependency) { BOOST_TEST_MESSAGE("Testing vanilla-swap dependency on floating spread..."); @@ -220,7 +223,7 @@ void SwapTest::testSpreadDependency() { } } -void SwapTest::testInArrears() { +BOOST_AUTO_TEST_CASE(testInArrears) { BOOST_TEST_MESSAGE("Testing in-arrears swap calculation..."); @@ -288,7 +291,7 @@ void SwapTest::testInArrears() { << " calculated: " << swap.NPV()); } -void SwapTest::testCachedValue() { +BOOST_AUTO_TEST_CASE(testCachedValue) { BOOST_TEST_MESSAGE("Testing vanilla-swap calculation against cached value..."); @@ -321,7 +324,7 @@ void SwapTest::testCachedValue() { << " expected: " << cachedNPV); } -void SwapTest::testThirdWednesdayAdjustment() { +BOOST_AUTO_TEST_CASE(testThirdWednesdayAdjustment) { BOOST_TEST_MESSAGE("Testing third-Wednesday adjustment..."); @@ -340,15 +343,6 @@ void SwapTest::testThirdWednesdayAdjustment() { } } -test_suite* SwapTest::suite() { - auto* suite = BOOST_TEST_SUITE("Swap tests"); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testFairRate)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testFairSpread)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testRateDependency)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testSpreadDependency)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testInArrears)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testCachedValue)); - suite->add(QUANTLIB_TEST_CASE(&SwapTest::testThirdWednesdayAdjustment)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/swap.hpp b/test-suite/swap.hpp deleted file mode 100644 index 521742406a5..00000000000 --- a/test-suite/swap.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003, 2004 StatPro Italia srl - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_swap_hpp -#define quantlib_test_swap_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class SwapTest { - public: - static void testFairRate(); - static void testFairSpread(); - static void testRateDependency(); - static void testSpreadDependency(); - static void testInArrears(); - static void testCachedValue(); - static void testThirdWednesdayAdjustment(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index be7503cc8a2..9cd44f3cd25 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -814,7 +814,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index f35e3f3aa32..6759e6593a8 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -539,9 +539,6 @@ Header Files - - Header Files - Header Files From 6276ee274204fa6a0a5fa6e2851ee66d3ca1ca5d Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 16 Nov 2023 10:38:03 +0800 Subject: [PATCH 056/102] Migrated swapforwardmappings.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 2 - test-suite/swapforwardmappings.cpp | 174 +++++++++++++-------------- test-suite/swapforwardmappings.hpp | 37 ------ test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 82 insertions(+), 137 deletions(-) delete mode 100644 test-suite/swapforwardmappings.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index bbb246aa426..4ac4cbad70c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -178,7 +178,6 @@ set(QL_TEST_HEADERS paralleltestrunner.hpp preconditions.hpp quantlibglobalfixture.hpp - swapforwardmappings.hpp swaption.hpp swaptionvolatilitycube.hpp swaptionvolatilitymatrix.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ea2a059318c..413c55d00a5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ marketmodel.hpp \ preconditions.hpp \ quantlibglobalfixture.hpp \ - swapforwardmappings.hpp \ swaption.hpp \ swaptionvolatilitycube.hpp \ swaptionvolatilitymatrix.hpp \ diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index bf9675f3447..86103ce993a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "swapforwardmappings.hpp" #include "swaption.hpp" #include "swaptionvolatilitycube.hpp" #include "swaptionvolatilitymatrix.hpp" @@ -70,7 +69,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(MarketModelTest::suite(speed)); - test->add(SwapForwardMappingsTest::suite()); test->add(SwaptionTest::suite(speed)); test->add(SwaptionVolatilityCubeTest::suite()); test->add(SwaptionVolatilityMatrixTest::suite()); diff --git a/test-suite/swapforwardmappings.cpp b/test-suite/swapforwardmappings.cpp index e1874cef249..976da73dffa 100644 --- a/test-suite/swapforwardmappings.cpp +++ b/test-suite/swapforwardmappings.cpp @@ -18,7 +18,7 @@ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "swapforwardmappings.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -181,8 +181,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void SwapForwardMappingsTest::testForwardSwapJacobians() +BOOST_AUTO_TEST_SUITE(SwapForwardMappingsTest) + +BOOST_AUTO_TEST_CASE(testForwardSwapJacobians) { { BOOST_TEST_MESSAGE("Testing forward-rate coinitial-swap Jacobian..."); @@ -291,82 +294,81 @@ void SwapForwardMappingsTest::testForwardSwapJacobians() } } - -void SwapForwardMappingsTest::testForwardCoterminalMappings() { - - BOOST_TEST_MESSAGE("Testing forward-rate coterminal-swap mappings..."); - MarketModelData marketData; - const std::vector diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 1c2f1c36952..5a3f8abf6ac 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -548,9 +548,6 @@ Header Files - - Header Files - Header Files diff --git a/test-suite/xoshiro256starstar.cpp b/test-suite/xoshiro256starstar.cpp index a750ea0e108..61a7a682b71 100644 --- a/test-suite/xoshiro256starstar.cpp +++ b/test-suite/xoshiro256starstar.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "xoshiro256starstar.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -152,10 +152,14 @@ extern "C" { // NOLINTEND // clang-format on -using QuantLib::Real; +using namespace QuantLib; using QuantLib::Xoshiro256StarStarUniformRng; -void Xoshiro256StarStarTest::testMeanAndStdDevOfNextReal() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(Xoshiro256StarStarTest) + +BOOST_AUTO_TEST_CASE(testMeanAndStdDevOfNextReal) { BOOST_TEST_MESSAGE( "Testing Xoshiro256StarStarUniformRng::nextReal() for mean=0.5 and stddev=1/12..."); @@ -185,7 +189,7 @@ void Xoshiro256StarStarTest::testMeanAndStdDevOfNextReal() { } } -void Xoshiro256StarStarTest::testAgainstReferenceImplementationInC() { +BOOST_AUTO_TEST_CASE(testAgainstReferenceImplementationInC) { BOOST_TEST_MESSAGE( "Testing Xoshiro256StarStarUniformRng::nextInt64() against reference implementation in C..."); @@ -224,7 +228,7 @@ void Xoshiro256StarStarTest::testAgainstReferenceImplementationInC() { } } -void Xoshiro256StarStarTest::testAbsenceOfInteractionBetweenInstances() { +BOOST_AUTO_TEST_CASE(testAbsenceOfInteractionBetweenInstances) { BOOST_TEST_MESSAGE( "Testing Xoshiro256StarStarUniformRng for absence of interaction between instances..."); @@ -255,12 +259,6 @@ void Xoshiro256StarStarTest::testAbsenceOfInteractionBetweenInstances() { "parallel computation"); } -boost::unit_test_framework::test_suite* Xoshiro256StarStarTest::suite() { - auto* suite = BOOST_TEST_SUITE("Xoshiro256StarStar Tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&Xoshiro256StarStarTest::testMeanAndStdDevOfNextReal)); - suite->add(QUANTLIB_TEST_CASE(&Xoshiro256StarStarTest::testAgainstReferenceImplementationInC)); - suite->add(QUANTLIB_TEST_CASE(&Xoshiro256StarStarTest::testAbsenceOfInteractionBetweenInstances)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/xoshiro256starstar.hpp b/test-suite/xoshiro256starstar.hpp deleted file mode 100644 index 354ba06debf..00000000000 --- a/test-suite/xoshiro256starstar.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2023 Ralf Konrad Eckel - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - - -#ifndef quantlib_test_xoshiro256starstar_hpp -#define quantlib_test_xoshiro256starstar_hpp - -#include - -class Xoshiro256StarStarTest { - public: - static void testMeanAndStdDevOfNextReal(); - static void testAgainstReferenceImplementationInC(); - static void testAbsenceOfInteractionBetweenInstances(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif // quantlib_test_xoshiro256starstar_hpp From 9ef8982cdb963bd04f26a9eab29dee522d768835 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 17 Nov 2023 11:14:48 +0800 Subject: [PATCH 077/102] Migrated zabr.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/quantlibtestsuite.cpp | 4 ---- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- test-suite/zabr.cpp | 19 +++++++-------- test-suite/zabr.hpp | 36 ---------------------------- 7 files changed, 9 insertions(+), 56 deletions(-) delete mode 100644 test-suite/zabr.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d823d82738a..4ff87d9133a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -181,7 +181,6 @@ set(QL_TEST_HEADERS swaptionvolstructuresutilities.hpp toplevelfixture.hpp utilities.hpp - zabr.hpp zerocouponswap.hpp ) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e4c3be9aa0c..d953c9723bc 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -180,7 +180,6 @@ QL_TEST_HDRS = \ swaptionvolstructuresutilities.hpp \ toplevelfixture.hpp \ utilities.hpp \ - zabr.hpp \ zerocouponswap.hpp QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS} diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index d5286683d88..78d12026eb6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "zabr.hpp" #include "zerocouponswap.hpp" using namespace boost::unit_test_framework; @@ -53,8 +52,5 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); - // tests for experimental classes - test->add(ZabrTest::suite(speed)); - return test; } diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index cb6aea38ed3..cd4056801c6 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -817,7 +817,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 5a3f8abf6ac..ec6df37cd37 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -548,9 +548,6 @@ Header Files - - Header Files - Header Files diff --git a/test-suite/zabr.cpp b/test-suite/zabr.cpp index 2569dc0c2ec..bfaa12e77e5 100644 --- a/test-suite/zabr.cpp +++ b/test-suite/zabr.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "zabr.hpp" +#include "preconditions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -25,7 +26,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void ZabrTest::testConsistency() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ZabrExperimentalTest) + +BOOST_AUTO_TEST_CASE(testConsistency, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE("Testing the consistency of ZABR interpolation..."); Real tol = 1E-4; @@ -86,12 +91,6 @@ void ZabrTest::testConsistency() { } } -test_suite *ZabrTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Zabr model tests"); +BOOST_AUTO_TEST_SUITE_END() - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&ZabrTest::testConsistency)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/zabr.hpp b/test-suite/zabr.hpp deleted file mode 100644 index d85f249d914..00000000000 --- a/test-suite/zabr.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 Peter Caspers - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_zabr_hpp -#define quantlib_test_zabr_hpp - -#include "preconditions.hpp" -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ZabrTest { - public: - static void testConsistency(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif From 77013dbc9bf4d9e58f3cd1a5a6b874e4aaebfc75 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 17 Nov 2023 11:18:30 +0800 Subject: [PATCH 078/102] Migrated zerocouponswap.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 3 +-- test-suite/quantlibtestsuite.cpp | 3 --- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- test-suite/zerocouponswap.cpp | 31 ++++++++++------------- test-suite/zerocouponswap.hpp | 37 ---------------------------- 7 files changed, 14 insertions(+), 65 deletions(-) delete mode 100644 test-suite/zerocouponswap.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 4ff87d9133a..7d4348e38cc 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -181,7 +181,6 @@ set(QL_TEST_HEADERS swaptionvolstructuresutilities.hpp toplevelfixture.hpp utilities.hpp - zerocouponswap.hpp ) set(QL_BENCHMARK_SOURCES diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index d953c9723bc..d110b6236ca 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -179,8 +179,7 @@ QL_TEST_HDRS = \ quantlibglobalfixture.hpp \ swaptionvolstructuresutilities.hpp \ toplevelfixture.hpp \ - utilities.hpp \ - zerocouponswap.hpp + utilities.hpp QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS} diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 78d12026eb6..516ede1303e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ #include "marketmodel.hpp" #include "quantlibglobalfixture.hpp" -#include "zerocouponswap.hpp" using namespace boost::unit_test_framework; @@ -50,7 +49,5 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(MarketModelTest::suite(speed)); - test->add(ZeroCouponSwapTest::suite()); - return test; } diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index cd4056801c6..2271edbeb03 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -817,7 +817,6 @@ - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index ec6df37cd37..dc3f01586ad 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -548,8 +548,5 @@ Header Files - - Header Files - diff --git a/test-suite/zerocouponswap.cpp b/test-suite/zerocouponswap.cpp index e9c8ad11232..69fca265bf3 100644 --- a/test-suite/zerocouponswap.cpp +++ b/test-suite/zerocouponswap.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "zerocouponswap.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -190,7 +190,11 @@ namespace zerocouponswap_test { } } -void ZeroCouponSwapTest::testInstrumentValuation() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ZeroCouponSwapTest) + +BOOST_AUTO_TEST_CASE(testInstrumentValuation) { BOOST_TEST_MESSAGE("Testing zero coupon swap valuation..."); using namespace zerocouponswap_test; @@ -206,7 +210,7 @@ void ZeroCouponSwapTest::testInstrumentValuation() { checkReplicationOfZeroCouponSwapNPV(Date(12, February, 2000), Date(12, February, 2020)); } -void ZeroCouponSwapTest::testFairFixedPayment() { +BOOST_AUTO_TEST_CASE(testFairFixedPayment) { BOOST_TEST_MESSAGE("Testing fair fixed payment..."); using namespace zerocouponswap_test; @@ -220,7 +224,7 @@ void ZeroCouponSwapTest::testFairFixedPayment() { Swap::Payer); } -void ZeroCouponSwapTest::testFairFixedRate() { +BOOST_AUTO_TEST_CASE(testFairFixedRate) { BOOST_TEST_MESSAGE("Testing fair fixed rate..."); using namespace zerocouponswap_test; @@ -233,7 +237,7 @@ void ZeroCouponSwapTest::testFairFixedRate() { checkFairFixedRate(Date(17, March, 2021), Date(12, February, 2041), Swap::Payer); } -void ZeroCouponSwapTest::testFixedPaymentFromRate() { +BOOST_AUTO_TEST_CASE(testFixedPaymentFromRate) { BOOST_TEST_MESSAGE("Testing fixed payment calculation from rate..."); using namespace zerocouponswap_test; @@ -259,7 +263,7 @@ void ZeroCouponSwapTest::testFixedPaymentFromRate() { << " end: " << end << "\n"); } -void ZeroCouponSwapTest::testArgumentsValidation() { +BOOST_AUTO_TEST_CASE(testArgumentsValidation) { BOOST_TEST_MESSAGE("Testing arguments validation..."); using namespace zerocouponswap_test; @@ -277,7 +281,7 @@ void ZeroCouponSwapTest::testArgumentsValidation() { BOOST_CHECK_THROW(vars.createZCSwap(end, start, 0.01), Error); } -void ZeroCouponSwapTest::testExpectedCashFlowsInLegs() { +BOOST_AUTO_TEST_CASE(testExpectedCashFlowsInLegs) { BOOST_TEST_MESSAGE("Testing expected cash flows in legs..."); using namespace zerocouponswap_test; @@ -313,15 +317,6 @@ void ZeroCouponSwapTest::testExpectedCashFlowsInLegs() { << " expected payment date: " << paymentDate << "\n"); } -test_suite* ZeroCouponSwapTest::suite() { - auto* suite = BOOST_TEST_SUITE("Zero coupon swap tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testInstrumentValuation)); - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testFairFixedPayment)); - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testFairFixedRate)); - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testFixedPaymentFromRate)); - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testArgumentsValidation)); - suite->add(QUANTLIB_TEST_CASE(&ZeroCouponSwapTest::testExpectedCashFlowsInLegs)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/zerocouponswap.hpp b/test-suite/zerocouponswap.hpp deleted file mode 100644 index a5e26dcf9dd..00000000000 --- a/test-suite/zerocouponswap.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2021 Marcin Rybacki - - This file is part of QuantLib, a free-software/open-source library - for financial quantitative analysts and developers - http://quantlib.org/ - - QuantLib is free software: you can redistribute it and/or modify it - under the terms of the QuantLib license. You should have received a - copy of the license along with this program; if not, please email - . The license is also available online at - . - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -*/ - -#ifndef quantlib_test_zerocouponswap_hpp -#define quantlib_test_zerocouponswap_hpp - -#include - -class ZeroCouponSwapTest { - public: - static void testInstrumentValuation(); - static void testFairFixedPayment(); - static void testFairFixedRate(); - static void testFixedPaymentFromRate(); - static void testArgumentsValidation(); - static void testExpectedCashFlowsInLegs(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif From 9ea78221a2c0c0ce565358869c317c655ee254c0 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Fri, 17 Nov 2023 14:34:31 +0100 Subject: [PATCH 079/102] Move test to Fast section --- test-suite/hestonslvmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suite/hestonslvmodel.cpp b/test-suite/hestonslvmodel.cpp index 299f65fc47e..b46dbb04935 100644 --- a/test-suite/hestonslvmodel.cpp +++ b/test-suite/hestonslvmodel.cpp @@ -2263,7 +2263,7 @@ BOOST_AUTO_TEST_CASE(testMonteCarloCalibration, *precondition(if_speed(Fast))) { // } //} -BOOST_AUTO_TEST_CASE(testMoustacheGraph, *precondition(if_speed(Slow))) { +BOOST_AUTO_TEST_CASE(testMoustacheGraph, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing double no touch pricing with SLV and mixing..."); From f99e73f33bce84cdaa9dbdbe60a6a478f1764ffd Mon Sep 17 00:00:00 2001 From: Eugene Toder Date: Sat, 18 Nov 2023 00:48:24 -0500 Subject: [PATCH 080/102] Allow different frequencies in MakeOIS and OISRateHelper Allow setting different payment frequencies for fixed and overnight legs. --- ql/instruments/makeois.cpp | 74 ++++++++++++++++++----- ql/instruments/makeois.hpp | 10 ++- ql/termstructures/yield/oisratehelper.cpp | 25 +++++--- ql/termstructures/yield/oisratehelper.hpp | 7 ++- 4 files changed, 88 insertions(+), 28 deletions(-) diff --git a/ql/instruments/makeois.cpp b/ql/instruments/makeois.cpp index 4e896ac3b92..1ddf3aa5a6a 100644 --- a/ql/instruments/makeois.cpp +++ b/ql/instruments/makeois.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace QuantLib { @@ -77,20 +78,48 @@ namespace QuantLib { endDate = startDate + swapTenor_; } - Schedule schedule(startDate, endDate, - Period(paymentFrequency_), - calendar_, - ModifiedFollowing, - ModifiedFollowing, - rule_, - usedEndOfMonth); + Frequency fixedPaymentFrequency, overnightPaymentFrequency; + DateGeneration::Rule fixedRule, overnightRule; + if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) { + fixedPaymentFrequency = Once; + fixedRule = DateGeneration::Zero; + } else { + fixedPaymentFrequency = fixedPaymentFrequency_; + fixedRule = fixedRule_; + } + if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) { + overnightPaymentFrequency = Once; + overnightRule = DateGeneration::Zero; + } else { + overnightPaymentFrequency = overnightPaymentFrequency_; + overnightRule = overnightRule_; + } + + Schedule fixedSchedule(startDate, endDate, + Period(fixedPaymentFrequency), + calendar_, + ModifiedFollowing, + ModifiedFollowing, + fixedRule, + usedEndOfMonth); + ext::optional overnightSchedule; + if (fixedPaymentFrequency != overnightPaymentFrequency || fixedRule != overnightRule) { + overnightSchedule.emplace(startDate, endDate, + Period(overnightPaymentFrequency), + calendar_, + ModifiedFollowing, + ModifiedFollowing, + overnightRule, + usedEndOfMonth); + } Rate usedFixedRate = fixedRate_; if (fixedRate_ == Null()) { OvernightIndexedSwap temp(type_, nominal_, - schedule, + fixedSchedule, 0.0, // fixed rate fixedDayCount_, + overnightSchedule ? *overnightSchedule : fixedSchedule, overnightIndex_, overnightSpread_, paymentLag_, paymentAdjustment_, paymentCalendar_, telescopicValueDates_); @@ -112,8 +141,9 @@ namespace QuantLib { ext::shared_ptr ois(new OvernightIndexedSwap(type_, nominal_, - schedule, + fixedSchedule, usedFixedRate, fixedDayCount_, + overnightSchedule ? *overnightSchedule : fixedSchedule, overnightIndex_, overnightSpread_, paymentLag_, paymentAdjustment_, paymentCalendar_, telescopicValueDates_, @@ -165,9 +195,16 @@ namespace QuantLib { } MakeOIS& MakeOIS::withPaymentFrequency(Frequency f) { - paymentFrequency_ = f; - if (paymentFrequency_==Once) - rule_ = DateGeneration::Zero; + return withFixedLegPaymentFrequency(f).withOvernightLegPaymentFrequency(f); + } + + MakeOIS& MakeOIS::withFixedLegPaymentFrequency(Frequency f) { + fixedPaymentFrequency_ = f; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegPaymentFrequency(Frequency f) { + overnightPaymentFrequency_ = f; return *this; } @@ -187,9 +224,16 @@ namespace QuantLib { } MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) { - rule_ = r; - if (r==DateGeneration::Zero) - paymentFrequency_ = Once; + return withFixedLegRule(r).withOvernightLegRule(r); + } + + MakeOIS& MakeOIS::withFixedLegRule(DateGeneration::Rule r) { + fixedRule_ = r; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegRule(DateGeneration::Rule r) { + overnightRule_ = r; return *this; } diff --git a/ql/instruments/makeois.hpp b/ql/instruments/makeois.hpp index 117d598d483..a7703c41434 100644 --- a/ql/instruments/makeois.hpp +++ b/ql/instruments/makeois.hpp @@ -54,8 +54,12 @@ namespace QuantLib { MakeOIS& withEffectiveDate(const Date&); MakeOIS& withTerminationDate(const Date&); MakeOIS& withRule(DateGeneration::Rule r); + MakeOIS& withFixedLegRule(DateGeneration::Rule r); + MakeOIS& withOvernightLegRule(DateGeneration::Rule r); MakeOIS& withPaymentFrequency(Frequency f); + MakeOIS& withFixedLegPaymentFrequency(Frequency f); + MakeOIS& withOvernightLegPaymentFrequency(Frequency f); MakeOIS& withPaymentAdjustment(BusinessDayConvention convention); MakeOIS& withPaymentLag(Integer lag); MakeOIS& withPaymentCalendar(const Calendar& cal); @@ -85,12 +89,14 @@ namespace QuantLib { Date effectiveDate_, terminationDate_; Calendar calendar_; - Frequency paymentFrequency_ = Annual; + Frequency fixedPaymentFrequency_ = Annual; + Frequency overnightPaymentFrequency_ = Annual; Calendar paymentCalendar_; BusinessDayConvention paymentAdjustment_ = Following; Integer paymentLag_ = 0; - DateGeneration::Rule rule_ = DateGeneration::Backward; + DateGeneration::Rule fixedRule_ = DateGeneration::Backward; + DateGeneration::Rule overnightRule_ = DateGeneration::Backward; bool endOfMonth_ = false, isDefaultEOM_ = true; Swap::Type type_ = Swap::Payer; diff --git a/ql/termstructures/yield/oisratehelper.cpp b/ql/termstructures/yield/oisratehelper.cpp index ab9707ae212..175288764da 100644 --- a/ql/termstructures/yield/oisratehelper.cpp +++ b/ql/termstructures/yield/oisratehelper.cpp @@ -42,13 +42,15 @@ namespace QuantLib { Pillar::Choice pillar, Date customPillarDate, RateAveraging::Type averagingMethod, - ext::optional endOfMonth) + ext::optional endOfMonth, + ext::optional fixedPaymentFrequency) : RelativeDateRateHelper(fixedRate), pillarChoice_(pillar), settlementDays_(settlementDays), tenor_(tenor), discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates), paymentLag_(paymentLag), paymentConvention_(paymentConvention), paymentFrequency_(paymentFrequency), paymentCalendar_(std::move(paymentCalendar)), forwardStart_(forwardStart), overnightSpread_(overnightSpread), - averagingMethod_(averagingMethod), endOfMonth_(endOfMonth) { + averagingMethod_(averagingMethod), endOfMonth_(endOfMonth), + fixedPaymentFrequency_(fixedPaymentFrequency) { overnightIndex_ = ext::dynamic_pointer_cast(overnightIndex->clone(termStructureHandle_)); @@ -79,10 +81,12 @@ namespace QuantLib { .withOvernightLegSpread(overnightSpread_) .withAveragingMethod(averagingMethod_); if (endOfMonth_) { - swap_ = tmp.withEndOfMonth(*endOfMonth_); - } else { - swap_ = tmp; + tmp.withEndOfMonth(*endOfMonth_); } + if (fixedPaymentFrequency_) { + tmp.withFixedLegPaymentFrequency(*fixedPaymentFrequency_); + } + swap_ = tmp; simplifyNotificationGraph(*swap_, true); @@ -162,7 +166,8 @@ namespace QuantLib { const Calendar& paymentCalendar, const Period& forwardStart, Spread overnightSpread, - ext::optional endOfMonth) + ext::optional endOfMonth, + ext::optional fixedPaymentFrequency) : RateHelper(fixedRate), discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates), averagingMethod_(averagingMethod) { @@ -190,10 +195,12 @@ namespace QuantLib { .withOvernightLegSpread(overnightSpread) .withAveragingMethod(averagingMethod_); if (endOfMonth) { - swap_ = tmp.withEndOfMonth(*endOfMonth); - } else { - swap_ = tmp; + tmp.withEndOfMonth(*endOfMonth); + } + if (fixedPaymentFrequency) { + tmp.withFixedLegPaymentFrequency(*fixedPaymentFrequency); } + swap_ = tmp; earliestDate_ = swap_->startDate(); Date lastPaymentDate = std::max(swap_->overnightLeg().back()->date(), diff --git a/ql/termstructures/yield/oisratehelper.hpp b/ql/termstructures/yield/oisratehelper.hpp index f65ada8bd5b..ac84f038cc0 100644 --- a/ql/termstructures/yield/oisratehelper.hpp +++ b/ql/termstructures/yield/oisratehelper.hpp @@ -50,7 +50,8 @@ namespace QuantLib { Pillar::Choice pillar = Pillar::LastRelevantDate, Date customPillarDate = Date(), RateAveraging::Type averagingMethod = RateAveraging::Compound, - ext::optional endOfMonth = ext::nullopt); + ext::optional endOfMonth = ext::nullopt, + ext::optional fixedPaymentFrequency = ext::nullopt); //! \name RateHelper interface //@{ Real impliedQuote() const override; @@ -88,6 +89,7 @@ namespace QuantLib { Spread overnightSpread_; RateAveraging::Type averagingMethod_; ext::optional endOfMonth_; + ext::optional fixedPaymentFrequency_; }; //! Rate helper for bootstrapping over Overnight Indexed Swap rates @@ -107,7 +109,8 @@ namespace QuantLib { const Calendar& paymentCalendar = Calendar(), const Period& forwardStart = 0 * Days, Spread overnightSpread = 0.0, - ext::optional endOfMonth = ext::nullopt); + ext::optional endOfMonth = ext::nullopt, + ext::optional fixedPaymentFrequency = ext::nullopt); //! \name RateHelper interface //@{ Real impliedQuote() const override; From fd2ca08638adfa74ac21792ea9434a0c5e99238a Mon Sep 17 00:00:00 2001 From: Eugene Toder Date: Sat, 18 Nov 2023 04:25:40 -0500 Subject: [PATCH 081/102] Allow different calendars in MakeOIS and OISRateHelper --- ql/instruments/makeois.cpp | 42 ++++++++++++++--------- ql/instruments/makeois.hpp | 4 ++- ql/termstructures/yield/oisratehelper.cpp | 14 ++++++-- ql/termstructures/yield/oisratehelper.hpp | 7 ++-- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ql/instruments/makeois.cpp b/ql/instruments/makeois.cpp index 1ddf3aa5a6a..eef85a1a1e7 100644 --- a/ql/instruments/makeois.cpp +++ b/ql/instruments/makeois.cpp @@ -34,9 +34,8 @@ namespace QuantLib { const Period& forwardStart) : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate), forwardStart_(forwardStart), - - calendar_(overnightIndex->fixingCalendar()), - + fixedCalendar_(overnightIndex->fixingCalendar()), + overnightCalendar_(overnightIndex->fixingCalendar()), fixedDayCount_(overnightIndex->dayCounter()) {} MakeOIS::operator OvernightIndexedSwap() const { @@ -53,27 +52,27 @@ namespace QuantLib { Date refDate = Settings::instance().evaluationDate(); // if the evaluation date is not a business day // then move to the next business day - refDate = calendar_.adjust(refDate); - Date spotDate = calendar_.advance(refDate, - settlementDays_*Days); + refDate = overnightCalendar_.adjust(refDate); + Date spotDate = overnightCalendar_.advance(refDate, + settlementDays_*Days); startDate = spotDate+forwardStart_; if (forwardStart_.length()<0) - startDate = calendar_.adjust(startDate, Preceding); + startDate = overnightCalendar_.adjust(startDate, Preceding); else - startDate = calendar_.adjust(startDate, Following); + startDate = overnightCalendar_.adjust(startDate, Following); } // OIS end of month default bool usedEndOfMonth = - isDefaultEOM_ ? calendar_.isEndOfMonth(startDate) : endOfMonth_; + isDefaultEOM_ ? overnightCalendar_.isEndOfMonth(startDate) : endOfMonth_; Date endDate = terminationDate_; if (endDate == Date()) { if (usedEndOfMonth) - endDate = calendar_.advance(startDate, - swapTenor_, - ModifiedFollowing, - usedEndOfMonth); + endDate = overnightCalendar_.advance(startDate, + swapTenor_, + ModifiedFollowing, + usedEndOfMonth); else endDate = startDate + swapTenor_; } @@ -97,16 +96,17 @@ namespace QuantLib { Schedule fixedSchedule(startDate, endDate, Period(fixedPaymentFrequency), - calendar_, + fixedCalendar_, ModifiedFollowing, ModifiedFollowing, fixedRule, usedEndOfMonth); ext::optional overnightSchedule; - if (fixedPaymentFrequency != overnightPaymentFrequency || fixedRule != overnightRule) { + if (fixedPaymentFrequency != overnightPaymentFrequency || fixedRule != overnightRule || + fixedCalendar_ != overnightCalendar_) { overnightSchedule.emplace(startDate, endDate, Period(overnightPaymentFrequency), - calendar_, + overnightCalendar_, ModifiedFollowing, ModifiedFollowing, overnightRule, @@ -223,6 +223,16 @@ namespace QuantLib { return *this; } + MakeOIS& MakeOIS::withFixedLegCalendar(const Calendar& cal) { + fixedCalendar_ = cal; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegCalendar(const Calendar& cal) { + overnightCalendar_ = cal; + return *this; + } + MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) { return withFixedLegRule(r).withOvernightLegRule(r); } diff --git a/ql/instruments/makeois.hpp b/ql/instruments/makeois.hpp index a7703c41434..6c39b9a69e7 100644 --- a/ql/instruments/makeois.hpp +++ b/ql/instruments/makeois.hpp @@ -63,6 +63,8 @@ namespace QuantLib { MakeOIS& withPaymentAdjustment(BusinessDayConvention convention); MakeOIS& withPaymentLag(Integer lag); MakeOIS& withPaymentCalendar(const Calendar& cal); + MakeOIS& withFixedLegCalendar(const Calendar& cal); + MakeOIS& withOvernightLegCalendar(const Calendar& cal); MakeOIS& withEndOfMonth(bool flag = true); @@ -87,7 +89,7 @@ namespace QuantLib { Natural settlementDays_ = 2; Date effectiveDate_, terminationDate_; - Calendar calendar_; + Calendar fixedCalendar_, overnightCalendar_; Frequency fixedPaymentFrequency_ = Annual; Frequency overnightPaymentFrequency_ = Annual; diff --git a/ql/termstructures/yield/oisratehelper.cpp b/ql/termstructures/yield/oisratehelper.cpp index 175288764da..a20843d4dd8 100644 --- a/ql/termstructures/yield/oisratehelper.cpp +++ b/ql/termstructures/yield/oisratehelper.cpp @@ -43,14 +43,15 @@ namespace QuantLib { Date customPillarDate, RateAveraging::Type averagingMethod, ext::optional endOfMonth, - ext::optional fixedPaymentFrequency) + ext::optional fixedPaymentFrequency, + Calendar fixedCalendar) : RelativeDateRateHelper(fixedRate), pillarChoice_(pillar), settlementDays_(settlementDays), tenor_(tenor), discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates), paymentLag_(paymentLag), paymentConvention_(paymentConvention), paymentFrequency_(paymentFrequency), paymentCalendar_(std::move(paymentCalendar)), forwardStart_(forwardStart), overnightSpread_(overnightSpread), averagingMethod_(averagingMethod), endOfMonth_(endOfMonth), - fixedPaymentFrequency_(fixedPaymentFrequency) { + fixedPaymentFrequency_(fixedPaymentFrequency), fixedCalendar_(std::move(fixedCalendar)) { overnightIndex_ = ext::dynamic_pointer_cast(overnightIndex->clone(termStructureHandle_)); @@ -86,6 +87,9 @@ namespace QuantLib { if (fixedPaymentFrequency_) { tmp.withFixedLegPaymentFrequency(*fixedPaymentFrequency_); } + if (!fixedCalendar_.empty()) { + tmp.withFixedLegCalendar(fixedCalendar_); + } swap_ = tmp; simplifyNotificationGraph(*swap_, true); @@ -167,7 +171,8 @@ namespace QuantLib { const Period& forwardStart, Spread overnightSpread, ext::optional endOfMonth, - ext::optional fixedPaymentFrequency) + ext::optional fixedPaymentFrequency, + const Calendar& fixedCalendar) : RateHelper(fixedRate), discountHandle_(std::move(discount)), telescopicValueDates_(telescopicValueDates), averagingMethod_(averagingMethod) { @@ -200,6 +205,9 @@ namespace QuantLib { if (fixedPaymentFrequency) { tmp.withFixedLegPaymentFrequency(*fixedPaymentFrequency); } + if (!fixedCalendar.empty()) { + tmp.withFixedLegCalendar(fixedCalendar); + } swap_ = tmp; earliestDate_ = swap_->startDate(); diff --git a/ql/termstructures/yield/oisratehelper.hpp b/ql/termstructures/yield/oisratehelper.hpp index ac84f038cc0..4390421f931 100644 --- a/ql/termstructures/yield/oisratehelper.hpp +++ b/ql/termstructures/yield/oisratehelper.hpp @@ -51,7 +51,8 @@ namespace QuantLib { Date customPillarDate = Date(), RateAveraging::Type averagingMethod = RateAveraging::Compound, ext::optional endOfMonth = ext::nullopt, - ext::optional fixedPaymentFrequency = ext::nullopt); + ext::optional fixedPaymentFrequency = ext::nullopt, + Calendar fixedCalendar = Calendar()); //! \name RateHelper interface //@{ Real impliedQuote() const override; @@ -90,6 +91,7 @@ namespace QuantLib { RateAveraging::Type averagingMethod_; ext::optional endOfMonth_; ext::optional fixedPaymentFrequency_; + Calendar fixedCalendar_; }; //! Rate helper for bootstrapping over Overnight Indexed Swap rates @@ -110,7 +112,8 @@ namespace QuantLib { const Period& forwardStart = 0 * Days, Spread overnightSpread = 0.0, ext::optional endOfMonth = ext::nullopt, - ext::optional fixedPaymentFrequency = ext::nullopt); + ext::optional fixedPaymentFrequency = ext::nullopt, + const Calendar& fixedCalendar = Calendar()); //! \name RateHelper interface //@{ Real impliedQuote() const override; From 7ae8d53f57813122ce930d898b58567bac93de4a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 19 Nov 2023 01:41:52 +0000 Subject: [PATCH 082/102] Automated fixes by clang-tidy --- ql/math/randomnumbers/burley2020sobolrsg.cpp | 48 ++++++++++---------- ql/math/randomnumbers/sobolrsg.cpp | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ql/math/randomnumbers/burley2020sobolrsg.cpp b/ql/math/randomnumbers/burley2020sobolrsg.cpp index ec441ee21b7..b8c52452a8c 100644 --- a/ql/math/randomnumbers/burley2020sobolrsg.cpp +++ b/ql/math/randomnumbers/burley2020sobolrsg.cpp @@ -54,26 +54,26 @@ namespace QuantLib { // for reverseBits() see http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable - static const std::uint8_t bitReverseTable[] = { - 0u, 128u, 64u, 192u, 32u, 160u, 96u, 224u, 16u, 144u, 80u, 208u, 48u, 176u, - 112u, 240u, 8u, 136u, 72u, 200u, 40u, 168u, 104u, 232u, 24u, 152u, 88u, 216u, - 56u, 184u, 120u, 248u, 4u, 132u, 68u, 196u, 36u, 164u, 100u, 228u, 20u, 148u, - 84u, 212u, 52u, 180u, 116u, 244u, 12u, 140u, 76u, 204u, 44u, 172u, 108u, 236u, - 28u, 156u, 92u, 220u, 60u, 188u, 124u, 252u, 2u, 130u, 66u, 194u, 34u, 162u, - 98u, 226u, 18u, 146u, 82u, 210u, 50u, 178u, 114u, 242u, 10u, 138u, 74u, 202u, - 42u, 170u, 106u, 234u, 26u, 154u, 90u, 218u, 58u, 186u, 122u, 250u, 6u, 134u, - 70u, 198u, 38u, 166u, 102u, 230u, 22u, 150u, 86u, 214u, 54u, 182u, 118u, 246u, - 14u, 142u, 78u, 206u, 46u, 174u, 110u, 238u, 30u, 158u, 94u, 222u, 62u, 190u, - 126u, 254u, 1u, 129u, 65u, 193u, 33u, 161u, 97u, 225u, 17u, 145u, 81u, 209u, - 49u, 177u, 113u, 241u, 9u, 137u, 73u, 201u, 41u, 169u, 105u, 233u, 25u, 153u, - 89u, 217u, 57u, 185u, 121u, 249u, 5u, 133u, 69u, 197u, 37u, 165u, 101u, 229u, - 21u, 149u, 85u, 213u, 53u, 181u, 117u, 245u, 13u, 141u, 77u, 205u, 45u, 173u, - 109u, 237u, 29u, 157u, 93u, 221u, 61u, 189u, 125u, 253u, 3u, 131u, 67u, 195u, - 35u, 163u, 99u, 227u, 19u, 147u, 83u, 211u, 51u, 179u, 115u, 243u, 11u, 139u, - 75u, 203u, 43u, 171u, 107u, 235u, 27u, 155u, 91u, 219u, 59u, 187u, 123u, 251u, - 7u, 135u, 71u, 199u, 39u, 167u, 103u, 231u, 23u, 151u, 87u, 215u, 55u, 183u, - 119u, 247u, 15u, 143u, 79u, 207u, 47u, 175u, 111u, 239u, 31u, 159u, 95u, 223u, - 63u, 191u, 127u, 255u}; + const std::uint8_t bitReverseTable[] = { + 0U, 128U, 64U, 192U, 32U, 160U, 96U, 224U, 16U, 144U, 80U, 208U, 48U, 176U, + 112U, 240U, 8U, 136U, 72U, 200U, 40U, 168U, 104U, 232U, 24U, 152U, 88U, 216U, + 56U, 184U, 120U, 248U, 4U, 132U, 68U, 196U, 36U, 164U, 100U, 228U, 20U, 148U, + 84U, 212U, 52U, 180U, 116U, 244U, 12U, 140U, 76U, 204U, 44U, 172U, 108U, 236U, + 28U, 156U, 92U, 220U, 60U, 188U, 124U, 252U, 2U, 130U, 66U, 194U, 34U, 162U, + 98U, 226U, 18U, 146U, 82U, 210U, 50U, 178U, 114U, 242U, 10U, 138U, 74U, 202U, + 42U, 170U, 106U, 234U, 26U, 154U, 90U, 218U, 58U, 186U, 122U, 250U, 6U, 134U, + 70U, 198U, 38U, 166U, 102U, 230U, 22U, 150U, 86U, 214U, 54U, 182U, 118U, 246U, + 14U, 142U, 78U, 206U, 46U, 174U, 110U, 238U, 30U, 158U, 94U, 222U, 62U, 190U, + 126U, 254U, 1U, 129U, 65U, 193U, 33U, 161U, 97U, 225U, 17U, 145U, 81U, 209U, + 49U, 177U, 113U, 241U, 9U, 137U, 73U, 201U, 41U, 169U, 105U, 233U, 25U, 153U, + 89U, 217U, 57U, 185U, 121U, 249U, 5U, 133U, 69U, 197U, 37U, 165U, 101U, 229U, + 21U, 149U, 85U, 213U, 53U, 181U, 117U, 245U, 13U, 141U, 77U, 205U, 45U, 173U, + 109U, 237U, 29U, 157U, 93U, 221U, 61U, 189U, 125U, 253U, 3U, 131U, 67U, 195U, + 35U, 163U, 99U, 227U, 19U, 147U, 83U, 211U, 51U, 179U, 115U, 243U, 11U, 139U, + 75U, 203U, 43U, 171U, 107U, 235U, 27U, 155U, 91U, 219U, 59U, 187U, 123U, 251U, + 7U, 135U, 71U, 199U, 39U, 167U, 103U, 231U, 23U, 151U, 87U, 215U, 55U, 183U, + 119U, 247U, 15U, 143U, 79U, 207U, 47U, 175U, 111U, 239U, 31U, 159U, 95U, 223U, + 63U, 191U, 127U, 255U}; inline std::uint32_t reverseBits(std::uint32_t x) { return (bitReverseTable[x & 0xff] << 24) | (bitReverseTable[(x >> 8) & 0xff] << 16) | @@ -82,10 +82,10 @@ namespace QuantLib { inline std::uint32_t laine_karras_permutation(std::uint32_t x, std::uint32_t seed) { x += seed; - x ^= x * 0x6c50b47cu; - x ^= x * 0xb82f1e52u; - x ^= x * 0xc7afe638u; - x ^= x * 0x8d22f6e6u; + x ^= x * 0x6c50b47cU; + x ^= x * 0xb82f1e52U; + x ^= x * 0xc7afe638U; + x ^= x * 0x8d22f6e6U; return x; } diff --git a/ql/math/randomnumbers/sobolrsg.cpp b/ql/math/randomnumbers/sobolrsg.cpp index 1e0810e843c..b98f9bbf165 100644 --- a/ql/math/randomnumbers/sobolrsg.cpp +++ b/ql/math/randomnumbers/sobolrsg.cpp @@ -78793,7 +78793,7 @@ namespace QuantLib { } } } else { - std::fill(integerSequence_.begin(), integerSequence_.end(), 0u); + std::fill(integerSequence_.begin(), integerSequence_.end(), 0U); std::uint_least32_t mask = 1; for (Size index = 0; index < bits_; index++) { if ((N & mask) != 0U) { From 3a00f85968454a4dcd89fdd3ff385f0114c5b549 Mon Sep 17 00:00:00 2001 From: Eugene Toder Date: Mon, 20 Nov 2023 20:09:14 -0500 Subject: [PATCH 083/102] Fix skipping expired additionalDates * Do not assume additionalDates are sorted. * Fix appending additionalDates to dates (2*firstAdditionalDate_ were skipped leading to an abort later). * Simplify the code. --- ql/termstructures/globalbootstrap.hpp | 39 +++++++++++++-------------- test-suite/piecewiseyieldcurve.cpp | 10 +++++-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/ql/termstructures/globalbootstrap.hpp b/ql/termstructures/globalbootstrap.hpp index ed966215bf6..77af4532ba3 100644 --- a/ql/termstructures/globalbootstrap.hpp +++ b/ql/termstructures/globalbootstrap.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace QuantLib { @@ -75,8 +76,6 @@ template class GlobalBootstrap { mutable bool initialized_ = false, validCurve_ = false; mutable Size firstHelper_, numberHelpers_; mutable Size firstAdditionalHelper_, numberAdditionalHelpers_; - mutable Size firstAdditionalDate_, numberAdditionalDates_; - mutable std::vector lowerBounds_, upperBounds_; }; // template definitions @@ -111,7 +110,7 @@ template void GlobalBootstrap::initialize() const { std::sort(additionalHelpers_.begin(), additionalHelpers_.end(), detail::BootstrapHelperSorter()); // skip expired helpers - Date firstDate = Traits::initialDate(ts_); + const Date firstDate = Traits::initialDate(ts_); firstHelper_ = 0; if (!ts_->instruments_.empty()) { @@ -133,16 +132,18 @@ template void GlobalBootstrap::initialize() const { std::vector additionalDates; if (additionalDates_) additionalDates = additionalDates_(); - firstAdditionalDate_ = 0; if (!additionalDates.empty()) { - while (firstAdditionalDate_ < additionalDates.size() && additionalDates[firstAdditionalDate_] <= firstDate) - ++firstAdditionalDate_; + additionalDates.erase( + std::remove_if(additionalDates.begin(), additionalDates.end(), + [=](const Date& date) { return date <= firstDate; }), + additionalDates.end() + ); } - numberAdditionalDates_ = additionalDates.size() - firstAdditionalDate_; + const Size numberAdditionalDates = additionalDates.size(); - QL_REQUIRE(numberHelpers_ + numberAdditionalDates_ >= Interpolator::requiredPoints - 1, - "not enough alive instruments (" << numberHelpers_ << ") + additional dates (" << numberAdditionalDates_ - << ") = " << numberHelpers_ + numberAdditionalDates_ << " provided, " + QL_REQUIRE(numberHelpers_ + numberAdditionalDates >= Interpolator::requiredPoints - 1, + "not enough alive instruments (" << numberHelpers_ << ") + additional dates (" << numberAdditionalDates + << ") = " << numberHelpers_ + numberAdditionalDates << " provided, " << Interpolator::requiredPoints - 1 << " required"); // calculate dates and times @@ -154,8 +155,7 @@ template void GlobalBootstrap::initialize() const { dates.push_back(firstDate); for (Size j = 0; j < numberHelpers_; ++j) dates.push_back(ts_->instruments_[firstHelper_ + j]->pillarDate()); - for (Size j = firstAdditionalDate_; j < numberAdditionalDates_; ++j) - dates.push_back(additionalDates[firstAdditionalDate_ + j]); + dates.insert(dates.end(), additionalDates.begin(), additionalDates.end()); std::sort(dates.begin(), dates.end()); auto it = std::unique(dates.begin(), dates.end()); QL_REQUIRE(it == dates.end(), "duplicate dates among alive instruments and additional dates"); @@ -166,13 +166,10 @@ template void GlobalBootstrap::initialize() const { times.push_back(ts_->timeFromReference(date)); // determine maxDate - Date maxDate = firstDate; + Date maxDate = dates.back(); for (Size j = 0; j < numberHelpers_; ++j) { maxDate = std::max(ts_->instruments_[firstHelper_ + j]->latestRelevantDate(), maxDate); } - for (Size j = 0; j < numberAdditionalDates_; ++j) { - maxDate = std::max(additionalDates[firstAdditionalDate_ + j], maxDate); - } ts_->maxDate_ = maxDate; // set initial guess only if the current curve cannot be used as guess @@ -231,9 +228,9 @@ template void GlobalBootstrap::calculate() const { } // determine bounds, we use an unconstrained optimisation transforming the free variables to [lowerBound,upperBound] - std::vector lowerBounds(numberHelpers_ + numberAdditionalDates_), - upperBounds(numberHelpers_ + numberAdditionalDates_); - for (Size i = 0; i < numberHelpers_ + numberAdditionalDates_; ++i) { + const Size numberBounds = ts_->times_.size() - 1; + std::vector lowerBounds(numberBounds), upperBounds(numberBounds); + for (Size i = 0; i < numberBounds; ++i) { // just pass zero as the first alive helper, it's not used in the standard QL traits anyway lowerBounds[i] = Traits::minValueAfter(i + 1, ts_, validCurve_, 0); upperBounds[i] = Traits::maxValueAfter(i + 1, ts_, validCurve_, 0); @@ -295,8 +292,8 @@ template void GlobalBootstrap::calculate() const { TargetFunction cost(firstHelper_, numberHelpers_, additionalErrors_, ts_, lowerBounds, upperBounds); // setup guess - Array guess(numberHelpers_ + numberAdditionalDates_); - for (Size i = 0; i < guess.size(); ++i) { + Array guess(numberBounds); + for (Size i = 0; i < numberBounds; ++i) { // just pass zero as the first alive helper, it's not used in the standard QL traits anyway guess[i] = cost.transformInverse(Traits::guess(i + 1, ts_, validCurve_, 0), i); } diff --git a/test-suite/piecewiseyieldcurve.cpp b/test-suite/piecewiseyieldcurve.cpp index 41d789219de..2c893252ec4 100644 --- a/test-suite/piecewiseyieldcurve.cpp +++ b/test-suite/piecewiseyieldcurve.cpp @@ -1276,10 +1276,16 @@ namespace piecewise_yield_curve_test { // functor returning additional dates used in the bootstrap struct additionalDates { std::vector operator()() { - Date settl = TARGET().advance(Settings::instance().evaluationDate(), 2 * Days); + Date today = Settings::instance().evaluationDate(); + Calendar cal = TARGET(); + Date settl = cal.advance(today, 2 * Days); std::vector dates; for (Size i = 0; i < 5; ++i) - dates.push_back(TARGET().advance(settl, (1 + i) * Months)); + dates.push_back(cal.advance(settl, (1 + i) * Months)); + // Add dates before the referenceDate and not in sorted order. + // These should be skipped by GlobalBootstrap::initialize(). + dates.insert(dates.begin(), today - 1); + dates.push_back(today - 2); return dates; } }; From 7389c6640be13515e3f2eb349e6d6b9bf42893ea Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Fri, 1 Dec 2023 11:40:27 +0100 Subject: [PATCH 084/102] Update rolling Ubuntu image for CI builds --- .github/workflows/devenv-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/devenv-images.yml b/.github/workflows/devenv-images.yml index aa5aaa6edef..f2dfd4652d2 100644 --- a/.github/workflows/devenv-images.yml +++ b/.github/workflows/devenv-images.yml @@ -6,7 +6,7 @@ on: description: 'Boost version' required: true env: - ROLLING: lunar + ROLLING: mantic jobs: docker-images: runs-on: ubuntu-latest From 1b2fcf5bcb63da3541890eb348545b05b930f2e8 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Fri, 1 Dec 2023 16:18:13 +0100 Subject: [PATCH 085/102] Move test to faster section --- test-suite/andreasenhugevolatilityinterpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suite/andreasenhugevolatilityinterpl.cpp b/test-suite/andreasenhugevolatilityinterpl.cpp index 26973bb8710..f993d20742c 100644 --- a/test-suite/andreasenhugevolatilityinterpl.cpp +++ b/test-suite/andreasenhugevolatilityinterpl.cpp @@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(testAndreasenHugePut, *precondition(if_speed(Fast))) { testAndreasenHugeVolatilityInterpolation(data, expected); } -BOOST_AUTO_TEST_CASE(testAndreasenHugeCall, *precondition(if_speed(Fast))) { +BOOST_AUTO_TEST_CASE(testAndreasenHugeCall) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with Call calibration..."); From 87e6e3c8936559d1c7c85bb53d0b0b626667bfea Mon Sep 17 00:00:00 2001 From: Jonathan Sweemer Date: Sun, 3 Dec 2023 20:31:01 +0900 Subject: [PATCH 086/102] Initialize bounds --- ql/math/solver1d.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ql/math/solver1d.hpp b/ql/math/solver1d.hpp index 81d1f896d0c..c09c53e5c30 100644 --- a/ql/math/solver1d.hpp +++ b/ql/math/solver1d.hpp @@ -227,7 +227,7 @@ namespace QuantLib { mutable Size evaluationNumber_; private: Real enforceBounds_(Real x) const; - Real lowerBound_, upperBound_; + Real lowerBound_{}, upperBound_{}; bool lowerBoundEnforced_ = false, upperBoundEnforced_ = false; }; From 1cb2dfc4acccdfa78d0a24ca4898bc281e7235f7 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Tue, 5 Dec 2023 18:17:46 +0100 Subject: [PATCH 087/102] Remove spurious messages in test case --- test-suite/lowdiscrepancysequences.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test-suite/lowdiscrepancysequences.cpp b/test-suite/lowdiscrepancysequences.cpp index 7aa80404dbd..b9c4f681f60 100644 --- a/test-suite/lowdiscrepancysequences.cpp +++ b/test-suite/lowdiscrepancysequences.cpp @@ -1072,7 +1072,7 @@ BOOST_AUTO_TEST_CASE(testSobolSkipping) { } BOOST_AUTO_TEST_CASE(testHighDimensionalIntegrals, *precondition(if_speed(Slow))) { - BOOST_TEST_MESSAGE("Testing High Dimensional Integrals"); + BOOST_TEST_MESSAGE("Testing high-dimensional integrals..."); /* We are running "Integration test 1, results for high dimensions" (Figure 9) from: @@ -1094,8 +1094,6 @@ BOOST_AUTO_TEST_CASE(testHighDimensionalIntegrals, *precondition(if_speed(Slow)) Size N = 30031; - BOOST_TEST_MESSAGE("dimension,Sobol(Gray),Sobol(Seq),Burley2020"); - std::vector dimension = {1000, 2000, 5000}; std::vector> expectedOrderOfError = { {-3.0, -3.0, -4.5}, {-2.5, -2.5, -4.0}, {-2.0, -2.0, -4.0}}; @@ -1119,9 +1117,6 @@ BOOST_AUTO_TEST_CASE(testHighDimensionalIntegrals, *precondition(if_speed(Slow)) Real errOrder2 = std::log10(std::abs(I2 - 1.0)); Real errOrder3 = std::log10(std::abs(I3 - 1.0)); - BOOST_TEST_MESSAGE(dimension[d] << "," << errOrder1 << "," << errOrder2 << "," - << errOrder3); - BOOST_CHECK_MESSAGE(errOrder1 < expectedOrderOfError[d][0], "order of error for dimension " + std::to_string(dimension[d]) + " is" + std::to_string(errOrder1) + " expected " + From 79df5df65a007425b56fd3b593a0af12477f7009 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 27 Nov 2023 20:32:23 +0100 Subject: [PATCH 088/102] add test for operator/(money, money) --- test-suite/money.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/test-suite/money.cpp b/test-suite/money.cpp index 9a131ec5f8b..3795aecd518 100644 --- a/test-suite/money.cpp +++ b/test-suite/money.cpp @@ -43,8 +43,11 @@ BOOST_AUTO_TEST_CASE(testNone) { Money::Settings::instance().conversionType() = Money::NoConversion; - Money calculated = m1*3.0 + 2.5*m2 - m3/5.0; - Decimal x = m1.value()*3.0 + 2.5*m2.value() - m3.value()/5.0; + Money calculated = m1*3.0 + 2.5*m2 - m3/5.0 + m1 * (m2 / m3); + Decimal x = m1.value() * 3.0 + + 2.5 * m2.value() + - m3.value() / 5.0 + + m1.value() * (m2.value() / m3.value()); Money expected(x, EUR); if (calculated != expected) { @@ -75,11 +78,13 @@ BOOST_AUTO_TEST_CASE(testBaseCurrency) { money_settings.conversionType() = Money::BaseCurrencyConversion; money_settings.baseCurrency() = EUR; - Money calculated = m1*3.0 + 2.5*m2 - m3/5.0; + Money calculated = m1*3.0 + 2.5*m2 - m3/5.0 + m1 * (m2/m3); - Rounding round = money_settings.baseCurrency().rounding(); - Decimal x = round(m1.value()*3.0/eur_gbp.rate()) + 2.5*m2.value() - - round(m3.value()/(5.0*eur_usd.rate())); + const Rounding& round = money_settings.baseCurrency().rounding(); + Decimal x = round(m1.value()*3.0/eur_gbp.rate()) + + 2.5*m2.value() + - round(m3.value()/(5.0*eur_usd.rate())) + + round((m1.value()* (m2.value() / round(m3.value()/eur_usd.rate()))) / eur_gbp.rate()) ; Money expected(x, EUR); money_settings.conversionType() = Money::NoConversion; @@ -110,11 +115,15 @@ BOOST_AUTO_TEST_CASE(testAutomated) { auto & money_settings = Money::Settings::instance(); money_settings.conversionType() = Money::AutomatedConversion; - Money calculated = (m1*3.0 + 2.5*m2) - m3/5.0; + Money calculated = (m1*3.0 + 2.5*m2) - m3/5.0 + m1 * (m2/m3); + + const Rounding& round1 = m1.currency().rounding(); + const Rounding& round2 = m2.currency().rounding(); + Decimal x = m1.value()*3.0 + + round1(2.5*m2.value()*eur_gbp.rate()) + - round1((m3.value()/5.0)*eur_gbp.rate()/eur_usd.rate()) + + m1.value() * ( m2.value() / round2(m3.value()/eur_usd.rate())); - Rounding round = m1.currency().rounding(); - Decimal x = m1.value()*3.0 + round(2.5*m2.value()*eur_gbp.rate()) - - round((m3.value()/5.0)*eur_gbp.rate()/eur_usd.rate()); Money expected(x, GBP); money_settings.conversionType() = Money::NoConversion; From 6f9f82640003e231f7b74df879f5acca1e3cd95c Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 28 Nov 2023 20:53:56 +0100 Subject: [PATCH 089/102] money: unify comparison operators --- ql/money.cpp | 122 +++++++++++++++------------------------------------ 1 file changed, 36 insertions(+), 86 deletions(-) diff --git a/ql/money.cpp b/ql/money.cpp index f0f45656bbf..d85f6678474 100644 --- a/ql/money.cpp +++ b/ql/money.cpp @@ -44,6 +44,27 @@ namespace QuantLib { convertTo(m, base_currency); } + template< typename CompareMonies, typename CompareValues > + bool compare(const Money& m1, const Money& m2, + const CompareMonies compMonies, const CompareValues compValues) { + const auto & conversion_type = + Money::Settings::instance().conversionType(); + if (m1.currency() == m2.currency()) { + return compValues(m1.value(),m2.value()); + } else if (conversion_type == Money::BaseCurrencyConversion) { + Money tmp1 = m1; + convertToBase(tmp1); + Money tmp2 = m2; + convertToBase(tmp2); + return compMonies(tmp1,tmp2); + } else if (conversion_type == Money::AutomatedConversion) { + Money tmp = m2; + convertTo(tmp, m1.currency()); + return compMonies(m1,tmp); + } else { + QL_FAIL("currency mismatch and no conversion specified"); + } + } } Money& Money::operator+=(const Money& m) { @@ -105,106 +126,35 @@ namespace QuantLib { } bool operator==(const Money& m1, const Money& m2) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return m1.value() == m2.value(); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return tmp1 == tmp2; - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return m1 == tmp; - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare(m1, m2, + [](const Money& m1, const Money& m2) { return m1 == m2; }, + [](const Real x, const Real y) { return x == y; }); } bool operator<(const Money& m1, const Money& m2) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return m1.value() < m2.value(); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return tmp1 < tmp2; - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return m1 < tmp; - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare(m1, m2, + [](const Money& m1, const Money& m2) { return m1 < m2; }, + [](const Real x, const Real y) { return x < y; }); } bool operator<=(const Money& m1, const Money& m2) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return m1.value() <= m2.value(); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return tmp1 <= tmp2; - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return m1 <= tmp; - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare(m1, m2, + [](const Money& m1, const Money& m2) { return m1 <= m2; }, + [](const Real x, const Real y) { return x <= y; }); } bool close(const Money& m1, const Money& m2, Size n) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return close(m1.value(),m2.value(),n); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return close(tmp1,tmp2,n); - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return close(m1,tmp,n); - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare(m1, m2, + [n](const Money& m1, const Money& m2) { return close(m1, m2, n); }, + [n](const Real x, const Real y) { return close(x, y, n); }); } bool close_enough(const Money& m1, const Money& m2, Size n) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return close_enough(m1.value(),m2.value(),n); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return close_enough(tmp1,tmp2,n); - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return close_enough(m1,tmp,n); - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare(m1, m2, + [n](const Money& m1, const Money& m2) { return close_enough(m1, m2, n); }, + [n](const Real x, const Real y) { return close_enough(x, y, n); }); } - std::ostream& operator<<(std::ostream& out, const Money& m) { boost::format fmt(m.currency().format()); fmt.exceptions(boost::io::all_error_bits ^ From 70f47bb171e07a5c9f510254b666458970158430 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 28 Nov 2023 21:08:09 +0100 Subject: [PATCH 090/102] money: operator-= in terms of operator+= --- ql/money.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/ql/money.cpp b/ql/money.cpp index d85f6678474..33a67fd4972 100644 --- a/ql/money.cpp +++ b/ql/money.cpp @@ -87,22 +87,7 @@ namespace QuantLib { } Money& Money::operator-=(const Money& m) { - const auto & conversion_type = Settings::instance().conversionType(); - if (currency_ == m.currency_) { - value_ -= m.value_; - } else if (conversion_type == Money::BaseCurrencyConversion) { - convertToBase(*this); - Money tmp = m; - convertToBase(tmp); - *this -= tmp; - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m; - convertTo(tmp, currency_); - *this -= tmp; - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } - return *this; + return *this += (-m); } Decimal operator/(const Money& m1, const Money& m2) { From e79c868a648cbaee15cf9c35f21e829ef50acf64 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 28 Nov 2023 21:08:54 +0100 Subject: [PATCH 091/102] money: operator/ --- ql/money.cpp | 62 +++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/ql/money.cpp b/ql/money.cpp index 33a67fd4972..268ebd0c5ab 100644 --- a/ql/money.cpp +++ b/ql/money.cpp @@ -44,9 +44,9 @@ namespace QuantLib { convertTo(m, base_currency); } - template< typename CompareMonies, typename CompareValues > - bool compare(const Money& m1, const Money& m2, - const CompareMonies compMonies, const CompareValues compValues) { + template< typename ReturnValue, typename CompareMonies, typename CompareValues > + ReturnValue compare(const Money& m1, const Money& m2, + const CompareMonies compMonies, const CompareValues compValues) { const auto & conversion_type = Money::Settings::instance().conversionType(); if (m1.currency() == m2.currency()) { @@ -91,53 +91,45 @@ namespace QuantLib { } Decimal operator/(const Money& m1, const Money& m2) { - const auto & conversion_type = - Money::Settings::instance().conversionType(); - if (m1.currency() == m2.currency()) { - return m1.value()/m2.value(); - } else if (conversion_type == Money::BaseCurrencyConversion) { - Money tmp1 = m1; - convertToBase(tmp1); - Money tmp2 = m2; - convertToBase(tmp2); - return tmp1/tmp2; - } else if (conversion_type == Money::AutomatedConversion) { - Money tmp = m2; - convertTo(tmp, m1.currency()); - return m1/tmp; - } else { - QL_FAIL("currency mismatch and no conversion specified"); - } + return compare( + m1, m2, + [](const Money& m1, const Money& m2) { return m1 / m2; }, + [](const Real x, const Real y) { return x / y; }); } bool operator==(const Money& m1, const Money& m2) { - return compare(m1, m2, - [](const Money& m1, const Money& m2) { return m1 == m2; }, - [](const Real x, const Real y) { return x == y; }); + return compare( + m1, m2, + [](const Money& m1, const Money& m2) { return m1 == m2; }, + [](const Real x, const Real y) { return x == y; }); } bool operator<(const Money& m1, const Money& m2) { - return compare(m1, m2, - [](const Money& m1, const Money& m2) { return m1 < m2; }, - [](const Real x, const Real y) { return x < y; }); + return compare( + m1, m2, + [](const Money& m1, const Money& m2) { return m1 < m2; }, + [](const Real x, const Real y) { return x < y; }); } bool operator<=(const Money& m1, const Money& m2) { - return compare(m1, m2, - [](const Money& m1, const Money& m2) { return m1 <= m2; }, - [](const Real x, const Real y) { return x <= y; }); + return compare( + m1, m2, + [](const Money& m1, const Money& m2) { return m1 <= m2; }, + [](const Real x, const Real y) { return x <= y; }); } bool close(const Money& m1, const Money& m2, Size n) { - return compare(m1, m2, - [n](const Money& m1, const Money& m2) { return close(m1, m2, n); }, - [n](const Real x, const Real y) { return close(x, y, n); }); + return compare( + m1, m2, + [n](const Money& m1, const Money& m2) { return close(m1, m2, n); }, + [n](const Real x, const Real y) { return close(x, y, n); }); } bool close_enough(const Money& m1, const Money& m2, Size n) { - return compare(m1, m2, - [n](const Money& m1, const Money& m2) { return close_enough(m1, m2, n); }, - [n](const Real x, const Real y) { return close_enough(x, y, n); }); + return compare( + m1, m2, + [n](const Money& m1, const Money& m2) { return close_enough(m1, m2, n); }, + [n](const Real x, const Real y) { return close_enough(x, y, n); }); } std::ostream& operator<<(std::ostream& out, const Money& m) { From 143a732f899aa8df0bb24204f259f785b1892876 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 6 Dec 2023 20:56:04 +0100 Subject: [PATCH 092/102] unit test: compare values with tolerance (+style changes) --- test-suite/money.cpp | 106 +++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/test-suite/money.cpp b/test-suite/money.cpp index 3795aecd518..98cc6635f7a 100644 --- a/test-suite/money.cpp +++ b/test-suite/money.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace QuantLib; using namespace boost::unit_test_framework; @@ -31,26 +32,37 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(MoneyTest) +namespace { + bool IsSameCurrencyAndValuesAreClose(const Money& lhs, const Money& rhs) { + return (lhs.currency() == rhs.currency()) + && std::abs(lhs.value() - rhs.value()) < 0.01; + } + + const Currency EUR = EURCurrency(); + const Currency GBP = GBPCurrency(); + const Currency USD = USDCurrency(); + const ExchangeRate eur_usd = ExchangeRate(EUR, USD, 1.2042); + const ExchangeRate eur_gbp = ExchangeRate(EUR, GBP, 0.6612); +} + BOOST_AUTO_TEST_CASE(testNone) { BOOST_TEST_MESSAGE("Testing money arithmetic without conversions..."); - Currency EUR = EURCurrency(); - - Money m1 = 50000.0 * EUR; - Money m2 = 100000.0 * EUR; - Money m3 = 500000.0 * EUR; + const Money m1 = 50000.0 * EUR; + const Money m2 = 100000.0 * EUR; + const Money m3 = 500000.0 * EUR; Money::Settings::instance().conversionType() = Money::NoConversion; - Money calculated = m1*3.0 + 2.5*m2 - m3/5.0 + m1 * (m2 / m3); - Decimal x = m1.value() * 3.0 + const Money calculated = m1*3.0 + 2.5*m2 - m3/5.0 + m1 * (m2 / m3); + const Decimal x = m1.value() * 3.0 + 2.5 * m2.value() - m3.value() / 5.0 + m1.value() * (m2.value() / m3.value()); - Money expected(x, EUR); + const Money expected(x, EUR); - if (calculated != expected) { + if (!IsSameCurrencyAndValuesAreClose(calculated, expected)) { BOOST_FAIL("Wrong result: \n" << " expected: " << expected << "\n" << " calculated: " << calculated); @@ -59,37 +71,33 @@ BOOST_AUTO_TEST_CASE(testNone) { BOOST_AUTO_TEST_CASE(testBaseCurrency) { - BOOST_TEST_MESSAGE("Testing money arithmetic with conversion " - "to base currency..."); - - Currency EUR = EURCurrency(), GBP = GBPCurrency(), USD = USDCurrency(); + BOOST_TEST_MESSAGE("Testing money arithmetic with conversion to base currency..."); - Money m1 = 50000.0 * GBP; - Money m2 = 100000.0 * EUR; - Money m3 = 500000.0 * USD; + const Money gbp = 50000.0 * GBP; + const Money eur = 100000.0 * EUR; + const Money usd = 500000.0 * USD; ExchangeRateManager::instance().clear(); - ExchangeRate eur_usd = ExchangeRate(EUR, USD, 1.2042); - ExchangeRate eur_gbp = ExchangeRate(EUR, GBP, 0.6612); ExchangeRateManager::instance().add(eur_usd); ExchangeRateManager::instance().add(eur_gbp); + const auto GBP_to_EUR = [eur_gbp = eur_gbp.rate()](const Real gbp) -> Real { return gbp / eur_gbp; }; + const auto USD_to_EUR = [eur_usd = eur_usd.rate()](const Real usd) -> Real { return usd / eur_usd; }; - auto & money_settings = Money::Settings::instance(); - money_settings.conversionType() = Money::BaseCurrencyConversion; - money_settings.baseCurrency() = EUR; + Money::Settings::instance().conversionType() = Money::BaseCurrencyConversion; + Money::Settings::instance().baseCurrency() = EUR; - Money calculated = m1*3.0 + 2.5*m2 - m3/5.0 + m1 * (m2/m3); + const Money calculated = gbp*3.0 + 2.5*eur - usd/5.0 + gbp * (eur/usd); - const Rounding& round = money_settings.baseCurrency().rounding(); - Decimal x = round(m1.value()*3.0/eur_gbp.rate()) - + 2.5*m2.value() - - round(m3.value()/(5.0*eur_usd.rate())) - + round((m1.value()* (m2.value() / round(m3.value()/eur_usd.rate()))) / eur_gbp.rate()) ; - Money expected(x, EUR); + const Decimal x = GBP_to_EUR(gbp.value()) * 3.0 + + 2.5 * eur.value() + - USD_to_EUR(usd.value()) / 5.0 + + GBP_to_EUR(gbp.value()) * eur.value() / USD_to_EUR(usd.value()); + const Money expected(x, EUR); - money_settings.conversionType() = Money::NoConversion; + ExchangeRateManager::instance().clear(); + Money::Settings::instance().conversionType() = Money::NoConversion; - if (calculated != expected) { + if (!IsSameCurrencyAndValuesAreClose(calculated, expected)) { BOOST_FAIL("Wrong result: \n" << " expected: " << expected << "\n" << " calculated: " << calculated); @@ -100,35 +108,33 @@ BOOST_AUTO_TEST_CASE(testAutomated) { BOOST_TEST_MESSAGE("Testing money arithmetic with automated conversion..."); - Currency EUR = EURCurrency(), GBP = GBPCurrency(), USD = USDCurrency(); - - Money m1 = 50000.0 * GBP; - Money m2 = 100000.0 * EUR; - Money m3 = 500000.0 * USD; + const Money gbp = 50000.0 * GBP; + const Money eur = 100000.0 * EUR; + const Money usd = 500000.0 * USD; ExchangeRateManager::instance().clear(); - ExchangeRate eur_usd = ExchangeRate(EUR, USD, 1.2042); - ExchangeRate eur_gbp = ExchangeRate(EUR, GBP, 0.6612); ExchangeRateManager::instance().add(eur_usd); ExchangeRateManager::instance().add(eur_gbp); + const auto EUR_to_GBP = [eur_gbp = eur_gbp.rate()](const Real eur) -> Real { return eur * eur_gbp; }; + const auto USD_to_EUR = [eur_usd = eur_usd.rate()](const Real usd) -> Real { return usd / eur_usd; }; + const auto USD_to_GBP = [eur_gbp = eur_gbp.rate(), eur_usd = eur_usd.rate()](const Real usd) -> Real + { return usd * eur_gbp / eur_usd; }; - auto & money_settings = Money::Settings::instance(); - money_settings.conversionType() = Money::AutomatedConversion; + Money::Settings::instance().conversionType() = Money::AutomatedConversion; - Money calculated = (m1*3.0 + 2.5*m2) - m3/5.0 + m1 * (m2/m3); + const Money calculated = (gbp*3.0 + 2.5*eur) - usd/5.0 + gbp * (eur/usd); - const Rounding& round1 = m1.currency().rounding(); - const Rounding& round2 = m2.currency().rounding(); - Decimal x = m1.value()*3.0 - + round1(2.5*m2.value()*eur_gbp.rate()) - - round1((m3.value()/5.0)*eur_gbp.rate()/eur_usd.rate()) - + m1.value() * ( m2.value() / round2(m3.value()/eur_usd.rate())); + const Decimal x = gbp.value() * 3.0 + + 2.5 * EUR_to_GBP(eur.value()) + - USD_to_GBP(usd.value()) / 5.0 + + gbp.value() * eur.value() / USD_to_EUR(usd.value()); - Money expected(x, GBP); + const Money expected(x, GBP); - money_settings.conversionType() = Money::NoConversion; + ExchangeRateManager::instance().clear(); + Money::Settings::instance().conversionType() = Money::NoConversion; - if (calculated != expected) { + if (!IsSameCurrencyAndValuesAreClose(calculated, expected)) { BOOST_FAIL("Wrong result: \n" << " expected: " << expected << "\n" << " calculated: " << calculated); @@ -137,4 +143,4 @@ BOOST_AUTO_TEST_CASE(testAutomated) { BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() From 2aabea04d51db05da98f034f65ca035a0bc85c68 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 1 Dec 2023 21:34:20 +0100 Subject: [PATCH 093/102] unit test: check comparisons --- test-suite/money.cpp | 64 ++++++++++++++++++++++++++++++++++++ test-suite/preconditions.hpp | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/test-suite/money.cpp b/test-suite/money.cpp index 98cc6635f7a..166c6fa943f 100644 --- a/test-suite/money.cpp +++ b/test-suite/money.cpp @@ -141,6 +141,70 @@ BOOST_AUTO_TEST_CASE(testAutomated) { } } +BOOST_AUTO_TEST_CASE(testComparisons) { + + BOOST_TEST_MESSAGE("Testing money comparisons..."); + + for (const auto conversionType : {Money::AutomatedConversion, Money::NoConversion, Money::BaseCurrencyConversion}) { + ExchangeRateManager::instance().add(eur_usd); + ExchangeRateManager::instance().add(eur_gbp); + Money::Settings::instance().conversionType() = conversionType; + if (conversionType == Money::BaseCurrencyConversion) + Money::Settings::instance().baseCurrency() = EUR; + + // equality + BOOST_CHECK_EQUAL(Money(123.45, EUR), Money(123.45, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_EQUAL(Money(1, EUR), Money(eur_usd.rate(), USD)); + + // unequal + BOOST_CHECK_NE(Money(1, EUR), Money(2, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_NE(Money(1, EUR), Money(100, USD)); + + // less than + BOOST_CHECK_LT(Money(1, EUR), Money(2, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_LT(Money(1, EUR), Money(100, USD)); + + // less or equal than + BOOST_CHECK_LE(Money(1, EUR), Money(2, EUR)); + BOOST_CHECK_LE(Money(2, EUR), Money(2, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_LE(Money(1, EUR), Money(100, USD)); + + // greater than + BOOST_CHECK_GT(Money(2, EUR), Money(1, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_GT(Money(100, EUR), Money(1, USD)); + + // less or equal than + BOOST_CHECK_GE(Money(2, EUR), Money(1, EUR)); + BOOST_CHECK_GE(Money(2, EUR), Money(2, EUR)); + if (conversionType != Money::NoConversion) + BOOST_CHECK_GE(Money(100, EUR), Money(1, USD)); + + // close + BOOST_CHECK(close(Money(1, EUR), Money(1, EUR))); + BOOST_CHECK(close(Money(1+1e-15, EUR), Money(1, EUR))); + if (conversionType != Money::NoConversion){ + BOOST_CHECK(close(Money(1, EUR), Money(eur_usd.rate(), USD))); + BOOST_CHECK(close(Money(1+1e-15, EUR), Money(eur_usd.rate(), USD))); + } + + // close enough + BOOST_CHECK(close_enough(Money(1, EUR), Money(1, EUR))); + BOOST_CHECK(close_enough(Money(1+1e-15, EUR), Money(1, EUR))); + if (conversionType != Money::NoConversion){ + BOOST_CHECK(close_enough(Money(1, EUR), Money(eur_usd.rate(), USD))); + BOOST_CHECK(close_enough(Money(1+1e-15, EUR), Money(eur_usd.rate(), USD))); + } + + ExchangeRateManager::instance().clear(); + Money::Settings::instance().conversionType() = Money::NoConversion; + } +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/preconditions.hpp b/test-suite/preconditions.hpp index 5bcbd74d039..4d0156cc13c 100644 --- a/test-suite/preconditions.hpp +++ b/test-suite/preconditions.hpp @@ -40,4 +40,4 @@ struct usingAtParCoupons { boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id); }; -#endif //quantlib_test_preconditions_hpp \ No newline at end of file +#endif //quantlib_test_preconditions_hpp From 1bc5f91c0f578c8fa3fc5cb58198d9149a350d09 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 6 Dec 2023 20:22:54 +0100 Subject: [PATCH 094/102] simplify generic compare/apply function --- ql/money.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/ql/money.cpp b/ql/money.cpp index 268ebd0c5ab..29f3503f575 100644 --- a/ql/money.cpp +++ b/ql/money.cpp @@ -44,23 +44,22 @@ namespace QuantLib { convertTo(m, base_currency); } - template< typename ReturnValue, typename CompareMonies, typename CompareValues > - ReturnValue compare(const Money& m1, const Money& m2, - const CompareMonies compMonies, const CompareValues compValues) { + template< typename ReturnValue, typename Funtion > + ReturnValue apply(const Money& m1, const Money& m2, const Funtion f) { const auto & conversion_type = Money::Settings::instance().conversionType(); if (m1.currency() == m2.currency()) { - return compValues(m1.value(),m2.value()); + return f(m1.value(), m2.value()); } else if (conversion_type == Money::BaseCurrencyConversion) { Money tmp1 = m1; convertToBase(tmp1); Money tmp2 = m2; convertToBase(tmp2); - return compMonies(tmp1,tmp2); + return f(tmp1.value(), tmp2.value()); } else if (conversion_type == Money::AutomatedConversion) { Money tmp = m2; convertTo(tmp, m1.currency()); - return compMonies(m1,tmp); + return f(m1.value(), tmp.value()); } else { QL_FAIL("currency mismatch and no conversion specified"); } @@ -91,44 +90,38 @@ namespace QuantLib { } Decimal operator/(const Money& m1, const Money& m2) { - return compare( + return apply( m1, m2, - [](const Money& m1, const Money& m2) { return m1 / m2; }, [](const Real x, const Real y) { return x / y; }); } bool operator==(const Money& m1, const Money& m2) { - return compare( + return apply( m1, m2, - [](const Money& m1, const Money& m2) { return m1 == m2; }, [](const Real x, const Real y) { return x == y; }); } bool operator<(const Money& m1, const Money& m2) { - return compare( + return apply( m1, m2, - [](const Money& m1, const Money& m2) { return m1 < m2; }, [](const Real x, const Real y) { return x < y; }); } bool operator<=(const Money& m1, const Money& m2) { - return compare( + return apply( m1, m2, - [](const Money& m1, const Money& m2) { return m1 <= m2; }, [](const Real x, const Real y) { return x <= y; }); } bool close(const Money& m1, const Money& m2, Size n) { - return compare( + return apply( m1, m2, - [n](const Money& m1, const Money& m2) { return close(m1, m2, n); }, [n](const Real x, const Real y) { return close(x, y, n); }); } bool close_enough(const Money& m1, const Money& m2, Size n) { - return compare( + return apply( m1, m2, - [n](const Money& m1, const Money& m2) { return close_enough(m1, m2, n); }, [n](const Real x, const Real y) { return close_enough(x, y, n); }); } From eff0c83ffa8a4a75d5ab8ed711cacac0521a3558 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 8 Dec 2023 23:01:35 +0100 Subject: [PATCH 095/102] full test coverage of timegrid --- test-suite/timegrid.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test-suite/timegrid.cpp b/test-suite/timegrid.cpp index be75146aed4..db7e476faa9 100644 --- a/test-suite/timegrid.cpp +++ b/test-suite/timegrid.cpp @@ -56,6 +56,19 @@ BOOST_AUTO_TEST_CASE(testConstructorMandatorySteps) tg.begin(), tg.end(), expected_times.begin(), expected_times.end()); } +BOOST_AUTO_TEST_CASE(testConstructorAdditionalStepsAutomatically) +{ + BOOST_TEST_MESSAGE("Testing TimeGrid construction with time step length determined automatically..."); + + const TimeGrid tg{{0.0, 1.0, 2.0, 4.0}, 0}; + + // Time step length is determined by minimal adjacent distance in given times + const std::vector