From 333c79cc2bbc15377b0f3015e4cdef1b3b360f9f Mon Sep 17 00:00:00 2001 From: Nathaniel Brough Date: Fri, 6 Oct 2023 14:02:27 -0700 Subject: [PATCH 001/132] testing: Add basic fuzz test harnesses --- CMakeLists.txt | 9 ++++++++- fuzz-test-suite/CMakeLists.txt | 21 +++++++++++++++++++++ fuzz-test-suite/dateparserfuzzer.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 fuzz-test-suite/CMakeLists.txt create mode 100644 fuzz-test-suite/dateparserfuzzer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 97aad9d6131..2d75a07aa36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,10 @@ -cmake_minimum_required(VERSION 3.15.0) +cmake_minimum_required(VERSION 3.22.0) # For MSVC RUNTIME LIBRARY, need CMP0091=NEW and cmake 3.15+ cmake_policy(SET CMP0091 NEW) +include(CMakeDependentOption) + # Version info set(QUANTLIB_VERSION_MAJOR 1) set(QUANTLIB_VERSION_MINOR 32) @@ -42,6 +44,7 @@ set(QL_INSTALL_CMAKEDIR "lib/cmake/${PACKAGE_NAME}" CACHE STRING option(QL_BUILD_BENCHMARK "Build benchmark" ON) option(QL_BUILD_EXAMPLES "Build examples" ON) option(QL_BUILD_TEST_SUITE "Build test suite" ON) +cmake_dependent_option(QL_BUILD_FUZZ_TEST_SUITE "Build fuzz test suite" ON "'${CMAKE_CXX_COMPILER_ID}' MATCHES 'Clang'" OFF) option(QL_ENABLE_OPENMP "Detect and use OpenMP" OFF) option(QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER "Enable the parallel unit test runner" OFF) option(QL_ENABLE_SESSIONS "Singletons return different instances for different sessions" OFF) @@ -269,6 +272,10 @@ if (QL_BUILD_TEST_SUITE OR QL_BUILD_BENCHMARK) add_subdirectory(test-suite) endif() +if (QL_BUILD_FUZZ_TEST_SUITE) + add_subdirectory(fuzz-test-suite) +endif() + # CPack support (make package, make package_source) set(CPACK_PACKAGE_VERSION_MAJOR ${QUANTLIB_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${QUANTLIB_VERSION_MINOR}) diff --git a/fuzz-test-suite/CMakeLists.txt b/fuzz-test-suite/CMakeLists.txt new file mode 100644 index 00000000000..aaddcbfefd4 --- /dev/null +++ b/fuzz-test-suite/CMakeLists.txt @@ -0,0 +1,21 @@ +# Determine the flags for fuzzing. Use OSS-Fuzz's configuration if available, otherwise fall back to defaults. +if(DEFINED ENV{LIB_FUZZING_ENGINE}) + set(FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE}) + set(FUZZING_COMPILE_FLAGS "") + set(FUZZING_LINK_FLAGS "${FUZZING_ENGINE}") +else() + set(FUZZING_COMPILE_FLAGS "-fsanitize=fuzzer") + set(FUZZING_LINK_FLAGS "-fsanitize=fuzzer") +endif() + +# Define the fuzz target +add_executable(DateParserFuzzer dateparserfuzzer.cpp) + +# Apply the determined flags +set_target_properties(DateParserFuzzer PROPERTIES + COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}" + LINK_FLAGS "${FUZZING_LINK_FLAGS}" +) + +# Link QuantLib and any other necessary libraries +target_link_libraries(DateParserFuzzer ql_library ${QL_THREAD_LIBRARIES}) diff --git a/fuzz-test-suite/dateparserfuzzer.cpp b/fuzz-test-suite/dateparserfuzzer.cpp new file mode 100644 index 00000000000..7c6f6423fdd --- /dev/null +++ b/fuzz-test-suite/dateparserfuzzer.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include +#include + +#ifndef __clang__ +#pragma message("Fuzzer headers are available from clang, other compilers have not been tested.") +#endif +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider fdp(data, size); + constexpr int kMaxString = 100; + try { + (void)QuantLib::DateParser::parseFormatted(fdp.ConsumeRandomLengthString(kMaxString), "%Y-%m-%d"); + (void)QuantLib::DateParser::parseISO(fdp.ConsumeRandomLengthString(kMaxString)); + } catch (const std::exception& e) { + // Handle or ignore exceptions + } + return 0; +} From a90a17dd7951f0d13eee384ec7c5ebc7f0ec0f89 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 14 Sep 2023 17:29:38 +0800 Subject: [PATCH 002/132] Updates to use automated registration --- test-suite/CMakeLists.txt | 8 ++- test-suite/Makefile.am | 8 +-- test-suite/americanoption.cpp | 101 ++++++++------------------- test-suite/americanoption.hpp | 62 ---------------- test-suite/instruments.cpp | 31 ++++---- test-suite/instruments.hpp | 37 ---------- test-suite/paralleltestrunner.hpp | 3 +- test-suite/quantlibbenchmark.cpp | 4 +- test-suite/quantlibglobalfixture.cpp | 66 +++++++++++++++++ test-suite/quantlibglobalfixture.hpp | 19 +++++ test-suite/quantlibtestsuite.cpp | 64 +++++------------ test-suite/speedlevel.cpp | 15 ++++ test-suite/speedlevel.hpp | 9 +++ test-suite/testsuite.vcxproj | 6 +- test-suite/testsuite.vcxproj.filters | 18 +++-- test-suite/toplevelfixture.hpp | 34 +++++++++ tools/check_test_times.py | 11 ++- 17 files changed, 242 insertions(+), 254 deletions(-) delete mode 100644 test-suite/americanoption.hpp delete mode 100644 test-suite/instruments.hpp create mode 100644 test-suite/quantlibglobalfixture.cpp create mode 100644 test-suite/quantlibglobalfixture.hpp create mode 100644 test-suite/speedlevel.cpp create mode 100644 test-suite/toplevelfixture.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index f706e2dd1d0..64db657289c 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 + quantlibglobalfixture.cpp quantlibtestsuite.cpp quantooption.cpp quotes.cpp @@ -140,6 +141,7 @@ set(QL_TEST_SOURCES shortratemodels.cpp sofrfutures.cpp solvers.cpp + speedlevel.cpp spreadoption.cpp squarerootclvmodel.cpp stats.cpp @@ -171,7 +173,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - americanoption.hpp amortizingbond.hpp andreasenhugevolatilityinterpl.hpp array.hpp @@ -257,7 +258,6 @@ set(QL_TEST_HEADERS inflationcpicapfloor.hpp inflationcpiswap.hpp inflationvolatility.hpp - instruments.hpp integrals.hpp interestrates.hpp interpolations.hpp @@ -299,6 +299,7 @@ set(QL_TEST_HEADERS period.hpp piecewiseyieldcurve.hpp piecewisezerospreadedtermstructure.hpp + quantlibglobalfixture.hpp quantooption.hpp quotes.hpp rangeaccrual.hpp @@ -329,6 +330,7 @@ set(QL_TEST_HEADERS timegrid.hpp timeseries.hpp tqreigendecomposition.hpp + toplevelfixture.hpp tracing.hpp transformedgrid.hpp twoassetbarrieroption.hpp @@ -347,7 +349,7 @@ set(QL_TEST_HEADERS set(QL_BENCHMARK_SOURCES quantlibbenchmark.cpp - americanoption.cpp americanoption.hpp +# americanoption.cpp asianoptions.cpp asianoptions.hpp barrieroption.cpp barrieroption.hpp basketoption.cpp basketoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 04e2d5bf963..8cdf884d5fe 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -128,6 +128,7 @@ QL_TEST_SRCS = \ period.cpp \ piecewiseyieldcurve.cpp \ piecewisezerospreadedtermstructure.cpp \ + quantlibglobalfixture.cpp \ quantooption.cpp \ quotes.cpp \ rangeaccrual.cpp \ @@ -141,6 +142,7 @@ QL_TEST_SRCS = \ shortratemodels.cpp \ sofrfutures.cpp \ solvers.cpp \ + speedlevel.cpp \ spreadoption.cpp \ squarerootclvmodel.cpp \ stats.cpp \ @@ -172,7 +174,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ speedlevel.hpp \ - americanoption.hpp \ amortizingbond.hpp \ andreasenhugevolatilityinterpl.hpp \ array.hpp \ @@ -258,7 +259,6 @@ QL_TEST_HDRS = \ inflationcpicapfloor.hpp \ inflationcpiswap.hpp \ inflationvolatility.hpp \ - instruments.hpp \ integrals.hpp \ interestrates.hpp \ interpolations.hpp \ @@ -299,6 +299,7 @@ QL_TEST_HDRS = \ period.hpp \ piecewiseyieldcurve.hpp \ piecewisezerospreadedtermstructure.hpp \ + quantlibglobalfixture.hpp \ quantooption.hpp \ quotes.hpp \ rangeaccrual.hpp \ @@ -329,6 +330,7 @@ QL_TEST_HDRS = \ timeseries.hpp \ transformedgrid.hpp \ tqreigendecomposition.hpp \ + toplevelfixture.hpp \ tracing.hpp \ twoassetbarrieroption.hpp \ twoassetcorrelationoption.hpp \ @@ -346,7 +348,6 @@ QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS} QL_BENCHMARK_SRCS = \ quantlibbenchmark.cpp \ - americanoption.cpp \ asianoptions.cpp \ barrieroption.cpp \ doublebarrieroption.cpp \ @@ -369,7 +370,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - americanoption.hpp \ asianoptions.hpp \ barrieroption.hpp \ doublebarrieroption.hpp \ diff --git a/test-suite/americanoption.cpp b/test-suite/americanoption.cpp index 777c4ce53e0..229cf7d483d 100644 --- a/test-suite/americanoption.cpp +++ b/test-suite/americanoption.cpp @@ -19,7 +19,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "americanoption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -83,8 +84,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) -void AmericanOptionTest::testBaroneAdesiWhaleyValues() { +BOOST_AUTO_TEST_SUITE(AmericanOptionTest) + +BOOST_AUTO_TEST_CASE(testBaroneAdesiWhaleyValues) { BOOST_TEST_MESSAGE("Testing Barone-Adesi and Whaley approximation " "for American options..."); @@ -184,8 +188,7 @@ void AmericanOptionTest::testBaroneAdesiWhaleyValues() { } } - -void AmericanOptionTest::testBjerksundStenslandValues() { +BOOST_AUTO_TEST_CASE(testBjerksundStenslandValues) { BOOST_TEST_MESSAGE("Testing Bjerksund and Stensland approximation " "for American options..."); @@ -330,8 +333,7 @@ namespace { } - -void AmericanOptionTest::testJuValues() { +BOOST_AUTO_TEST_CASE(testJuValues) { BOOST_TEST_MESSAGE("Testing Ju approximation for American options..."); @@ -381,8 +383,7 @@ void AmericanOptionTest::testJuValues() { } } - -void AmericanOptionTest::testFdValues() { +BOOST_AUTO_TEST_CASE(testFdValues) { BOOST_TEST_MESSAGE("Testing finite-difference and QR+ engine " "for American options..."); @@ -563,18 +564,17 @@ namespace { } - -void AmericanOptionTest::testFdAmericanGreeks() { +BOOST_AUTO_TEST_CASE(testFdAmericanGreeks) { BOOST_TEST_MESSAGE("Testing finite-differences American option greeks..."); testFdGreeks(); } -void AmericanOptionTest::testFdShoutGreeks() { +BOOST_AUTO_TEST_CASE(testFdShoutGreeks, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing finite-differences shout option greeks..."); testFdGreeks(); } -void AmericanOptionTest::testFDShoutNPV() { +BOOST_AUTO_TEST_CASE(testFDShoutNPV) { BOOST_TEST_MESSAGE("Testing finite-differences shout option pricing..."); const auto dc = Actual365Fixed(); @@ -631,7 +631,7 @@ void AmericanOptionTest::testFDShoutNPV() { } } -void AmericanOptionTest::testZeroVolFDShoutNPV() { +BOOST_AUTO_TEST_CASE(testZeroVolFDShoutNPV) { BOOST_TEST_MESSAGE("Testing zero volatility shout option pricing with discrete dividends..."); const auto dc = Actual365Fixed(); @@ -710,7 +710,7 @@ void AmericanOptionTest::testZeroVolFDShoutNPV() { } } -void AmericanOptionTest::testLargeDividendShoutNPV() { +BOOST_AUTO_TEST_CASE(testLargeDividendShoutNPV) { BOOST_TEST_MESSAGE("Testing zero strike shout option pricing with discrete dividends..."); const auto dc = Actual365Fixed(); @@ -792,7 +792,7 @@ void AmericanOptionTest::testLargeDividendShoutNPV() { } } -void AmericanOptionTest::testEscrowedVsSpotAmericanOption() { +BOOST_AUTO_TEST_CASE(testEscrowedVsSpotAmericanOption) { BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model for American options..."); const auto dc = Actual360(); @@ -863,8 +863,7 @@ void AmericanOptionTest::testEscrowedVsSpotAmericanOption() { } } - -void AmericanOptionTest::testTodayIsDividendDate() { +BOOST_AUTO_TEST_CASE(testTodayIsDividendDate) { BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model on dividend dates for American options..."); const auto dc = Actual360(); @@ -982,8 +981,7 @@ void AmericanOptionTest::testTodayIsDividendDate() { } } - -void AmericanOptionTest::testCallPutParity() { +BOOST_AUTO_TEST_CASE(testCallPutParity) { BOOST_TEST_MESSAGE("Testing call/put parity for American options..."); // R.L. McDonald, M.D. Schroder: A parity result for American option @@ -1071,7 +1069,7 @@ void AmericanOptionTest::testCallPutParity() { } } -void AmericanOptionTest::testQdPlusBoundaryValues() { +BOOST_AUTO_TEST_CASE(testQdPlusBoundaryValues) { BOOST_TEST_MESSAGE("Testing QD+ boundary approximation..."); const DayCounter dc = Actual365Fixed(); @@ -1122,7 +1120,7 @@ void AmericanOptionTest::testQdPlusBoundaryValues() { } } -void AmericanOptionTest::testQdPlusBoundaryConvergence() { +BOOST_AUTO_TEST_CASE(testQdPlusBoundaryConvergence) { BOOST_TEST_MESSAGE("Testing QD+ boundary convergence..."); const DayCounter dc = Actual365Fixed(); @@ -1187,7 +1185,7 @@ void AmericanOptionTest::testQdPlusBoundaryConvergence() { } } -void AmericanOptionTest::testQdAmericanEngines() { +BOOST_AUTO_TEST_CASE(testQdAmericanEngines) { BOOST_TEST_MESSAGE("Testing QD+ American option pricing..."); const DayCounter dc = Actual365Fixed(); @@ -1432,7 +1430,7 @@ void AmericanOptionTest::testQdAmericanEngines() { }; } -void AmericanOptionTest::testQdFpIterationScheme() { +BOOST_AUTO_TEST_CASE(testQdFpIterationScheme) { BOOST_TEST_MESSAGE("Testing Legendre and tanh-sinh iteration " "scheme for QD+ fixed-point American engine..."); @@ -1459,8 +1457,7 @@ void AmericanOptionTest::testQdFpIterationScheme() { } } - -void AmericanOptionTest::testAndersenLakeHighPrecisionExample() { +BOOST_AUTO_TEST_CASE(testAndersenLakeHighPrecisionExample) { BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden " "high precision example..."); @@ -1556,8 +1553,7 @@ void AmericanOptionTest::testAndersenLakeHighPrecisionExample() { } } - -void AmericanOptionTest::testQdEngineStandardExample() { +BOOST_AUTO_TEST_CASE(testQdEngineStandardExample) { BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden " "standard example..."); @@ -1649,7 +1645,7 @@ namespace { }; } -void AmericanOptionTest::testBulkQdFpAmericanEngine() { +BOOST_AUTO_TEST_CASE(testBulkQdFpAmericanEngine) { BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden " "bulk examples..."); @@ -1758,7 +1754,7 @@ void AmericanOptionTest::testBulkQdFpAmericanEngine() { << "\n tol : " << tolMax); } -void AmericanOptionTest::testQdEngineWithLobattoIntegral() { +BOOST_AUTO_TEST_CASE(testQdEngineWithLobattoIntegral) { BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden " "with high precision Gauss-Lobatto integration..."); @@ -1825,7 +1821,7 @@ void AmericanOptionTest::testQdEngineWithLobattoIntegral() { } } -void AmericanOptionTest::testQdNegativeDividendYield() { +BOOST_AUTO_TEST_CASE(testQdNegativeDividendYield) { BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden " "with positive or zero interest rate and " "negative dividend yield..."); @@ -1896,7 +1892,7 @@ void AmericanOptionTest::testQdNegativeDividendYield() { } } -void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() { +BOOST_AUTO_TEST_CASE(testBjerksundStenslandEuropeanGreeks) { BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland greeks when early " "exercise is not optimal..."); @@ -1973,8 +1969,7 @@ void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() { } } - -void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() { +BOOST_AUTO_TEST_CASE(testBjerksundStenslandAmericanGreeks) { BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland American greeks..."); const Date today = Date(5, December, 2022); @@ -2164,8 +2159,7 @@ void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() { } } - -void AmericanOptionTest::testSingleBjerksundStenslandGreeks() { +BOOST_AUTO_TEST_CASE(testSingleBjerksundStenslandGreeks) { BOOST_TEST_MESSAGE("Testing a single Bjerksund-Stensland greeks set..."); const Date today = Date(20, January, 2023); @@ -2248,39 +2242,6 @@ void AmericanOptionTest::testSingleBjerksundStenslandGreeks() { BOOST_FAIL("American exercise type expected"); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* AmericanOptionTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("American option tests"); - - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBaroneAdesiWhaleyValues)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandValues)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testJuValues)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdValues)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdAmericanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFDShoutNPV)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testZeroVolFDShoutNPV)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testLargeDividendShoutNPV)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testEscrowedVsSpotAmericanOption)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testTodayIsDividendDate)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testCallPutParity)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdPlusBoundaryValues)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdPlusBoundaryConvergence)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdAmericanEngines)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdFpIterationScheme)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testAndersenLakeHighPrecisionExample)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdEngineStandardExample)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBulkQdFpAmericanEngine)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdEngineWithLobattoIntegral)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdNegativeDividendYield)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandEuropeanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandAmericanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testSingleBjerksundStenslandGreeks)); - - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdShoutGreeks)); - } - - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/americanoption.hpp b/test-suite/americanoption.hpp deleted file mode 100644 index 251eade5538..00000000000 --- a/test-suite/americanoption.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Ferdinando Ametrano - Copyright (C) 2005 Joseph Wang - 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_american_option_hpp -#define quantlib_test_american_option_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class AmericanOptionTest { - public: - static void testBaroneAdesiWhaleyValues(); - static void testBjerksundStenslandValues(); - static void testJuValues(); - static void testFdValues(); - static void testFdAmericanGreeks(); - static void testFdShoutGreeks(); - static void testFDShoutNPV(); - static void testZeroVolFDShoutNPV(); - static void testLargeDividendShoutNPV(); - static void testEscrowedVsSpotAmericanOption(); - static void testTodayIsDividendDate(); - static void testCallPutParity(); - static void testQdPlusBoundaryValues(); - static void testQdPlusBoundaryConvergence(); - static void testQdAmericanEngines(); - static void testQdFpIterationScheme(); - static void testAndersenLakeHighPrecisionExample(); - static void testQdEngineStandardExample(); - static void testBulkQdFpAmericanEngine(); - static void testQdEngineWithLobattoIntegral(); - static void testQdNegativeDividendYield(); - static void testBjerksundStenslandEuropeanGreeks(); - static void testBjerksundStenslandAmericanGreeks(); - static void testSingleBjerksundStenslandGreeks(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/instruments.cpp b/test-suite/instruments.cpp index 3b8b1411fa6..fa94c8e1e3e 100644 --- a/test-suite/instruments.cpp +++ b/test-suite/instruments.cpp @@ -17,19 +17,23 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "instruments.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" -#include #include #include +#include #include #include #include using namespace QuantLib; -using namespace boost::unit_test_framework; +using namespace boost::unit_test; + +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) -void InstrumentTest::testObservable() { +BOOST_AUTO_TEST_SUITE(InstrumentTest) + +BOOST_AUTO_TEST_CASE(testObservable) { BOOST_TEST_MESSAGE("Testing observability of instruments..."); @@ -39,12 +43,12 @@ void InstrumentTest::testObservable() { Flag f; f.registerWith(s); - + s->NPV(); me1->setValue(3.14); if (!f.isUp()) BOOST_FAIL("Observer was not notified of instrument change"); - + s->NPV(); f.lower(); ext::shared_ptr me2(new SimpleQuote(0.0)); @@ -64,9 +68,7 @@ void InstrumentTest::testObservable() { BOOST_FAIL("Observer was not notified of instrument change"); } - -void InstrumentTest::testCompositeWhenShiftingDates() { - +BOOST_AUTO_TEST_CASE(testCompositeWhenShiftingDates) { BOOST_TEST_MESSAGE( "Testing reaction of composite instrument to date changes..."); @@ -74,7 +76,7 @@ void InstrumentTest::testCompositeWhenShiftingDates() { DayCounter dc = Actual360(); ext::shared_ptr payoff( - new PlainVanillaPayoff(Option::Call, 100.0)); + new PlainVanillaPayoff(Option::Call, 100.0)); ext::shared_ptr exercise(new EuropeanExercise(today+30)); ext::shared_ptr option(new EuropeanOption(payoff, exercise)); @@ -111,11 +113,6 @@ void InstrumentTest::testCompositeWhenShiftingDates() { BOOST_FAIL("Composite didn't recalculate"); } -test_suite* InstrumentTest::suite() { - auto* suite = BOOST_TEST_SUITE("Instrument tests"); - suite->add(QUANTLIB_TEST_CASE(&InstrumentTest::testObservable)); - suite->add(QUANTLIB_TEST_CASE( - &InstrumentTest::testCompositeWhenShiftingDates)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/instruments.hpp b/test-suite/instruments.hpp deleted file mode 100644 index 6fdcfebeeb5..00000000000 --- a/test-suite/instruments.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - Copyright (C) 2016 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_instruments_hpp -#define quantlib_test_instruments_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class InstrumentTest { - public: - static void testObservable(); - static void testCompositeWhenShiftingDates(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/paralleltestrunner.hpp b/test-suite/paralleltestrunner.hpp index a1ff58e79c8..e55e32aeca3 100755 --- a/test-suite/paralleltestrunner.hpp +++ b/test-suite/paralleltestrunner.hpp @@ -87,7 +87,8 @@ namespace { bool visit(test_unit const& tu) { if (tu.p_parent_id == framework::master_test_suite().p_id) { - QL_REQUIRE(!tu.p_name.get().compare("QuantLib test suite"), + BOOST_TEST_MESSAGE(tu.p_name.get()); + QL_REQUIRE(!tu.p_name.get().compare("QuantLibTest") or !tu.p_name.get().compare("QuantLib test suite"), "could not find QuantLib test suite"); testSuiteId_ = tu.p_id; diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 72734b5b6a9..7f1866a1cb1 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,7 @@ #endif #include "utilities.hpp" -#include "americanoption.hpp" +//#include "americanoption.hpp" #include "asianoptions.hpp" #include "barrieroption.hpp" #include "basketoption.hpp" @@ -188,7 +188,7 @@ namespace { }; std::vector bm = { - Benchmark("AmericanOption::FdAmericanGreeks", &AmericanOptionTest::testFdAmericanGreeks, 518.31), +// Benchmark("AmericanOption::FdAmericanGreeks", &AmericanOptionTest::testFdAmericanGreeks, 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", &AsianOptionTest::testMCDiscreteArithmeticAveragePrice, 5186.13), Benchmark("BarrierOption::BabsiriValues", &BarrierOptionTest::testBabsiriValues, 880.8), Benchmark("BasketOption::EuroTwoValues", &BasketOptionTest::testEuroTwoValues, 340.04), diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp new file mode 100644 index 00000000000..072a79fef3c --- /dev/null +++ b/test-suite/quantlibglobalfixture.cpp @@ -0,0 +1,66 @@ +#include + +#define BOOST_TEST_NO_MAIN +#define BOOST_TEST_ALTERNATIVE_INIT_API + +#include +#include +#include + +#include "quantlibglobalfixture.hpp" +#include "speedlevel.hpp" + +using namespace boost::unit_test; + +QuantLibGlobalFixture::QuantLibGlobalFixture() { + start = std::chrono::steady_clock::now(); + int argc = boost::unit_test::framework::master_test_suite().argc; + char **argv = boost::unit_test::framework::master_test_suite().argv; + speed = speed_level(argc, argv); +} + +QuantLibGlobalFixture::~QuantLibGlobalFixture(){ + stop = std::chrono::steady_clock::now(); + + double seconds = std::chrono::duration_cast(start - stop).count() * 1e-3; + int hours = int (seconds/3600); + seconds -= hours * 3600; + int minutes = int(seconds/60); + seconds -= minutes * 60; + + std::cout << "\nTests completed in "; + if (hours > 0) + std::cout << hours << " h "; + if (hours > 0 || minutes > 0) + std::cout << minutes << " m "; + std::cout << std::fixed << std::setprecision(0) + << seconds << " s\n" << std::endl; +} + +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 + +class QuantLibGlobalFixture { + public: + QuantLibGlobalFixture(); + ~QuantLibGlobalFixture(); + static SpeedLevel get_speed (); + SpeedLevel speed_level (int argc, char **argv); + + private: + static SpeedLevel speed; + decltype(std::chrono::steady_clock::now()) start; + decltype(std::chrono::steady_clock::now()) stop; +}; + +#endif // quantlib_global_fixture_hpp \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f28008fbe89..c8d50e2bebc 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,12 +36,8 @@ # include #endif -#include "utilities.hpp" -#include "speedlevel.hpp" - -#include "americanoption.hpp" -#include "andreasenhugevolatilityinterpl.hpp" #include "amortizingbond.hpp" +#include "andreasenhugevolatilityinterpl.hpp" #include "array.hpp" #include "asianoptions.hpp" #include "assetswap.hpp" @@ -55,8 +51,8 @@ #include "binaryoption.hpp" #include "blackdeltacalculator.hpp" #include "blackformula.hpp" -#include "bonds.hpp" #include "bondforward.hpp" +#include "bonds.hpp" #include "brownianbridge.hpp" #include "businessdayconventions.hpp" #include "calendars.hpp" @@ -91,26 +87,26 @@ #include "dividendoption.hpp" #include "doublebarrieroption.hpp" #include "doublebinaryoption.hpp" -#include "europeanoption.hpp" -#include "everestoption.hpp" -#include "equityindex.hpp" #include "equitycashflow.hpp" +#include "equityindex.hpp" #include "equitytotalreturnswap.hpp" +#include "europeanoption.hpp" +#include "everestoption.hpp" #include "exchangerate.hpp" #include "extendedtrees.hpp" #include "extensibleoptions.hpp" #include "fastfouriertransform.hpp" -#include "fdheston.hpp" +#include "fdcev.hpp" #include "fdcir.hpp" +#include "fdheston.hpp" #include "fdmlinearop.hpp" -#include "fdcev.hpp" #include "fdsabr.hpp" #include "fittedbonddiscountcurve.hpp" #include "forwardoption.hpp" #include "forwardrateagreement.hpp" #include "functions.hpp" -#include "gaussianquadratures.hpp" #include "garch.hpp" +#include "gaussianquadratures.hpp" #include "gjrgarchmodel.hpp" #include "gsr.hpp" #include "hestonmodel.hpp" @@ -125,7 +121,6 @@ #include "inflationcpicapfloor.hpp" #include "inflationcpiswap.hpp" #include "inflationvolatility.hpp" -#include "instruments.hpp" #include "integrals.hpp" #include "interestrates.hpp" #include "interpolations.hpp" @@ -138,11 +133,11 @@ #include "lowdiscrepancysequences.hpp" #include "margrabeoption.hpp" #include "marketmodel.hpp" +#include "marketmodel_cms.hpp" +#include "marketmodel_smm.hpp" #include "marketmodel_smmcapletalphacalibration.hpp" #include "marketmodel_smmcapletcalibration.hpp" #include "marketmodel_smmcaplethomocalibration.hpp" -#include "marketmodel_smm.hpp" -#include "marketmodel_cms.hpp" #include "markovfunctional.hpp" #include "matrices.hpp" #include "mclongstaffschwartzengine.hpp" @@ -179,9 +174,9 @@ #include "shortratemodels.hpp" #include "sofrfutures.hpp" #include "solvers.hpp" +#include "speedlevel.hpp" #include "spreadoption.hpp" #include "squarerootclvmodel.hpp" -#include "swingoption.hpp" #include "stats.hpp" #include "subperiodcoupons.hpp" #include "svivolatility.hpp" @@ -190,6 +185,7 @@ #include "swaption.hpp" #include "swaptionvolatilitycube.hpp" #include "swaptionvolatilitymatrix.hpp" +#include "swingoption.hpp" #include "termstructures.hpp" #include "timegrid.hpp" #include "timeseries.hpp" @@ -199,6 +195,7 @@ #include "twoassetbarrieroption.hpp" #include "twoassetcorrelationoption.hpp" #include "ultimateforwardtermstructure.hpp" +#include "utilities.hpp" #include "variancegamma.hpp" #include "varianceoption.hpp" #include "varianceswaps.hpp" @@ -206,39 +203,14 @@ #include "vpp.hpp" #include "zabr.hpp" #include "zerocouponswap.hpp" - -#include -#include #include +#include +#include using namespace boost::unit_test_framework; namespace { - decltype(std::chrono::steady_clock::now()) start; - - void startTimer() { - start = std::chrono::steady_clock::now(); - } - - void stopTimer() { - auto stop = std::chrono::steady_clock::now(); - - double seconds = std::chrono::duration_cast(stop - start).count() * 1e-3; - int hours = int(seconds/3600); - seconds -= hours * 3600; - int minutes = int(seconds/60); - seconds -= minutes * 60; - - std::cout << "\nTests completed in "; - if (hours > 0) - std::cout << hours << " h "; - if (hours > 0 || minutes > 0) - std::cout << minutes << " m "; - std::cout << std::fixed << std::setprecision(0) - << seconds << " s\n" << std::endl; - } - void configure(QuantLib::Date evaluationDate) { /* if needed, a subset of the lines below can be uncommented and/or changed to run the test suite with a @@ -352,9 +324,8 @@ test_suite* init_unit_test_suite(int, char* []) { BOOST_TEST_MESSAGE(rule); auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(QUANTLIB_TEST_CASE(startTimer)); +// test->add(QUANTLIB_TEST_CASE(startTimer)); - test->add(AmericanOptionTest::suite(speed)); test->add(AmortizingBondTest::suite()); test->add(AndreasenHugeVolatilityInterplTest::suite(speed)); test->add(ArrayTest::suite()); @@ -421,7 +392,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(InflationCapFloorTest::suite()); test->add(InflationCapFlooredCouponTest::suite()); test->add(InflationCPIBondTest::suite()); - test->add(InstrumentTest::suite()); test->add(IntegralTest::suite()); test->add(InterestRateTest::suite()); test->add(InterpolationTest::suite(speed)); @@ -533,7 +503,7 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(LiborMarketModelTest::suite(speed)); test->add(LiborMarketModelProcessTest::suite(speed)); - test->add(QUANTLIB_TEST_CASE(stopTimer)); +// test->add(QUANTLIB_TEST_CASE(stopTimer)); return test; } diff --git a/test-suite/speedlevel.cpp b/test-suite/speedlevel.cpp new file mode 100644 index 00000000000..d6bf98f1e72 --- /dev/null +++ b/test-suite/speedlevel.cpp @@ -0,0 +1,15 @@ +#include "speedlevel.hpp" +#include "quantlibglobalfixture.hpp" + +#include + +namespace utf = boost::unit_test; +namespace tt = boost::test_tools; + +if_speed::if_speed(SpeedLevel speed) : speed(speed) {} + +tt::assertion_result if_speed::operator()(utf::test_unit_id) { + tt::assertion_result level (QuantLibGlobalFixture::get_speed() <= speed); + level.message() << "precondition failed"; + return level; +} \ No newline at end of file diff --git a/test-suite/speedlevel.hpp b/test-suite/speedlevel.hpp index 07faac8d8b8..17cf9cc604b 100644 --- a/test-suite/speedlevel.hpp +++ b/test-suite/speedlevel.hpp @@ -20,11 +20,20 @@ #ifndef quantlib_test_speed_level_hpp #define quantlib_test_speed_level_hpp +#include + enum SpeedLevel { Slow = 0, Fast = 1, Faster = 2 }; +struct if_speed { + SpeedLevel speed; + + if_speed(SpeedLevel speed); + + boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id); +}; #endif diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 1e08660bc57..ccbfbd97a38 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -763,6 +763,7 @@ + @@ -776,6 +777,7 @@ + @@ -807,7 +809,6 @@ - @@ -893,7 +894,6 @@ - @@ -935,6 +935,7 @@ + @@ -965,6 +966,7 @@ + diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 88982b008a1..83cfa8f4d83 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -335,6 +335,9 @@ Source Files + + Header Files + Source Files @@ -371,6 +374,9 @@ Source Files + + Source Files + Source Files @@ -518,9 +524,6 @@ - - Header Files - Header Files @@ -725,9 +728,6 @@ Header Files - - Header Files - Header Files @@ -845,6 +845,9 @@ Header Files + + Header Files + Header Files @@ -923,6 +926,9 @@ Header Files + + Header Files + Header Files diff --git a/test-suite/toplevelfixture.hpp b/test-suite/toplevelfixture.hpp new file mode 100644 index 00000000000..d9354b04061 --- /dev/null +++ b/test-suite/toplevelfixture.hpp @@ -0,0 +1,34 @@ +#ifndef quantlib_top_level_fixture_hpp +#define quantlib_top_level_fixture_hpp + +#include +#include +#include + +namespace QuantLib { + + using QuantLib::SavedSettings; + using QuantLib::IndexManager; + + class TopLevelFixture { + public: + // Restore settings after each test. + SavedSettings restore; + + TopLevelFixture() {} + + ~TopLevelFixture() { + IndexManager::instance().clearHistories(); + BOOST_CHECK(true); + } + +#if BOOST_VERSION <= 105300 + // defined to avoid unused-variable warnings. It doesn't + // work after Boost 1.53 because the functions were + // overloaded and the address can't be resolved. + void _use_check(const void* = &boost::test_tools::check_is_close, + const void* = &boost::test_tools::check_is_small) const {} +#endif + }; +} +#endif //quantlib_top_level_fixture_hpp \ No newline at end of file diff --git a/tools/check_test_times.py b/tools/check_test_times.py index 6baebb6c4b6..d3560e124a4 100644 --- a/tools/check_test_times.py +++ b/tools/check_test_times.py @@ -6,7 +6,7 @@ regex1 = re.compile(".*test_case\(&(.*?)__(.*?)\)") regex2 = re.compile(".*ext__bind\(&(.*?)__(.*?)__.*\)\)") regex3 = re.compile(".*{_?([a-zA-Z]*Test)__([a-zA-Z]*?)\(") - +regex4 = re.compile("([^.]+)\.(.+)") def parse_simple(t): # test names get mangled - here we extract class and method name @@ -28,13 +28,18 @@ def parse_lambda(t): if m: return m.groups() +def parse_simple_auto_generated(t): + # used for classname generated by automated registration using boost test + m = regex4.match(t.attrib["classname"]) + if m: + return m.groups() def extract_test_info(filename): root = ET.parse(filename).getroot() tests = root.findall("testcase") - tests = tests[1:-1] # exclude start_timer / stop_timer + # tests = tests[1:-1] # exclude start_timer / stop_timer for t in tests: - cls, method = parse_simple(t) or parse_bound(t) or parse_lambda(t) + cls, method = parse_simple(t) or parse_bound(t) or parse_lambda(t) or parse_simple_auto_generated(t) time = float(t.attrib["time"]) yield (cls, method, time) From 583aafd5e313e086572ad1c085e69be8ee37cf81 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 18 Oct 2023 17:20:45 +0800 Subject: [PATCH 003/132] adds test case in quantlibbenchmark.cpp using std::bind --- test-suite/CMakeLists.txt | 5 +++-- test-suite/quantlibbenchmark.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 4c379017901..ae35a6c8be3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -351,7 +351,7 @@ set(QL_TEST_HEADERS set(QL_BENCHMARK_SOURCES quantlibbenchmark.cpp -# americanoption.cpp + americanoption.cpp asianoptions.cpp asianoptions.hpp barrieroption.cpp barrieroption.hpp basketoption.cpp basketoption.hpp @@ -367,10 +367,11 @@ set(QL_BENCHMARK_SOURCES lowdiscrepancysequences.cpp lowdiscrepancysequences.hpp marketmodel_cms.cpp marketmodel_cms.hpp marketmodel_smm.cpp marketmodel_smm.hpp + quantlibglobalfixture.cpp quantlibglobalfixture.hpp quantooption.cpp quantooption.hpp riskstats.cpp riskstats.hpp shortratemodels.cpp shortratemodels.hpp - + speedlevel.cpp speedlevel.hpp utilities.cpp utilities.hpp swaptionvolstructuresutilities.hpp ) diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 7f1866a1cb1..56142de583f 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -//#include "americanoption.hpp" #include "asianoptions.hpp" #include "barrieroption.hpp" #include "basketoption.hpp" @@ -157,14 +156,21 @@ #include "riskstats.hpp" #include "shortratemodels.hpp" +namespace QuantLibTest { + namespace AmericanOptionTest { + struct testFdAmericanGreeks : public BOOST_AUTO_TEST_CASE_FIXTURE { + void test_method(); + }; + } +} namespace { class Benchmark { public: - typedef void (*fct_ptr)(); + typedef std::function fct_ptr; Benchmark(std::string name, fct_ptr f, double mflop) - : f_(f), name_(std::move(name)), mflop_(mflop) {} + : f_(std::move(f)), name_(std::move(name)), mflop_(mflop) {} fct_ptr getTestCase() const { return f_; @@ -188,7 +194,7 @@ namespace { }; std::vector bm = { -// Benchmark("AmericanOption::FdAmericanGreeks", &AmericanOptionTest::testFdAmericanGreeks, 518.31), + Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", &AsianOptionTest::testMCDiscreteArithmeticAveragePrice, 5186.13), Benchmark("BarrierOption::BabsiriValues", &BarrierOptionTest::testBabsiriValues, 880.8), Benchmark("BasketOption::EuroTwoValues", &BasketOptionTest::testEuroTwoValues, 340.04), @@ -221,8 +227,8 @@ namespace { class TimedBenchmark { public: - typedef void (*fct_ptr)(); - explicit TimedBenchmark(fct_ptr f) : f_(f) {} + typedef std::function fct_ptr; + explicit TimedBenchmark(fct_ptr f) : f_(std::move(f)) {} void startMeasurement() const { /* PAPI code From 849d213bd7b4a1f270ea95e228303b5fe5ace767 Mon Sep 17 00:00:00 2001 From: klaus spanderen Date: Thu, 19 Oct 2023 20:30:48 +0200 Subject: [PATCH 004/132] declare benchmark tests --- test-suite/CMakeLists.txt | 4 ++-- test-suite/Makefile.am | 5 +++++ test-suite/quantlibbenchmark.cpp | 19 ++++++++----------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index ae35a6c8be3..14ce3dc89f1 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -367,11 +367,11 @@ set(QL_BENCHMARK_SOURCES lowdiscrepancysequences.cpp lowdiscrepancysequences.hpp marketmodel_cms.cpp marketmodel_cms.hpp marketmodel_smm.cpp marketmodel_smm.hpp - quantlibglobalfixture.cpp quantlibglobalfixture.hpp quantooption.cpp quantooption.hpp + quantlibglobalfixture.cpp quantlibglobalfixture.hpp riskstats.cpp riskstats.hpp shortratemodels.cpp shortratemodels.hpp - speedlevel.cpp speedlevel.hpp + speedlevel.cpp speedlevel.hpp utilities.cpp utilities.hpp swaptionvolstructuresutilities.hpp ) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index f4442d2f8c8..1faadc68a1e 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -350,6 +350,7 @@ QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS} QL_BENCHMARK_SRCS = \ quantlibbenchmark.cpp \ + americanoption.cpp \ asianoptions.cpp \ barrieroption.cpp \ doublebarrieroption.cpp \ @@ -366,9 +367,11 @@ QL_BENCHMARK_SRCS = \ lowdiscrepancysequences.cpp \ marketmodel_cms.cpp \ marketmodel_smm.cpp \ + quantlibglobalfixture.cpp \ quantooption.cpp \ riskstats.cpp \ shortratemodels.cpp \ + speedlevel.cpp \ utilities.cpp QL_BENCHMARK_HDRS = \ @@ -388,9 +391,11 @@ QL_BENCHMARK_HDRS = \ lowdiscrepancysequences.hpp \ marketmodel_cms.hpp \ marketmodel_smm.hpp \ + quantlibglobalfixture.hpp \ quantooption.hpp \ riskstats.hpp \ shortratemodels.hpp \ + speedlevel.hpp \ utilities.hpp QL_BENCHMARKS = ${QL_BENCHMARK_SRCS} ${QL_BENCHMARK_HDRS} diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 56142de583f..5e5ed6df481 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -156,11 +156,10 @@ #include "riskstats.hpp" #include "shortratemodels.hpp" + namespace QuantLibTest { namespace AmericanOptionTest { - struct testFdAmericanGreeks : public BOOST_AUTO_TEST_CASE_FIXTURE { - void test_method(); - }; + struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } } @@ -168,11 +167,10 @@ namespace { class Benchmark { public: - typedef std::function fct_ptr; - Benchmark(std::string name, fct_ptr f, double mflop) - : f_(std::move(f)), name_(std::move(name)), mflop_(mflop) {} + Benchmark(std::string name, std::function f, double mflop) + : f_(f), name_(std::move(name)), mflop_(mflop) {} - fct_ptr getTestCase() const { + std::function getTestCase() const { return f_; } double getMflop() const { @@ -187,7 +185,7 @@ namespace { std::swap(mflop_, other.mflop_); } private: - fct_ptr f_; + std::function f_; std::string name_; double mflop_; // total number of mega floating // point operations (not per sec!) @@ -227,8 +225,7 @@ namespace { class TimedBenchmark { public: - typedef std::function fct_ptr; - explicit TimedBenchmark(fct_ptr f) : f_(std::move(f)) {} + explicit TimedBenchmark(std::function f) : f_(f) {} void startMeasurement() const { /* PAPI code @@ -256,7 +253,7 @@ namespace { stopTime - startTime).count() * 1e-6; } private: - fct_ptr f_; + std::function f_; }; void printResults( From 8be12adadb57fd743e3fb3af9a2268ddeacb47e5 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 20 Oct 2023 14:52:59 +0800 Subject: [PATCH 005/132] Migrated asianoptions.cpp, array.cpp, andreasenhugevolatilityinterpl.cpp and amortizingbond.cpp --- test-suite/CMakeLists.txt | 6 +- test-suite/Makefile.am | 5 - test-suite/amortizingbond.cpp | 22 +- test-suite/amortizingbond.hpp | 33 - test-suite/andreasenhugevolatilityinterpl.cpp | 147 ++- test-suite/andreasenhugevolatilityinterpl.hpp | 49 - test-suite/array.cpp | 25 +- test-suite/array.hpp | 38 - test-suite/asianoptions.cpp | 968 +++++++++--------- test-suite/asianoptions.hpp | 58 -- test-suite/quantlibbenchmark.cpp | 6 +- test-suite/quantlibtestsuite.cpp | 13 - test-suite/testsuite.vcxproj | 4 - test-suite/testsuite.vcxproj.filters | 12 - 14 files changed, 548 insertions(+), 838 deletions(-) delete mode 100644 test-suite/amortizingbond.hpp delete mode 100644 test-suite/andreasenhugevolatilityinterpl.hpp delete mode 100644 test-suite/array.hpp delete mode 100644 test-suite/asianoptions.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 14ce3dc89f1..768c9e31807 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,10 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - amortizingbond.hpp - andreasenhugevolatilityinterpl.hpp - array.hpp - asianoptions.hpp assetswap.hpp autocovariances.hpp barrieroption.hpp @@ -352,7 +348,7 @@ set(QL_BENCHMARK_SOURCES quantlibbenchmark.cpp americanoption.cpp - asianoptions.cpp asianoptions.hpp + asianoptions.cpp barrieroption.cpp barrieroption.hpp basketoption.cpp basketoption.hpp batesmodel.cpp batesmodel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1faadc68a1e..1732a96e4ae 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,10 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ speedlevel.hpp \ - amortizingbond.hpp \ - andreasenhugevolatilityinterpl.hpp \ - array.hpp \ - asianoptions.hpp \ assetswap.hpp \ autocovariances.hpp \ barrieroption.hpp \ @@ -375,7 +371,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - asianoptions.hpp \ barrieroption.hpp \ doublebarrieroption.hpp \ basketoption.hpp \ diff --git a/test-suite/amortizingbond.cpp b/test-suite/amortizingbond.cpp index 0cf4bc7fc5e..4ab83e8a06d 100644 --- a/test-suite/amortizingbond.cpp +++ b/test-suite/amortizingbond.cpp @@ -15,7 +15,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "amortizingbond.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -31,7 +31,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void AmortizingBondTest::testAmortizingFixedRateBond() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(AmortizingBondTest) + +BOOST_AUTO_TEST_CASE(testAmortizingFixedRateBond) { BOOST_TEST_MESSAGE("Testing amortizing fixed rate bond..."); /* @@ -93,7 +97,7 @@ void AmortizingBondTest::testAmortizingFixedRateBond() { } } -void AmortizingBondTest::testBrazilianAmortizingFixedRateBond() { +BOOST_AUTO_TEST_CASE(testBrazilianAmortizingFixedRateBond) { BOOST_TEST_MESSAGE("Testing Brazilian amortizing fixed rate bond..."); /* @@ -213,7 +217,7 @@ void AmortizingBondTest::testBrazilianAmortizingFixedRateBond() { } -void AmortizingBondTest::testAmortizingFixedRateBondWithDrawDown() { +BOOST_AUTO_TEST_CASE(testAmortizingFixedRateBondWithDrawDown) { BOOST_TEST_MESSAGE("Testing amortizing fixed rate bond with draw-down..."); Date issueDate = Date(19, May, 2012); @@ -273,10 +277,6 @@ void AmortizingBondTest::testAmortizingFixedRateBondWithDrawDown() { } -test_suite* AmortizingBondTest::suite() { - auto* suite = BOOST_TEST_SUITE("Amortizing Bond tests"); - suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testAmortizingFixedRateBond)); - suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testBrazilianAmortizingFixedRateBond)); - suite->add(QUANTLIB_TEST_CASE(&AmortizingBondTest::testAmortizingFixedRateBondWithDrawDown)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/amortizingbond.hpp b/test-suite/amortizingbond.hpp deleted file mode 100644 index dd9a9597a18..00000000000 --- a/test-suite/amortizingbond.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 Cheng Li - - 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_amortizing_bond_hpp -#define quantlib_test_amortizing_bond_hpp - -#include - -class AmortizingBondTest { - public: - static void testAmortizingFixedRateBond(); - static void testBrazilianAmortizingFixedRateBond(); - static void testAmortizingFixedRateBondWithDrawDown(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/andreasenhugevolatilityinterpl.cpp b/test-suite/andreasenhugevolatilityinterpl.cpp index 8d004a0cbef..124fe095f84 100644 --- a/test-suite/andreasenhugevolatilityinterpl.cpp +++ b/test-suite/andreasenhugevolatilityinterpl.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "andreasenhugevolatilityinterpl.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -341,10 +342,56 @@ namespace andreasen_huge_volatility_interpl_test { return { spot, rTS, qTS, calibrationSet }; } + + std::pair > sabrData() { + + const DayCounter dc = Actual365Fixed(); + const Date today = Date(4, January, 2018); + + const Real alpha = 0.15; + const Real beta = 0.8; + const Real nu = 0.5; + const Real rho = -0.48; + const Real forward = 0.03; + const Size maturityInYears = 20; + + const Date maturityDate = today + Period(maturityInYears, Years); + const Time maturity = dc.yearFraction(today, maturityDate); + + AndreasenHugeVolatilityInterpl::CalibrationSet calibrationSet; + + const Real strikes[] = { 0.02, 0.025, 0.03, 0.035, 0.04, 0.05, 0.06 }; + + for (Real strike : strikes) { + const Volatility vol = sabrVolatility(strike, forward, maturity, alpha, beta, nu, rho); + + calibrationSet.emplace_back( + ext::make_shared( + ext::make_shared( + Option::Call, strike), + ext::make_shared(maturityDate)), + ext::make_shared(vol)); + } + + const Handle rTS(flatRate(today, forward, dc)); + const Handle qTS(flatRate(today, forward, dc)); + + Handle spot(ext::make_shared(forward)); + + const CalibrationData data = { spot, rTS, qTS, calibrationSet}; + + std::vector parameter = { alpha, beta, nu, rho, forward, maturity }; + + return std::make_pair(data, parameter); + } } -void AndreasenHugeVolatilityInterplTest::testAndreasenHugePut() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(AndreasenHugeVolatilityInterplTest) + +BOOST_AUTO_TEST_CASE(testAndreasenHugePut, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with Put calibration..."); @@ -363,7 +410,7 @@ void AndreasenHugeVolatilityInterplTest::testAndreasenHugePut() { testAndreasenHugeVolatilityInterpolation(data, expected); } -void AndreasenHugeVolatilityInterplTest::testAndreasenHugeCall() { +BOOST_AUTO_TEST_CASE(testAndreasenHugeCall, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with Call calibration..."); @@ -382,7 +429,7 @@ void AndreasenHugeVolatilityInterplTest::testAndreasenHugeCall() { testAndreasenHugeVolatilityInterpolation(data, expected); } -void AndreasenHugeVolatilityInterplTest::testAndreasenHugeCallPut() { +BOOST_AUTO_TEST_CASE(testAndreasenHugeCallPut, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with instantaneous " @@ -402,7 +449,7 @@ void AndreasenHugeVolatilityInterplTest::testAndreasenHugeCallPut() { testAndreasenHugeVolatilityInterpolation(data, expected); } -void AndreasenHugeVolatilityInterplTest::testLinearInterpolation() { +BOOST_AUTO_TEST_CASE(testLinearInterpolation, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with linear interpolation..."); @@ -420,7 +467,7 @@ void AndreasenHugeVolatilityInterplTest::testLinearInterpolation() { testAndreasenHugeVolatilityInterpolation(data, expected); } -void AndreasenHugeVolatilityInterplTest::testPiecewiseConstantInterpolation() { +BOOST_AUTO_TEST_CASE(testPiecewiseConstantInterpolation, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with piecewise constant interpolation..."); @@ -438,7 +485,7 @@ void AndreasenHugeVolatilityInterplTest::testPiecewiseConstantInterpolation() { testAndreasenHugeVolatilityInterpolation(data, expected); } -void AndreasenHugeVolatilityInterplTest::testTimeDependentInterestRates() { +BOOST_AUTO_TEST_CASE(testTimeDependentInterestRates, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge volatility interpolation with " @@ -524,7 +571,7 @@ void AndreasenHugeVolatilityInterplTest::testTimeDependentInterestRates() { testAndreasenHugeVolatilityInterpolation(irData, expected); } -void AndreasenHugeVolatilityInterplTest::testSingleOptionCalibration() { +BOOST_AUTO_TEST_CASE(testSingleOptionCalibration) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge volatility interpolation with " "a single option..."); @@ -583,7 +630,7 @@ void AndreasenHugeVolatilityInterplTest::testSingleOptionCalibration() { } } -void AndreasenHugeVolatilityInterplTest::testArbitrageFree() { +BOOST_AUTO_TEST_CASE(testArbitrageFree) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge volatility interpolation gives " "arbitrage free prices..."); @@ -672,7 +719,7 @@ void AndreasenHugeVolatilityInterplTest::testArbitrageFree() { } } -void AndreasenHugeVolatilityInterplTest::testBarrierOptionPricing() { +BOOST_AUTO_TEST_CASE(testBarrierOptionPricing, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE( "Testing Barrier option pricing with Andreasen-Huge " "local volatility surface..."); @@ -776,51 +823,7 @@ void AndreasenHugeVolatilityInterplTest::testBarrierOptionPricing() { } } -namespace andreasen_huge_volatility_interpl_test { - std::pair > sabrData() { - - const DayCounter dc = Actual365Fixed(); - const Date today = Date(4, January, 2018); - - const Real alpha = 0.15; - const Real beta = 0.8; - const Real nu = 0.5; - const Real rho = -0.48; - const Real forward = 0.03; - const Size maturityInYears = 20; - - const Date maturityDate = today + Period(maturityInYears, Years); - const Time maturity = dc.yearFraction(today, maturityDate); - - AndreasenHugeVolatilityInterpl::CalibrationSet calibrationSet; - - const Real strikes[] = { 0.02, 0.025, 0.03, 0.035, 0.04, 0.05, 0.06 }; - - for (Real strike : strikes) { - const Volatility vol = sabrVolatility(strike, forward, maturity, alpha, beta, nu, rho); - - calibrationSet.emplace_back( - ext::make_shared( - ext::make_shared( - Option::Call, strike), - ext::make_shared(maturityDate)), - ext::make_shared(vol)); - } - - const Handle rTS(flatRate(today, forward, dc)); - const Handle qTS(flatRate(today, forward, dc)); - - Handle spot(ext::make_shared(forward)); - - const CalibrationData data = { spot, rTS, qTS, calibrationSet}; - - std::vector parameter = { alpha, beta, nu, rho, forward, maturity }; - - return std::make_pair(data, parameter); - } -} - -void AndreasenHugeVolatilityInterplTest::testPeterAndFabiensExample() { +BOOST_AUTO_TEST_CASE(testPeterAndFabiensExample) { BOOST_TEST_MESSAGE( "Testing Peter's and Fabien's SABR example..."); @@ -868,7 +871,7 @@ void AndreasenHugeVolatilityInterplTest::testPeterAndFabiensExample() { } } -void AndreasenHugeVolatilityInterplTest::testDifferentOptimizers() { +BOOST_AUTO_TEST_CASE(testDifferentOptimizers) { BOOST_TEST_MESSAGE( "Testing different optimizer for Andreasen-Huge " "volatility interpolation..."); @@ -899,7 +902,7 @@ void AndreasenHugeVolatilityInterplTest::testDifferentOptimizers() { } } -void AndreasenHugeVolatilityInterplTest::testMovingReferenceDate() { +BOOST_AUTO_TEST_CASE(testMovingReferenceDate) { BOOST_TEST_MESSAGE( "Testing that reference date of adapter surface moves along with " "evaluation date..."); @@ -974,7 +977,7 @@ void AndreasenHugeVolatilityInterplTest::testMovingReferenceDate() { << "\n tolerance : " << tol); } -void AndreasenHugeVolatilityInterplTest::testFlatVolCalibration() { +BOOST_AUTO_TEST_CASE(testFlatVolCalibration) { BOOST_TEST_MESSAGE( "Testing Andreasen-Huge example with flat volatility surface..."); @@ -1036,30 +1039,6 @@ void AndreasenHugeVolatilityInterplTest::testFlatVolCalibration() { testAndreasenHugeVolatilityInterpolation(flatVolData, expected); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* AndreasenHugeVolatilityInterplTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Andreasen-Huge volatility interpolation tests"); - - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testSingleOptionCalibration)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testArbitrageFree)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testPeterAndFabiensExample)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testDifferentOptimizers)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testMovingReferenceDate)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testFlatVolCalibration)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testAndreasenHugePut)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testAndreasenHugeCall)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testAndreasenHugeCallPut)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testLinearInterpolation)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testPiecewiseConstantInterpolation)); - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testTimeDependentInterestRates)); - } - - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&AndreasenHugeVolatilityInterplTest::testBarrierOptionPricing)); - } - - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/andreasenhugevolatilityinterpl.hpp b/test-suite/andreasenhugevolatilityinterpl.hpp deleted file mode 100644 index 3522e75cf35..00000000000 --- a/test-suite/andreasenhugevolatilityinterpl.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2017, 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_local_volatility_hpp -#define quantlib_test_local_volatility_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class AndreasenHugeVolatilityInterplTest { - public: - static void testAndreasenHugePut(); - static void testAndreasenHugeCall(); - static void testAndreasenHugeCallPut(); - static void testLinearInterpolation(); - static void testPiecewiseConstantInterpolation(); - static void testTimeDependentInterestRates(); - static void testSingleOptionCalibration(); - static void testArbitrageFree(); - static void testBarrierOptionPricing(); - static void testPeterAndFabiensExample(); - static void testDifferentOptimizers(); - static void testMovingReferenceDate(); - static void testFlatVolCalibration(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel speed); -}; - - -#endif diff --git a/test-suite/array.cpp b/test-suite/array.cpp index 33cc2abe197..164406b5aad 100644 --- a/test-suite/array.cpp +++ b/test-suite/array.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "array.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -32,7 +32,11 @@ namespace array_test { }; } -void ArrayTest::testConstruction() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ArrayTest) + +BOOST_AUTO_TEST_CASE(testConstruction) { BOOST_TEST_MESSAGE("Testing array construction..."); @@ -117,7 +121,7 @@ void ArrayTest::testConstruction() { } } -void ArrayTest::testArrayFunctions() { +BOOST_AUTO_TEST_CASE(testArrayFunctions) { BOOST_TEST_MESSAGE("Testing array functions..."); @@ -178,7 +182,7 @@ void ArrayTest::testArrayFunctions() { } } -void ArrayTest::testArrayResize() { +BOOST_AUTO_TEST_CASE(testArrayResize) { BOOST_TEST_MESSAGE("Testing array resize..."); Array a(10,1.0,1.0); @@ -213,7 +217,7 @@ void ArrayTest::testArrayResize() { QL_CHECK_CLOSE(actual[i], expected[i], 100 * QL_EPSILON); \ } \ -void ArrayTest::testArrayOperators() { +BOOST_AUTO_TEST_CASE(testArrayOperators) { BOOST_TEST_MESSAGE("Testing array operators..."); auto get_array = []() { @@ -327,12 +331,7 @@ void ArrayTest::testArrayOperators() { QL_CHECK_CLOSE_ARRAY(real_rvalue_quotient, scalar_quotient_2); } -test_suite* ArrayTest::suite() { - auto* suite = BOOST_TEST_SUITE("array tests"); - suite->add(QUANTLIB_TEST_CASE(&ArrayTest::testConstruction)); - suite->add(QUANTLIB_TEST_CASE(&ArrayTest::testArrayFunctions)); - suite->add(QUANTLIB_TEST_CASE(&ArrayTest::testArrayResize)); - suite->add(QUANTLIB_TEST_CASE(&ArrayTest::testArrayOperators)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/array.hpp b/test-suite/array.hpp deleted file mode 100644 index ea2d280d3b0..00000000000 --- a/test-suite/array.hpp +++ /dev/null @@ -1,38 +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_array_hpp -#define quantlib_test_array_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ArrayTest { - public: - static void testConstruction(); - static void testArrayFunctions(); - static void testArrayResize(); - static void testArrayOperators(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/asianoptions.cpp b/test-suite/asianoptions.cpp index 07c30b134e1..d5e270a70a3 100644 --- a/test-suite/asianoptions.cpp +++ b/test-suite/asianoptions.cpp @@ -22,7 +22,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "asianoptions.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -89,10 +90,63 @@ namespace { QL_FAIL("unknown averaging"); } + struct DiscreteAverageData { + Option::Type type; + Real underlying; + Real strike; + Rate dividendYield; + Rate riskFreeRate; + Time first; + Time length; + Size fixings; + Volatility volatility; + bool controlVariate; + Real result; + }; + + struct ContinuousAverageData { + Option::Type type; + Real spot; + Real currentAverage; + Real strike; + Rate dividendYield; + Rate riskFreeRate; + Volatility volatility; + Natural length; + Natural elapsed; + Real result; + }; + + struct DiscreteAverageDataTermStructure { + Option::Type type; + Real underlying; + Real strike; + Rate b; + Rate riskFreeRate; + Time first; // t1 + Time expiry; + Size fixings; + Volatility volatility; + std::string slope; + Real result; + }; + + struct VecerData { + Real spot; + Rate riskFreeRate; + Volatility volatility; + Real strike; + Natural length; + Real result; + Real tolerance; + }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) -void AsianOptionTest::testAnalyticContinuousGeometricAveragePrice() { +BOOST_AUTO_TEST_SUITE(AsianOptionTest) + +BOOST_AUTO_TEST_CASE(testAnalyticContinuousGeometricAveragePrice) { BOOST_TEST_MESSAGE( "Testing analytic continuous geometric average-price Asians..."); @@ -172,8 +226,7 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePrice() { } - -void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceGreeks() { +BOOST_AUTO_TEST_CASE(testAnalyticContinuousGeometricAveragePriceGreeks) { BOOST_TEST_MESSAGE( "Testing analytic continuous geometric average-price Asian greeks..."); @@ -316,8 +369,7 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceGreeks() { } } - -void AsianOptionTest::testAnalyticDiscreteGeometricAveragePrice() { +BOOST_AUTO_TEST_CASE(testAnalyticDiscreteGeometricAveragePrice) { BOOST_TEST_MESSAGE( "Testing analytic discrete geometric average-price Asians..."); @@ -379,7 +431,7 @@ void AsianOptionTest::testAnalyticDiscreteGeometricAveragePrice() { } } -void AsianOptionTest::testAnalyticDiscreteGeometricAverageStrike() { +BOOST_AUTO_TEST_CASE(testAnalyticDiscreteGeometricAverageStrike) { BOOST_TEST_MESSAGE( "Testing analytic discrete geometric average-strike Asians..."); @@ -438,8 +490,7 @@ void AsianOptionTest::testAnalyticDiscreteGeometricAverageStrike() { } } - -void AsianOptionTest::testMCDiscreteGeometricAveragePrice() { +BOOST_AUTO_TEST_CASE(testMCDiscreteGeometricAveragePrice) { BOOST_TEST_MESSAGE( "Testing Monte Carlo discrete geometric average-price Asians..."); @@ -508,7 +559,6 @@ void AsianOptionTest::testMCDiscreteGeometricAveragePrice() { } } - void testDiscreteGeometricAveragePriceHeston(const ext::shared_ptr& engine, const Real tol[]) { @@ -571,7 +621,7 @@ void testDiscreteGeometricAveragePriceHeston(const ext::shared_ptr tolerance) { REPORT_FAILURE("value", averageType, 1.0, 0.0, std::vector(), payoff, europeanExercise, spot->value(), @@ -581,44 +631,7 @@ void testDiscreteGeometricAveragePriceHeston(const ext::shared_ptr spot(ext::shared_ptr(new SimpleQuote(100))); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - ext::shared_ptr qTS = flatRate(today, qRate, dc); - ext::shared_ptr rRate(new SimpleQuote(0.05)); - ext::shared_ptr rTS = flatRate(today, rRate, dc); - - Real v0 = 0.09; - Real kappa = 1.15; - Real theta = 0.0348; - Real sigma = 0.39; - Real rho = -0.64; - - ext::shared_ptr hestonProcess(new - HestonProcess(Handle(rTS), Handle(qTS), - spot, v0, kappa, theta, sigma, rho)); - - ext::shared_ptr engine(new - AnalyticDiscreteGeometricAveragePriceAsianHestonEngine(hestonProcess)); - - testDiscreteGeometricAveragePriceHeston(engine, tol); -} - - -void AsianOptionTest::testMCDiscreteGeometricAveragePriceHeston() { +BOOST_AUTO_TEST_CASE(testMCDiscreteGeometricAveragePriceHeston, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing MC discrete geometric average-price Asians under Heston..."); @@ -657,179 +670,7 @@ void AsianOptionTest::testMCDiscreteGeometricAveragePriceHeston() { testDiscreteGeometricAveragePriceHeston(engine, tol); } - -void AsianOptionTest::testDiscreteGeometricAveragePriceHestonPastFixings() { - - BOOST_TEST_MESSAGE("Testing Analytic vs MC for seasoned discrete geometric Asians under Heston..."); - - // 30-day options need wider tolerance due to uncertainty around what "weekly - // fixing" dates mean over a 30-day month! - - int days[] = {30, 90, 180, 360, 720}; - Real strikes[] = {90, 100, 110}; - - Real tol[3][5][2] = {{{ - 0.04, // strike=90, days=30, k=0 - 0.04, // strike=90, days=30, k=1 - }, - { - 0.04, // strike=90, days=90, k=0 - 0.04, // strike=90, days=90, k=1 - }, - { - 0.04, // strike=90, days=180, k=0 - 0.04, // strike=90, days=180, k=1 - }, - { - 0.05, // strike=90, days=360, k=0 - 0.04, // strike=90, days=360, k=1 - }, - { - 0.04, // strike=90, days=720, k=0 - 0.04, // strike=90, days=720, k=1 - }}, - - {{ - 0.04, // strike=100, days=30, k=0 - 0.04, // strike=100, days=30, k=1 - }, - { - 0.04, // strike=100, days=90, k=0 - 0.04, // strike=100, days=90, k=1 - }, - { - 0.04, // strike=100, days=180, k=0 - 0.04, // strike=100, days=180, k=1 - }, - { - 0.06, // strike=100, days=360, k=0 - 0.06, // strike=100, days=360, k=1 - }, - { - 0.06, // strike=100, days=720, k=0 - 0.05, // strike=100, days=720, k=1 - }}, - - {{ - 0.04, // strike=110, days=30, k=0 - 0.04, // strike=110, days=30, k=1 - }, - { - 0.04, // strike=110, days=90, k=0 - 0.04, // strike=110, days=90, k=1 - }, - { - 0.04, // strike=110, days=180, k=0 - 0.04, // strike=110, days=180, k=1 - }, - { - 0.05, // strike=110, days=360, k=0 - 0.04, // strike=110, days=360, k=1 - }, - { - 0.06, // strike=110, days=720, k=0 - 0.05, // strike=110, days=720, k=1 - }}}; - - DayCounter dc = Actual365Fixed(); - Date today = Settings::instance().evaluationDate(); - - Handle spot(ext::shared_ptr(new SimpleQuote(100))); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - ext::shared_ptr qTS = flatRate(today, qRate, dc); - ext::shared_ptr rRate(new SimpleQuote(0.05)); - ext::shared_ptr rTS = flatRate(today, rRate, dc); - - Real v0 = 0.09; - Real kappa = 1.15; - Real theta = 0.0348; - Real sigma = 0.39; - Real rho = -0.64; - - ext::shared_ptr hestonProcess(new - HestonProcess(Handle(rTS), Handle(qTS), - spot, v0, kappa, theta, sigma, rho)); - - ext::shared_ptr analyticEngine(new - AnalyticDiscreteGeometricAveragePriceAsianHestonEngine(hestonProcess)); - - ext::shared_ptr mcEngine = - MakeMCDiscreteGeometricAPHestonEngine(hestonProcess) - .withSamples(8191) - .withSeed(43); - - Option::Type type(Option::Call); - Average::Type averageType = Average::Geometric; - - for (Size strike_index = 0; strike_index < LENGTH(strikes); strike_index++) { - - for (Size day_index = 0; day_index < LENGTH(days); day_index++) { - - for (Size k=0; k<2; k++) { - - Size futureFixings = int(std::floor(days[day_index] / 30.0)); - std::vector fixingDates(futureFixings); - Date expiryDate = today + days[day_index] * Days; - - for (int i=futureFixings-1; i>=0; i--) { - fixingDates[i] = expiryDate - i * 30; - } - - ext::shared_ptr europeanExercise(new EuropeanExercise(expiryDate)); - ext::shared_ptr payoff(new PlainVanillaPayoff(type, strikes[strike_index])); - - Real runningAccumulator = 1.0; - Size pastFixingsCount = 0; - if (k == 0) { - runningAccumulator = 100.0; - pastFixingsCount = 1; - } else { - runningAccumulator = 95.0 * 100.0 * 105.0; - pastFixingsCount = 3; - } - - DiscreteAveragingAsianOption option(averageType, runningAccumulator, pastFixingsCount, - fixingDates, payoff, europeanExercise); - - option.setPricingEngine(analyticEngine); - Real analyticPrice = option.NPV(); - - option.setPricingEngine(mcEngine); - Real mcPrice = option.NPV(); - - auto tolerance = tol[strike_index][day_index][k]; - - if (std::fabs(analyticPrice-mcPrice) > tolerance) { - REPORT_FAILURE("value", averageType, runningAccumulator, pastFixingsCount, - std::vector(), payoff, europeanExercise, spot->value(), - qRate->value(), rRate->value(), today, - std::sqrt(v0), analyticPrice, mcPrice, tolerance); - } - } - } - } -} - -namespace { - - struct DiscreteAverageData { - Option::Type type; - Real underlying; - Real strike; - Rate dividendYield; - Rate riskFreeRate; - Time first; - Time length; - Size fixings; - Volatility volatility; - bool controlVariate; - Real result; - }; - -} - - -void AsianOptionTest::testMCDiscreteArithmeticAveragePrice() { +BOOST_AUTO_TEST_CASE(testMCDiscreteArithmeticAveragePrice, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Monte Carlo discrete arithmetic average-price Asians..."); @@ -990,8 +831,7 @@ void AsianOptionTest::testMCDiscreteArithmeticAveragePrice() { } } - -void AsianOptionTest::testMCDiscreteArithmeticAveragePriceHeston() { +BOOST_AUTO_TEST_CASE(testMCDiscreteArithmeticAveragePriceHeston, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE( "Testing Monte Carlo discrete arithmetic average-price Asians in Heston model..."); @@ -1183,8 +1023,7 @@ void AsianOptionTest::testMCDiscreteArithmeticAveragePriceHeston() { } - -void AsianOptionTest::testMCDiscreteArithmeticAverageStrike() { +BOOST_AUTO_TEST_CASE(testMCDiscreteArithmeticAverageStrike) { BOOST_TEST_MESSAGE( "Testing Monte Carlo discrete arithmetic average-strike Asians..."); @@ -1317,7 +1156,7 @@ void AsianOptionTest::testMCDiscreteArithmeticAverageStrike() { } } -void AsianOptionTest::testAnalyticDiscreteGeometricAveragePriceGreeks() { +BOOST_AUTO_TEST_CASE(testAnalyticDiscreteGeometricAveragePriceGreeks) { BOOST_TEST_MESSAGE("Testing discrete-averaging geometric Asian greeks..."); @@ -1465,8 +1304,7 @@ void AsianOptionTest::testAnalyticDiscreteGeometricAveragePriceGreeks() { } } - -void AsianOptionTest::testPastFixings() { +BOOST_AUTO_TEST_CASE(testPastFixings) { BOOST_TEST_MESSAGE("Testing use of past fixings in Asian options..."); @@ -1634,7 +1472,7 @@ void AsianOptionTest::testPastFixings() { } -void AsianOptionTest::testPastFixingsModelDependency() { +BOOST_AUTO_TEST_CASE(testPastFixingsModelDependency) { BOOST_TEST_MESSAGE( "Testing use of past fixings in Asian options where model dependency is flagged..."); @@ -1759,8 +1597,7 @@ void AsianOptionTest::testPastFixingsModelDependency() { } } - -void AsianOptionTest::testAllFixingsInThePast() { +BOOST_AUTO_TEST_CASE(testAllFixingsInThePast) { BOOST_TEST_MESSAGE( "Testing Asian options with all fixing dates in the past..."); @@ -1893,49 +1730,214 @@ void AsianOptionTest::testAllFixingsInThePast() { } } -namespace { +BOOST_AUTO_TEST_CASE(testTurnbullWakemanAsianEngine) { - struct ContinuousAverageData { - Option::Type type; - Real spot; - Real currentAverage; - Real strike; - Rate dividendYield; - Rate riskFreeRate; - Volatility volatility; - Natural length; - Natural elapsed; - Real result; - }; + BOOST_TEST_MESSAGE("Testing Turnbull-Wakeman engine for discrete-time arithmetic average-rate " + "Asians options with term structure support..."); + + // Data from Haug, "Option Pricing Formulas", Table 4-28, p.201 + // Type, underlying, strike, b, rfRate, t1, expiry, fixings, base vol, slope, expected result + DiscreteAverageDataTermStructure cases[] = { + {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 19.5152}, + {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 19.5063}, + {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 19.5885}, + {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.0090}, + {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0001}, + {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.0823}, + + {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 10.1437}, + {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 9.8313}, + {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 10.7062}, + {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.3906}, + {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0782}, + {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.9531}, + + {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 3.2700}, + {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 2.2819}, + {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 4.3370}, + {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 3.2700}, + {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 2.2819}, + {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 4.3370}, + + {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.5515}, + {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.1314}, + {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 1.2429}, + {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 10.3046}, + {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 9.8845}, + {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 10.9960}, + + {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.0479}, + {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0016}, + {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.2547}, + {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 19.5541}, + {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 19.5078}, + {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 19.7609}}; + + DayCounter dc = Actual360(); + Date today = Settings::instance().evaluationDate(); + + for (auto& l : cases) { + Time dt = (l.expiry - l.first) / (l.fixings - 1); + std::vector fixingDates(l.fixings); + fixingDates[0] = today + timeToDays(l.first, 360); + + for (Size i = 1; i < l.fixings; i++) { + fixingDates[i] = today + timeToDays(i * dt + l.first, 360); + } + + // Set up market data + ext::shared_ptr spot(new SimpleQuote(l.underlying)); + ext::shared_ptr qTS = flatRate(today, l.b + l.riskFreeRate, dc); + ext::shared_ptr rTS = flatRate(today, l.riskFreeRate, dc); + ext::shared_ptr volTS; + Volatility volSlope = 0.005; + if (l.slope == "flat") { + volTS = flatVol(today, l.volatility, dc); + } else if (l.slope == "up") { + std::vector volatilities(l.fixings); + for (Size i = 0; i < l.fixings; ++i) { + // Loop to fill a vector of vols from 7.5 % to 20 % + volatilities[i] = l.volatility - (l.fixings - 1) * volSlope + i * volSlope; + } + volTS = + ext::make_shared(today, fixingDates, volatilities, dc, true); + } else if (l.slope == "down") { + std::vector volatilities(l.fixings); + for (Size i = 0; i < l.fixings; ++i) { + // Loop to fill a vector of vols from 32.5 % to 20 % + volatilities[i] = l.volatility + (l.fixings - 1) * volSlope - i * volSlope; + } + volTS = + ext::make_shared(today, fixingDates, volatilities, dc, false); + } else { + QL_FAIL("unexpected slope type in engine test case"); + } + + Average::Type averageType = Average::Arithmetic; + + ext::shared_ptr payoff(new PlainVanillaPayoff(l.type, l.strike)); + + Date maturity = today + timeToDays(l.expiry, 360); + + ext::shared_ptr exercise(new EuropeanExercise(maturity)); + + ext::shared_ptr stochProcess(new BlackScholesMertonProcess( + Handle(spot), Handle(qTS), Handle(rTS), + Handle(volTS))); + + // Construct engine + ext::shared_ptr engine( + new TurnbullWakemanAsianEngine(stochProcess)); + + DiscreteAveragingAsianOption option(averageType, 0, 0, fixingDates, payoff, exercise); + option.setPricingEngine(engine); + + Real calculated = option.NPV(); + Real expected = l.result; + Real tolerance = 2.5e-3; + Real error = std::fabs(expected - calculated); + if (error > tolerance) { + BOOST_ERROR( + "Failed to reproduce expected NPV:" + << "\n type: " << l.type << "\n spot: " << l.underlying + << "\n strike: " << l.strike << "\n dividend yield: " + << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate + << "\n volatility: " << l.volatility << "\n slope: " << l.slope + << "\n reference date: " << today << "\n expiry: " << l.expiry + << "\n expected value: " << expected << "\n calculated: " << calculated + << "\n error: " << error); + } + + // Compare greeks to numerical greeks + Real dS = 0.001; + Real delta = option.delta(); + Real gamma = option.gamma(); + + ext::shared_ptr spotUp(new SimpleQuote(l.underlying+dS)); + ext::shared_ptr spotDown(new SimpleQuote(l.underlying-dS)); + + ext::shared_ptr stochProcessUp(new BlackScholesMertonProcess( + Handle(spotUp), Handle(qTS), Handle(rTS), + Handle(volTS))); + + ext::shared_ptr stochProcessDown(new BlackScholesMertonProcess( + Handle(spotDown), Handle(qTS), Handle(rTS), + Handle(volTS))); + + ext::shared_ptr engineUp( + new TurnbullWakemanAsianEngine(stochProcessUp)); + + ext::shared_ptr engineDown( + new TurnbullWakemanAsianEngine(stochProcessDown)); + + option.setPricingEngine(engineUp); + Real calculatedUp = option.NPV(); + + option.setPricingEngine(engineDown); + Real calculatedDown = option.NPV(); + Real deltaBump = (calculatedUp - calculatedDown) / (2 * dS); + Real gammaBump = (calculatedUp + calculatedDown - 2*calculated) / (dS * dS); + + tolerance = 1.0e-6; + Real deltaError = std::fabs(deltaBump - delta); + if (deltaError > tolerance) { + BOOST_ERROR( + "Analytical delta failed to match bump delta:" + << "\n type: " << l.type << "\n spot: " << l.underlying + << "\n strike: " << l.strike << "\n dividend yield: " + << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate + << "\n volatility: " << l.volatility << "\n slope: " << l.slope + << "\n reference date: " << today << "\n expiry: " << l.expiry + << "\n analytic delta: " << delta << "\n bump delta: " << deltaBump + << "\n error: " << deltaError); + } + + Real gammaError = std::fabs(gammaBump - gamma); + if (gammaError > tolerance) { + BOOST_ERROR( + "Analytical gamma failed to match bump gamma:" + << "\n type: " << l.type << "\n spot: " << l.underlying + << "\n strike: " << l.strike << "\n dividend yield: " + << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate + << "\n volatility: " << l.volatility << "\n slope: " << l.slope + << "\n reference date: " << today << "\n expiry: " << l.expiry + << "\n analytic gamma: " << gamma << "\n bump gamma: " << gammaBump + << "\n error: " << gammaError); + } + } } -void AsianOptionTest::testLevyEngine() { +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(AsianOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testLevyEngine) { BOOST_TEST_MESSAGE("Testing Levy engine for Asians options..."); // data from Haug, "Option Pricing Formulas", p.99-100 ContinuousAverageData cases[] = { - { Option::Call, 6.80, 6.80, 6.90, 0.09, 0.07, 0.14, 180, 0, 0.0944 }, - { Option::Put, 6.80, 6.80, 6.90, 0.09, 0.07, 0.14, 180, 0, 0.2237 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 0, 7.0544 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 90, 5.6731 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 180, 5.0806 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 0, 10.1213 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 90, 6.9705 }, - { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 180, 5.1411 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 0, 3.7845 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 90, 1.9964 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 180, 0.6722 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 0, 7.5038 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 90, 4.0687 }, - { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 180, 1.4222 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 0, 1.6729 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 90, 0.3565 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 180, 0.0004 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 0, 5.4071 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 90, 2.1359 }, - { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 180, 0.1552 } + { Option::Call, 6.80, 6.80, 6.90, 0.09, 0.07, 0.14, 180, 0, 0.0944 }, + { Option::Put, 6.80, 6.80, 6.90, 0.09, 0.07, 0.14, 180, 0, 0.2237 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 0, 7.0544 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 90, 5.6731 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.15, 270, 180, 5.0806 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 0, 10.1213 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 90, 6.9705 }, + { Option::Call, 100.0, 100.0, 95.0, 0.05, 0.1, 0.35, 270, 180, 5.1411 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 0, 3.7845 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 90, 1.9964 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.15, 270, 180, 0.6722 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 0, 7.5038 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 90, 4.0687 }, + { Option::Call, 100.0, 100.0, 100.0, 0.05, 0.1, 0.35, 270, 180, 1.4222 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 0, 1.6729 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 90, 0.3565 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.15, 270, 180, 0.0004 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 0, 5.4071 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 90, 2.1359 }, + { Option::Call, 100.0, 100.0, 105.0, 0.05, 0.1, 0.35, 270, 180, 0.1552 } }; DayCounter dc = Actual360(); @@ -1959,14 +1961,14 @@ void AsianOptionTest::testLevyEngine() { ext::shared_ptr exercise(new EuropeanExercise(maturity)); ext::shared_ptr stochProcess(new - BlackScholesMertonProcess(Handle(spot), - Handle(qTS), - Handle(rTS), - Handle(volTS))); + BlackScholesMertonProcess(Handle(spot), + Handle(qTS), + Handle(rTS), + Handle(volTS))); ext::shared_ptr engine( new ContinuousArithmeticAsianLevyEngine( - stochProcess, Handle(average), startDate)); + stochProcess, Handle(average), startDate)); ContinuousAveragingAsianOption option(averageType, payoff, exercise); @@ -1990,21 +1992,7 @@ void AsianOptionTest::testLevyEngine() { } } -namespace { - - struct VecerData { - Real spot; - Rate riskFreeRate; - Volatility volatility; - Real strike; - Natural length; - Real result; - Real tolerance; - }; - -} - -void AsianOptionTest::testVecerEngine() { +BOOST_AUTO_TEST_CASE(testVecerEngine) { BOOST_TEST_MESSAGE("Testing Vecer engine for Asian options..."); VecerData cases[] = { @@ -2056,7 +2044,7 @@ void AsianOptionTest::testVecerEngine() { } } -void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { +BOOST_AUTO_TEST_CASE(testAnalyticContinuousGeometricAveragePriceHeston) { BOOST_TEST_MESSAGE("Testing analytic continuous geometric Asians under Heston..."); @@ -2070,11 +2058,11 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { // Prices from Table 1 (params obey Feller condition) Real prices[] = {10.6571, 6.5871, 3.4478, 1.4552, 0.4724, 16.5030, 13.7625, 11.3374, 9.2245, - 7.4122, 20.5102, 18.3060, 16.2895, 14.4531, 12.7882}; + 7.4122, 20.5102, 18.3060, 16.2895, 14.4531, 12.7882}; // Prices from Table 4 (params do not obey Feller condition) Real prices_2[] = {10.6425, 6.4362, 3.1578, 1.1936, 0.3609, 14.9955, 11.6707, 8.7767, 6.3818, - 4.5118, 18.1219, 15.2009, 12.5707, 10.2539, 8.2611}; + 4.5118, 18.1219, 15.2009, 12.5707, 10.2539, 8.2611}; // 0.2 and 3.0 match to 1e-4. Unfortunatly 1.5 corresponds to 547.5 days, 547 and 548 // bound the expected answer but are both out by ~5e-3 @@ -2098,11 +2086,11 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { Real rho = -0.64; ext::shared_ptr hestonProcess(new - HestonProcess(Handle(rTS), Handle(qTS), - spot, v0, kappa, theta, sigma, rho)); + HestonProcess(Handle(rTS), Handle(qTS), + spot, v0, kappa, theta, sigma, rho)); ext::shared_ptr engine(new - AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess)); + AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess)); for (Size i=0; i tolerance) { REPORT_FAILURE("value", averageType, 1.0, 0.0, - std::vector(), payoff, europeanExercise, spot->value(), - qRate->value(), rRate->value(), today, - std::sqrt(v0), expected, calculated, tolerance); + std::vector(), payoff, europeanExercise, spot->value(), + qRate->value(), rRate->value(), today, + std::sqrt(v0), expected, calculated, tolerance); } } @@ -2134,11 +2122,11 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { Real rho_2 = -0.3; ext::shared_ptr hestonProcess_2(new - HestonProcess(Handle(rTS), Handle(qTS), - spot, v0_2, kappa_2, theta_2, sigma_2, rho_2)); + HestonProcess(Handle(rTS), Handle(qTS), + spot, v0_2, kappa_2, theta_2, sigma_2, rho_2)); ext::shared_ptr engine_2(new - AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_2)); + AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_2)); for (Size i=0; i tolerance) { REPORT_FAILURE("value", averageType, 1.0, 0.0, - std::vector(), payoff, europeanExercise, spot->value(), - qRate->value(), rRate->value(), today, - std::sqrt(v0), expected, calculated, tolerance); + std::vector(), payoff, europeanExercise, spot->value(), + qRate->value(), rRate->value(), today, + std::sqrt(v0), expected, calculated, tolerance); } } @@ -2170,19 +2158,19 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { // 73, 348 and 1095 are 0.2, 1.5 and 3.0 years respectively in Actual365Fixed Time days_3[] = {30, 91, 182, 365, 730, 1095, 30, 91, 182, 365, 730, 1095, 30, - 91, 182, 365, 730, 1095}; + 91, 182, 365, 730, 1095}; Real strikes_3[] = {90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 110, 110, 110, 110, 110, 110}; // 30-day options need wider tolerance due to the day-bracket issue discussed above Real tol_3[] = {2.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, 2.0e-2, 1.0e-2, - 1.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, 2.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, - 1.0e-2, 1.0e-2}; + 1.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, 2.0e-2, 1.0e-2, 1.0e-2, 1.0e-2, + 1.0e-2, 1.0e-2}; // Prices from Tables 1, 2 and 3 Real prices_3[] = {10.1513, 10.8175, 11.8664, 13.5931, 16.0988, 17.9475, 2.0472, - 3.5735, 5.0588, 7.1132, 9.9139, 11.9959, 0.0350, 0.4869, - 1.3376, 2.8569, 5.2804, 7.2682}; + 3.5735, 5.0588, 7.1132, 9.9139, 11.9959, 0.0350, 0.4869, + 1.3376, 2.8569, 5.2804, 7.2682}; // Note that although these parameters look similar to the first set above, theta // is a factor of 10 smaller. I guess there is a mis-transcription somewhere! @@ -2193,11 +2181,11 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston() { Real rho_3 = -0.64; ext::shared_ptr hestonProcess_3(new - HestonProcess(Handle(rTS), Handle(qTS), - spot, v0_3, kappa_3, theta_3, sigma_3, rho_3)); + HestonProcess(Handle(rTS), Handle(qTS), + spot, v0_3, kappa_3, theta_3, sigma_3, rho_3)); ext::shared_ptr engine_3(new - AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_3)); + AnalyticContinuousGeometricAveragePriceAsianHestonEngine(hestonProcess_3)); for (Size i=0; i tolerance) { REPORT_FAILURE("value", averageType, 1.0, 0.0, - std::vector(), payoff, europeanExercise, spot->value(), - qRate->value(), rRate->value(), today, - std::sqrt(v0), expected, calculated, tolerance); + std::vector(), payoff, europeanExercise, spot->value(), + qRate->value(), rRate->value(), today, + std::sqrt(v0), expected, calculated, tolerance); } } } -namespace { - struct DiscreteAverageDataTermStructure { - Option::Type type; - Real underlying; - Real strike; - Rate b; - Rate riskFreeRate; - Time first; // t1 - Time expiry; - Size fixings; - Volatility volatility; - std::string slope; - Real result; - }; -} +BOOST_AUTO_TEST_CASE(testAnalyticDiscreteGeometricAveragePriceHeston) { -void AsianOptionTest::testTurnbullWakemanAsianEngine() { + BOOST_TEST_MESSAGE("Testing analytic discrete geometric average-price Asians under Heston..."); - BOOST_TEST_MESSAGE("Testing Turnbull-Wakeman engine for discrete-time arithmetic average-rate " - "Asians options with term structure support..."); + // 30-day options need wider tolerance due to uncertainty around what "weekly + // fixing" dates mean over a 30-day month! + Real tol[] = {3.0e-2, 2.0e-2, 2.0e-2, 2.0e-2, 3.0e-2, 4.0e-2, 8.0e-2, 1.0e-2, + 2.0e-2, 3.0e-2, 3.0e-2, 4.0e-2, 2.0e-2, 1.0e-2, 1.0e-2, 2.0e-2, + 3.0e-2, 4.0e-2}; - // Data from Haug, "Option Pricing Formulas", Table 4-28, p.201 - // Type, underlying, strike, b, rfRate, t1, expiry, fixings, base vol, slope, expected result - DiscreteAverageDataTermStructure cases[] = { - {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 19.5152}, - {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 19.5063}, - {Option::Call, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 19.5885}, - {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.0090}, - {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0001}, - {Option::Put, 100, 80, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.0823}, - - {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 10.1437}, - {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 9.8313}, - {Option::Call, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 10.7062}, - {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.3906}, - {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0782}, - {Option::Put, 100, 90, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.9531}, + DayCounter dc = Actual365Fixed(); + Date today = Settings::instance().evaluationDate(); - {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 3.2700}, - {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 2.2819}, - {Option::Call, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 4.3370}, - {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 3.2700}, - {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 2.2819}, - {Option::Put, 100, 100, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 4.3370}, + Handle spot(ext::shared_ptr(new SimpleQuote(100))); + ext::shared_ptr qRate(new SimpleQuote(0.0)); + ext::shared_ptr qTS = flatRate(today, qRate, dc); + ext::shared_ptr rRate(new SimpleQuote(0.05)); + ext::shared_ptr rTS = flatRate(today, rRate, dc); - {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.5515}, - {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.1314}, - {Option::Call, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 1.2429}, - {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 10.3046}, - {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 9.8845}, - {Option::Put, 100, 110, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 10.9960}, + Real v0 = 0.09; + Real kappa = 1.15; + Real theta = 0.0348; + Real sigma = 0.39; + Real rho = -0.64; - {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 0.0479}, - {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 0.0016}, - {Option::Call, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 0.2547}, - {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "flat", 19.5541}, - {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "up", 19.5078}, - {Option::Put, 100, 120, 0, 0.05, 1.0 / 52, 0.5, 26, 0.2, "down", 19.7609}}; + ext::shared_ptr hestonProcess(new + HestonProcess(Handle(rTS), Handle(qTS), + spot, v0, kappa, theta, sigma, rho)); - DayCounter dc = Actual360(); - Date today = Settings::instance().evaluationDate(); + ext::shared_ptr engine(new + AnalyticDiscreteGeometricAveragePriceAsianHestonEngine(hestonProcess)); - for (auto& l : cases) { - Time dt = (l.expiry - l.first) / (l.fixings - 1); - std::vector fixingDates(l.fixings); - fixingDates[0] = today + timeToDays(l.first, 360); + AsianOptionTest::testDiscreteGeometricAveragePriceHeston(engine, tol); +} - for (Size i = 1; i < l.fixings; i++) { - fixingDates[i] = today + timeToDays(i * dt + l.first, 360); - } +BOOST_AUTO_TEST_CASE(testDiscreteGeometricAveragePriceHestonPastFixings) { - // Set up market data - ext::shared_ptr spot(new SimpleQuote(l.underlying)); - ext::shared_ptr qTS = flatRate(today, l.b + l.riskFreeRate, dc); - ext::shared_ptr rTS = flatRate(today, l.riskFreeRate, dc); - ext::shared_ptr volTS; - Volatility volSlope = 0.005; - if (l.slope == "flat") { - volTS = flatVol(today, l.volatility, dc); - } else if (l.slope == "up") { - std::vector volatilities(l.fixings); - for (Size i = 0; i < l.fixings; ++i) { - // Loop to fill a vector of vols from 7.5 % to 20 % - volatilities[i] = l.volatility - (l.fixings - 1) * volSlope + i * volSlope; - } - volTS = - ext::make_shared(today, fixingDates, volatilities, dc, true); - } else if (l.slope == "down") { - std::vector volatilities(l.fixings); - for (Size i = 0; i < l.fixings; ++i) { - // Loop to fill a vector of vols from 32.5 % to 20 % - volatilities[i] = l.volatility + (l.fixings - 1) * volSlope - i * volSlope; - } - volTS = - ext::make_shared(today, fixingDates, volatilities, dc, false); - } else { - QL_FAIL("unexpected slope type in engine test case"); - } + BOOST_TEST_MESSAGE("Testing Analytic vs MC for seasoned discrete geometric Asians under Heston..."); - Average::Type averageType = Average::Arithmetic; + // 30-day options need wider tolerance due to uncertainty around what "weekly + // fixing" dates mean over a 30-day month! - ext::shared_ptr payoff(new PlainVanillaPayoff(l.type, l.strike)); + int days[] = {30, 90, 180, 360, 720}; + Real strikes[] = {90, 100, 110}; - Date maturity = today + timeToDays(l.expiry, 360); + Real tol[3][5][2] = {{{ + 0.04, // strike=90, days=30, k=0 + 0.04, // strike=90, days=30, k=1 + }, + { + 0.04, // strike=90, days=90, k=0 + 0.04, // strike=90, days=90, k=1 + }, + { + 0.04, // strike=90, days=180, k=0 + 0.04, // strike=90, days=180, k=1 + }, + { + 0.05, // strike=90, days=360, k=0 + 0.04, // strike=90, days=360, k=1 + }, + { + 0.04, // strike=90, days=720, k=0 + 0.04, // strike=90, days=720, k=1 + }}, - ext::shared_ptr exercise(new EuropeanExercise(maturity)); + {{ + 0.04, // strike=100, days=30, k=0 + 0.04, // strike=100, days=30, k=1 + }, + { + 0.04, // strike=100, days=90, k=0 + 0.04, // strike=100, days=90, k=1 + }, + { + 0.04, // strike=100, days=180, k=0 + 0.04, // strike=100, days=180, k=1 + }, + { + 0.06, // strike=100, days=360, k=0 + 0.06, // strike=100, days=360, k=1 + }, + { + 0.06, // strike=100, days=720, k=0 + 0.05, // strike=100, days=720, k=1 + }}, - ext::shared_ptr stochProcess(new BlackScholesMertonProcess( - Handle(spot), Handle(qTS), Handle(rTS), - Handle(volTS))); + {{ + 0.04, // strike=110, days=30, k=0 + 0.04, // strike=110, days=30, k=1 + }, + { + 0.04, // strike=110, days=90, k=0 + 0.04, // strike=110, days=90, k=1 + }, + { + 0.04, // strike=110, days=180, k=0 + 0.04, // strike=110, days=180, k=1 + }, + { + 0.05, // strike=110, days=360, k=0 + 0.04, // strike=110, days=360, k=1 + }, + { + 0.06, // strike=110, days=720, k=0 + 0.05, // strike=110, days=720, k=1 + }}}; - // Construct engine - ext::shared_ptr engine( - new TurnbullWakemanAsianEngine(stochProcess)); + DayCounter dc = Actual365Fixed(); + Date today = Settings::instance().evaluationDate(); - DiscreteAveragingAsianOption option(averageType, 0, 0, fixingDates, payoff, exercise); - option.setPricingEngine(engine); + Handle spot(ext::shared_ptr(new SimpleQuote(100))); + ext::shared_ptr qRate(new SimpleQuote(0.0)); + ext::shared_ptr qTS = flatRate(today, qRate, dc); + ext::shared_ptr rRate(new SimpleQuote(0.05)); + ext::shared_ptr rTS = flatRate(today, rRate, dc); - Real calculated = option.NPV(); - Real expected = l.result; - Real tolerance = 2.5e-3; - Real error = std::fabs(expected - calculated); - if (error > tolerance) { - BOOST_ERROR( - "Failed to reproduce expected NPV:" - << "\n type: " << l.type << "\n spot: " << l.underlying - << "\n strike: " << l.strike << "\n dividend yield: " - << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate - << "\n volatility: " << l.volatility << "\n slope: " << l.slope - << "\n reference date: " << today << "\n expiry: " << l.expiry - << "\n expected value: " << expected << "\n calculated: " << calculated - << "\n error: " << error); - } + Real v0 = 0.09; + Real kappa = 1.15; + Real theta = 0.0348; + Real sigma = 0.39; + Real rho = -0.64; - // Compare greeks to numerical greeks - Real dS = 0.001; - Real delta = option.delta(); - Real gamma = option.gamma(); + ext::shared_ptr hestonProcess(new + HestonProcess(Handle(rTS), Handle(qTS), + spot, v0, kappa, theta, sigma, rho)); - ext::shared_ptr spotUp(new SimpleQuote(l.underlying+dS)); - ext::shared_ptr spotDown(new SimpleQuote(l.underlying-dS)); + ext::shared_ptr analyticEngine(new + AnalyticDiscreteGeometricAveragePriceAsianHestonEngine(hestonProcess)); - ext::shared_ptr stochProcessUp(new BlackScholesMertonProcess( - Handle(spotUp), Handle(qTS), Handle(rTS), - Handle(volTS))); + ext::shared_ptr mcEngine = + MakeMCDiscreteGeometricAPHestonEngine(hestonProcess) + .withSamples(8191) + .withSeed(43); - ext::shared_ptr stochProcessDown(new BlackScholesMertonProcess( - Handle(spotDown), Handle(qTS), Handle(rTS), - Handle(volTS))); + Option::Type type(Option::Call); + Average::Type averageType = Average::Geometric; - ext::shared_ptr engineUp( - new TurnbullWakemanAsianEngine(stochProcessUp)); + for (Size strike_index = 0; strike_index < LENGTH(strikes); strike_index++) { - ext::shared_ptr engineDown( - new TurnbullWakemanAsianEngine(stochProcessDown)); + for (Size day_index = 0; day_index < LENGTH(days); day_index++) { - option.setPricingEngine(engineUp); - Real calculatedUp = option.NPV(); + for (Size k=0; k<2; k++) { - option.setPricingEngine(engineDown); - Real calculatedDown = option.NPV(); + Size futureFixings = int(std::floor(days[day_index] / 30.0)); + std::vector fixingDates(futureFixings); + Date expiryDate = today + days[day_index] * Days; - Real deltaBump = (calculatedUp - calculatedDown) / (2 * dS); - Real gammaBump = (calculatedUp + calculatedDown - 2*calculated) / (dS * dS); + for (int i=futureFixings-1; i>=0; i--) { + fixingDates[i] = expiryDate - i * 30; + } - tolerance = 1.0e-6; - Real deltaError = std::fabs(deltaBump - delta); - if (deltaError > tolerance) { - BOOST_ERROR( - "Analytical delta failed to match bump delta:" - << "\n type: " << l.type << "\n spot: " << l.underlying - << "\n strike: " << l.strike << "\n dividend yield: " - << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate - << "\n volatility: " << l.volatility << "\n slope: " << l.slope - << "\n reference date: " << today << "\n expiry: " << l.expiry - << "\n analytic delta: " << delta << "\n bump delta: " << deltaBump - << "\n error: " << deltaError); - } + ext::shared_ptr europeanExercise(new EuropeanExercise(expiryDate)); + ext::shared_ptr payoff(new PlainVanillaPayoff(type, strikes[strike_index])); - Real gammaError = std::fabs(gammaBump - gamma); - if (gammaError > tolerance) { - BOOST_ERROR( - "Analytical gamma failed to match bump gamma:" - << "\n type: " << l.type << "\n spot: " << l.underlying - << "\n strike: " << l.strike << "\n dividend yield: " - << l.b + l.riskFreeRate << "\n risk-free rate: " << l.riskFreeRate - << "\n volatility: " << l.volatility << "\n slope: " << l.slope - << "\n reference date: " << today << "\n expiry: " << l.expiry - << "\n analytic gamma: " << gamma << "\n bump gamma: " << gammaBump - << "\n error: " << gammaError); - } - } -} + Real runningAccumulator = 1.0; + Size pastFixingsCount = 0; + if (k == 0) { + runningAccumulator = 100.0; + pastFixingsCount = 1; + } else { + runningAccumulator = 95.0 * 100.0 * 105.0; + pastFixingsCount = 3; + } -test_suite* AsianOptionTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Asian option tests"); - - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticContinuousGeometricAveragePrice)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticContinuousGeometricAveragePriceGreeks)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticDiscreteGeometricAveragePrice)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticDiscreteGeometricAverageStrike)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testMCDiscreteGeometricAveragePrice)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testMCDiscreteArithmeticAverageStrike)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticDiscreteGeometricAveragePriceGreeks)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testPastFixings)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAllFixingsInThePast)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testTurnbullWakemanAsianEngine)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testPastFixingsModelDependency)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testMCDiscreteArithmeticAveragePrice)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testMCDiscreteGeometricAveragePriceHeston)); - } + DiscreteAveragingAsianOption option(averageType, runningAccumulator, pastFixingsCount, + fixingDates, payoff, europeanExercise); - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testMCDiscreteArithmeticAveragePriceHeston)); - } + option.setPricingEngine(analyticEngine); + Real analyticPrice = option.NPV(); - return suite; -} + option.setPricingEngine(mcEngine); + Real mcPrice = option.NPV(); -test_suite* AsianOptionTest::experimental(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Asian option experimental tests"); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testLevyEngine)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testVecerEngine)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticContinuousGeometricAveragePriceHeston)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testAnalyticDiscreteGeometricAveragePriceHeston)); - suite->add(QUANTLIB_TEST_CASE(&AsianOptionTest::testDiscreteGeometricAveragePriceHestonPastFixings)); + auto tolerance = tol[strike_index][day_index][k]; - return suite; + if (std::fabs(analyticPrice-mcPrice) > tolerance) { + REPORT_FAILURE("value", averageType, runningAccumulator, pastFixingsCount, + std::vector(), payoff, europeanExercise, spot->value(), + qRate->value(), rRate->value(), today, + std::sqrt(v0), analyticPrice, mcPrice, tolerance); + } + } + } + } } +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/asianoptions.hpp b/test-suite/asianoptions.hpp deleted file mode 100644 index 25337aecf98..00000000000 --- a/test-suite/asianoptions.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003, 2004 Ferdinando Ametrano - Copyright (C) 2008, 2017 StatPro Italia srl - Copyright (C) 2009 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis - Copyright (C) 2021 Skandinaviska Enskilda Banken AB (publ) - - 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_asian_options_hpp -#define quantlib_test_asian_options_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class AsianOptionTest { - public: - static void testAnalyticContinuousGeometricAveragePrice(); - static void testAnalyticContinuousGeometricAveragePriceGreeks(); - static void testAnalyticContinuousGeometricAveragePriceHeston(); - static void testAnalyticDiscreteGeometricAveragePrice(); - static void testAnalyticDiscreteGeometricAveragePriceHeston(); - static void testAnalyticDiscreteGeometricAverageStrike(); - static void testDiscreteGeometricAveragePriceHestonPastFixings(); - static void testMCDiscreteGeometricAveragePrice(); - static void testMCDiscreteGeometricAveragePriceHeston(); - static void testMCDiscreteArithmeticAveragePrice(); - static void testMCDiscreteArithmeticAveragePriceHeston(); - static void testMCDiscreteArithmeticAverageStrike(); - static void testAnalyticDiscreteGeometricAveragePriceGreeks(); - static void testPastFixings(); - static void testPastFixingsModelDependency(); - static void testAllFixingsInThePast(); - static void testLevyEngine(); - static void testVecerEngine(); - static void testTurnbullWakemanAsianEngine(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); - static boost::unit_test_framework::test_suite* experimental(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 5e5ed6df481..56fd338c09e 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "asianoptions.hpp" #include "barrieroption.hpp" #include "basketoption.hpp" #include "batesmodel.hpp" @@ -161,6 +160,9 @@ namespace QuantLibTest { namespace AmericanOptionTest { struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace AsianOptionTest { + struct testMCDiscreteArithmeticAveragePrice: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -193,7 +195,7 @@ namespace { std::vector bm = { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), - Benchmark("AsianOption::MCArithmeticAveragePrice", &AsianOptionTest::testMCDiscreteArithmeticAveragePrice, 5186.13), + Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), Benchmark("BarrierOption::BabsiriValues", &BarrierOptionTest::testBabsiriValues, 880.8), Benchmark("BasketOption::EuroTwoValues", &BasketOptionTest::testEuroTwoValues, 340.04), Benchmark("BasketOption::TavellaValues", &BasketOptionTest::testTavellaValues, 933.80), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index a1fbce04090..aee46aaf67e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,10 +36,6 @@ # include #endif -#include "amortizingbond.hpp" -#include "andreasenhugevolatilityinterpl.hpp" -#include "array.hpp" -#include "asianoptions.hpp" #include "assetswap.hpp" #include "autocovariances.hpp" #include "barrieroption.hpp" @@ -325,12 +321,6 @@ test_suite* init_unit_test_suite(int, char* []) { BOOST_TEST_MESSAGE(rule); auto* test = BOOST_TEST_SUITE("QuantLib test suite"); -// test->add(QUANTLIB_TEST_CASE(startTimer)); - - test->add(AmortizingBondTest::suite()); - test->add(AndreasenHugeVolatilityInterplTest::suite(speed)); - test->add(ArrayTest::suite()); - test->add(AsianOptionTest::suite(speed)); test->add(AssetSwapTest::suite()); // fails with QL_USE_INDEXED_COUPON test->add(AutocovariancesTest::suite()); test->add(BarrierOptionTest::suite()); @@ -458,7 +448,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(AsianOptionTest::experimental(speed)); test->add(BasismodelsTest::suite()); test->add(BasisSwapRateHelpersTest::suite()); test->add(BarrierOptionTest::experimental()); @@ -505,7 +494,5 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(LiborMarketModelTest::suite(speed)); test->add(LiborMarketModelProcessTest::suite(speed)); -// test->add(QUANTLIB_TEST_CASE(stopTimer)); - return test; } diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 112cb5979e2..230df517267 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -810,10 +810,6 @@ - - - - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 629fa97a980..4a3cec0a0f9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,18 +527,6 @@ - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files From 6f5ac277eeba435b55a22c389ac29ff91f0ee4b6 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 10:48:52 +0800 Subject: [PATCH 006/132] Migrated functions from quantlibtestsuite.cpp to quantlibglobalfixture.cpp --- test-suite/quantlibbenchmark.cpp | 4 +- test-suite/quantlibglobalfixture.cpp | 129 ++++++++++++++++++++++++++- test-suite/quantlibtestsuite.cpp | 106 ---------------------- 3 files changed, 127 insertions(+), 112 deletions(-) diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 56fd338c09e..3c33743a75b 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -170,7 +170,7 @@ namespace { class Benchmark { public: Benchmark(std::string name, std::function f, double mflop) - : f_(f), name_(std::move(name)), mflop_(mflop) {} + : f_(std::move(f)), name_(std::move(name)), mflop_(mflop) {} std::function getTestCase() const { return f_; @@ -227,7 +227,7 @@ namespace { class TimedBenchmark { public: - explicit TimedBenchmark(std::function f) : f_(f) {} + explicit TimedBenchmark(std::function f) : f_(std::move(f)) {} void startMeasurement() const { /* PAPI code diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 072a79fef3c..c9e9b58947d 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -1,22 +1,143 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2004, 2005, 2006, 2007 Ferdinando Ametrano + Copyright (C) 2004, 2005, 2006, 2007, 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. +*/ + +#include +#include +#include +#include + +#ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER +#include "paralleltestrunner.hpp" +#else #include +#endif + +/* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks, + for example) also #define _MSC_VER +*/ +#if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC) +# include +#endif #define BOOST_TEST_NO_MAIN #define BOOST_TEST_ALTERNATIVE_INIT_API - +#include "quantlibglobalfixture.hpp" +#include "speedlevel.hpp" #include #include #include -#include "quantlibglobalfixture.hpp" -#include "speedlevel.hpp" - using namespace boost::unit_test; +namespace { + + void configure(QuantLib::Date evaluationDate) { + /* if needed, a subset of the lines below can be + uncommented and/or changed to run the test suite with a + different configuration. In the future, we'll need a + mechanism that doesn't force us to recompile (possibly a + couple of command-line flags for the test suite?) + */ + + // QuantLib::Settings::instance().includeReferenceDateCashFlows() = true; + // QuantLib::Settings::instance().includeTodaysCashFlows() = ext::nullopt; + + QuantLib::Settings::instance().evaluationDate() = evaluationDate; + } + +} + +QuantLib::Date evaluation_date(int argc, char** argv) { + /*! Dead simple parser: + - passing --date=YYYY-MM-DD causes the test suite to run on + that date; + - passing --date=today causes it to run on today's date; + - passing nothing causes it to run on a known date for which + there should be no date-dependent errors as far as we know. + + Dates that should eventually be checked include: + - 2015-08-29 causes three tests to fail; + - 2016-02-29 causes two tests to fail. + */ + + QuantLib::Date knownGoodDefault = + QuantLib::Date(16, QuantLib::September, 2015); + + for (int i=1; i underlying = - ext::make_shared(S); - ext::shared_ptr qTS = flatRate(today, q, dc); - ext::shared_ptr rTS = flatRate(today, r, dc); - - std::vector dates(2); - std::vector vols(2); - - dates[0] = today + 90; vols[0] = 0.105; - dates[1] = today + 180; vols[1] = 0.11; - - ext::shared_ptr volTS = - ext::make_shared(today, dates, vols, dc); - - ext::shared_ptr stochProcess = - ext::make_shared( - Handle(underlying), - Handle(qTS), - Handle(rTS), - Handle(volTS)); - - Real strike = 101.0; - Real barrier = 101.0; - Date exDate = today+180; - - ext::shared_ptr exercise = - ext::make_shared(exDate); - ext::shared_ptr payoff = - ext::make_shared(Option::Put, strike); - - BarrierOption option(Barrier::UpOut, barrier, rebate, payoff, exercise); - - Natural order = 0; - bool zeroGamma = false; - ext::shared_ptr engine = - ext::make_shared(stochProcess, - order, zeroGamma); - - option.setPricingEngine(engine); - - Real calculated = option.NPV(); - Real expected = 0.897365; - Real tolerance = 1.0e-6; - if (std::fabs(calculated-expected) > tolerance) { - BOOST_ERROR("Failed to reproduce expected value" - << "\n calculated: " << std::setprecision(8) << calculated - << "\n expected: " << std::setprecision(8) << expected); - } - - order = 1; - engine = ext::make_shared(stochProcess, - order, - zeroGamma); - - option.setPricingEngine(engine); - - calculated = option.NPV(); - expected = 0.894374; - if (std::fabs(calculated-expected) > tolerance) { - BOOST_ERROR("Failed to reproduce expected value" - << "\n calculated: " << std::setprecision(8) << calculated - << "\n expected: " << std::setprecision(8) << expected); - } - - /* Too slow, skip - order = 2; - engine = ext::make_shared(stochProcess, - order, - zeroGamma); - - option.setPricingEngine(engine); - - calculated = option.NPV(); - expected = 0.8943769; - if (std::fabs(calculated-expected) > tolerance) { - BOOST_ERROR("Failed to reproduce expected value" - << "\n calculated: " << std::setprecision(8) << calculated - << "\n expected: " << std::setprecision(8) << expected); - } - */ -} - -void BarrierOptionTest::testLocalVolAndHestonComparison() { +BOOST_AUTO_TEST_CASE(testLocalVolAndHestonComparison) { BOOST_TEST_MESSAGE("Testing local volatility and Heston FD engines " "for barrier options..."); @@ -936,316 +846,92 @@ void BarrierOptionTest::testLocalVolAndHestonComparison() { } } +BOOST_AUTO_TEST_CASE(testOldDividendBarrierOption) { + BOOST_TEST_MESSAGE("Testing old-style barrier option pricing with discrete dividends..."); -void BarrierOptionTest::testVannaVolgaSimpleBarrierValues() { - BOOST_TEST_MESSAGE("Testing barrier FX options against Vanna/Volga values..."); + const DayCounter dc = Actual365Fixed(); - using namespace barrier_option_test; + const Date today(11, February, 2018); + const Date maturity = today + Period(1, Years); + Settings::instance().evaluationDate() = today; - BarrierFxOptionData values[] = { + const Real spot = 100.0; + const Real strike = 105.0; + const Real rebate = 5.0; - //barrierType,barrier,rebate,type,strike,s,q,r,t,vol25Put,volAtm,vol25Call,vol, result, tol - { Barrier::UpOut,1.5,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.148127, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.075943, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0274771, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00573, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00012, 1.0e-4}, + const Real barriers[] = { 80.0, 120.0 }; + const Barrier::Type barrierTypes[] = { Barrier::DownOut, Barrier::UpOut }; - { Barrier::UpOut,1.5,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00697606, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.020078, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0489395, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.0969877, 1.0e-4}, - { Barrier::UpOut,1.5,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.157, 1.0e-4}, + const Rate r = 0.05; + const Rate q = 0.0; + const Volatility v = 0.02; - { Barrier::UpIn,1.5,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.0322202, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.0241491, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0164275, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00489, 1.0e-4}, + const Handle s0(ext::make_shared(spot)); + const Handle qTS(flatRate(today, q, dc)); + const Handle rTS(flatRate(today, r, dc)); + const Handle volTS(flatVol(today, v, dc)); - { Barrier::UpIn,1.5,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.000560713, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.000546804, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.000130649, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.000300828, 1.0e-4}, - { Barrier::UpIn,1.5,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00135, 1.0e-4}, + const ext::shared_ptr bsProcess = + ext::make_shared(s0, qTS, rTS, volTS); - { Barrier::DownOut,1.1,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.17746, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.0994142, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0439, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01574, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00501, 1.0e-4}, + const ext::shared_ptr douglas = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::Douglas()); - { Barrier::DownOut,1.3,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00612, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00426, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.00257, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00122, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00045, 1.0e-4}, + const ext::shared_ptr crankNicolson = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::CrankNicolson()); - { Barrier::DownOut,1.1,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00022, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00284, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.02032, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.058235, 1.0e-4}, - { Barrier::DownOut,1.1,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.109432, 1.0e-4}, + const ext::shared_ptr craigSnyed = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::CraigSneyd()); - { Barrier::DownOut,1.3,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00017, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00083, 1.0e-4}, + const ext::shared_ptr hundsdorfer = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::Hundsdorfer()); - { Barrier::DownIn,1.1,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00289, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00067784, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0, 1.0e-4}, + const ext::shared_ptr mol = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::MethodOfLines()); - { Barrier::DownIn,1.3,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.17423, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.09584, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.04133, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01452, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00456, 1.0e-4}, + const ext::shared_ptr trPDF2 = + ext::make_shared( + bsProcess, 100, 100, 0, FdmSchemeDesc::TrBDF2()); - { Barrier::DownIn,1.1,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00732, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.01778, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.02875, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.0390535, 1.0e-4}, - { Barrier::DownIn,1.1,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.0489236, 1.0e-4}, + const ext::shared_ptr hestonEngine = + ext::make_shared( + ext::make_shared( + ext::make_shared( + rTS, qTS, s0, v*v, 1.0, v*v, 0.005, 0.0)), 50, 101, 3); - { Barrier::DownIn,1.3,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00753, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.02062, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.04907, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.09711, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.15752, 1.0e-4}, + const ext::shared_ptr engines[] = { + douglas, crankNicolson, + trPDF2, craigSnyed, hundsdorfer, mol, hestonEngine + }; - { Barrier::UpOut,1.6,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.20493, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.105577, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0358872, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.00634958, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0, 1.0e-4}, + const ext::shared_ptr payoff = + ext::make_shared(Option::Put, strike); - { Barrier::UpOut,1.6,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.0108218, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0313339, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0751237, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.153407, 1.0e-4}, - { Barrier::UpOut,1.6,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.253767, 1.0e-4}, + const ext::shared_ptr exercise = + ext::make_shared(maturity); - { Barrier::UpIn,1.6,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.05402, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0410069, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0279562, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0173055, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00764, 1.0e-4}, + const Real divAmount = 30; + const Date divDate = today + Period(6, Months); - { Barrier::UpIn,1.6,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.000962737, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00102637, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.000419834, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.00159277, 1.0e-4}, - { Barrier::UpIn,1.6,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00473629, 1.0e-4}, + const Real expected[] = { + rTS->discount(divDate)*rebate, + (*payoff)( + (spot - divAmount*rTS->discount(divDate))/rTS->discount(maturity)) + *rTS->discount(maturity) + }; - { Barrier::DownOut,1,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.255098, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.145701, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.06384, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.02366, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00764, 1.0e-4}, + const Real relTol = 1e-4; + for (Size i=0; i < LENGTH(barriers); ++i) { + for (const auto& engine : engines) { + const Real barrier = barriers[i]; + const Barrier::Type barrierType = barrierTypes[i]; - { Barrier::DownOut,1.3,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.00592, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00421, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.00256, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0012, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.0004, 1.0e-4}, - - { Barrier::DownOut,1,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00280549, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0279945, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0896352, 1.0e-4}, - { Barrier::DownOut,1,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.175182, 1.0e-4}, - - { Barrier::DownOut,1.3,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511, 0.00000, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089, 0.00000, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444, 0.00000, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0002, 1.0e-4}, - { Barrier::DownOut,1.3,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00096, 1.0e-4}, - - { Barrier::DownIn,1,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.00384783, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.000883232, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197, 0.00000, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261, 0.00000, 1.0e-4}, - - { Barrier::DownIn,1.3,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.25302, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.14238, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.06128, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.02245, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00725, 1.0e-4}, - - { Barrier::DownIn,1,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.01178, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0295548, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.047549, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0653642, 1.0e-4}, - { Barrier::DownIn,1,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.0833221, 1.0e-4}, - - { Barrier::DownIn,1.3,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.01178, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.03236, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.07554, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.15479, 1.0e-4}, - { Barrier::DownIn,1.3,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.25754, 1.0e-4}, - - }; - - DayCounter dc = Actual365Fixed(); - Date today(5, March, 2013); - Settings::instance().evaluationDate() = today; - - ext::shared_ptr spot = ext::make_shared(0.0); - ext::shared_ptr qRate = ext::make_shared(0.0); - ext::shared_ptr qTS = flatRate(today, qRate, dc); - ext::shared_ptr rRate = ext::make_shared(0.0); - ext::shared_ptr rTS = flatRate(today, rRate, dc); - ext::shared_ptr vol25Put = ext::make_shared(0.0); - ext::shared_ptr volAtm = ext::make_shared(0.0); - ext::shared_ptr vol25Call = ext::make_shared(0.0); - - for (auto& value : values) { - - spot->setValue(value.s); - qRate->setValue(value.q); - rRate->setValue(value.r); - vol25Put->setValue(value.vol25Put); - volAtm->setValue(value.volAtm); - vol25Call->setValue(value.vol25Call); - - ext::shared_ptr payoff = - ext::make_shared(value.type, value.strike); - - Date exDate = today + timeToDays(value.t, 365); - ext::shared_ptr exercise = - ext::make_shared(exDate); - - Handle volAtmQuote = Handle(ext::make_shared( - Handle(volAtm), DeltaVolQuote::Fwd, value.t, DeltaVolQuote::AtmDeltaNeutral)); - - Handle vol25PutQuote(Handle(ext::make_shared( - -0.25, Handle(vol25Put), value.t, DeltaVolQuote::Fwd))); - - Handle vol25CallQuote(Handle(ext::make_shared( - 0.25, Handle(vol25Call), value.t, DeltaVolQuote::Fwd))); - - BarrierOption barrierOption(value.barrierType, value.barrier, value.rebate, payoff, - exercise); - - Real bsVanillaPrice = - blackFormula(value.type, value.strike, - spot->value() * qTS->discount(value.t) / rTS->discount(value.t), - value.v * std::sqrt(value.t), rTS->discount(value.t)); - ext::shared_ptr vannaVolgaEngine = - ext::make_shared( - volAtmQuote, - vol25PutQuote, - vol25CallQuote, - Handle (spot), - Handle (rTS), - Handle (qTS), - true, - bsVanillaPrice); - barrierOption.setPricingEngine(vannaVolgaEngine); - - Real calculated = barrierOption.NPV(); - Real expected = value.result; - Real error = std::fabs(calculated-expected); - if (error > value.tol) { - REPORT_FX_FAILURE("value", value.barrierType, value.barrier, value.rebate, payoff, - exercise, value.s, value.q, value.r, today, value.vol25Put, - value.volAtm, value.vol25Call, value.v, expected, calculated, error, - value.tol); - } - } -} - -void BarrierOptionTest::testOldDividendBarrierOption() { - BOOST_TEST_MESSAGE("Testing old-style barrier option pricing with discrete dividends..."); - - const DayCounter dc = Actual365Fixed(); - - const Date today(11, February, 2018); - const Date maturity = today + Period(1, Years); - Settings::instance().evaluationDate() = today; - - const Real spot = 100.0; - const Real strike = 105.0; - const Real rebate = 5.0; - - const Real barriers[] = { 80.0, 120.0 }; - const Barrier::Type barrierTypes[] = { Barrier::DownOut, Barrier::UpOut }; - - const Rate r = 0.05; - const Rate q = 0.0; - const Volatility v = 0.02; - - const Handle s0(ext::make_shared(spot)); - const Handle qTS(flatRate(today, q, dc)); - const Handle rTS(flatRate(today, r, dc)); - const Handle volTS(flatVol(today, v, dc)); - - const ext::shared_ptr bsProcess = - ext::make_shared(s0, qTS, rTS, volTS); - - const ext::shared_ptr douglas = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::Douglas()); - - const ext::shared_ptr crankNicolson = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::CrankNicolson()); - - const ext::shared_ptr craigSnyed = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::CraigSneyd()); - - const ext::shared_ptr hundsdorfer = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::Hundsdorfer()); - - const ext::shared_ptr mol = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::MethodOfLines()); - - const ext::shared_ptr trPDF2 = - ext::make_shared( - bsProcess, 100, 100, 0, FdmSchemeDesc::TrBDF2()); - - const ext::shared_ptr hestonEngine = - ext::make_shared( - ext::make_shared( - ext::make_shared( - rTS, qTS, s0, v*v, 1.0, v*v, 0.005, 0.0)), 50, 101, 3); - - const ext::shared_ptr engines[] = { - douglas, crankNicolson, - trPDF2, craigSnyed, hundsdorfer, mol, hestonEngine - }; - - const ext::shared_ptr payoff = - ext::make_shared(Option::Put, strike); - - const ext::shared_ptr exercise = - ext::make_shared(maturity); - - const Real divAmount = 30; - const Date divDate = today + Period(6, Months); - - const Real expected[] = { - rTS->discount(divDate)*rebate, - (*payoff)( - (spot - divAmount*rTS->discount(divDate))/rTS->discount(maturity)) - *rTS->discount(maturity) - }; - - const Real relTol = 1e-4; - for (Size i=0; i < LENGTH(barriers); ++i) { - for (const auto& engine : engines) { - const Real barrier = barriers[i]; - const Barrier::Type barrierType = barrierTypes[i]; - - QL_DEPRECATED_DISABLE_WARNING + QL_DEPRECATED_DISABLE_WARNING DividendBarrierOption barrierOption( barrierType, barrier, rebate, payoff, exercise, @@ -1275,7 +961,7 @@ void BarrierOptionTest::testOldDividendBarrierOption() { } } -void BarrierOptionTest::testDividendBarrierOption() { +BOOST_AUTO_TEST_CASE(testDividendBarrierOption) { BOOST_TEST_MESSAGE("Testing barrier option pricing with discrete dividends..."); DayCounter dc = Actual365Fixed(); @@ -1381,8 +1067,7 @@ void BarrierOptionTest::testDividendBarrierOption() { } } - -void BarrierOptionTest::testDividendBarrierOptionWithDividendsPastMaturity() { +BOOST_AUTO_TEST_CASE(testDividendBarrierOptionWithDividendsPastMaturity) { BOOST_TEST_MESSAGE("Testing barrier option pricing with discrete dividends past maturity..."); DayCounter dc = Actual365Fixed(); @@ -1466,7 +1151,7 @@ void BarrierOptionTest::testDividendBarrierOptionWithDividendsPastMaturity() { } } -void BarrierOptionTest::testBarrierAndDividendEngine() { +BOOST_AUTO_TEST_CASE(testBarrierAndDividendEngine) { BOOST_TEST_MESSAGE("Testing the use of a single engine for barrier and dividend options..."); auto today = Date(1, January, 2023); @@ -1506,7 +1191,7 @@ void BarrierOptionTest::testBarrierAndDividendEngine() { } } -void BarrierOptionTest::testImpliedVolatility() { +BOOST_AUTO_TEST_CASE(testImpliedVolatility) { BOOST_TEST_MESSAGE("Testing implied volatility for barrier options..."); DayCounter dc = Actual365Fixed(); @@ -1585,7 +1270,7 @@ void BarrierOptionTest::testImpliedVolatility() { } } -void BarrierOptionTest::testLowVolatility() { +BOOST_AUTO_TEST_CASE(testLowVolatility) { BOOST_TEST_MESSAGE("Testing barrier options with low volatility value..."); DayCounter dc = Actual365Fixed(); @@ -1681,25 +1366,326 @@ void BarrierOptionTest::testLowVolatility() { check( 95.0, Option::Call, 99.0, Barrier::DownIn, 4.0, 0.01, 0.04, 2.0); // fwd = 97, call, ITM } -test_suite* BarrierOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Barrier option tests"); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testParity)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testHaugValues)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testBabsiriValues)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testBeagleholeValues)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testLocalVolAndHestonComparison)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testOldDividendBarrierOption)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testDividendBarrierOption)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testDividendBarrierOptionWithDividendsPastMaturity)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testBarrierAndDividendEngine)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testImpliedVolatility)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testLowVolatility)); - return suite; +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(BarrierOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testPerturbative) { + BOOST_TEST_MESSAGE("Testing perturbative engine for barrier options..."); + + Real S = 100.0; + Real rebate = 0.0; + Rate r = 0.03; + Rate q = 0.02; + + DayCounter dc = Actual360(); + Date today = Date::todaysDate(); + + ext::shared_ptr underlying = + ext::make_shared(S); + ext::shared_ptr qTS = flatRate(today, q, dc); + ext::shared_ptr rTS = flatRate(today, r, dc); + + std::vector dates(2); + std::vector vols(2); + + dates[0] = today + 90; vols[0] = 0.105; + dates[1] = today + 180; vols[1] = 0.11; + + ext::shared_ptr volTS = + ext::make_shared(today, dates, vols, dc); + + ext::shared_ptr stochProcess = + ext::make_shared( + Handle(underlying), + Handle(qTS), + Handle(rTS), + Handle(volTS)); + + Real strike = 101.0; + Real barrier = 101.0; + Date exDate = today+180; + + ext::shared_ptr exercise = + ext::make_shared(exDate); + ext::shared_ptr payoff = + ext::make_shared(Option::Put, strike); + + BarrierOption option(Barrier::UpOut, barrier, rebate, payoff, exercise); + + Natural order = 0; + bool zeroGamma = false; + ext::shared_ptr engine = + ext::make_shared(stochProcess, + order, zeroGamma); + + option.setPricingEngine(engine); + + Real calculated = option.NPV(); + Real expected = 0.897365; + Real tolerance = 1.0e-6; + if (std::fabs(calculated-expected) > tolerance) { + BOOST_ERROR("Failed to reproduce expected value" + << "\n calculated: " << std::setprecision(8) << calculated + << "\n expected: " << std::setprecision(8) << expected); + } + + order = 1; + engine = ext::make_shared(stochProcess, + order, + zeroGamma); + + option.setPricingEngine(engine); + + calculated = option.NPV(); + expected = 0.894374; + if (std::fabs(calculated-expected) > tolerance) { + BOOST_ERROR("Failed to reproduce expected value" + << "\n calculated: " << std::setprecision(8) << calculated + << "\n expected: " << std::setprecision(8) << expected); + } + + /* Too slow, skip + order = 2; + engine = ext::make_shared(stochProcess, + order, + zeroGamma); + + option.setPricingEngine(engine); + + calculated = option.NPV(); + expected = 0.8943769; + if (std::fabs(calculated-expected) > tolerance) { + BOOST_ERROR("Failed to reproduce expected value" + << "\n calculated: " << std::setprecision(8) << calculated + << "\n expected: " << std::setprecision(8) << expected); + } + */ } -test_suite* BarrierOptionTest::experimental() { - auto* suite = BOOST_TEST_SUITE("Barrier option experimental tests"); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testPerturbative)); - suite->add(QUANTLIB_TEST_CASE(&BarrierOptionTest::testVannaVolgaSimpleBarrierValues)); - return suite; +BOOST_AUTO_TEST_CASE(testVannaVolgaSimpleBarrierValues) { + BOOST_TEST_MESSAGE("Testing barrier FX options against Vanna/Volga values..."); + + using namespace barrier_option_test; + + BarrierFxOptionData values[] = { + + //barrierType,barrier,rebate,type,strike,s,q,r,t,vol25Put,volAtm,vol25Call,vol, result, tol + { Barrier::UpOut,1.5,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.148127, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.075943, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0274771, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00573, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00012, 1.0e-4}, + + { Barrier::UpOut,1.5,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00697606, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.020078, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0489395, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.0969877, 1.0e-4}, + { Barrier::UpOut,1.5,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.157, 1.0e-4}, + + { Barrier::UpIn,1.5,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.0322202, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.0241491, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0164275, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00489, 1.0e-4}, + + { Barrier::UpIn,1.5,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.000560713, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.000546804, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.000130649, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.000300828, 1.0e-4}, + { Barrier::UpIn,1.5,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00135, 1.0e-4}, + + { Barrier::DownOut,1.1,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.17746, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.0994142, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.0439, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01574, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00501, 1.0e-4}, + + { Barrier::DownOut,1.3,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00612, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00426, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.00257, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00122, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00045, 1.0e-4}, + + { Barrier::DownOut,1.1,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00022, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00284, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.02032, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.058235, 1.0e-4}, + { Barrier::DownOut,1.1,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.109432, 1.0e-4}, + + { Barrier::DownOut,1.3,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.00017, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00083, 1.0e-4}, + + { Barrier::DownIn,1.1,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00289, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.00067784, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0, 1.0e-4}, + + { Barrier::DownIn,1.3,0, Option::Call,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.17423, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.09584, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.04133, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.01452, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.00456, 1.0e-4}, + + { Barrier::DownIn,1.1,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00732, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.01778, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.02875, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.0390535, 1.0e-4}, + { Barrier::DownIn,1.1,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.0489236, 1.0e-4}, + + { Barrier::DownIn,1.3,0, Option::Put,1.13321,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.11638,0.00753, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.22687,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.10088,0.02062, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.31179,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08925,0.04907, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.38843,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08463,0.09711, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.46047,1.30265,0.0003541,0.0033871,1,0.10087,0.08925,0.08463,0.08412,0.15752, 1.0e-4}, + + { Barrier::UpOut,1.6,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.20493, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.105577, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0358872, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.00634958, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0, 1.0e-4}, + + { Barrier::UpOut,1.6,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.0108218, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0313339, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0751237, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.153407, 1.0e-4}, + { Barrier::UpOut,1.6,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.253767, 1.0e-4}, + + { Barrier::UpIn,1.6,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.05402, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0410069, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0279562, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0173055, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00764, 1.0e-4}, + + { Barrier::UpIn,1.6,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.000962737, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00102637, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.000419834, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.00159277, 1.0e-4}, + { Barrier::UpIn,1.6,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00473629, 1.0e-4}, + + { Barrier::DownOut,1,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.255098, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.145701, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.06384, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.02366, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00764, 1.0e-4}, + + { Barrier::DownOut,1.3,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.00592, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00421, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.00256, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0012, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.0004, 1.0e-4}, + + { Barrier::DownOut,1,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.00280549, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.0279945, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0896352, 1.0e-4}, + { Barrier::DownOut,1,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.175182, 1.0e-4}, + + { Barrier::DownOut,1.3,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511, 0.00000, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089, 0.00000, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444, 0.00000, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0002, 1.0e-4}, + { Barrier::DownOut,1.3,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00096, 1.0e-4}, + + { Barrier::DownIn,1,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.00384783, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.000883232, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197, 0.00000, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261, 0.00000, 1.0e-4}, + + { Barrier::DownIn,1.3,0, Option::Call,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.25302, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.14238, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.06128, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.02245, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Call,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.00725, 1.0e-4}, + + { Barrier::DownIn,1,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.01178, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.0295548, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.047549, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.0653642, 1.0e-4}, + { Barrier::DownIn,1,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.0833221, 1.0e-4}, + + { Barrier::DownIn,1.3,0, Option::Put,1.06145,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.12511,0.01178, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.19545,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.1089,0.03236, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.32238,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09444,0.07554, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.44298,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09197,0.15479, 1.0e-4}, + { Barrier::DownIn,1.3,0, Option::Put,1.56345,1.30265,0.0009418,0.0039788,2,0.10891,0.09525,0.09197,0.09261,0.25754, 1.0e-4}, + + }; + + DayCounter dc = Actual365Fixed(); + Date today(5, March, 2013); + Settings::instance().evaluationDate() = today; + + ext::shared_ptr spot = ext::make_shared(0.0); + ext::shared_ptr qRate = ext::make_shared(0.0); + ext::shared_ptr qTS = flatRate(today, qRate, dc); + ext::shared_ptr rRate = ext::make_shared(0.0); + ext::shared_ptr rTS = flatRate(today, rRate, dc); + ext::shared_ptr vol25Put = ext::make_shared(0.0); + ext::shared_ptr volAtm = ext::make_shared(0.0); + ext::shared_ptr vol25Call = ext::make_shared(0.0); + + for (auto& value : values) { + + spot->setValue(value.s); + qRate->setValue(value.q); + rRate->setValue(value.r); + vol25Put->setValue(value.vol25Put); + volAtm->setValue(value.volAtm); + vol25Call->setValue(value.vol25Call); + + ext::shared_ptr payoff = + ext::make_shared(value.type, value.strike); + + Date exDate = today + timeToDays(value.t, 365); + ext::shared_ptr exercise = + ext::make_shared(exDate); + + Handle volAtmQuote = Handle(ext::make_shared( + Handle(volAtm), DeltaVolQuote::Fwd, value.t, DeltaVolQuote::AtmDeltaNeutral)); + + Handle vol25PutQuote(Handle(ext::make_shared( + -0.25, Handle(vol25Put), value.t, DeltaVolQuote::Fwd))); + + Handle vol25CallQuote(Handle(ext::make_shared( + 0.25, Handle(vol25Call), value.t, DeltaVolQuote::Fwd))); + + BarrierOption barrierOption(value.barrierType, value.barrier, value.rebate, payoff, + exercise); + + Real bsVanillaPrice = + blackFormula(value.type, value.strike, + spot->value() * qTS->discount(value.t) / rTS->discount(value.t), + value.v * std::sqrt(value.t), rTS->discount(value.t)); + ext::shared_ptr vannaVolgaEngine = + ext::make_shared( + volAtmQuote, + vol25PutQuote, + vol25CallQuote, + Handle (spot), + Handle (rTS), + Handle (qTS), + true, + bsVanillaPrice); + barrierOption.setPricingEngine(vannaVolgaEngine); + + Real calculated = barrierOption.NPV(); + Real expected = value.result; + Real error = std::fabs(calculated-expected); + if (error > value.tol) { + REPORT_FX_FAILURE("value", value.barrierType, value.barrier, value.rebate, payoff, + exercise, value.s, value.q, value.r, today, value.vol25Put, + value.volAtm, value.vol25Call, value.v, expected, calculated, error, + value.tol); + } + } } + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/barrieroption.hpp b/test-suite/barrieroption.hpp deleted file mode 100644 index 3383eeb6ed4..00000000000 --- a/test-suite/barrieroption.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Neil Firth - - 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_barrier_option_hpp -#define quantlib_test_barrier_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BarrierOptionTest { - public: - static void testParity(); - static void testHaugValues(); - static void testBabsiriValues(); - static void testBeagleholeValues(); - static void testPerturbative(); - static void testLocalVolAndHestonComparison(); - static void testVannaVolgaSimpleBarrierValues(); - static void testVannaVolgaDoubleBarrierValues(); - static void testOldDividendBarrierOption(); - static void testDividendBarrierOption(); - static void testDividendBarrierOptionWithDividendsPastMaturity(); - static void testBarrierAndDividendEngine(); - static void testImpliedVolatility(); - static void testLowVolatility(); - - static boost::unit_test_framework::test_suite* suite(); - static boost::unit_test_framework::test_suite* experimental(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 3c33743a75b..cfefc22600f 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "barrieroption.hpp" #include "basketoption.hpp" #include "batesmodel.hpp" #include "convertiblebonds.hpp" @@ -163,6 +162,9 @@ namespace QuantLibTest { namespace AsianOptionTest { struct testMCDiscreteArithmeticAveragePrice: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace BarrierOptionTest { + struct testBabsiriValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -196,7 +198,7 @@ namespace { std::vector bm = { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), - Benchmark("BarrierOption::BabsiriValues", &BarrierOptionTest::testBabsiriValues, 880.8), + Benchmark("BarrierOption::BabsiriValues", std::bind(&QuantLibTest::BarrierOptionTest::testBabsiriValues::test_method, QuantLibTest::BarrierOptionTest::testBabsiriValues()), 880.8), Benchmark("BasketOption::EuroTwoValues", &BasketOptionTest::testEuroTwoValues, 340.04), Benchmark("BasketOption::TavellaValues", &BasketOptionTest::testTavellaValues, 933.80), Benchmark("BasketOption::OddSamples", &BasketOptionTest::testOddSamples, 642.46), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 989833a5cb2..42caa603532 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "barrieroption.hpp" #include "basismodels.hpp" #include "basisswapratehelpers.hpp" #include "basketoption.hpp" @@ -213,7 +212,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BarrierOptionTest::suite()); test->add(BasketOptionTest::suite(speed)); test->add(BatesModelTest::suite()); test->add(BermudanSwaptionTest::suite(speed)); @@ -340,7 +338,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(BasismodelsTest::suite()); test->add(BasisSwapRateHelpersTest::suite()); - test->add(BarrierOptionTest::experimental()); test->add(DoubleBarrierOptionTest::experimental(speed)); test->add(BlackDeltaCalculatorTest::suite()); test->add(CallableBondTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b5c7a5f82cf..591ed2de518 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 55b4cecb43e..843b330a643 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 231f93c1ac51a834305acbbca526181b9d3b7349 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 12:20:31 +0800 Subject: [PATCH 010/132] Migrated basismodels.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/basismodels.cpp | 23 ++++++++--------- test-suite/basismodels.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 test-suite/basismodels.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9edb12b67f4..abf289eb9b3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - basismodels.hpp basisswapratehelpers.hpp basketoption.hpp batesmodel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6483143e4e6..ab781f2de18 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ binaryoption.hpp \ - basismodels.hpp \ basisswapratehelpers.hpp \ basketoption.hpp \ batesmodel.hpp \ diff --git a/test-suite/basismodels.cpp b/test-suite/basismodels.cpp index f555c16899c..5135a2522d9 100644 --- a/test-suite/basismodels.cpp +++ b/test-suite/basismodels.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "basismodels.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -224,19 +224,22 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) -void BasismodelsTest::testSwaptioncfsContCompSpread() { +BOOST_AUTO_TEST_SUITE(BasismodelsExperimentalTest) + +BOOST_AUTO_TEST_CASE(testSwaptioncfsContCompSpread) { BOOST_TEST_MESSAGE( "Testing deterministic tenor basis model with continuous compounded spreads..."); testSwaptioncfs(true); } -void BasismodelsTest::testSwaptioncfsSimpleCompSpread() { +BOOST_AUTO_TEST_CASE(testSwaptioncfsSimpleCompSpread) { BOOST_TEST_MESSAGE("Testing deterministic tenor basis model with simple compounded spreads..."); testSwaptioncfs(false); } -void BasismodelsTest::testTenoroptionletvts() { +BOOST_AUTO_TEST_CASE(testTenoroptionletvts) { BOOST_TEST_MESSAGE("Testing volatility transformation for caplets/floorlets..."); // market data and floating rate index Real spread = 0.01; @@ -320,7 +323,7 @@ void BasismodelsTest::testTenoroptionletvts() { } } -void BasismodelsTest::testTenorswaptionvts() { +BOOST_AUTO_TEST_CASE(testTenorswaptionvts) { BOOST_TEST_MESSAGE("Testing volatility transformation for swaptions..."); // market data and floating rate index Real spread = 0.01; @@ -397,12 +400,6 @@ void BasismodelsTest::testTenorswaptionvts() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* BasismodelsTest::suite() { - auto* suite = BOOST_TEST_SUITE("Basismodels tests"); - suite->add(QUANTLIB_TEST_CASE(&BasismodelsTest::testSwaptioncfsContCompSpread)); - suite->add(QUANTLIB_TEST_CASE(&BasismodelsTest::testSwaptioncfsSimpleCompSpread)); - suite->add(QUANTLIB_TEST_CASE(&BasismodelsTest::testTenoroptionletvts)); - suite->add(QUANTLIB_TEST_CASE(&BasismodelsTest::testTenorswaptionvts)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/basismodels.hpp b/test-suite/basismodels.hpp deleted file mode 100644 index bd49b9fa742..00000000000 --- a/test-suite/basismodels.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2018 Sebastian Schlenkrich - - 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_basismodels_hpp -#define quantlib_test_basismodels_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BasismodelsTest { - public: - static void testSwaptioncfsContCompSpread(); - static void testSwaptioncfsSimpleCompSpread(); - static void testTenoroptionletvts(); - static void testTenorswaptionvts(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 42caa603532..80cb93f9b30 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "basismodels.hpp" #include "basisswapratehelpers.hpp" #include "basketoption.hpp" #include "batesmodel.hpp" @@ -336,7 +335,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(BasismodelsTest::suite()); test->add(BasisSwapRateHelpersTest::suite()); test->add(DoubleBarrierOptionTest::experimental(speed)); test->add(BlackDeltaCalculatorTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 591ed2de518..4d2b487d41c 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 843b330a643..de1ce3498c2 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -977,9 +977,6 @@ Header Files - - Header Files - Header Files From 636d7bc69af69490fe4b91ab422a18dec0c90667 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 12:30:22 +0800 Subject: [PATCH 011/132] Migrated basisswapratehelpers.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/basisswapratehelpers.cpp | 25 ++++++++---------- test-suite/basisswapratehelpers.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 61 deletions(-) delete mode 100644 test-suite/basisswapratehelpers.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index abf289eb9b3..071e74cbb31 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - basisswapratehelpers.hpp basketoption.hpp batesmodel.hpp bermudanswaption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ab781f2de18..0354214f9b2 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ binaryoption.hpp \ - basisswapratehelpers.hpp \ basketoption.hpp \ batesmodel.hpp \ bermudanswaption.hpp \ diff --git a/test-suite/basisswapratehelpers.cpp b/test-suite/basisswapratehelpers.cpp index bd42e8a162b..d960feddbd0 100644 --- a/test-suite/basisswapratehelpers.cpp +++ b/test-suite/basisswapratehelpers.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "basisswapratehelpers.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -210,39 +210,34 @@ namespace basisswapratehelpers_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) -void BasisSwapRateHelpersTest::testIborIborBaseCurveBootstrap() { +BOOST_AUTO_TEST_SUITE(BasisSwapRateHelpersExperimentalTest) + +BOOST_AUTO_TEST_CASE(testIborIborBaseCurveBootstrap) { BOOST_TEST_MESSAGE("Testing IBOR-IBOR basis-swap rate helpers (base curve bootstrap)..."); basisswapratehelpers_test::testIborIborBootstrap(true); } -void BasisSwapRateHelpersTest::testIborIborOtherCurveBootstrap() { +BOOST_AUTO_TEST_CASE(testIborIborOtherCurveBootstrap) { BOOST_TEST_MESSAGE("Testing IBOR-IBOR basis-swap rate helpers (other curve bootstrap)..."); basisswapratehelpers_test::testIborIborBootstrap(false); } -void BasisSwapRateHelpersTest::testOvernightIborBootstrap() { +BOOST_AUTO_TEST_CASE(testOvernightIborBootstrap) { BOOST_TEST_MESSAGE("Testing overnight-IBOR basis-swap rate helpers..."); basisswapratehelpers_test::testOvernightIborBootstrap(false); } -void BasisSwapRateHelpersTest::testOvernightIborBootstrapWithDiscountCurve() { +BOOST_AUTO_TEST_CASE(testOvernightIborBootstrapWithDiscountCurve) { BOOST_TEST_MESSAGE("Testing overnight-IBOR basis-swap rate helpers with external discount curve..."); basisswapratehelpers_test::testOvernightIborBootstrap(true); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* BasisSwapRateHelpersTest::suite() { - auto* suite = BOOST_TEST_SUITE("Basis swap rate helpers tests"); - - suite->add(QUANTLIB_TEST_CASE(&BasisSwapRateHelpersTest::testIborIborBaseCurveBootstrap)); - suite->add(QUANTLIB_TEST_CASE(&BasisSwapRateHelpersTest::testIborIborOtherCurveBootstrap)); - suite->add(QUANTLIB_TEST_CASE(&BasisSwapRateHelpersTest::testOvernightIborBootstrap)); - suite->add(QUANTLIB_TEST_CASE(&BasisSwapRateHelpersTest::testOvernightIborBootstrapWithDiscountCurve)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/basisswapratehelpers.hpp b/test-suite/basisswapratehelpers.hpp deleted file mode 100644 index f97fbe8d35b..00000000000 --- a/test-suite/basisswapratehelpers.hpp +++ /dev/null @@ -1,38 +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_basisswapratehelpers_hpp -#define quantlib_test_basisswapratehelpers_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BasisSwapRateHelpersTest { - public: - static void testIborIborBaseCurveBootstrap(); - static void testIborIborOtherCurveBootstrap(); - static void testOvernightIborBootstrap(); - static void testOvernightIborBootstrapWithDiscountCurve(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 80cb93f9b30..2fa69edf8e3 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "basisswapratehelpers.hpp" #include "basketoption.hpp" #include "batesmodel.hpp" #include "bermudanswaption.hpp" @@ -335,7 +334,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(BasisSwapRateHelpersTest::suite()); test->add(DoubleBarrierOptionTest::experimental(speed)); test->add(BlackDeltaCalculatorTest::suite()); test->add(CallableBondTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 4d2b487d41c..751493f1a3a 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 de1ce3498c2..9936b806d28 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -989,9 +989,6 @@ Header Files - - Header Files - Header Files From d325e5cacd55584152a48938c6634fa3c1b205d7 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 14:35:54 +0800 Subject: [PATCH 012/132] Migrated basketoption.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 1 - test-suite/basketoption.cpp | 248 +++++++++++++-------------- test-suite/basketoption.hpp | 43 ----- test-suite/quantlibbenchmark.cpp | 12 +- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 8 files changed, 124 insertions(+), 189 deletions(-) delete mode 100644 test-suite/basketoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 071e74cbb31..9dcdec0a205 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - basketoption.hpp batesmodel.hpp bermudanswaption.hpp binaryoption.hpp @@ -345,7 +344,7 @@ set(QL_BENCHMARK_SOURCES americanoption.cpp asianoptions.cpp barrieroption.cpp - basketoption.cpp basketoption.hpp + basketoption.cpp batesmodel.cpp batesmodel.hpp convertiblebonds.cpp convertiblebonds.hpp digitaloption.cpp digitaloption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 0354214f9b2..2cdfb3d9d5a 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ binaryoption.hpp \ - basketoption.hpp \ batesmodel.hpp \ bermudanswaption.hpp \ blackdeltacalculator.hpp \ diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index 79513f4e77c..4a44e9bcce8 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -19,7 +19,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "basketoption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -167,10 +168,53 @@ namespace { Real amValue; }; + BasketOptionOneData oneDataValues[] = { + // type, strike, spot, q, r, t, vol, value, tol + { Option::Put, 100.00, 80.00, 0.0, 0.06, 0.5, 0.4, 21.6059, 1e-2 }, + { Option::Put, 100.00, 85.00, 0.0, 0.06, 0.5, 0.4, 18.0374, 1e-2 }, + { Option::Put, 100.00, 90.00, 0.0, 0.06, 0.5, 0.4, 14.9187, 1e-2 }, + { Option::Put, 100.00, 95.00, 0.0, 0.06, 0.5, 0.4, 12.2314, 1e-2 }, + { Option::Put, 100.00, 100.00, 0.0, 0.06, 0.5, 0.4, 9.9458, 1e-2 }, + { Option::Put, 100.00, 105.00, 0.0, 0.06, 0.5, 0.4, 8.0281, 1e-2 }, + { Option::Put, 100.00, 110.00, 0.0, 0.06, 0.5, 0.4, 6.4352, 1e-2 }, + { Option::Put, 100.00, 115.00, 0.0, 0.06, 0.5, 0.4, 5.1265, 1e-2 }, + { Option::Put, 100.00, 120.00, 0.0, 0.06, 0.5, 0.4, 4.0611, 1e-2 }, + + // Longstaff Schwartz 1D example + // use constant and three Laguerre polynomials + // 100,000 paths and 50 timesteps per year + { Option::Put, 40.00, 36.00, 0.0, 0.06, 1.0, 0.2, 4.478, 1e-2 }, + { Option::Put, 40.00, 36.00, 0.0, 0.06, 2.0, 0.2, 4.840, 1e-2 }, + { Option::Put, 40.00, 36.00, 0.0, 0.06, 1.0, 0.4, 7.101, 1e-2 }, + { Option::Put, 40.00, 36.00, 0.0, 0.06, 2.0, 0.4, 8.508, 1e-2 }, + + { Option::Put, 40.00, 38.00, 0.0, 0.06, 1.0, 0.2, 3.250, 1e-2 }, + { Option::Put, 40.00, 38.00, 0.0, 0.06, 2.0, 0.2, 3.745, 1e-2 }, + { Option::Put, 40.00, 38.00, 0.0, 0.06, 1.0, 0.4, 6.148, 1e-2 }, + { Option::Put, 40.00, 38.00, 0.0, 0.06, 2.0, 0.4, 7.670, 1e-2 }, + + { Option::Put, 40.00, 40.00, 0.0, 0.06, 1.0, 0.2, 2.314, 1e-2 }, + { Option::Put, 40.00, 40.00, 0.0, 0.06, 2.0, 0.2, 2.885, 1e-2 }, + { Option::Put, 40.00, 40.00, 0.0, 0.06, 1.0, 0.4, 5.312, 1e-2 }, + { Option::Put, 40.00, 40.00, 0.0, 0.06, 2.0, 0.4, 6.920, 1e-2 }, + + { Option::Put, 40.00, 42.00, 0.0, 0.06, 1.0, 0.2, 1.617, 1e-2 }, + { Option::Put, 40.00, 42.00, 0.0, 0.06, 2.0, 0.2, 2.212, 1e-2 }, + { Option::Put, 40.00, 42.00, 0.0, 0.06, 1.0, 0.4, 4.582, 1e-2 }, + { Option::Put, 40.00, 42.00, 0.0, 0.06, 2.0, 0.4, 6.248, 1e-2 }, + + { Option::Put, 40.00, 44.00, 0.0, 0.06, 1.0, 0.2, 1.110, 1e-2 }, + { Option::Put, 40.00, 44.00, 0.0, 0.06, 2.0, 0.2, 1.690, 1e-2 }, + { Option::Put, 40.00, 44.00, 0.0, 0.06, 1.0, 0.4, 3.948, 1e-2 }, + { Option::Put, 40.00, 44.00, 0.0, 0.06, 2.0, 0.4, 5.647, 1e-2 } + }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(BasketOptionTest) -void BasketOptionTest::testEuroTwoValues() { +BOOST_AUTO_TEST_CASE(testEuroTwoValues) { BOOST_TEST_MESSAGE("Testing two-asset European basket options..."); @@ -377,7 +421,7 @@ void BasketOptionTest::testEuroTwoValues() { } } -void BasketOptionTest::testBarraquandThreeValues() { +BOOST_AUTO_TEST_CASE(testBarraquandThreeValues, *precondition(if_speed(Slow))) { BOOST_TEST_MESSAGE("Testing three-asset basket options " "against Barraquand's values..."); @@ -580,7 +624,7 @@ void BasketOptionTest::testBarraquandThreeValues() { } } -void BasketOptionTest::testTavellaValues() { +BOOST_AUTO_TEST_CASE(testTavellaValues) { BOOST_TEST_MESSAGE("Testing three-asset American basket options " "against Tavella's values..."); @@ -697,122 +741,81 @@ void BasketOptionTest::testTavellaValues() { } } -namespace { - BasketOptionOneData oneDataValues[] = { - // type, strike, spot, q, r, t, vol, value, tol - { Option::Put, 100.00, 80.00, 0.0, 0.06, 0.5, 0.4, 21.6059, 1e-2 }, - { Option::Put, 100.00, 85.00, 0.0, 0.06, 0.5, 0.4, 18.0374, 1e-2 }, - { Option::Put, 100.00, 90.00, 0.0, 0.06, 0.5, 0.4, 14.9187, 1e-2 }, - { Option::Put, 100.00, 95.00, 0.0, 0.06, 0.5, 0.4, 12.2314, 1e-2 }, - { Option::Put, 100.00, 100.00, 0.0, 0.06, 0.5, 0.4, 9.9458, 1e-2 }, - { Option::Put, 100.00, 105.00, 0.0, 0.06, 0.5, 0.4, 8.0281, 1e-2 }, - { Option::Put, 100.00, 110.00, 0.0, 0.06, 0.5, 0.4, 6.4352, 1e-2 }, - { Option::Put, 100.00, 115.00, 0.0, 0.06, 0.5, 0.4, 5.1265, 1e-2 }, - { Option::Put, 100.00, 120.00, 0.0, 0.06, 0.5, 0.4, 4.0611, 1e-2 }, - - // Longstaff Schwartz 1D example - // use constant and three Laguerre polynomials - // 100,000 paths and 50 timesteps per year - { Option::Put, 40.00, 36.00, 0.0, 0.06, 1.0, 0.2, 4.478, 1e-2 }, - { Option::Put, 40.00, 36.00, 0.0, 0.06, 2.0, 0.2, 4.840, 1e-2 }, - { Option::Put, 40.00, 36.00, 0.0, 0.06, 1.0, 0.4, 7.101, 1e-2 }, - { Option::Put, 40.00, 36.00, 0.0, 0.06, 2.0, 0.4, 8.508, 1e-2 }, - - { Option::Put, 40.00, 38.00, 0.0, 0.06, 1.0, 0.2, 3.250, 1e-2 }, - { Option::Put, 40.00, 38.00, 0.0, 0.06, 2.0, 0.2, 3.745, 1e-2 }, - { Option::Put, 40.00, 38.00, 0.0, 0.06, 1.0, 0.4, 6.148, 1e-2 }, - { Option::Put, 40.00, 38.00, 0.0, 0.06, 2.0, 0.4, 7.670, 1e-2 }, - - { Option::Put, 40.00, 40.00, 0.0, 0.06, 1.0, 0.2, 2.314, 1e-2 }, - { Option::Put, 40.00, 40.00, 0.0, 0.06, 2.0, 0.2, 2.885, 1e-2 }, - { Option::Put, 40.00, 40.00, 0.0, 0.06, 1.0, 0.4, 5.312, 1e-2 }, - { Option::Put, 40.00, 40.00, 0.0, 0.06, 2.0, 0.4, 6.920, 1e-2 }, - - { Option::Put, 40.00, 42.00, 0.0, 0.06, 1.0, 0.2, 1.617, 1e-2 }, - { Option::Put, 40.00, 42.00, 0.0, 0.06, 2.0, 0.2, 2.212, 1e-2 }, - { Option::Put, 40.00, 42.00, 0.0, 0.06, 1.0, 0.4, 4.582, 1e-2 }, - { Option::Put, 40.00, 42.00, 0.0, 0.06, 2.0, 0.4, 6.248, 1e-2 }, - - { Option::Put, 40.00, 44.00, 0.0, 0.06, 1.0, 0.2, 1.110, 1e-2 }, - { Option::Put, 40.00, 44.00, 0.0, 0.06, 2.0, 0.2, 1.690, 1e-2 }, - { Option::Put, 40.00, 44.00, 0.0, 0.06, 1.0, 0.4, 3.948, 1e-2 }, - { Option::Put, 40.00, 44.00, 0.0, 0.06, 2.0, 0.4, 5.647, 1e-2 } - }; -} - -void BasketOptionTest::testOneDAmericanValues(std::size_t from, std::size_t to) { - - BOOST_TEST_MESSAGE("Testing basket American options against 1-D case " - "from " << from << " to " << to-1 << "..."); - - DayCounter dc = Actual360(); - Date today = Date::todaysDate(); - - ext::shared_ptr spot1(new SimpleQuote(0.0)); +BOOST_AUTO_TEST_CASE(testOneDAmericanValues) { + std::size_t from{0}, to{5}; - ext::shared_ptr qRate(new SimpleQuote(0.0)); - ext::shared_ptr qTS = flatRate(today, qRate, dc); + for (int iter{0}; iter < 5; iter++) { - ext::shared_ptr rRate(new SimpleQuote(0.05)); - ext::shared_ptr rTS = flatRate(today, rRate, dc); + BOOST_TEST_MESSAGE("Testing basket American options against 1-D case " + "from " << from << " to " << to - 1 << "..."); - ext::shared_ptr vol1(new SimpleQuote(0.0)); - ext::shared_ptr volTS1 = flatVol(today, vol1, dc); + DayCounter dc = Actual360(); + Date today = Date::todaysDate(); - Size requiredSamples = 10000; - Size timeSteps = 52; - BigNatural seed = 0; + ext::shared_ptr spot1(new SimpleQuote(0.0)); - ext::shared_ptr stochProcess1(new - BlackScholesMertonProcess(Handle(spot1), - Handle(qTS), - Handle(rTS), - Handle(volTS1))); + ext::shared_ptr qRate(new SimpleQuote(0.0)); + ext::shared_ptr qTS = flatRate(today, qRate, dc); - std::vector > procs = {stochProcess1}; + ext::shared_ptr rRate(new SimpleQuote(0.05)); + ext::shared_ptr rTS = flatRate(today, rRate, dc); - Matrix correlation(1, 1, 1.0); + ext::shared_ptr vol1(new SimpleQuote(0.0)); + ext::shared_ptr volTS1 = flatVol(today, vol1, dc); - ext::shared_ptr process( - new StochasticProcessArray(procs,correlation)); + Size requiredSamples = 10000; + Size timeSteps = 52; + BigNatural seed = 0; - ext::shared_ptr mcLSMCEngine = - MakeMCAmericanBasketEngine<>(process) - .withSteps(timeSteps) - .withAntitheticVariate() - .withSamples(requiredSamples) - .withCalibrationSamples(requiredSamples/4) - .withSeed(seed); - - for (Size i=from; i payoff(new - PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike)); + ext::shared_ptr stochProcess1(new + BlackScholesMertonProcess(Handle(spot1), + Handle(qTS), + Handle(rTS), + Handle(volTS1))); - Date exDate = today + timeToDays(oneDataValues[i].t); - ext::shared_ptr exercise(new AmericanExercise(today, - exDate)); + std::vector> procs = {stochProcess1}; - spot1 ->setValue(oneDataValues[i].s); - vol1 ->setValue(oneDataValues[i].v); - rRate ->setValue(oneDataValues[i].r); - qRate ->setValue(oneDataValues[i].q); + Matrix correlation(1, 1, 1.0); - BasketOption basketOption(// process, - basketTypeToPayoff(MaxBasket, payoff), - exercise); - basketOption.setPricingEngine(mcLSMCEngine); - - Real calculated = basketOption.NPV(); - Real expected = oneDataValues[i].result; - // Real errorEstimate = basketOption.errorEstimate(); - Real relError = relativeError(calculated, expected, oneDataValues[i].s); - // Real error = std::fabs(calculated-expected); + ext::shared_ptr process( + new StochasticProcessArray(procs, correlation)); - if (relError > oneDataValues[i].tol) { - BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n" - << "calculated: " << calculated); + ext::shared_ptr mcLSMCEngine = + MakeMCAmericanBasketEngine<>(process) + .withSteps(timeSteps) + .withAntitheticVariate() + .withSamples(requiredSamples) + .withCalibrationSamples(requiredSamples / 4) + .withSeed(seed); + + for (Size i = from; i < to; i++) { + ext::shared_ptr payoff( + new PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike)); + + Date exDate = today + timeToDays(oneDataValues[i].t); + ext::shared_ptr exercise(new AmericanExercise(today, exDate)); + + spot1 ->setValue(oneDataValues[i].s); + vol1 ->setValue(oneDataValues[i].v); + rRate ->setValue(oneDataValues[i].r); + qRate ->setValue(oneDataValues[i].q); + + BasketOption basketOption( // process, + basketTypeToPayoff(MaxBasket, payoff), exercise); + basketOption.setPricingEngine(mcLSMCEngine); + + Real calculated = basketOption.NPV(); + Real expected = oneDataValues[i].result; + // Real errorEstimate = basketOption.errorEstimate(); + Real relError = relativeError(calculated, expected, oneDataValues[i].s); + // Real error = std::fabs(calculated-expected); + + if (relError > oneDataValues[i].tol) { + BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n" + << "calculated: " << calculated); + } } - + from = to; to += 6; } } @@ -821,7 +824,8 @@ void BasketOptionTest::testOneDAmericanValues(std::size_t from, std::size_t to) because the samples array size was off by one when antithetic paths were added. */ -void BasketOptionTest::testOddSamples() { + +BOOST_AUTO_TEST_CASE(testOddSamples) { BOOST_TEST_MESSAGE("Testing antithetic engine using odd sample number..."); @@ -902,7 +906,7 @@ void BasketOptionTest::testOddSamples() { } } -void BasketOptionTest::testLocalVolatilitySpreadOption() { +BOOST_AUTO_TEST_CASE(testLocalVolatilitySpreadOption, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing 2D local-volatility spread-option pricing..."); @@ -968,7 +972,7 @@ void BasketOptionTest::testLocalVolatilitySpreadOption() { } } -void BasketOptionTest::test2DPDEGreeks() { +BOOST_AUTO_TEST_CASE(test2DPDEGreeks) { BOOST_TEST_MESSAGE("Testing Greeks of two-dimensional PDE engine..."); @@ -1043,28 +1047,6 @@ void BasketOptionTest::test2DPDEGreeks() { } } -test_suite* BasketOptionTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Basket option tests"); - - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::testEuroTwoValues)); - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::testTavellaValues)); - - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::testOddSamples)); - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::test2DPDEGreeks)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::testLocalVolatilitySpreadOption)); - // unrolled to get different test names - suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues( 0, 5); })); - suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues( 5, 11); })); - suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(11, 17); })); - suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(17, 23); })); - suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(23, 29); })); - } - - if (speed == Slow) { - suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::testBarraquandThreeValues)); - } +BOOST_AUTO_TEST_SUITE_END() - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/basketoption.hpp b/test-suite/basketoption.hpp deleted file mode 100644 index 0dd31bc1f22..00000000000 --- a/test-suite/basketoption.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004 Neil Firth - - 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_basket_option_hpp -#define quantlib_test_basket_option_hpp - -#include -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BasketOptionTest { - public: - static void testEuroTwoValues(); - static void testBarraquandThreeValues(); - static void testTavellaValues(); - static void testOneDAmericanValues(std::size_t from, std::size_t to); - static void testOddSamples(); - static void testLocalVolatilitySpreadOption(); - static void test2DPDEGreeks(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index cfefc22600f..56114495e9e 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "basketoption.hpp" #include "batesmodel.hpp" #include "convertiblebonds.hpp" #include "digitaloption.hpp" @@ -165,6 +164,11 @@ namespace QuantLibTest { namespace BarrierOptionTest { struct testBabsiriValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace BasketOptionTest { + struct testEuroTwoValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testTavellaValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testOddSamples: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -199,9 +203,9 @@ namespace { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), Benchmark("BarrierOption::BabsiriValues", std::bind(&QuantLibTest::BarrierOptionTest::testBabsiriValues::test_method, QuantLibTest::BarrierOptionTest::testBabsiriValues()), 880.8), - Benchmark("BasketOption::EuroTwoValues", &BasketOptionTest::testEuroTwoValues, 340.04), - Benchmark("BasketOption::TavellaValues", &BasketOptionTest::testTavellaValues, 933.80), - Benchmark("BasketOption::OddSamples", &BasketOptionTest::testOddSamples, 642.46), + Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testEuroTwoValues::test_method, QuantLibTest::BasketOptionTest::testEuroTwoValues()), 340.04), + Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testTavellaValues::test_method, QuantLibTest::BasketOptionTest::testTavellaValues()), 933.80), + Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testOddSamples::test_method, QuantLibTest::BasketOptionTest::testOddSamples()), 642.46), Benchmark("BatesModel::DAXCalibration", &BatesModelTest::testDAXCalibration, 1993.35), Benchmark("ConvertibleBondTest::testBond", &ConvertibleBondTest::testBond, 159.85), Benchmark("DigitalOption::MCCashAtHit", &DigitalOptionTest::testMCCashAtHit, 995.87), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2fa69edf8e3..af0182e9fe0 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "basketoption.hpp" #include "batesmodel.hpp" #include "bermudanswaption.hpp" #include "binaryoption.hpp" @@ -210,7 +209,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BasketOptionTest::suite(speed)); test->add(BatesModelTest::suite()); test->add(BermudanSwaptionTest::suite(speed)); test->add(BinaryOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 751493f1a3a..25af2c73d4f 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 9936b806d28..aa98b58fd79 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From ffffa1784dd3bd68f3f79233d034399868e5e3c3 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 14:40:09 +0800 Subject: [PATCH 013/132] Removed redundant qualification from TopLevelFixture --- test-suite/americanoption.cpp | 2 +- test-suite/amortizingbond.cpp | 2 +- test-suite/andreasenhugevolatilityinterpl.cpp | 2 +- test-suite/array.cpp | 2 +- test-suite/asianoptions.cpp | 2 +- test-suite/assetswap.cpp | 2 +- test-suite/autocovariances.cpp | 2 +- test-suite/barrieroption.cpp | 2 +- test-suite/basismodels.cpp | 2 +- test-suite/basisswapratehelpers.cpp | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test-suite/americanoption.cpp b/test-suite/americanoption.cpp index 229cf7d483d..3c2688f8403 100644 --- a/test-suite/americanoption.cpp +++ b/test-suite/americanoption.cpp @@ -84,7 +84,7 @@ namespace { } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(AmericanOptionTest) diff --git a/test-suite/amortizingbond.cpp b/test-suite/amortizingbond.cpp index 4ab83e8a06d..c5ad555cd26 100644 --- a/test-suite/amortizingbond.cpp +++ b/test-suite/amortizingbond.cpp @@ -31,7 +31,7 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(AmortizingBondTest) diff --git a/test-suite/andreasenhugevolatilityinterpl.cpp b/test-suite/andreasenhugevolatilityinterpl.cpp index 124fe095f84..48f9cfeccbf 100644 --- a/test-suite/andreasenhugevolatilityinterpl.cpp +++ b/test-suite/andreasenhugevolatilityinterpl.cpp @@ -387,7 +387,7 @@ namespace andreasen_huge_volatility_interpl_test { } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(AndreasenHugeVolatilityInterplTest) diff --git a/test-suite/array.cpp b/test-suite/array.cpp index 164406b5aad..673a58b6790 100644 --- a/test-suite/array.cpp +++ b/test-suite/array.cpp @@ -32,7 +32,7 @@ namespace array_test { }; } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(ArrayTest) diff --git a/test-suite/asianoptions.cpp b/test-suite/asianoptions.cpp index d5e270a70a3..836e7b452e7 100644 --- a/test-suite/asianoptions.cpp +++ b/test-suite/asianoptions.cpp @@ -142,7 +142,7 @@ namespace { }; } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(AsianOptionTest) diff --git a/test-suite/assetswap.cpp b/test-suite/assetswap.cpp index 620b2736a86..a4c0a9dcb9d 100644 --- a/test-suite/assetswap.cpp +++ b/test-suite/assetswap.cpp @@ -113,7 +113,7 @@ namespace asset_swap_test { } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) // fails with QL_USE_INDEXED_COUPON +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) // fails with QL_USE_INDEXED_COUPON BOOST_AUTO_TEST_SUITE(AssetSwapTest) diff --git a/test-suite/autocovariances.cpp b/test-suite/autocovariances.cpp index b096f301daa..e7e5d63e76b 100644 --- a/test-suite/autocovariances.cpp +++ b/test-suite/autocovariances.cpp @@ -24,7 +24,7 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(AutocovariancesTest) diff --git a/test-suite/barrieroption.cpp b/test-suite/barrieroption.cpp index 65d3cb05ba4..f73885a281f 100644 --- a/test-suite/barrieroption.cpp +++ b/test-suite/barrieroption.cpp @@ -173,7 +173,7 @@ namespace barrier_option_test { BOOST_FAIL("exception expected"); \ } \ -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(BarrierOptionTest) diff --git a/test-suite/basismodels.cpp b/test-suite/basismodels.cpp index 5135a2522d9..d4390b928f8 100644 --- a/test-suite/basismodels.cpp +++ b/test-suite/basismodels.cpp @@ -224,7 +224,7 @@ namespace { } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(BasismodelsExperimentalTest) diff --git a/test-suite/basisswapratehelpers.cpp b/test-suite/basisswapratehelpers.cpp index d960feddbd0..8b9affad4bc 100644 --- a/test-suite/basisswapratehelpers.cpp +++ b/test-suite/basisswapratehelpers.cpp @@ -210,7 +210,7 @@ namespace basisswapratehelpers_test { } -BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture) +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) BOOST_AUTO_TEST_SUITE(BasisSwapRateHelpersExperimentalTest) From 8088cdd931245f3e4f132d952b46907f41359974 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 15:09:49 +0800 Subject: [PATCH 014/132] Migrated batesmodel.cpp --- test-suite/CMakeLists.txt | 5 ++-- test-suite/Makefile.am | 1 - test-suite/batesmodel.cpp | 27 +++++++++----------- test-suite/batesmodel.hpp | 38 ---------------------------- test-suite/quantlibbenchmark.cpp | 25 ++++++++++++------ test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 31 insertions(+), 71 deletions(-) delete mode 100644 test-suite/batesmodel.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9dcdec0a205..af55fae67cd 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - batesmodel.hpp bermudanswaption.hpp binaryoption.hpp blackdeltacalculator.hpp @@ -345,8 +344,8 @@ set(QL_BENCHMARK_SOURCES asianoptions.cpp barrieroption.cpp basketoption.cpp - batesmodel.cpp batesmodel.hpp - convertiblebonds.cpp convertiblebonds.hpp + batesmodel.cpp + convertiblebonds.cpp convertiblebonds.hpp digitaloption.cpp digitaloption.hpp dividendoption.cpp dividendoption.hpp europeanoption.cpp europeanoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 2cdfb3d9d5a..ac4628442f0 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ binaryoption.hpp \ - batesmodel.hpp \ bermudanswaption.hpp \ blackdeltacalculator.hpp \ blackformula.hpp \ diff --git a/test-suite/batesmodel.cpp b/test-suite/batesmodel.cpp index fff6f386612..086c0dc4bec 100644 --- a/test-suite/batesmodel.cpp +++ b/test-suite/batesmodel.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "batesmodel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -56,8 +56,11 @@ namespace bates_model_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BatesModelTest::testAnalyticVsBlack() { +BOOST_AUTO_TEST_SUITE(BatesModelTest) + +BOOST_AUTO_TEST_CASE(testAnalyticVsBlack) { BOOST_TEST_MESSAGE("Testing analytic Bates engine against Black formula..."); @@ -167,8 +170,7 @@ void BatesModelTest::testAnalyticVsBlack() { } } - -void BatesModelTest::testAnalyticAndMcVsJumpDiffusion() { +BOOST_AUTO_TEST_CASE(testAnalyticAndMcVsJumpDiffusion) { BOOST_TEST_MESSAGE("Testing analytic Bates engine against Merton-76 engine..."); @@ -292,7 +294,7 @@ namespace bates_model_test { }; } -void BatesModelTest::testAnalyticVsMCPricing() { +BOOST_AUTO_TEST_CASE(testAnalyticVsMCPricing) { BOOST_TEST_MESSAGE("Testing analytic Bates engine against Monte-Carlo " "engine..."); @@ -365,7 +367,7 @@ void BatesModelTest::testAnalyticVsMCPricing() { } } -void BatesModelTest::testDAXCalibration() { +BOOST_AUTO_TEST_CASE(testDAXCalibration) { /* this example is taken from A. Sepp Pricing European-Style Options under Jump Diffusion Processes with Stochstic Volatility: Applications of Fourier Transform @@ -375,7 +377,7 @@ void BatesModelTest::testDAXCalibration() { BOOST_TEST_MESSAGE( "Testing Bates model calibration using DAX volatility data..."); - using namespace bates_model_test; + using namespace ::bates_model_test; Date settlementDate(5, July, 2002); Settings::instance().evaluationDate() = settlementDate; @@ -516,11 +518,6 @@ void BatesModelTest::testDAXCalibration() { } } -test_suite* BatesModelTest::suite() { - auto* suite = BOOST_TEST_SUITE("Bates model tests"); - suite->add(QUANTLIB_TEST_CASE(&BatesModelTest::testAnalyticVsBlack)); - suite->add(QUANTLIB_TEST_CASE(&BatesModelTest::testAnalyticAndMcVsJumpDiffusion)); - suite->add(QUANTLIB_TEST_CASE(&BatesModelTest::testAnalyticVsMCPricing)); - suite->add(QUANTLIB_TEST_CASE(&BatesModelTest::testDAXCalibration)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/batesmodel.hpp b/test-suite/batesmodel.hpp deleted file mode 100644 index a7556763593..00000000000 --- a/test-suite/batesmodel.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005 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_bates_model_hpp -#define quantlib_test_bates_model_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BatesModelTest { - public: - static void testAnalyticVsBlack(); - static void testAnalyticAndMcVsJumpDiffusion(); - static void testAnalyticVsMCPricing(); - static void testDAXCalibration(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 56114495e9e..32ddd03c889 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "batesmodel.hpp" #include "convertiblebonds.hpp" #include "digitaloption.hpp" #include "dividendoption.hpp" @@ -156,18 +155,28 @@ namespace QuantLibTest { namespace AmericanOptionTest { - struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testFdAmericanGreeks: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } namespace AsianOptionTest { - struct testMCDiscreteArithmeticAveragePrice: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testMCDiscreteArithmeticAveragePrice: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } namespace BarrierOptionTest { - struct testBabsiriValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testBabsiriValues: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } namespace BasketOptionTest { - struct testEuroTwoValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; - struct testTavellaValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; - struct testOddSamples: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testEuroTwoValues: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testTavellaValues: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testOddSamples: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } + namespace BatesModelTest { + struct testDAXCalibration: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } } @@ -206,7 +215,7 @@ namespace { Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testEuroTwoValues::test_method, QuantLibTest::BasketOptionTest::testEuroTwoValues()), 340.04), Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testTavellaValues::test_method, QuantLibTest::BasketOptionTest::testTavellaValues()), 933.80), Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testOddSamples::test_method, QuantLibTest::BasketOptionTest::testOddSamples()), 642.46), - Benchmark("BatesModel::DAXCalibration", &BatesModelTest::testDAXCalibration, 1993.35), + Benchmark("BatesModel::DAXCalibration", std::bind(&QuantLibTest::BatesModelTest::testDAXCalibration::test_method, QuantLibTest::BatesModelTest::testDAXCalibration()), 1993.35), Benchmark("ConvertibleBondTest::testBond", &ConvertibleBondTest::testBond, 159.85), Benchmark("DigitalOption::MCCashAtHit", &DigitalOptionTest::testMCCashAtHit, 995.87), Benchmark("DividendOption::FdEuropeanGreeks", &DividendOptionTest::testFdEuropeanGreeks, 949.52), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index af0182e9fe0..9d8d759d231 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "batesmodel.hpp" #include "bermudanswaption.hpp" #include "binaryoption.hpp" #include "blackdeltacalculator.hpp" @@ -209,7 +208,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BatesModelTest::suite()); test->add(BermudanSwaptionTest::suite(speed)); test->add(BinaryOptionTest::suite()); test->add(BlackFormulaTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 25af2c73d4f..726515c0eb5 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 aa98b58fd79..3303b4c1210 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 11144ff6acd9d0b38c0831ee99baad18c9c58acd Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 15:24:21 +0800 Subject: [PATCH 015/132] Migrated bermudanswaption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/bermudanswaption.cpp | 25 +++++++----------- test-suite/bermudanswaption.hpp | 39 ---------------------------- 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/bermudanswaption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index af55fae67cd..5f785877008 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - bermudanswaption.hpp binaryoption.hpp blackdeltacalculator.hpp blackformula.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ac4628442f0..39c5d872522 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ binaryoption.hpp \ - bermudanswaption.hpp \ blackdeltacalculator.hpp \ blackformula.hpp \ bondforward.hpp \ diff --git a/test-suite/bermudanswaption.cpp b/test-suite/bermudanswaption.cpp index eda05067aa1..90ac0756202 100644 --- a/test-suite/bermudanswaption.cpp +++ b/test-suite/bermudanswaption.cpp @@ -19,7 +19,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "bermudanswaption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -106,8 +107,11 @@ namespace bermudan_swaption_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BermudanSwaptionTest::testCachedValues() { +BOOST_AUTO_TEST_SUITE(BermudanSwaptionTest) + +BOOST_AUTO_TEST_CASE(testCachedValues) { BOOST_TEST_MESSAGE( "Testing Bermudan swaption with HW model against cached values..."); @@ -235,7 +239,7 @@ void BermudanSwaptionTest::testCachedValues() { << "expected: " << otmValue); } -void BermudanSwaptionTest::testCachedG2Values() { +BOOST_AUTO_TEST_CASE(testCachedG2Values, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE( "Testing Bermudan swaption with G2 model against cached values..."); @@ -312,7 +316,7 @@ void BermudanSwaptionTest::testCachedG2Values() { } } -void BermudanSwaptionTest::testTreeEngineTimeSnapping() { +BOOST_AUTO_TEST_CASE(testTreeEngineTimeSnapping) { BOOST_TEST_MESSAGE("Testing snap of exercise dates for discretized swaption..."); Date today = Date(8, Jul, 2021); @@ -373,15 +377,6 @@ void BermudanSwaptionTest::testTreeEngineTimeSnapping() { } } -test_suite* BermudanSwaptionTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Bermudan swaption tests"); - - suite->add(QUANTLIB_TEST_CASE(&BermudanSwaptionTest::testCachedValues)); - suite->add(QUANTLIB_TEST_CASE(&BermudanSwaptionTest::testTreeEngineTimeSnapping)); +BOOST_AUTO_TEST_SUITE_END() - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&BermudanSwaptionTest::testCachedG2Values)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/bermudanswaption.hpp b/test-suite/bermudanswaption.hpp deleted file mode 100644 index c9f83a8b465..00000000000 --- a/test-suite/bermudanswaption.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2005 StatPro Italia srl - Copyright (C) 2021, 2022 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_bermudan_swaption_hpp -#define quantlib_test_bermudan_swaption_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BermudanSwaptionTest { - public: - static void testCachedValues(); - static void testCachedG2Values(); - static void testTreeEngineTimeSnapping(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 9d8d759d231..3776b182df6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "bermudanswaption.hpp" #include "binaryoption.hpp" #include "blackdeltacalculator.hpp" #include "blackformula.hpp" @@ -208,7 +207,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BermudanSwaptionTest::suite(speed)); test->add(BinaryOptionTest::suite()); test->add(BlackFormulaTest::suite()); test->add(BondTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 726515c0eb5..4798375ed95 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 3303b4c1210..99a49893625 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d21cfa78b38bd26a9cfa0f372eed77847bfefe05 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 15:28:16 +0800 Subject: [PATCH 016/132] Migrated binaryoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/binaryoption.cpp | 18 +++++++------- test-suite/binaryoption.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/binaryoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 5f785877008..b5a22077a9b 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - binaryoption.hpp blackdeltacalculator.hpp blackformula.hpp bondforward.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 39c5d872522..ef29471a7b5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - binaryoption.hpp \ blackdeltacalculator.hpp \ blackformula.hpp \ bondforward.hpp \ diff --git a/test-suite/binaryoption.cpp b/test-suite/binaryoption.cpp index 582dd73d533..9124d0ac2b6 100644 --- a/test-suite/binaryoption.cpp +++ b/test-suite/binaryoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "binaryoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -88,8 +88,11 @@ namespace binary_option_test { }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BinaryOptionTest::testCashOrNothingHaugValues() { +BOOST_AUTO_TEST_SUITE(BinaryOptionTest) + +BOOST_AUTO_TEST_CASE(testCashOrNothingHaugValues) { BOOST_TEST_MESSAGE("Testing cash-or-nothing barrier options against Haug's values..."); @@ -188,7 +191,7 @@ void BinaryOptionTest::testCashOrNothingHaugValues() { } } -void BinaryOptionTest::testAssetOrNothingHaugValues() { +BOOST_AUTO_TEST_CASE(testAssetOrNothingHaugValues) { BOOST_TEST_MESSAGE("Testing asset-or-nothing barrier options against Haug's values..."); @@ -269,9 +272,6 @@ void BinaryOptionTest::testAssetOrNothingHaugValues() { } } -test_suite* BinaryOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Binary"); - suite->add(QUANTLIB_TEST_CASE(&BinaryOptionTest::testCashOrNothingHaugValues)); - suite->add(QUANTLIB_TEST_CASE(&BinaryOptionTest::testAssetOrNothingHaugValues)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/binaryoption.hpp b/test-suite/binaryoption.hpp deleted file mode 100644 index cd6aaef560f..00000000000 --- a/test-suite/binaryoption.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2014 Thema Consulting SA - - 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_binary_option_hpp -#define quantlib_test_binary_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BinaryOptionTest { - public: - static void testCashOrNothingHaugValues(); - static void testAssetOrNothingHaugValues(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 3776b182df6..c86180eb6a6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "binaryoption.hpp" #include "blackdeltacalculator.hpp" #include "blackformula.hpp" #include "bondforward.hpp" @@ -207,7 +206,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BinaryOptionTest::suite()); test->add(BlackFormulaTest::suite()); test->add(BondTest::suite()); test->add(BondForwardTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 4798375ed95..ba515a40848 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 99a49893625..8ef7e1f4096 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -947,9 +947,6 @@ Header Files - - Header Files - Header Files From 05430d63c9edb6665ddd1e818c82ed8d31e9e5ac Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 16:52:41 +0800 Subject: [PATCH 017/132] Combines namespace members into one in batesmodel.cpp. Updates testsuite.vcxproj.filters file --- test-suite/batesmodel.cpp | 53 +++++++++++++--------------- test-suite/testsuite.vcxproj.filters | 2 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/test-suite/batesmodel.cpp b/test-suite/batesmodel.cpp index 086c0dc4bec..37fca3cfb15 100644 --- a/test-suite/batesmodel.cpp +++ b/test-suite/batesmodel.cpp @@ -54,6 +54,30 @@ namespace bates_model_test { return sse; } + struct HestonModelData { + const char* const name; + Real v0; + Real kappa; + Real theta; + Real sigma; + Real rho; + Real r; + Real q; + }; + + HestonModelData hestonModels[] = { + // ADI finite difference schemes for option pricing in the + // Heston model with correlation, K.J. in t'Hout and S. Foulon, + {"'t Hout case 1", 0.04, 1.5, 0.04, 0.3, -0.9, 0.025, 0.0}, + // Efficient numerical methods for pricing American options under + // stochastic volatility, Samuli Ikonen and Jari Toivanen, + {"Ikonen-Toivanen", 0.0625, 5, 0.16, 0.9, 0.1, 0.1, 0.0}, + // Not-so-complex logarithms in the Heston model, + // Christian Kahl and Peter Jäckel + {"Kahl-Jaeckel", 0.16, 1.0, 0.16, 2.0, -0.8, 0.0, 0.0}, + // self defined test cases + {"Equity case", 0.07, 2.0, 0.04, 0.55, -0.8, 0.03, 0.035 }, + }; } BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) @@ -267,33 +291,6 @@ BOOST_AUTO_TEST_CASE(testAnalyticAndMcVsJumpDiffusion) { } } -namespace bates_model_test { - struct HestonModelData { - const char* const name; - Real v0; - Real kappa; - Real theta; - Real sigma; - Real rho; - Real r; - Real q; - }; - - HestonModelData hestonModels[] = { - // ADI finite difference schemes for option pricing in the - // Heston model with correlation, K.J. in t'Hout and S. Foulon, - {"'t Hout case 1", 0.04, 1.5, 0.04, 0.3, -0.9, 0.025, 0.0}, - // Efficient numerical methods for pricing American options under - // stochastic volatility, Samuli Ikonen and Jari Toivanen, - {"Ikonen-Toivanen", 0.0625, 5, 0.16, 0.9, 0.1, 0.1, 0.0}, - // Not-so-complex logarithms in the Heston model, - // Christian Kahl and Peter Jäckel - {"Kahl-Jaeckel", 0.16, 1.0, 0.16, 2.0, -0.8, 0.0, 0.0}, - // self defined test cases - {"Equity case", 0.07, 2.0, 0.04, 0.55, -0.8, 0.03, 0.035 }, - }; -} - BOOST_AUTO_TEST_CASE(testAnalyticVsMCPricing) { BOOST_TEST_MESSAGE("Testing analytic Bates engine against Monte-Carlo " "engine..."); @@ -377,7 +374,7 @@ BOOST_AUTO_TEST_CASE(testDAXCalibration) { BOOST_TEST_MESSAGE( "Testing Bates model calibration using DAX volatility data..."); - using namespace ::bates_model_test; + using namespace bates_model_test; Date settlementDate(5, July, 2002); Settings::instance().evaluationDate() = settlementDate; diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 8ef7e1f4096..6ad5cb9a6bb 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -336,7 +336,7 @@ Source Files - Header Files + Source Files Source Files From 852cf902f22350bb863049ba02f2ab24577bea7f Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 16:59:57 +0800 Subject: [PATCH 018/132] Migrated blackdeltacalculator.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/blackdeltacalculator.cpp | 27 ++++++++------------ test-suite/blackdeltacalculator.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 63 deletions(-) delete mode 100644 test-suite/blackdeltacalculator.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index b5a22077a9b..f51d6f78baa 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - blackdeltacalculator.hpp blackformula.hpp bondforward.hpp bonds.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ef29471a7b5..6c9a75b76c8 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - blackdeltacalculator.hpp \ blackformula.hpp \ bondforward.hpp \ bonds.hpp \ diff --git a/test-suite/blackdeltacalculator.cpp b/test-suite/blackdeltacalculator.cpp index f019fefaea8..89c5c08c493 100644 --- a/test-suite/blackdeltacalculator.cpp +++ b/test-suite/blackdeltacalculator.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "blackdeltacalculator.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -61,8 +61,11 @@ namespace black_delta_calculator_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BlackDeltaCalculatorTest::testDeltaValues(){ +BOOST_AUTO_TEST_SUITE(BlackDeltaCalculatorExperimentalTest) + +BOOST_AUTO_TEST_CASE(testDeltaValues){ BOOST_TEST_MESSAGE("Testing delta calculator values..."); @@ -147,7 +150,7 @@ void BlackDeltaCalculatorTest::testDeltaValues(){ } } -void BlackDeltaCalculatorTest::testDeltaPriceConsistency() { +BOOST_AUTO_TEST_CASE(testDeltaPriceConsistency) { BOOST_TEST_MESSAGE("Testing premium-adjusted delta price consistency..."); @@ -312,7 +315,7 @@ void BlackDeltaCalculatorTest::testDeltaPriceConsistency() { } } -void BlackDeltaCalculatorTest::testPutCallParity(){ +BOOST_AUTO_TEST_CASE(testPutCallParity){ BOOST_TEST_MESSAGE("Testing put-call parity for deltas..."); @@ -517,7 +520,7 @@ void BlackDeltaCalculatorTest::testPutCallParity(){ } } -void BlackDeltaCalculatorTest::testAtmCalcs(){ +BOOST_AUTO_TEST_CASE(testAtmCalcs){ BOOST_TEST_MESSAGE("Testing delta-neutral ATM quotations..."); @@ -679,17 +682,7 @@ void BlackDeltaCalculatorTest::testAtmCalcs(){ } } +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() - -test_suite* BlackDeltaCalculatorTest::suite() { - auto* suite = BOOST_TEST_SUITE("Black delta calculator tests"); - suite->add(QUANTLIB_TEST_CASE(&BlackDeltaCalculatorTest::testDeltaValues)); - suite->add(QUANTLIB_TEST_CASE( - &BlackDeltaCalculatorTest::testDeltaPriceConsistency)); - suite->add(QUANTLIB_TEST_CASE( - &BlackDeltaCalculatorTest::testPutCallParity)); - suite->add(QUANTLIB_TEST_CASE(&BlackDeltaCalculatorTest::testAtmCalcs)); - - return suite; -} diff --git a/test-suite/blackdeltacalculator.hpp b/test-suite/blackdeltacalculator.hpp deleted file mode 100644 index de3d435d793..00000000000 --- a/test-suite/blackdeltacalculator.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2010 Dimitri Reiswich - - 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_black_delta_calculator_test_hpp -#define quantlib_black_delta_calculator_test_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BlackDeltaCalculatorTest { - public: - static void testDeltaValues(); - static void testDeltaPriceConsistency(); - static void testPutCallParity(); - static void testAtmCalcs(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index c86180eb6a6..f06211eefcf 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "blackdeltacalculator.hpp" #include "blackformula.hpp" #include "bondforward.hpp" #include "bonds.hpp" @@ -327,7 +326,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(BlackDeltaCalculatorTest::suite()); test->add(CallableBondTest::suite()); test->add(CatBondTest::suite()); test->add(CdoTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ba515a40848..100877367ac 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 6ad5cb9a6bb..a4065a6f341 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 0c2ac52606df204eb2e46edabaaa3f9434960f36 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:08:22 +0800 Subject: [PATCH 019/132] Migrated blackformula.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/blackformula.cpp | 54 +++++++++------------------- test-suite/blackformula.hpp | 46 ------------------------ test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 17 insertions(+), 91 deletions(-) delete mode 100644 test-suite/blackformula.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index f51d6f78baa..77bcc6dcbae 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - blackformula.hpp bondforward.hpp bonds.hpp brownianbridge.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6c9a75b76c8..b673dbc5105 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - blackformula.hpp \ bondforward.hpp \ bonds.hpp \ brownianbridge.hpp \ diff --git a/test-suite/blackformula.cpp b/test-suite/blackformula.cpp index 3bae78bc706..067158b7764 100644 --- a/test-suite/blackformula.cpp +++ b/test-suite/blackformula.cpp @@ -21,7 +21,7 @@ */ -#include "blackformula.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -29,8 +29,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BlackFormulaTest::testBachelierImpliedVol(){ +BOOST_AUTO_TEST_SUITE(BlackFormulaTest) + +BOOST_AUTO_TEST_CASE(testBachelierImpliedVol){ BOOST_TEST_MESSAGE("Testing Bachelier implied vol..."); @@ -58,7 +61,7 @@ void BlackFormulaTest::testBachelierImpliedVol(){ } } -void BlackFormulaTest::testChambersImpliedVol() { +BOOST_AUTO_TEST_CASE(testChambersImpliedVol) { BOOST_TEST_MESSAGE("Testing Chambers-Nawalkha implied vol approximation..."); @@ -107,7 +110,7 @@ void BlackFormulaTest::testChambersImpliedVol() { } } -void BlackFormulaTest::testRadoicicStefanicaImpliedVol() { +BOOST_AUTO_TEST_CASE(testRadoicicStefanicaImpliedVol) { BOOST_TEST_MESSAGE( "Testing Radoicic-Stefanica implied vol approximation..."); @@ -154,7 +157,7 @@ void BlackFormulaTest::testRadoicicStefanicaImpliedVol() { } } -void BlackFormulaTest::testRadoicicStefanicaLowerBound() { +BOOST_AUTO_TEST_CASE(testRadoicicStefanicaLowerBound) { BOOST_TEST_MESSAGE("Testing Radoicic-Stefanica lower bound..."); @@ -195,7 +198,7 @@ void BlackFormulaTest::testRadoicicStefanicaLowerBound() { } } -void BlackFormulaTest::testImpliedVolAdaptiveSuccessiveOverRelaxation() { +BOOST_AUTO_TEST_CASE(testImpliedVolAdaptiveSuccessiveOverRelaxation) { BOOST_TEST_MESSAGE("Testing implied volatility calculation via " "adaptive successive over-relaxation..."); @@ -302,7 +305,7 @@ void assertBlackFormulaForwardDerivative( } } -void BlackFormulaTest::testBlackFormulaForwardDerivative() { +BOOST_AUTO_TEST_CASE(testBlackFormulaForwardDerivative) { BOOST_TEST_MESSAGE("Testing forward derivative of the Black formula..."); @@ -317,7 +320,7 @@ void BlackFormulaTest::testBlackFormulaForwardDerivative() { assertBlackFormulaForwardDerivative(Option::Put, strikes, vol); } -void BlackFormulaTest::testBlackFormulaForwardDerivativeWithZeroStrike() { +BOOST_AUTO_TEST_CASE(testBlackFormulaForwardDerivativeWithZeroStrike) { BOOST_TEST_MESSAGE("Testing forward derivative of the Black formula " "with zero strike..."); @@ -329,7 +332,7 @@ void BlackFormulaTest::testBlackFormulaForwardDerivativeWithZeroStrike() { assertBlackFormulaForwardDerivative(Option::Put, strikes, vol); } -void BlackFormulaTest::testBlackFormulaForwardDerivativeWithZeroVolatility() { +BOOST_AUTO_TEST_CASE(testBlackFormulaForwardDerivativeWithZeroVolatility) { BOOST_TEST_MESSAGE("Testing forward derivative of the Black formula " "with zero volatility..."); @@ -392,7 +395,7 @@ void assertBachelierBlackFormulaForwardDerivative( } } -void BlackFormulaTest::testBachelierBlackFormulaForwardDerivative() { +BOOST_AUTO_TEST_CASE(testBachelierBlackFormulaForwardDerivative) { BOOST_TEST_MESSAGE("Testing forward derivative of the " "Bachelier Black formula..."); @@ -412,7 +415,7 @@ void BlackFormulaTest::testBachelierBlackFormulaForwardDerivative() { assertBachelierBlackFormulaForwardDerivative(Option::Put, strikes, vol); } -void BlackFormulaTest::testBachelierBlackFormulaForwardDerivativeWithZeroVolatility() { +BOOST_AUTO_TEST_CASE(testBachelierBlackFormulaForwardDerivativeWithZeroVolatility) { BOOST_TEST_MESSAGE("Testing forward derivative of the Bachelier Black formula " "with zero volatility..."); @@ -432,29 +435,6 @@ void BlackFormulaTest::testBachelierBlackFormulaForwardDerivativeWithZeroVolatil assertBachelierBlackFormulaForwardDerivative(Option::Put, strikes, vol); } -test_suite* BlackFormulaTest::suite() { - auto* suite = BOOST_TEST_SUITE("Black formula tests"); - - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBachelierImpliedVol)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testChambersImpliedVol)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testRadoicicStefanicaImpliedVol)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testRadoicicStefanicaLowerBound)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testImpliedVolAdaptiveSuccessiveOverRelaxation)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBlackFormulaForwardDerivative)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBlackFormulaForwardDerivativeWithZeroStrike)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBlackFormulaForwardDerivativeWithZeroVolatility)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBachelierBlackFormulaForwardDerivative)); - suite->add(QUANTLIB_TEST_CASE( - &BlackFormulaTest::testBachelierBlackFormulaForwardDerivativeWithZeroVolatility)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/blackformula.hpp b/test-suite/blackformula.hpp deleted file mode 100644 index cf9ae00da26..00000000000 --- a/test-suite/blackformula.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2013 Gary Kennedy - Copyright (C) 2015 Peter Caspers - Copyright (C) 2017 Klaus Spanderen - Copyright (C) 2020 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_blackformula_hpp -#define quantlib_test_blackformula_hpp - -#include - - -class BlackFormulaTest { - public: - static void testBachelierImpliedVol(); - static void testChambersImpliedVol(); - static void testRadoicicStefanicaImpliedVol(); - static void testRadoicicStefanicaLowerBound(); - static void testImpliedVolAdaptiveSuccessiveOverRelaxation(); - static void testBlackFormulaForwardDerivative(); - static void testBlackFormulaForwardDerivativeWithZeroStrike(); - static void testBlackFormulaForwardDerivativeWithZeroVolatility(); - static void testBachelierBlackFormulaForwardDerivative(); - static void testBachelierBlackFormulaForwardDerivativeWithZeroVolatility(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f06211eefcf..413921a08ee 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "blackformula.hpp" #include "bondforward.hpp" #include "bonds.hpp" #include "brownianbridge.hpp" @@ -205,7 +204,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BlackFormulaTest::suite()); test->add(BondTest::suite()); test->add(BondForwardTest::suite()); test->add(BrownianBridgeTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 100877367ac..ed9c9f37e54 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 a4065a6f341..3fa28f2ea7b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 36ed3071b6eb89f7917dc5a9e53aa6a14f314f5e Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:13:32 +0800 Subject: [PATCH 020/132] Migrated bondforward.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/bondforward.cpp | 22 ++++++++-------- test-suite/bondforward.hpp | 38 ---------------------------- 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/bondforward.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 77bcc6dcbae..9f421c60947 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - bondforward.hpp bonds.hpp brownianbridge.hpp businessdayconventions.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index b673dbc5105..c953f301321 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - bondforward.hpp \ bonds.hpp \ brownianbridge.hpp \ businessdayconventions.hpp \ diff --git a/test-suite/bondforward.cpp b/test-suite/bondforward.cpp index 3d2fc0b79ed..06c84a1cbf2 100644 --- a/test-suite/bondforward.cpp +++ b/test-suite/bondforward.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "bondforward.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -64,7 +64,11 @@ namespace bond_forward_test { } } -void BondForwardTest::testFuturesPriceReplication() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(BondForwardTest) + +BOOST_AUTO_TEST_CASE(testFuturesPriceReplication) { BOOST_TEST_MESSAGE("Testing futures price replication..."); using namespace bond_forward_test; @@ -94,7 +98,7 @@ void BondForwardTest::testFuturesPriceReplication() { << " expected: " << expectedFuturesPrice << "\n"); } -void BondForwardTest::testCleanForwardPriceReplication() { +BOOST_AUTO_TEST_CASE(testCleanForwardPriceReplication) { BOOST_TEST_MESSAGE("Testing clean forward price replication..."); using namespace bond_forward_test; @@ -123,7 +127,7 @@ void BondForwardTest::testCleanForwardPriceReplication() { << " expected: " << expectedFwdCleanPrice << "\n"); } -void BondForwardTest::testThatForwardValueIsEqualToSpotValueIfNoIncome() { +BOOST_AUTO_TEST_CASE(testThatForwardValueIsEqualToSpotValueIfNoIncome) { BOOST_TEST_MESSAGE( "Testing that forward value is equal to spot value if no income..."); @@ -153,12 +157,6 @@ void BondForwardTest::testThatForwardValueIsEqualToSpotValueIfNoIncome() { << " underlying bond: " << underlyingDirtyPrice << "\n"); } -test_suite* BondForwardTest::suite() { - auto* suite = BOOST_TEST_SUITE("Bond forward tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&BondForwardTest::testFuturesPriceReplication)); - suite->add(QUANTLIB_TEST_CASE(&BondForwardTest::testCleanForwardPriceReplication)); - suite->add(QUANTLIB_TEST_CASE( - &BondForwardTest::testThatForwardValueIsEqualToSpotValueIfNoIncome)); - return suite; -} \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/bondforward.hpp b/test-suite/bondforward.hpp deleted file mode 100644 index 79f486f4f05..00000000000 --- a/test-suite/bondforward.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2022 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_bond_forward_hpp -#define quantlib_test_bond_forward_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BondForwardTest { - public: - static void testFuturesPriceReplication(); - static void testCleanForwardPriceReplication(); - static void testThatForwardValueIsEqualToSpotValueIfNoIncome(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 413921a08ee..b1783d86f4a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "bondforward.hpp" #include "bonds.hpp" #include "brownianbridge.hpp" #include "businessdayconventions.hpp" @@ -205,7 +204,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(BondTest::suite()); - test->add(BondForwardTest::suite()); test->add(BrownianBridgeTest::suite()); test->add(BusinessDayConventionTest::suite()); test->add(CalendarTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ed9c9f37e54..b7e7bd50f7b 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 3fa28f2ea7b..f0b62dbcf4b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -983,9 +983,6 @@ Header Files - - Header Files - Header Files From 8dd1862e13324df6e934abe650b338d1ca83d4ff Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:27:12 +0800 Subject: [PATCH 021/132] Migrated bonds.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/bonds.cpp | 71 +++++++++------------------- test-suite/bonds.hpp | 50 -------------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 23 insertions(+), 106 deletions(-) delete mode 100644 test-suite/bonds.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9f421c60947..0b20956cea3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - bonds.hpp brownianbridge.hpp businessdayconventions.hpp calendars.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c953f301321..918036ebff6 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - bonds.hpp \ brownianbridge.hpp \ businessdayconventions.hpp \ calendars.hpp \ diff --git a/test-suite/bonds.cpp b/test-suite/bonds.cpp index c48e82a46cd..afbd748ad39 100644 --- a/test-suite/bonds.cpp +++ b/test-suite/bonds.cpp @@ -19,7 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "bonds.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -91,7 +91,11 @@ namespace bonds_test { } -void BondTest::testYield() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(BondsTest) + +BOOST_AUTO_TEST_CASE(testYield) { BOOST_TEST_MESSAGE("Testing consistency of bond price/yield calculation..."); @@ -191,7 +195,7 @@ void BondTest::testYield() { } } -void BondTest::testAtmRate() { +BOOST_AUTO_TEST_CASE(testAtmRate) { BOOST_TEST_MESSAGE("Testing consistency of bond price/ATM rate calculation..."); @@ -251,7 +255,7 @@ void BondTest::testAtmRate() { } } -void BondTest::testZspread() { +BOOST_AUTO_TEST_CASE(testZspread) { BOOST_TEST_MESSAGE("Testing consistency of bond price/z-spread calculation..."); @@ -330,9 +334,7 @@ void BondTest::testZspread() { } } - - -void BondTest::testTheoretical() { +BOOST_AUTO_TEST_CASE(testTheoretical) { BOOST_TEST_MESSAGE("Testing theoretical bond price/yield calculation..."); @@ -412,8 +414,7 @@ void BondTest::testTheoretical() { } } - -void BondTest::testCached() { +BOOST_AUTO_TEST_CASE(testCached) { BOOST_TEST_MESSAGE( "Testing bond price/yield calculation against cached values..."); @@ -685,9 +686,7 @@ void BondTest::testCached() { ); } - - -void BondTest::testCachedZero() { +BOOST_AUTO_TEST_CASE(testCachedZero) { BOOST_TEST_MESSAGE("Testing zero-coupon bond prices against cached values..."); @@ -769,8 +768,7 @@ void BondTest::testCachedZero() { } } - -void BondTest::testCachedFixed() { +BOOST_AUTO_TEST_CASE(testCachedFixed) { BOOST_TEST_MESSAGE("Testing fixed-coupon bond prices against cached values..."); @@ -869,8 +867,7 @@ void BondTest::testCachedFixed() { } } - -void BondTest::testCachedFloating() { +BOOST_AUTO_TEST_CASE(testCachedFloating) { BOOST_TEST_MESSAGE("Testing floating-rate bond prices against cached values..."); @@ -1011,7 +1008,7 @@ void BondTest::testCachedFloating() { } } -void BondTest::testBrazilianCached() { +BOOST_AUTO_TEST_CASE(testBrazilianCached) { BOOST_TEST_MESSAGE( "Testing Brazilian public bond prices against Andima cached values..."); @@ -1100,7 +1097,7 @@ void BondTest::testBrazilianCached() { } } -void BondTest::testExCouponGilt() { +BOOST_AUTO_TEST_CASE(testExCouponGilt) { BOOST_TEST_MESSAGE( "Testing ex-coupon UK Gilt price against market values..."); /* UK Gilts have an exCouponDate 7 business days before the coupon @@ -1228,8 +1225,7 @@ void BondTest::testExCouponGilt() { } } - -void BondTest::testExCouponAustralianBond() { +BOOST_AUTO_TEST_CASE(testExCouponAustralianBond) { BOOST_TEST_MESSAGE( "Testing ex-coupon Australian bond price against market values..."); /* Australian Government Bonds have an exCouponDate 7 calendar @@ -1362,7 +1358,7 @@ void BondTest::testExCouponAustralianBond() { /// This requires the use of the Schedule to be constructed /// with a custom date vector /// -void BondTest::testBondFromScheduleWithDateVector() +BOOST_AUTO_TEST_CASE(testBondFromScheduleWithDateVector) { BOOST_TEST_MESSAGE("Testing South African R2048 bond price using Schedule constructor with Date vector..."); //When pricing bond from Yield To Maturity, use NullCalendar() @@ -1439,7 +1435,7 @@ void BondTest::testBondFromScheduleWithDateVector() } } -void BondTest::testFixedBondWithGivenDates() { +BOOST_AUTO_TEST_CASE(testFixedBondWithGivenDates) { BOOST_TEST_MESSAGE("Testing fixed-coupon bond built on schedule with given dates..."); @@ -1561,7 +1557,7 @@ void BondTest::testFixedBondWithGivenDates() { } } -void BondTest::testRiskyBondWithGivenDates() { +BOOST_AUTO_TEST_CASE(testRiskyBondWithGivenDates) { BOOST_TEST_MESSAGE("Testing risky bond engine..."); @@ -1627,8 +1623,7 @@ void BondTest::testRiskyBondWithGivenDates() { } } - -void BondTest::testFixedRateBondWithArbitrarySchedule() { +BOOST_AUTO_TEST_CASE(testFixedRateBondWithArbitrarySchedule) { BOOST_TEST_MESSAGE("Testing fixed-rate bond with arbitrary schedule..."); Calendar calendar = NullCalendar(); @@ -1666,8 +1661,7 @@ void BondTest::testFixedRateBondWithArbitrarySchedule() { BOOST_CHECK_NO_THROW(bond.cleanPrice()); } - -void BondTest::testThirty360BondWithSettlementOn31st(){ +BOOST_AUTO_TEST_CASE(testThirty360BondWithSettlementOn31st){ BOOST_TEST_MESSAGE( "Testing Thirty/360 bond with settlement on 31st of the month..."); @@ -1711,25 +1705,6 @@ void BondTest::testThirty360BondWithSettlementOn31st(){ ASSERT_CLOSE("accrued", settlement, accrued, 0.7, 1e-6); } -test_suite* BondTest::suite() { - auto* suite = BOOST_TEST_SUITE("Bond tests"); - - suite->add(QUANTLIB_TEST_CASE(&BondTest::testYield)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testAtmRate)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testZspread)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testTheoretical)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testCached)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testCachedZero)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testCachedFixed)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testCachedFloating)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testBrazilianCached)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testFixedBondWithGivenDates)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testRiskyBondWithGivenDates)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testExCouponGilt)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testExCouponAustralianBond)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testBondFromScheduleWithDateVector)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testFixedRateBondWithArbitrarySchedule)); - suite->add(QUANTLIB_TEST_CASE(&BondTest::testThirty360BondWithSettlementOn31st)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/bonds.hpp b/test-suite/bonds.hpp deleted file mode 100644 index bb72791f26b..00000000000 --- a/test-suite/bonds.hpp +++ /dev/null @@ -1,50 +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_bonds_hpp -#define quantlib_test_bonds_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BondTest { - public: - static void testYield(); - static void testAtmRate(); - static void testZspread(); - static void testTheoretical(); - static void testCached(); - static void testCachedZero(); - static void testCachedFixed(); - static void testCachedFloating(); - static void testBrazilianCached(); - static void testFixedBondWithGivenDates(); - static void testRiskyBondWithGivenDates(); - static void testExCouponGilt(); - static void testExCouponAustralianBond(); - static void testBondFromScheduleWithDateVector(); - static void testFixedRateBondWithArbitrarySchedule(); - static void testThirty360BondWithSettlementOn31st(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index b1783d86f4a..689129117b8 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "bonds.hpp" #include "brownianbridge.hpp" #include "businessdayconventions.hpp" #include "calendars.hpp" @@ -203,7 +202,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BondTest::suite()); test->add(BrownianBridgeTest::suite()); test->add(BusinessDayConventionTest::suite()); test->add(CalendarTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b7e7bd50f7b..fc4ee93e393 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 f0b62dbcf4b..0638a4eb6ba 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From f8cbaa6a5f98ee8eddebefee017d180c8b9eacfe Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:36:34 +0800 Subject: [PATCH 022/132] Migrated brownianbridge.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/brownianbridge.cpp | 18 +++++++------- test-suite/brownianbridge.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 54 deletions(-) delete mode 100644 test-suite/brownianbridge.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 0b20956cea3..f8f3ec1f03c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - brownianbridge.hpp businessdayconventions.hpp calendars.hpp callablebonds.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 918036ebff6..48a6488dcd5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - brownianbridge.hpp \ businessdayconventions.hpp \ calendars.hpp \ callablebonds.hpp \ diff --git a/test-suite/brownianbridge.cpp b/test-suite/brownianbridge.cpp index c62687d91dd..bd53c766a81 100644 --- a/test-suite/brownianbridge.cpp +++ b/test-suite/brownianbridge.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "brownianbridge.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -58,8 +58,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void BrownianBridgeTest::testVariates() { +BOOST_AUTO_TEST_SUITE(BrownianBridgeTest) + +BOOST_AUTO_TEST_CASE(testVariates) { BOOST_TEST_MESSAGE("Testing Brownian-bridge variates..."); std::vector - diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index 0638a4eb6ba..3800630228d 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 7ccba120ecf4faa38505f21e95ea21d3adde12f1 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:40:30 +0800 Subject: [PATCH 023/132] Migrated businessdayconventions.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/businessdayconventions.cpp | 17 +++++++------- test-suite/businessdayconventions.hpp | 33 --------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 test-suite/businessdayconventions.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index f8f3ec1f03c..9a468d8f35d 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - businessdayconventions.hpp calendars.hpp callablebonds.hpp capfloor.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 48a6488dcd5..5928e8dcba1 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - businessdayconventions.hpp \ calendars.hpp \ callablebonds.hpp \ capfloor.hpp \ diff --git a/test-suite/businessdayconventions.cpp b/test-suite/businessdayconventions.cpp index 4c94ca847e1..6790fe31087 100644 --- a/test-suite/businessdayconventions.cpp +++ b/test-suite/businessdayconventions.cpp @@ -15,7 +15,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "businessdayconventions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -46,7 +46,11 @@ namespace business_day_conventions_test { } -void BusinessDayConventionTest::testConventions() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(BusinessDayConventionTest) + +BOOST_AUTO_TEST_CASE(testConventions) { BOOST_TEST_MESSAGE("Testing business day conventions..."); @@ -122,11 +126,6 @@ void BusinessDayConventionTest::testConventions() { } } -test_suite* BusinessDayConventionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Business day convention tests"); - suite->add(QUANTLIB_TEST_CASE(&BusinessDayConventionTest::testConventions)); - return suite; -} - - +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/businessdayconventions.hpp b/test-suite/businessdayconventions.hpp deleted file mode 100644 index 01ff0a4d806..00000000000 --- a/test-suite/businessdayconventions.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - 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_business_day_convention_hpp -#define quantlib_test_business_day_convention_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class BusinessDayConventionTest { - public: - static void testConventions(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index fcfdcb454c7..f076a41fe33 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "businessdayconventions.hpp" #include "calendars.hpp" #include "callablebonds.hpp" #include "capfloor.hpp" @@ -201,7 +200,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(BusinessDayConventionTest::suite()); test->add(CalendarTest::suite()); test->add(CapFloorTest::suite()); test->add(CapFlooredCouponTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index be4f015727f..37c8d37c189 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 3800630228d..3c8ce36cae0 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -935,9 +935,6 @@ Header Files - - Header Files - Header Files From 83ffcb79675741ae60373c1986a17b8ff2d11a72 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 17:59:12 +0800 Subject: [PATCH 024/132] Migrated calendars.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 1 - test-suite/calendars.cpp | 112 +++++++++------------------ test-suite/calendars.hpp | 72 ----------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 36 insertions(+), 158 deletions(-) delete mode 100644 test-suite/calendars.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9a468d8f35d..8b687f6945e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - calendars.hpp callablebonds.hpp capfloor.hpp capflooredcoupon.hpp @@ -337,7 +336,7 @@ set(QL_BENCHMARK_SOURCES barrieroption.cpp basketoption.cpp batesmodel.cpp - convertiblebonds.cpp convertiblebonds.hpp + convertiblebonds.cpp convertiblebonds.hpp digitaloption.cpp digitaloption.hpp dividendoption.cpp dividendoption.hpp europeanoption.cpp europeanoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 5928e8dcba1..93789fb093f 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - calendars.hpp \ callablebonds.hpp \ capfloor.hpp \ capflooredcoupon.hpp \ diff --git a/test-suite/calendars.cpp b/test-suite/calendars.cpp index 9860f726540..1bcf51daf85 100644 --- a/test-suite/calendars.cpp +++ b/test-suite/calendars.cpp @@ -26,7 +26,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "calendars.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -49,7 +49,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CalendarTest::testModifiedCalendars() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CalendarTest) + +BOOST_AUTO_TEST_CASE(testModifiedCalendars) { BOOST_TEST_MESSAGE("Testing calendar modification..."); @@ -109,8 +113,7 @@ void CalendarTest::testModifiedCalendars() { BOOST_FAIL(d2 << " still a holiday"); } - -void CalendarTest::testJointCalendars() { +BOOST_AUTO_TEST_CASE(testJointCalendars) { BOOST_TEST_MESSAGE("Testing joint calendars..."); @@ -185,7 +188,7 @@ void CalendarTest::testJointCalendars() { } } -void CalendarTest::testUSSettlement() { +BOOST_AUTO_TEST_CASE(testUSSettlement) { BOOST_TEST_MESSAGE("Testing US settlement holiday list..."); std::vector expectedHol; @@ -244,7 +247,7 @@ void CalendarTest::testUSSettlement() { } } -void CalendarTest::testUSGovernmentBondMarket() { +BOOST_AUTO_TEST_CASE(testUSGovernmentBondMarket) { BOOST_TEST_MESSAGE("Testing US government bond market holiday list..."); std::vector expectedHol; @@ -274,7 +277,7 @@ void CalendarTest::testUSGovernmentBondMarket() { << hol.size() << " calculated holidays"); } -void CalendarTest::testUSNewYorkStockExchange() { +BOOST_AUTO_TEST_CASE(testUSNewYorkStockExchange) { BOOST_TEST_MESSAGE("Testing New York Stock Exchange holiday list..."); std::vector expectedHol; @@ -370,8 +373,7 @@ void CalendarTest::testUSNewYorkStockExchange() { } } - -void CalendarTest::testSOFR() { +BOOST_AUTO_TEST_CASE(testSOFR) { BOOST_TEST_MESSAGE("Testing extra non-fixing day for SOFR..."); auto fedCalendar = UnitedStates(UnitedStates::GovernmentBond); @@ -385,8 +387,7 @@ void CalendarTest::testSOFR() { BOOST_ERROR(testDate << " should not be a fixing date for " << sofr.name()); } - -void CalendarTest::testTARGET() { +BOOST_AUTO_TEST_CASE(testTARGET) { BOOST_TEST_MESSAGE("Testing TARGET holiday list..."); std::vector expectedHol; @@ -448,7 +449,7 @@ void CalendarTest::testTARGET() { << hol.size() << " calculated holidays"); } -void CalendarTest::testGermanyFrankfurt() { +BOOST_AUTO_TEST_CASE(testGermanyFrankfurt) { BOOST_TEST_MESSAGE("Testing Frankfurt Stock Exchange holiday list..."); std::vector expectedHol; @@ -478,7 +479,7 @@ void CalendarTest::testGermanyFrankfurt() { << hol.size() << " calculated holidays"); } -void CalendarTest::testGermanyEurex() { +BOOST_AUTO_TEST_CASE(testGermanyEurex) { BOOST_TEST_MESSAGE("Testing Eurex holiday list..."); std::vector expectedHol; @@ -510,7 +511,7 @@ void CalendarTest::testGermanyEurex() { << hol.size() << " calculated holidays"); } -void CalendarTest::testGermanyXetra() { +BOOST_AUTO_TEST_CASE(testGermanyXetra) { BOOST_TEST_MESSAGE("Testing Xetra holiday list..."); std::vector expectedHol; @@ -540,7 +541,7 @@ void CalendarTest::testGermanyXetra() { << hol.size() << " calculated holidays"); } -void CalendarTest::testUKSettlement() { +BOOST_AUTO_TEST_CASE(testUKSettlement) { BOOST_TEST_MESSAGE("Testing UK settlement holiday list..."); std::vector expectedHol; @@ -593,7 +594,7 @@ void CalendarTest::testUKSettlement() { << hol.size() << " calculated holidays"); } -void CalendarTest::testUKExchange() { +BOOST_AUTO_TEST_CASE(testUKExchange) { BOOST_TEST_MESSAGE("Testing London Stock Exchange holiday list..."); std::vector expectedHol; @@ -646,7 +647,7 @@ void CalendarTest::testUKExchange() { << hol.size() << " calculated holidays"); } -void CalendarTest::testUKMetals() { +BOOST_AUTO_TEST_CASE(testUKMetals) { BOOST_TEST_MESSAGE("Testing London Metals Exchange holiday list..."); std::vector expectedHol; @@ -699,7 +700,7 @@ void CalendarTest::testUKMetals() { << hol.size() << " calculated holidays"); } -void CalendarTest::testItalyExchange() { +BOOST_AUTO_TEST_CASE(testItalyExchange) { BOOST_TEST_MESSAGE("Testing Milan Stock Exchange holiday list..."); std::vector expectedHol; @@ -742,7 +743,7 @@ void CalendarTest::testItalyExchange() { << hol.size() << " calculated holidays"); } -void CalendarTest::testRussia() { +BOOST_AUTO_TEST_CASE(testRussia) { BOOST_TEST_MESSAGE("Testing Russia holiday list..."); std::vector expectedHol; @@ -1343,7 +1344,7 @@ void CalendarTest::testRussia() { << hol.size() << " calculated holidays"); } -void CalendarTest::testBrazil() { +BOOST_AUTO_TEST_CASE(testBrazil) { BOOST_TEST_MESSAGE("Testing Brazil holiday list..."); std::vector expectedHol; @@ -1386,7 +1387,7 @@ void CalendarTest::testBrazil() { << hol.size() << " calculated holidays"); } -void CalendarTest::testDenmark() { +BOOST_AUTO_TEST_CASE(testDenmark) { BOOST_TEST_MESSAGE("Testing Denmark holiday list..."); @@ -1446,7 +1447,7 @@ void CalendarTest::testDenmark() { << hol.size() << " calculated holidays"); } -void CalendarTest::testSouthKoreanSettlement() { +BOOST_AUTO_TEST_CASE(testSouthKoreanSettlement) { BOOST_TEST_MESSAGE("Testing South-Korean settlement holiday list..."); std::vector expectedHol; @@ -2172,7 +2173,7 @@ void CalendarTest::testSouthKoreanSettlement() { << hol.size() << " calculated holidays"); } -void CalendarTest::testKoreaStockExchange() { +BOOST_AUTO_TEST_CASE(testKoreaStockExchange) { BOOST_TEST_MESSAGE("Testing Korea Stock Exchange holiday list..."); std::vector expectedHol; @@ -2947,7 +2948,7 @@ void CalendarTest::testKoreaStockExchange() { << hol.size() << " calculated holidays"); } -void CalendarTest::testChinaSSE() { +BOOST_AUTO_TEST_CASE(testChinaSSE) { BOOST_TEST_MESSAGE("Testing China Shanghai Stock Exchange holiday list..."); std::vector expectedHol; @@ -3159,7 +3160,7 @@ void CalendarTest::testChinaSSE() { << hol.size() << " calculated holidays"); } -void CalendarTest::testChinaIB() { +BOOST_AUTO_TEST_CASE(testChinaIB) { BOOST_TEST_MESSAGE("Testing China Inter Bank working weekends list..."); std::vector expectedWorkingWeekEnds; @@ -3268,7 +3269,7 @@ void CalendarTest::testChinaIB() { << " calculated working weekends"); } -void CalendarTest::testEndOfMonth() { +BOOST_AUTO_TEST_CASE(testEndOfMonth) { BOOST_TEST_MESSAGE("Testing end-of-month calculation..."); Calendar c = TARGET(); // any calendar would be OK @@ -3289,7 +3290,7 @@ void CalendarTest::testEndOfMonth() { } } -void CalendarTest::testBusinessDaysBetween() { +BOOST_AUTO_TEST_CASE(testBusinessDaysBetween) { BOOST_TEST_MESSAGE("Testing calculation of business days between dates..."); @@ -3364,8 +3365,7 @@ void CalendarTest::testBusinessDaysBetween() { } } - -void CalendarTest::testBespokeCalendars() { +BOOST_AUTO_TEST_CASE(testBespokeCalendars) { BOOST_TEST_MESSAGE("Testing bespoke calendars..."); @@ -3478,8 +3478,9 @@ void CalendarTest::testBespokeCalendars() { BOOST_ERROR(testDate4 << " (marked as holiday) not detected"); } -void CalendarTest::testIntradayAddHolidays() { #ifdef QL_HIGH_RESOLUTION_DATE +BOOST_AUTO_TEST_CASE(testIntradayAddHolidays) { + BOOST_TEST_MESSAGE("Testing addHolidays with enable-intraday..."); // test cases taken from testModifiedCalendars @@ -3565,11 +3566,10 @@ void CalendarTest::testIntradayAddHolidays() { << " and different hours/min/secs"); if (c1.isHoliday(d2Mock)) BOOST_FAIL(d2Mock << " still a holiday and different hours/min/secs"); - -#endif } +#endif -void CalendarTest::testDayLists() { +BOOST_AUTO_TEST_CASE(testDayLists) { BOOST_TEST_MESSAGE("Testing holidayList and businessDaysList..."); Calendar germany = Germany(); @@ -3599,48 +3599,6 @@ void CalendarTest::testDayLists() { } } -test_suite* CalendarTest::suite() { - auto* suite = BOOST_TEST_SUITE("Calendar tests"); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testBrazil)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testRussia)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testItalyExchange)); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUKSettlement)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUKExchange)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUKMetals)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testGermanyFrankfurt)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testGermanyXetra)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testGermanyEurex)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testTARGET)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testDenmark)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUSSettlement)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUSGovernmentBondMarket)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testUSNewYorkStockExchange)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testSOFR)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testSouthKoreanSettlement)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testKoreaStockExchange)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testChinaSSE)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testChinaIB)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testModifiedCalendars)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testJointCalendars)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testBespokeCalendars)); - - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testEndOfMonth)); - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testBusinessDaysBetween)); - - #ifdef QL_HIGH_RESOLUTION_DATE - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testIntradayAddHolidays)); - #endif - suite->add(QUANTLIB_TEST_CASE(&CalendarTest::testDayLists)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/calendars.hpp b/test-suite/calendars.hpp deleted file mode 100644 index 1f75f73eb78..00000000000 --- a/test-suite/calendars.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003, 2004, 2008 StatPro Italia srl - Copyright (C) 2008 Charles Chongseok Hyun - - 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_calendars_hpp -#define quantlib_test_calendars_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CalendarTest { - public: - static void testRussia(); - static void testBrazil(); - static void testItalyExchange(); - - static void testUKSettlement(); - static void testUKExchange(); - static void testUKMetals(); - - static void testGermanyFrankfurt(); - static void testGermanyXetra(); - static void testGermanyEurex(); - - static void testTARGET(); - - static void testDenmark(); - - static void testUSSettlement(); - static void testUSGovernmentBondMarket(); - static void testUSNewYorkStockExchange(); - static void testSOFR(); - - static void testSouthKoreanSettlement(); - static void testKoreaStockExchange(); - - static void testChinaSSE(); - static void testChinaIB(); - - static void testModifiedCalendars(); - static void testJointCalendars(); - static void testBespokeCalendars(); - - static void testEndOfMonth(); - static void testBusinessDaysBetween(); - - static void testIntradayAddHolidays(); - static void testDayLists(); - - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f076a41fe33..bd83948900c 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "calendars.hpp" #include "callablebonds.hpp" #include "capfloor.hpp" #include "capflooredcoupon.hpp" @@ -200,7 +199,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CalendarTest::suite()); test->add(CapFloorTest::suite()); test->add(CapFlooredCouponTest::suite()); test->add(CashFlowsTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 37c8d37c189..25af8b61fa2 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 3c8ce36cae0..594bb12fbf5 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 65effc2467ea82e340639e1fb127e7a485044c01 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 25 Oct 2023 18:07:35 +0800 Subject: [PATCH 025/132] Update Makefile.am --- test-suite/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 93789fb093f..23280621557 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -355,10 +355,7 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - barrieroption.hpp \ doublebarrieroption.hpp \ - basketoption.hpp \ - batesmodel.hpp \ convertiblebonds.hpp \ digitaloption.hpp \ dividendoption.hpp \ From 4c0e4ca6d075967d23129023d88bebed7f25bc8a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 10:10:12 +0800 Subject: [PATCH 026/132] Migrated callablebonds.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/callablebonds.cpp | 43 +++++++++++----------------- test-suite/callablebonds.hpp | 41 -------------------------- test-suite/quantlibglobalfixture.cpp | 3 ++ test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 19 insertions(+), 76 deletions(-) delete mode 100644 test-suite/callablebonds.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 8b687f6945e..99ac62ba39a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - callablebonds.hpp capfloor.hpp capflooredcoupon.hpp cashflows.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 23280621557..e9a0e424a84 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - callablebonds.hpp \ capfloor.hpp \ capflooredcoupon.hpp \ cashflows.hpp \ diff --git a/test-suite/callablebonds.cpp b/test-suite/callablebonds.cpp index 103e07da008..b43e4ff7812 100644 --- a/test-suite/callablebonds.cpp +++ b/test-suite/callablebonds.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "callablebonds.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -94,7 +94,11 @@ namespace { } -void CallableBondTest::testInterplay() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CallableBondExperimentalTest) + +BOOST_AUTO_TEST_CASE(testInterplay) { BOOST_TEST_MESSAGE("Testing interplay of callability and puttability for callable bonds..."); @@ -220,8 +224,7 @@ void CallableBondTest::testInterplay() { << " difference: " << bond.settlementValue()-expected); } - -void CallableBondTest::testConsistency() { +BOOST_AUTO_TEST_CASE(testConsistency) { BOOST_TEST_MESSAGE("Testing consistency of callable bonds..."); @@ -297,8 +300,7 @@ void CallableBondTest::testConsistency() { << " (should be higher)"); } - -void CallableBondTest::testObservability() { +BOOST_AUTO_TEST_CASE(testObservability) { BOOST_TEST_MESSAGE("Testing observability of callable bonds..."); @@ -357,7 +359,7 @@ void CallableBondTest::testObservability() { } -void CallableBondTest::testDegenerate() { +BOOST_AUTO_TEST_CASE(testDegenerate) { BOOST_TEST_MESSAGE("Repricing bonds using degenerate callable bonds..."); @@ -470,7 +472,7 @@ void CallableBondTest::testDegenerate() { << " expected: " << couponBond.cleanPrice()); } -void CallableBondTest::testCached() { +BOOST_AUTO_TEST_CASE(testCached) { BOOST_TEST_MESSAGE("Testing callable-bond value against cached values..."); @@ -569,7 +571,7 @@ void CallableBondTest::testCached() { } -void CallableBondTest::testSnappingExerciseDate2ClosestCouponDate() { +BOOST_AUTO_TEST_CASE(testSnappingExerciseDate2ClosestCouponDate) { BOOST_TEST_MESSAGE("Testing snap of callability dates to the closest coupon date..."); @@ -671,8 +673,7 @@ void CallableBondTest::testSnappingExerciseDate2ClosestCouponDate() { } } - -void CallableBondTest::testBlackEngine() { +BOOST_AUTO_TEST_CASE(testBlackEngine) { BOOST_TEST_MESSAGE("Testing Black engine for European callable bonds..."); @@ -711,8 +712,7 @@ void CallableBondTest::testBlackEngine() { << " difference: " << calculated - expected); } - -void CallableBondTest::testImpliedVol() { +BOOST_AUTO_TEST_CASE(testImpliedVol) { BOOST_TEST_MESSAGE("Testing implied-volatility calculation for callable bonds..."); @@ -807,7 +807,7 @@ void CallableBondTest::testImpliedVol() { << " difference: " << bond.NPV() - targetNPV); } -void CallableBondTest::testCallableFixedRateBondWithArbitrarySchedule() { +BOOST_AUTO_TEST_CASE(testCallableFixedRateBondWithArbitrarySchedule) { BOOST_TEST_MESSAGE("Testing callable fixed-rate bond with arbitrary schedule..."); Globals vars; @@ -848,17 +848,6 @@ void CallableBondTest::testCallableFixedRateBondWithArbitrarySchedule() { BOOST_CHECK_NO_THROW(callableBond.cleanPrice()); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CallableBondTest::suite() { - auto* suite = BOOST_TEST_SUITE("Callable-bond tests"); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testConsistency)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testInterplay)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testObservability)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testDegenerate)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testCached)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testSnappingExerciseDate2ClosestCouponDate)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testBlackEngine)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testImpliedVol)); - suite->add(QUANTLIB_TEST_CASE(&CallableBondTest::testCallableFixedRateBondWithArbitrarySchedule)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/callablebonds.hpp b/test-suite/callablebonds.hpp deleted file mode 100644 index ff39e371b45..00000000000 --- a/test-suite/callablebonds.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2018 StatPro Italia srl - Copyright (C) 2021, 2022 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_callable_bonds_hpp -#define quantlib_test_callable_bonds_hpp - -#include - -class CallableBondTest { - public: - static void testConsistency(); - static void testInterplay(); - static void testObservability(); - static void testDegenerate(); - static void testCached(); - static void testSnappingExerciseDate2ClosestCouponDate(); - static void testBlackEngine(); - static void testImpliedVol(); - static void testCallableFixedRateBondWithArbitrarySchedule(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index c9e9b58947d..e84b6fb4dd7 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -36,8 +36,11 @@ # include #endif +#ifndef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER #define BOOST_TEST_NO_MAIN #define BOOST_TEST_ALTERNATIVE_INIT_API +#endif + #include "quantlibglobalfixture.hpp" #include "speedlevel.hpp" #include diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index bd83948900c..27224ef5c04 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "callablebonds.hpp" #include "capfloor.hpp" #include "capflooredcoupon.hpp" #include "cashflows.hpp" @@ -314,7 +313,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CallableBondTest::suite()); test->add(CatBondTest::suite()); test->add(CdoTest::suite(speed)); test->add(CdsOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 25af8b61fa2..91fe1fd66a9 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 594bb12fbf5..da293bc257b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From ab99be273605fc1d3939283a65d370613b2f3c30 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 10:28:36 +0800 Subject: [PATCH 027/132] Migrated capfloor.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/capfloor.cpp | 42 ++++++++++--------------- test-suite/capfloor.hpp | 46 ---------------------------- test-suite/quantlibbenchmark.cpp | 6 ++++ test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 22 insertions(+), 80 deletions(-) delete mode 100644 test-suite/capfloor.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 99ac62ba39a..3eb62f3c237 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - capfloor.hpp capflooredcoupon.hpp cashflows.hpp catbonds.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e9a0e424a84..211838276c0 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - capfloor.hpp \ capflooredcoupon.hpp \ cashflows.hpp \ catbonds.hpp \ diff --git a/test-suite/capfloor.cpp b/test-suite/capfloor.cpp index 929cafa6242..4fae635e902 100644 --- a/test-suite/capfloor.cpp +++ b/test-suite/capfloor.cpp @@ -19,7 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "capfloor.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -145,8 +145,11 @@ namespace capfloor_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CapFloorTest::testVega() { +BOOST_AUTO_TEST_SUITE(CapFloorTest) + +BOOST_AUTO_TEST_CASE(testVega) { BOOST_TEST_MESSAGE("Testing cap/floor vega..."); @@ -197,7 +200,7 @@ void CapFloorTest::testVega() { } } -void CapFloorTest::testStrikeDependency() { +BOOST_AUTO_TEST_CASE(testStrikeDependency) { BOOST_TEST_MESSAGE("Testing cap/floor dependency on strike..."); @@ -252,7 +255,7 @@ void CapFloorTest::testStrikeDependency() { } } -void CapFloorTest::testConsistency() { +BOOST_AUTO_TEST_CASE(testConsistency) { BOOST_TEST_MESSAGE("Testing consistency between cap, floor and collar..."); @@ -359,7 +362,7 @@ void CapFloorTest::testConsistency() { } } -void CapFloorTest::testParity() { +BOOST_AUTO_TEST_CASE(testParity) { BOOST_TEST_MESSAGE("Testing cap/floor parity..."); @@ -404,7 +407,7 @@ void CapFloorTest::testParity() { } } -void CapFloorTest::testATMRate() { +BOOST_AUTO_TEST_CASE(testATMRate) { BOOST_TEST_MESSAGE("Testing cap/floor ATM rate..."); @@ -462,8 +465,7 @@ void CapFloorTest::testATMRate() { } } - -void CapFloorTest::testImpliedVolatility() { +BOOST_AUTO_TEST_CASE(testImpliedVolatility) { BOOST_TEST_MESSAGE("Testing implied term volatility for cap and floor..."); @@ -548,7 +550,7 @@ void CapFloorTest::testImpliedVolatility() { } } -void CapFloorTest::testCachedValue() { +BOOST_AUTO_TEST_CASE(testCachedValue) { BOOST_TEST_MESSAGE("Testing Black cap/floor price against cached values..."); @@ -594,7 +596,7 @@ void CapFloorTest::testCachedValue() { << " expected: " << cachedFloorNPV); } -void CapFloorTest::testCachedValueFromOptionLets() { +BOOST_AUTO_TEST_CASE(testCachedValueFromOptionLets) { BOOST_TEST_MESSAGE("Testing Black cap/floor price as a sum of optionlets prices against cached values..."); @@ -663,7 +665,7 @@ void CapFloorTest::testCachedValueFromOptionLets() { << " expected: " << cachedFloorNPV); } -void CapFloorTest::testOptionLetsDelta() { +BOOST_AUTO_TEST_CASE(testOptionLetsDelta) { BOOST_TEST_MESSAGE("Testing Black caplet/floorlet delta coefficients against finite difference values..."); @@ -786,7 +788,7 @@ void CapFloorTest::testOptionLetsDelta() { } -void CapFloorTest::testBachelierOptionLetsDelta() { +BOOST_AUTO_TEST_CASE(testBachelierOptionLetsDelta) { BOOST_TEST_MESSAGE("Testing Bachelier caplet/floorlet delta coefficients against finite difference values..."); @@ -912,18 +914,6 @@ void CapFloorTest::testBachelierOptionLetsDelta() { } -test_suite* CapFloorTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cap and floor tests"); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testStrikeDependency)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testConsistency)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testParity)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testVega)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testATMRate)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testImpliedVolatility)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testCachedValue)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testCachedValueFromOptionLets)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testOptionLetsDelta)); - suite->add(QUANTLIB_TEST_CASE(&CapFloorTest::testBachelierOptionLetsDelta)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/capfloor.hpp b/test-suite/capfloor.hpp deleted file mode 100644 index 55498d4d5fd..00000000000 --- a/test-suite/capfloor.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - Copyright (C) 2007 StatPro Italia srl - Copyright (C) 2019 Wojciech Ślusarski - - 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_cap_floor_hpp -#define quantlib_test_cap_floor_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CapFloorTest { - public: - static void testStrikeDependency(); - static void testConsistency(); - static void testParity(); - static void testVega(); - static void testATMRate(); - static void testImpliedVolatility(); - static void testCachedValue(); - static void testCachedValueFromOptionLets(); - static void testOptionLetsDelta(); - static void testBachelierOptionLetsDelta(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 32ddd03c889..1623ad647bf 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -158,22 +158,28 @@ namespace QuantLibTest { struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace AsianOptionTest { struct testMCDiscreteArithmeticAveragePrice: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace BarrierOptionTest { struct testBabsiriValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace BasketOptionTest { struct testEuroTwoValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testTavellaValues: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testOddSamples: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + namespace BatesModelTest { struct testDAXCalibration: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 27224ef5c04..2e6b044d198 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "capfloor.hpp" #include "capflooredcoupon.hpp" #include "cashflows.hpp" #include "catbonds.hpp" @@ -198,7 +197,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CapFloorTest::suite()); test->add(CapFlooredCouponTest::suite()); test->add(CashFlowsTest::suite()); test->add(ChooserOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 91fe1fd66a9..f6464aad841 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 da293bc257b..8e76bb62fa9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 6268784b4a5a1a4dc3ed9b62d11a5d931c7e1090 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 14:12:47 +0800 Subject: [PATCH 028/132] Migrated capflooredcoupon.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/capflooredcoupon.cpp | 18 +++++++------- test-suite/capflooredcoupon.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/capflooredcoupon.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 3eb62f3c237..7bf0778164a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - capflooredcoupon.hpp cashflows.hpp catbonds.hpp cdo.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 211838276c0..71085bdf847 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - capflooredcoupon.hpp \ cashflows.hpp \ catbonds.hpp \ cdo.hpp \ diff --git a/test-suite/capflooredcoupon.cpp b/test-suite/capflooredcoupon.cpp index b780fe0a02d..a95a502913e 100644 --- a/test-suite/capflooredcoupon.cpp +++ b/test-suite/capflooredcoupon.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "capflooredcoupon.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -185,8 +185,11 @@ namespace capfloored_coupon_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CapFlooredCouponTest::testLargeRates() { +BOOST_AUTO_TEST_SUITE(CapFlooredCouponTest) + +BOOST_AUTO_TEST_CASE(testLargeRates) { BOOST_TEST_MESSAGE("Testing degenerate collared coupon..."); @@ -232,7 +235,7 @@ void CapFlooredCouponTest::testLargeRates() { } } -void CapFlooredCouponTest::testDecomposition() { +BOOST_AUTO_TEST_CASE(testDecomposition) { BOOST_TEST_MESSAGE("Testing collared coupon against its decomposition..."); @@ -544,10 +547,7 @@ void CapFlooredCouponTest::testDecomposition() { } } -test_suite* CapFlooredCouponTest::suite() { - auto* suite = BOOST_TEST_SUITE("Capped and floored coupon tests"); - suite->add(QUANTLIB_TEST_CASE(&CapFlooredCouponTest::testLargeRates)); - suite->add(QUANTLIB_TEST_CASE(&CapFlooredCouponTest::testDecomposition)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/capflooredcoupon.hpp b/test-suite/capflooredcoupon.hpp deleted file mode 100644 index 7a98db04b3d..00000000000 --- a/test-suite/capflooredcoupon.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006 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_cap_floored_coupon_hpp -#define quantlib_test_cap_floored_coupon_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CapFlooredCouponTest { - public: - static void testLargeRates(); - static void testDecomposition(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2e6b044d198..d09f96cdba7 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "capflooredcoupon.hpp" #include "cashflows.hpp" #include "catbonds.hpp" #include "cdo.hpp" @@ -197,7 +196,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CapFlooredCouponTest::suite()); test->add(CashFlowsTest::suite()); test->add(ChooserOptionTest::suite()); test->add(CliquetOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f6464aad841..1084ee6dbf1 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 8e76bb62fa9..0981f716e7e 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From b6dc49b55395dd162bff974801051e4e638ba0b4 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 15:35:24 +0800 Subject: [PATCH 029/132] Migrated cashflows.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cashflows.cpp | 52 ++++++++++++++-------------- test-suite/cashflows.hpp | 40 --------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 26 insertions(+), 74 deletions(-) delete mode 100644 test-suite/cashflows.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 7bf0778164a..81c3ee03deb 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cashflows.hpp catbonds.hpp cdo.hpp cdsoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 71085bdf847..c13837900eb 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cashflows.hpp \ catbonds.hpp \ cdo.hpp \ cdsoption.hpp \ diff --git a/test-suite/cashflows.cpp b/test-suite/cashflows.cpp index f130ae65800..f4a915c7c0a 100644 --- a/test-suite/cashflows.cpp +++ b/test-suite/cashflows.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cashflows.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -41,7 +41,21 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CashFlowsTest::testSettings() { +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) + +BOOST_AUTO_TEST_CASE(testSettings) { BOOST_TEST_MESSAGE("Testing cash-flow settings..."); @@ -174,7 +188,7 @@ void CashFlowsTest::testSettings() { } -void CashFlowsTest::testAccessViolation() { +BOOST_AUTO_TEST_CASE(testAccessViolation) { BOOST_TEST_MESSAGE("Testing dynamic cast of coupon in Black pricer..."); Date todaysDate(7, April, 2010); @@ -217,7 +231,7 @@ void CashFlowsTest::testAccessViolation() { } } -void CashFlowsTest::testDefaultSettlementDate() { +BOOST_AUTO_TEST_CASE(testDefaultSettlementDate) { BOOST_TEST_MESSAGE("Testing default evaluation date in cashflows methods..."); Date today = Settings::instance().evaluationDate(); Schedule schedule = @@ -247,7 +261,7 @@ void CashFlowsTest::testDefaultSettlementDate() { BOOST_ERROR("null accrued amount with default settlement date"); } -void CashFlowsTest::testNullFixingDays() { +BOOST_AUTO_TEST_CASE(testNullFixingDays, *precondition(usingAtParCoupons())) { BOOST_TEST_MESSAGE("Testing ibor leg construction with null fixing days..."); Date today = Settings::instance().evaluationDate(); Schedule schedule = @@ -266,7 +280,7 @@ void CashFlowsTest::testNullFixingDays() { .withFixingDays(Null()); } -void CashFlowsTest::testExCouponDates() { +BOOST_AUTO_TEST_CASE(testExCouponDates) { BOOST_TEST_MESSAGE("Testing ex-coupon date calculation..."); Date today = Date::todaysDate(); @@ -349,7 +363,7 @@ void CashFlowsTest::testExCouponDates() { } } -void CashFlowsTest::testIrregularFirstCouponReferenceDatesAtEndOfMonth() { +BOOST_AUTO_TEST_CASE(testIrregularFirstCouponReferenceDatesAtEndOfMonth) { BOOST_TEST_MESSAGE("Testing irregular first coupon reference dates with end of month enabled..."); Schedule schedule = MakeSchedule() @@ -371,7 +385,7 @@ void CashFlowsTest::testIrregularFirstCouponReferenceDatesAtEndOfMonth() { "got " << firstCoupon->referencePeriodStart()); } -void CashFlowsTest::testIrregularLastCouponReferenceDatesAtEndOfMonth() { +BOOST_AUTO_TEST_CASE(testIrregularLastCouponReferenceDatesAtEndOfMonth) { BOOST_TEST_MESSAGE("Testing irregular last coupon reference dates with end of month enabled..."); Schedule schedule = MakeSchedule() @@ -394,7 +408,7 @@ void CashFlowsTest::testIrregularLastCouponReferenceDatesAtEndOfMonth() { "got " << lastCoupon->referencePeriodEnd()); } -void CashFlowsTest::testPartialScheduleLegConstruction() { +BOOST_AUTO_TEST_CASE(testPartialScheduleLegConstruction) { BOOST_TEST_MESSAGE("Testing leg construction with partial schedule..."); // schedule with irregular first and last period Schedule schedule = MakeSchedule() @@ -502,7 +516,7 @@ void CashFlowsTest::testPartialScheduleLegConstruction() { BOOST_CHECK_EQUAL(lastCpnF3->referencePeriodEnd(), Date(30, Sep, 2020)); } -void CashFlowsTest::testFixedIborCouponWithoutForecastCurve() { +BOOST_AUTO_TEST_CASE(testFixedIborCouponWithoutForecastCurve) { BOOST_TEST_MESSAGE("Testing past ibor coupon without forecast curve..."); Date today = Settings::instance().evaluationDate(); @@ -532,20 +546,6 @@ void CashFlowsTest::testFixedIborCouponWithoutForecastCurve() { } } -test_suite* CashFlowsTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cash flows tests"); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testSettings)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testAccessViolation)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testDefaultSettlementDate)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testExCouponDates)); - - if (IborCoupon::Settings::instance().usingAtParCoupons()) - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testNullFixingDays)); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testIrregularFirstCouponReferenceDatesAtEndOfMonth)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testIrregularLastCouponReferenceDatesAtEndOfMonth)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testPartialScheduleLegConstruction)); - suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testFixedIborCouponWithoutForecastCurve)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/cashflows.hpp b/test-suite/cashflows.hpp deleted file mode 100644 index 345639a5fee..00000000000 --- a/test-suite/cashflows.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2009, 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_cashflows_hpp -#define quantlib_test_cashflows_hpp - -#include - -class CashFlowsTest { - public: - static void testSettings(); - static void testAccessViolation(); - static void testDefaultSettlementDate(); - static void testExCouponDates(); - static void testNullFixingDays(); - static void testIrregularFirstCouponReferenceDatesAtEndOfMonth(); - static void testIrregularLastCouponReferenceDatesAtEndOfMonth(); - static void testPartialScheduleLegConstruction(); - static void testFixedIborCouponWithoutForecastCurve(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index d09f96cdba7..be215d4334c 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cashflows.hpp" #include "catbonds.hpp" #include "cdo.hpp" #include "cdsoption.hpp" @@ -196,7 +195,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CashFlowsTest::suite()); test->add(ChooserOptionTest::suite()); test->add(CliquetOptionTest::suite()); test->add(CmsTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 1084ee6dbf1..b3f277bb2ff 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 0981f716e7e..9914047d03a 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 2eab08d6ee47b0f17e0f50abcdb88a9e6f4c43cf Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 15:44:20 +0800 Subject: [PATCH 030/132] Migrated catbonds.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/catbonds.cpp | 80 +++++++++++----------------- test-suite/catbonds.hpp | 39 -------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 32 insertions(+), 95 deletions(-) delete mode 100644 test-suite/catbonds.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 81c3ee03deb..9b0d715c8b3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - catbonds.hpp cdo.hpp cdsoption.hpp chooseroption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c13837900eb..7d1ba878175 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - catbonds.hpp \ cdo.hpp \ cdsoption.hpp \ chooseroption.hpp \ diff --git a/test-suite/catbonds.cpp b/test-suite/catbonds.cpp index 079c4d79d5f..aed9fbde849 100644 --- a/test-suite/catbonds.cpp +++ b/test-suite/catbonds.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "catbonds.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -54,9 +54,28 @@ namespace catbonds_test { Date eventsStart(1, January, 2011); Date eventsEnd(31, December, 2014); + + struct CommonVars { + // common data + Calendar calendar; + Date today; + Real faceAmount; + + // setup + CommonVars() { + calendar = TARGET(); + today = calendar.adjust(Date::todaysDate()); + Settings::instance().evaluationDate() = today; + faceAmount = 1000000.0; + } + }; } -void CatBondTest::testEventSetForWholeYears() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CatBondExperimentaltest) + +BOOST_AUTO_TEST_CASE(testEventSetForWholeYears) { BOOST_TEST_MESSAGE("Testing that catastrophe events are split correctly for periods of whole years..."); using namespace catbonds_test; @@ -89,8 +108,7 @@ void CatBondTest::testEventSetForWholeYears() { BOOST_REQUIRE(!simulation->nextPath(path)); } - -void CatBondTest::testEventSetForIrregularPeriods() { +BOOST_AUTO_TEST_CASE(testEventSetForIrregularPeriods) { BOOST_TEST_MESSAGE("Testing that catastrophe events are split correctly for irregular periods..."); using namespace catbonds_test; @@ -115,8 +133,7 @@ void CatBondTest::testEventSetForIrregularPeriods() { BOOST_REQUIRE(!simulation->nextPath(path)); } - -void CatBondTest::testEventSetForNoEvents () { +BOOST_AUTO_TEST_CASE(testEventSetForNoEvents) { BOOST_TEST_MESSAGE("Testing that catastrophe events are split correctly when there are no simulated events..."); using namespace catbonds_test; @@ -138,7 +155,7 @@ void CatBondTest::testEventSetForNoEvents () { BOOST_REQUIRE(!simulation->nextPath(path)); } -void CatBondTest::testBetaRisk() { +BOOST_AUTO_TEST_CASE(testBetaRisk) { BOOST_TEST_MESSAGE("Testing that beta risk gives correct terminal distribution..."); const size_t PATHS = 1000000; @@ -187,25 +204,7 @@ void CatBondTest::testBetaRisk() { #endif } -namespace catbonds_test { - - struct CommonVars { - // common data - Calendar calendar; - Date today; - Real faceAmount; - - // setup - CommonVars() { - calendar = TARGET(); - today = calendar.adjust(Date::todaysDate()); - Settings::instance().evaluationDate() = today; - faceAmount = 1000000.0; - } - }; -} - -void CatBondTest::testRiskFreeAgainstFloatingRateBond() { +BOOST_AUTO_TEST_CASE(testRiskFreeAgainstFloatingRateBond) { BOOST_TEST_MESSAGE("Testing floating-rate cat bond against risk-free floating-rate bond..."); using namespace catbonds_test; @@ -373,9 +372,7 @@ void CatBondTest::testRiskFreeAgainstFloatingRateBond() { } } - - -void CatBondTest::testCatBondInDoomScenario() { +BOOST_AUTO_TEST_CASE(testCatBondInDoomScenario) { BOOST_TEST_MESSAGE("Testing floating-rate cat bond in a doom scenario (certain default)..."); using namespace catbonds_test; @@ -439,8 +436,7 @@ void CatBondTest::testCatBondInDoomScenario() { QL_CHECK_CLOSE(Real(1.0), expectedLoss, tolerance); } - -void CatBondTest::testCatBondWithDoomOnceInTenYears() { +BOOST_AUTO_TEST_CASE(testCatBondWithDoomOnceInTenYears) { BOOST_TEST_MESSAGE("Testing floating-rate cat bond in a doom once in 10 years scenario..."); using namespace catbonds_test; @@ -523,7 +519,7 @@ void CatBondTest::testCatBondWithDoomOnceInTenYears() { BOOST_CHECK_LT(riskFreeYield, yield); } -void CatBondTest::testCatBondWithDoomOnceInTenYearsProportional() { +BOOST_AUTO_TEST_CASE(testCatBondWithDoomOnceInTenYearsProportional) { BOOST_TEST_MESSAGE("Testing floating-rate cat bond in a doom once in 10 years scenario with proportional notional reduction..."); using namespace catbonds_test; @@ -604,8 +600,7 @@ void CatBondTest::testCatBondWithDoomOnceInTenYearsProportional() { BOOST_CHECK_LT(riskFreeYield, yield); } - -void CatBondTest::testCatBondWithGeneratedEventsProportional() { +BOOST_AUTO_TEST_CASE(testCatBondWithGeneratedEventsProportional) { BOOST_TEST_MESSAGE("Testing floating-rate cat bond in a generated scenario with proportional notional reduction..."); using namespace catbonds_test; @@ -682,17 +677,6 @@ void CatBondTest::testCatBondWithGeneratedEventsProportional() { BOOST_CHECK_LT(riskFreeYield, yield); } -test_suite* CatBondTest::suite() { - auto* suite = BOOST_TEST_SUITE("CatBond tests"); - - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testEventSetForWholeYears)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testEventSetForIrregularPeriods)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testEventSetForNoEvents)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testBetaRisk)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testRiskFreeAgainstFloatingRateBond)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testCatBondInDoomScenario)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testCatBondWithDoomOnceInTenYears)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testCatBondWithDoomOnceInTenYearsProportional)); - suite->add(QUANTLIB_TEST_CASE(&CatBondTest::testCatBondWithGeneratedEventsProportional)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/catbonds.hpp b/test-suite/catbonds.hpp deleted file mode 100644 index da2c9518a03..00000000000 --- a/test-suite/catbonds.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2012, 2013 Grzegorz Andruszkiewicz - - 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_catbond_hpp -#define quantlib_test_catbond_hpp - -#include - -class CatBondTest { - public: - static void testEventSetForWholeYears(); - static void testEventSetForIrregularPeriods(); - static void testEventSetForNoEvents(); - static void testBetaRisk(); - static void testRiskFreeAgainstFloatingRateBond(); - static void testCatBondInDoomScenario(); - static void testCatBondWithDoomOnceInTenYears(); - static void testCatBondWithDoomOnceInTenYearsProportional(); - static void testCatBondWithGeneratedEventsProportional(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index be215d4334c..2e3c09d847b 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "catbonds.hpp" #include "cdo.hpp" #include "cdsoption.hpp" #include "chooseroption.hpp" @@ -307,7 +306,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CatBondTest::suite()); test->add(CdoTest::suite(speed)); test->add(CdsOptionTest::suite()); test->add(CmsSpreadTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b3f277bb2ff..b12ca2fb537 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 9914047d03a..505de68809b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d46936e509cb4443acd715ba67cbccd9c216aec5 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 15:59:11 +0800 Subject: [PATCH 031/132] Migrated cdo.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cdo.cpp | 534 +++++++++++++-------------- test-suite/cdo.hpp | 36 -- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 254 insertions(+), 324 deletions(-) delete mode 100644 test-suite/cdo.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9b0d715c8b3..6aa672bf25a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cdo.hpp cdsoption.hpp chooseroption.hpp cliquetoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7d1ba878175..97274928d65 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cdo.hpp \ cdsoption.hpp \ chooseroption.hpp \ cliquetoption.hpp \ diff --git a/test-suite/cdo.cpp b/test-suite/cdo.cpp index 64eadd2067b..239194cdcf3 100644 --- a/test-suite/cdo.cpp +++ b/test-suite/cdo.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cdo.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -90,290 +91,263 @@ namespace cdo_test { #endif +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CdoTest::testHW(unsigned dataSet) { - #ifndef QL_PATCH_SOLARIS - - BOOST_TEST_MESSAGE ("Testing CDO premiums against Hull-White values" - " for data set " << dataSet << "..."); - - using namespace cdo_test; - - Size poolSize = 100; - Real lambda = 0.01; - - // nBuckets and period determine the computation time - Size nBuckets = 200; - // Period period = 1*Months; - // for MC engines - Size numSims = 5000; - - Real rate = 0.05; - DayCounter daycount = Actual360(); - Compounding cmp = Continuous; // Simple; - - Real recovery = 0.4; - std::vector nominals(poolSize, 100.0); - Real premium = 0.02; - Period maxTerm (5, Years); - Schedule schedule = MakeSchedule().from(Date (1, September, 2006)) - .to(Date (1, September, 2011)) - .withTenor(Period (3, Months)) - .withCalendar(TARGET()); - - Date asofDate = Date(31, August, 2006); - - Settings::instance().evaluationDate() = asofDate; - - ext::shared_ptr yieldPtr( - new FlatForward (asofDate, rate, - daycount, cmp)); - Handle yieldHandle (yieldPtr); - - Handle hazardRate(ext::shared_ptr(new SimpleQuote(lambda))); - std::vector > basket; - ext::shared_ptr ptr ( - new FlatHazardRate (asofDate, - hazardRate, - ActualActual(ActualActual::ISDA))); - ext::shared_ptr pool (new Pool()); - std::vector names; - // probability key items - std::vector issuers; - std::vector > > probabilities; - probabilities.emplace_back( - NorthAmericaCorpDefaultKey(EURCurrency(), SeniorSec, Period(0, Weeks), 10.), - Handle(ptr)); - - for (Size i=0; iadd(names.back(), issuers.back(), NorthAmericaCorpDefaultKey( - EURCurrency(), QuantLib::SeniorSec, Period(), 1.)); - } +BOOST_AUTO_TEST_SUITE(CdoExperimentalTest) - ext::shared_ptr correlation (new SimpleQuote(0.0)); - Handle hCorrelation (correlation); - QL_REQUIRE (LENGTH(hwAttachment) == LENGTH(hwDetachment), - "data length does not match"); - - ext::shared_ptr midPCDOEngine( new MidPointCDOEngine( - yieldHandle)); - ext::shared_ptr integralCDOEngine( new IntegralCDOEngine( - yieldHandle)); - - const Size i = dataSet; - correlation->setValue (hwData7[i].correlation); - QL_REQUIRE (LENGTH(hwAttachment) == LENGTH(hwData7[i].trancheSpread), - "data length does not match"); - std::vector > basketModels; - std::vector modelNames; - std::vector relativeToleranceMidp, relativeTolerancePeriod, - absoluteTolerance; - - if (hwData7[i].nm == -1 && hwData7[i].nz == -1){ - ext::shared_ptr gaussKtLossLM(new - GaussianConstantLossLM(hCorrelation, - std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, poolSize, - GaussianCopulaPolicy::initTraits())); - - // 1.-Inhomogeneous gaussian - modelNames.emplace_back("Inhomogeneous gaussian"); - basketModels.push_back(ext::shared_ptr( new - IHGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous gaussian - modelNames.emplace_back("Homogeneous gaussian"); - basketModels.push_back(ext::shared_ptr( new - HomogGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default gaussian - modelNames.emplace_back("Random default gaussian"); - basketModels.push_back(ext::shared_ptr(new - RandomDefaultLM(gaussKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // gaussian LHP - modelNames.emplace_back("Gaussian LHP"); - basketModels.push_back(ext::shared_ptr(new - GaussianLHPLossModel(hCorrelation, - std::vector(poolSize, recovery)))); - absoluteTolerance.push_back(10.); - relativeToleranceMidp.push_back(0.5); - relativeTolerancePeriod.push_back(0.5); - // Binomial... - // Saddle point... - // Recursive ... - } - else if (hwData7[i].nm > 0 && hwData7[i].nz > 0) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(hwData7[i].nm); - initTG.tOrders.push_back(hwData7[i].nz); - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, - poolSize, - initTG)); - // 1.-inhomogeneous studentT - modelNames.emplace_back("Inhomogeneous student"); - basketModels.push_back(ext::shared_ptr( new - IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous student T - modelNames.emplace_back("Homogeneous student"); - basketModels.push_back(ext::shared_ptr( new - HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default student T - modelNames.emplace_back("Random default studentT"); - basketModels.push_back(ext::shared_ptr(new - RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } - else if (hwData7[i].nm > 0 && hwData7[i].nz == -1) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(hwData7[i].nm); - initTG.tOrders.push_back(45); - /* T_{55} is pretty close to a gaussian. Probably theres no need to - be this conservative as the polynomial convolution gets shorter and - faster as the order decreases. - */ - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, - std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, - poolSize, - initTG)); - // 1.-inhomogeneous - modelNames.emplace_back("Inhomogeneous student-gaussian"); - basketModels.push_back(ext::shared_ptr( new - IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous - modelNames.emplace_back("Homogeneous student-gaussian"); - basketModels.push_back(ext::shared_ptr( new - HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default - modelNames.emplace_back("Random default student-gaussian"); - basketModels.push_back(ext::shared_ptr(new - RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } - else if (hwData7[i].nm == -1 && hwData7[i].nz > 0) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(45);// pretty close to gaussian - initTG.tOrders.push_back(hwData7[i].nz); - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, - std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, - poolSize, - initTG)); - // 1.-inhomogeneous gaussian - modelNames.emplace_back("Inhomogeneous gaussian-student"); - basketModels.push_back(ext::shared_ptr( new - IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous gaussian - modelNames.emplace_back("Homogeneous gaussian-student"); - basketModels.push_back(ext::shared_ptr( new - HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default gaussian - modelNames.emplace_back("Random default gaussian-student"); - basketModels.push_back(ext::shared_ptr(new - RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } - else { - return; - } +#ifndef QL_PATCH_SOLARIS - for (Size j = 0; j < LENGTH(hwAttachment); j ++) { - ext::shared_ptr basketPtr ( - new Basket(asofDate, names, nominals, pool, - hwAttachment[j], hwDetachment[j])); - std::ostringstream trancheId; - trancheId << "[" << hwAttachment[j] << " , " << hwDetachment[j] - << "]"; - SyntheticCDO cdoe(basketPtr, Protection::Seller, - schedule, 0.0, premium, daycount, Following); - - for(Size im=0; imsetLossModel(basketModels[im]); - - cdoe.setPricingEngine(midPCDOEngine); - check(i, j, modelNames[im] - +std::string(" with midp integration on ")+trancheId.str(), - cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], - absoluteTolerance[im], relativeToleranceMidp[im]); - - cdoe.setPricingEngine(integralCDOEngine); - check(i, j, modelNames[im] - +std::string(" with step integration on ")+trancheId.str(), - cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], - absoluteTolerance[im], relativeTolerancePeriod[im]); +BOOST_AUTO_TEST_CASE(testHW) { + + for (int dataSet{0}; dataSet < 5; dataSet++) { + + BOOST_TEST_MESSAGE("Testing CDO premiums against Hull-White values" + " for data set " + << dataSet << "..."); + + using namespace cdo_test; + + Size poolSize = 100; + Real lambda = 0.01; + + // nBuckets and period determine the computation time + Size nBuckets = 200; + // Period period = 1*Months; + // for MC engines + Size numSims = 5000; + + Real rate = 0.05; + DayCounter daycount = Actual360(); + Compounding cmp = Continuous; // Simple; + + Real recovery = 0.4; + std::vector nominals(poolSize, 100.0); + Real premium = 0.02; + Period maxTerm(5, Years); + Schedule schedule = MakeSchedule() + .from(Date(1, September, 2006)) + .to(Date(1, September, 2011)) + .withTenor(Period(3, Months)) + .withCalendar(TARGET()); + + Date asofDate = Date(31, August, 2006); + + Settings::instance().evaluationDate() = asofDate; + + ext::shared_ptr yieldPtr( + new FlatForward(asofDate, rate, daycount, cmp)); + Handle yieldHandle(yieldPtr); + + Handle hazardRate(ext::shared_ptr(new SimpleQuote(lambda))); + std::vector> basket; + ext::shared_ptr ptr( + new FlatHazardRate(asofDate, hazardRate, ActualActual(ActualActual::ISDA))); + ext::shared_ptr pool(new Pool()); + std::vector names; + // probability key items + std::vector issuers; + std::vector>> + probabilities; + probabilities.emplace_back( + NorthAmericaCorpDefaultKey(EURCurrency(), SeniorSec, Period(0, Weeks), 10.), + Handle(ptr)); + + for (Size i = 0; i < poolSize; ++i) { + std::ostringstream o; + o << "issuer-" << i; + names.push_back(o.str()); + basket.emplace_back(ptr); + issuers.emplace_back(probabilities); + pool->add(names.back(), issuers.back(), + NorthAmericaCorpDefaultKey(EURCurrency(), QuantLib::SeniorSec, Period(), 1.)); } - } - #endif -} + ext::shared_ptr correlation(new SimpleQuote(0.0)); + Handle hCorrelation(correlation); + QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwDetachment), "data length does not match"); + + ext::shared_ptr midPCDOEngine(new MidPointCDOEngine(yieldHandle)); + ext::shared_ptr integralCDOEngine(new IntegralCDOEngine(yieldHandle)); + + const Size i = dataSet; + correlation->setValue(hwData7[i].correlation); + QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwData7[i].trancheSpread), + "data length does not match"); + std::vector> basketModels; + std::vector modelNames; + std::vector relativeToleranceMidp, relativeTolerancePeriod, absoluteTolerance; + + if (hwData7[i].nm == -1 && hwData7[i].nz == -1) { + ext::shared_ptr gaussKtLossLM( + new GaussianConstantLossLM(hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, + GaussianCopulaPolicy::initTraits())); + + // 1.-Inhomogeneous gaussian + modelNames.emplace_back("Inhomogeneous gaussian"); + basketModels.push_back(ext::shared_ptr( + new IHGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous gaussian + modelNames.emplace_back("Homogeneous gaussian"); + basketModels.push_back(ext::shared_ptr( + new HomogGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default gaussian + modelNames.emplace_back("Random default gaussian"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(gaussKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // gaussian LHP + modelNames.emplace_back("Gaussian LHP"); + basketModels.push_back(ext::shared_ptr( + new GaussianLHPLossModel(hCorrelation, std::vector(poolSize, recovery)))); + absoluteTolerance.push_back(10.); + relativeToleranceMidp.push_back(0.5); + relativeTolerancePeriod.push_back(0.5); + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm > 0 && hwData7[i].nz > 0) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(hwData7[i].nm); + initTG.tOrders.push_back(hwData7[i].nz); + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous studentT + modelNames.emplace_back("Inhomogeneous student"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous student T + modelNames.emplace_back("Homogeneous student"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default student T + modelNames.emplace_back("Random default studentT"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm > 0 && hwData7[i].nz == -1) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(hwData7[i].nm); + initTG.tOrders.push_back(45); + /* T_{55} is pretty close to a gaussian. Probably theres no need to + be this conservative as the polynomial convolution gets shorter and + faster as the order decreases. + */ + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous + modelNames.emplace_back("Inhomogeneous student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous + modelNames.emplace_back("Homogeneous student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default + modelNames.emplace_back("Random default student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm == -1 && hwData7[i].nz > 0) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(45); // pretty close to gaussian + initTG.tOrders.push_back(hwData7[i].nz); + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous gaussian + modelNames.emplace_back("Inhomogeneous gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous gaussian + modelNames.emplace_back("Homogeneous gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default gaussian + modelNames.emplace_back("Random default gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else { + return; + } -test_suite* CdoTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("CDO tests"); - - #ifndef QL_PATCH_SOLARIS - if (speed == Slow) { - // unrolled to get different test names - suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(0); })); - suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(1); })); - suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(2); })); - suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(3); })); - suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(4); })); + for (Size j = 0; j < LENGTH(hwAttachment); j++) { + ext::shared_ptr basketPtr( + new Basket(asofDate, names, nominals, pool, hwAttachment[j], hwDetachment[j])); + std::ostringstream trancheId; + trancheId << "[" << hwAttachment[j] << " , " << hwDetachment[j] << "]"; + SyntheticCDO cdoe(basketPtr, Protection::Seller, schedule, 0.0, premium, daycount, + Following); + + for (Size im = 0; im < basketModels.size(); im++) { + + basketPtr->setLossModel(basketModels[im]); + + cdoe.setPricingEngine(midPCDOEngine); + check(i, j, + modelNames[im] + std::string(" with midp integration on ") + trancheId.str(), + cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], + relativeToleranceMidp[im]); + + cdoe.setPricingEngine(integralCDOEngine); + check(i, j, + modelNames[im] + std::string(" with step integration on ") + trancheId.str(), + cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], + relativeTolerancePeriod[im]); + } + } } - #endif - return suite; } +#endif + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/cdo.hpp b/test-suite/cdo.hpp deleted file mode 100644 index ec2c7558e77..00000000000 --- a/test-suite/cdo.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_cdo_hpp -#define quantlib_test_cdo_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CdoTest { - public: - static void testHW(unsigned dataSet); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2e3c09d847b..9ac2011ba6f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cdo.hpp" #include "cdsoption.hpp" #include "chooseroption.hpp" #include "cliquetoption.hpp" @@ -306,7 +305,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CdoTest::suite(speed)); test->add(CdsOptionTest::suite()); test->add(CmsSpreadTest::suite()); test->add(CommodityUnitOfMeasureTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b12ca2fb537..0cc9659958a 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 505de68809b..2742794fb9e 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From da5627f687af4bd895d30be512b67789600d4d83 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 16:05:51 +0800 Subject: [PATCH 032/132] Migrated cdsoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cdsoption.cpp | 15 ++++++------ test-suite/cdsoption.hpp | 35 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 test-suite/cdsoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 6aa672bf25a..8baf49e5e42 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cdsoption.hpp chooseroption.hpp cliquetoption.hpp cms.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 97274928d65..3e5a5e4d352 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cdsoption.hpp \ chooseroption.hpp \ cliquetoption.hpp \ cms.hpp \ diff --git a/test-suite/cdsoption.cpp b/test-suite/cdsoption.cpp index 8847a559f1e..889b3edf365 100644 --- a/test-suite/cdsoption.cpp +++ b/test-suite/cdsoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cdsoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -34,7 +34,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CdsOptionTest::testCached() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CdsOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testCached) { BOOST_TEST_MESSAGE("Testing CDS-option value against cached values..."); @@ -112,9 +116,6 @@ void CdsOptionTest::testCached() { << " expected: " << cachedValue); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CdsOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("range-accrual-swap tests"); - suite->add(QUANTLIB_TEST_CASE(&CdsOptionTest::testCached)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/cdsoption.hpp b/test-suite/cdsoption.hpp deleted file mode 100644 index 3ee68687df1..00000000000 --- a/test-suite/cdsoption.hpp +++ /dev/null @@ -1,35 +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_cds_option_hpp -#define quantlib_test_cds_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CdsOptionTest { - 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 9ac2011ba6f..693e598eb86 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cdsoption.hpp" #include "chooseroption.hpp" #include "cliquetoption.hpp" #include "cms.hpp" @@ -305,7 +304,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CdsOptionTest::suite()); test->add(CmsSpreadTest::suite()); test->add(CommodityUnitOfMeasureTest::suite()); test->add(CompiledBoostVersionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0cc9659958a..fceb378ac90 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 2742794fb9e..257df13b336 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From dde5d43b63916d2643530a9e9a8e784eb7369384 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 16:49:40 +0800 Subject: [PATCH 033/132] Migrated chooseroption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/chooseroption.cpp | 21 +++++++----------- test-suite/chooseroption.hpp | 32 ---------------------------- 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/chooseroption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 8baf49e5e42..d3a23546bae 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - chooseroption.hpp cliquetoption.hpp cms.hpp cms_normal.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 3e5a5e4d352..1e2237fca47 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - chooseroption.hpp \ cliquetoption.hpp \ cms.hpp \ cms_normal.hpp \ diff --git a/test-suite/chooseroption.cpp b/test-suite/chooseroption.cpp index 98777822de0..ff513066121 100644 --- a/test-suite/chooseroption.cpp +++ b/test-suite/chooseroption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "chooseroption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -49,8 +49,11 @@ using namespace boost::unit_test_framework; << "\n" \ << " tolerance: " << tolerance); +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void ChooserOptionTest::testAnalyticSimpleChooserEngine(){ +BOOST_AUTO_TEST_SUITE(ChooserOptionTest) + +BOOST_AUTO_TEST_CASE(testAnalyticSimpleChooserEngine){ BOOST_TEST_MESSAGE("Testing analytic simple chooser option..."); @@ -101,8 +104,7 @@ void ChooserOptionTest::testAnalyticSimpleChooserEngine(){ } - -void ChooserOptionTest::testAnalyticComplexChooserEngine(){ +BOOST_AUTO_TEST_CASE(testAnalyticComplexChooserEngine){ BOOST_TEST_MESSAGE("Testing analytic complex chooser option..."); /* The example below is from @@ -156,13 +158,6 @@ void ChooserOptionTest::testAnalyticComplexChooserEngine(){ } } -test_suite* ChooserOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Chooser option tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE( - &ChooserOptionTest::testAnalyticSimpleChooserEngine)); - suite->add(QUANTLIB_TEST_CASE( - &ChooserOptionTest::testAnalyticComplexChooserEngine)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/chooseroption.hpp b/test-suite/chooseroption.hpp deleted file mode 100644 index 3bcb5da21ec..00000000000 --- a/test-suite/chooseroption.hpp +++ /dev/null @@ -1,32 +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_chooser_option_hpp -#define quantlib_test_chooser_option_hpp - -#include - -class ChooserOptionTest{ - public: - static void testAnalyticSimpleChooserEngine(); - static void testAnalyticComplexChooserEngine(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 693e598eb86..65cd874c62b 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "chooseroption.hpp" #include "cliquetoption.hpp" #include "cms.hpp" #include "cms_normal.hpp" @@ -192,7 +191,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(ChooserOptionTest::suite()); test->add(CliquetOptionTest::suite()); test->add(CmsTest::suite()); test->add(CmsNormalTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index fceb378ac90..6b3b785fdb3 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 257df13b336..0f6892b2478 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From cdcf9b3931eecb1634c371456326228b0cb5b161 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 16:52:31 +0800 Subject: [PATCH 034/132] Migrated cliquetoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cliquetoption.cpp | 27 ++++++++------------ test-suite/cliquetoption.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 63 deletions(-) delete mode 100644 test-suite/cliquetoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d3a23546bae..1cff6925e3b 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cliquetoption.hpp cms.hpp cms_normal.hpp cmsspread.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1e2237fca47..8ce8b5df9e4 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cliquetoption.hpp \ cms.hpp \ cms_normal.hpp \ cmsspread.hpp \ diff --git a/test-suite/cliquetoption.cpp b/test-suite/cliquetoption.cpp index 9081391fd20..fa7b0317931 100644 --- a/test-suite/cliquetoption.cpp +++ b/test-suite/cliquetoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cliquetoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -50,8 +50,11 @@ using namespace boost::unit_test_framework; << " error: " << error << "\n" \ << " tolerance: " << tolerance); +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CliquetOptionTest::testValues() { +BOOST_AUTO_TEST_SUITE(CliquetOptionTest) + +BOOST_AUTO_TEST_CASE(testValues) { BOOST_TEST_MESSAGE("Testing Cliquet option values..."); @@ -252,20 +255,17 @@ namespace { } - -void CliquetOptionTest::testGreeks() { +BOOST_AUTO_TEST_CASE(testGreeks) { BOOST_TEST_MESSAGE("Testing Cliquet option greeks..."); testOptionGreeks(); } - -void CliquetOptionTest::testPerformanceGreeks() { +BOOST_AUTO_TEST_CASE(testPerformanceGreeks) { BOOST_TEST_MESSAGE("Testing performance option greeks..."); testOptionGreeks(); } - -void CliquetOptionTest::testMcPerformance() { +BOOST_AUTO_TEST_CASE(testMcPerformance) { BOOST_TEST_MESSAGE( "Testing Monte Carlo performance engine against analytic results..."); @@ -354,13 +354,6 @@ void CliquetOptionTest::testMcPerformance() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CliquetOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cliquet option tests"); - suite->add(QUANTLIB_TEST_CASE(&CliquetOptionTest::testValues)); - suite->add(QUANTLIB_TEST_CASE(&CliquetOptionTest::testGreeks)); - suite->add(QUANTLIB_TEST_CASE(&CliquetOptionTest::testPerformanceGreeks)); - suite->add(QUANTLIB_TEST_CASE(&CliquetOptionTest::testMcPerformance)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/cliquetoption.hpp b/test-suite/cliquetoption.hpp deleted file mode 100644 index 1be158d1ecd..00000000000 --- a/test-suite/cliquetoption.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004, 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_cliquet_option_hpp -#define quantlib_test_cliquet_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CliquetOptionTest { - public: - static void testValues(); - static void testGreeks(); - static void testPerformanceGreeks(); - static void testMcPerformance(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 65cd874c62b..61303a43497 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cliquetoption.hpp" #include "cms.hpp" #include "cms_normal.hpp" #include "cmsspread.hpp" @@ -191,7 +190,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CliquetOptionTest::suite()); test->add(CmsTest::suite()); test->add(CmsNormalTest::suite()); test->add(CompoundOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 6b3b785fdb3..a562f910f68 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 0f6892b2478..85102b4b6c5 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 298d38eb7d7917f76a70af92e89a9a878ee19eb7 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 16:55:11 +0800 Subject: [PATCH 035/132] Migrated cms.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cms.cpp | 21 ++++++++-------- test-suite/cms.hpp | 36 ---------------------------- 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/cms.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 1cff6925e3b..4e2bfc02d99 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cms.hpp cms_normal.hpp cmsspread.hpp commodityunitofmeasure.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 8ce8b5df9e4..c0944835667 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cms.hpp \ cms_normal.hpp \ cmsspread.hpp \ commodityunitofmeasure.hpp \ diff --git a/test-suite/cms.cpp b/test-suite/cms.cpp index 1698693ddb3..cdc47a5aa6a 100644 --- a/test-suite/cms.cpp +++ b/test-suite/cms.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cms.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -243,8 +243,11 @@ namespace cms_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CmsTest::testFairRate() { +BOOST_AUTO_TEST_SUITE(CmsTest) + +BOOST_AUTO_TEST_CASE(testFairRate) { BOOST_TEST_MESSAGE("Testing Hagan-pricer flat-vol equivalence for coupons (lognormal case)..."); @@ -310,7 +313,7 @@ void CmsTest::testFairRate() { } } -void CmsTest::testCmsSwap() { +BOOST_AUTO_TEST_CASE(testCmsSwap) { BOOST_TEST_MESSAGE("Testing Hagan-pricer flat-vol equivalence for swaps (lognormal case)..."); @@ -373,7 +376,7 @@ void CmsTest::testCmsSwap() { } -void CmsTest::testParity() { +BOOST_AUTO_TEST_CASE(testParity) { BOOST_TEST_MESSAGE("Testing put-call parity for capped-floored CMS coupons (lognormal case)..."); @@ -465,10 +468,6 @@ void CmsTest::testParity() { } } -test_suite* CmsTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cms tests"); - suite->add(QUANTLIB_TEST_CASE(&CmsTest::testFairRate)); - suite->add(QUANTLIB_TEST_CASE(&CmsTest::testCmsSwap)); - suite->add(QUANTLIB_TEST_CASE(&CmsTest::testParity)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/cms.hpp b/test-suite/cms.hpp deleted file mode 100644 index 87be989842a..00000000000 --- a/test-suite/cms.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006 Mario Pucci - - 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_cms_hpp -#define quantlib_test_cms_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CmsTest { - public: - static void testFairRate(); - static void testParity(); - static void testCmsSwap(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 61303a43497..240f1001608 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cms.hpp" #include "cms_normal.hpp" #include "cmsspread.hpp" #include "commodityunitofmeasure.hpp" @@ -190,7 +189,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CmsTest::suite()); test->add(CmsNormalTest::suite()); test->add(CompoundOptionTest::suite()); test->add(ConvertibleBondTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index a562f910f68..68c155229d7 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 85102b4b6c5..faed4594632 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From bc26486aa419b536decd19c8d9009e2f05b2c7c2 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 16:58:18 +0800 Subject: [PATCH 036/132] Migrated cms_normal.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cms_normal.cpp | 21 ++++++++-------- test-suite/cms_normal.hpp | 36 ---------------------------- 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/cms_normal.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 4e2bfc02d99..96b0e4446b7 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cms_normal.hpp cmsspread.hpp commodityunitofmeasure.hpp compiledboostversion.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c0944835667..05821b0b358 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cms_normal.hpp \ cmsspread.hpp \ commodityunitofmeasure.hpp \ compiledboostversion.hpp \ diff --git a/test-suite/cms_normal.cpp b/test-suite/cms_normal.cpp index c11b6c6d539..9d15f03c8cf 100644 --- a/test-suite/cms_normal.cpp +++ b/test-suite/cms_normal.cpp @@ -21,7 +21,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cms_normal.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -270,8 +270,11 @@ namespace cms_normal_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CmsNormalTest::testFairRate() { +BOOST_AUTO_TEST_SUITE(CmsNormalTest) + +BOOST_AUTO_TEST_CASE(testFairRate) { BOOST_TEST_MESSAGE("Testing Hagan-pricer flat-vol equivalence for coupons (normal case)..."); @@ -336,7 +339,7 @@ void CmsNormalTest::testFairRate() { } } -void CmsNormalTest::testCmsSwap() { +BOOST_AUTO_TEST_CASE(testCmsSwap) { BOOST_TEST_MESSAGE("Testing Hagan-pricer flat-vol equivalence for swaps (normal case)..."); @@ -398,7 +401,7 @@ void CmsNormalTest::testCmsSwap() { } -void CmsNormalTest::testParity() { +BOOST_AUTO_TEST_CASE(testParity) { BOOST_TEST_MESSAGE("Testing put-call parity for capped-floored CMS coupons (normal case)..."); @@ -500,10 +503,6 @@ void CmsNormalTest::testParity() { } } -test_suite* CmsNormalTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cms normal tests"); - suite->add(QUANTLIB_TEST_CASE(&CmsNormalTest::testFairRate)); - suite->add(QUANTLIB_TEST_CASE(&CmsNormalTest::testCmsSwap)); - suite->add(QUANTLIB_TEST_CASE(&CmsNormalTest::testParity)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/cms_normal.hpp b/test-suite/cms_normal.hpp deleted file mode 100644 index 3c3823c8aeb..00000000000 --- a/test-suite/cms_normal.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2023 Andre Miemiec - - 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_cms_normal_hpp -#define quantlib_test_cms_normal_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CmsNormalTest { - public: - static void testFairRate(); - static void testParity(); - static void testCmsSwap(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 240f1001608..0228dcc02d0 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cms_normal.hpp" #include "cmsspread.hpp" #include "commodityunitofmeasure.hpp" #include "compiledboostversion.hpp" @@ -189,7 +188,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CmsNormalTest::suite()); test->add(CompoundOptionTest::suite()); test->add(ConvertibleBondTest::suite()); test->add(CovarianceTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 68c155229d7..5b662499501 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 faed4594632..9c06fd7ef30 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d2f2ff5dffb5ca55198df016fd074442316d3f31 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:01:15 +0800 Subject: [PATCH 037/132] Migrated cmsspread.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/cmsspread.cpp | 20 ++++++++-------- test-suite/cmsspread.hpp | 35 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 10 insertions(+), 53 deletions(-) delete mode 100644 test-suite/cmsspread.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 96b0e4446b7..a8ca04d4eb1 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - cmsspread.hpp commodityunitofmeasure.hpp compiledboostversion.hpp compoundoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 05821b0b358..8a8775672bd 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - cmsspread.hpp \ commodityunitofmeasure.hpp \ compiledboostversion.hpp \ compoundoption.hpp \ diff --git a/test-suite/cmsspread.cpp b/test-suite/cmsspread.cpp index ad5a987cff9..ffcdb38b1eb 100644 --- a/test-suite/cmsspread.cpp +++ b/test-suite/cmsspread.cpp @@ -17,9 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "cmsspread.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" - #include #include #include @@ -92,7 +91,11 @@ struct TestData { }; } // namespace -void CmsSpreadTest::testFixings() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CmsSpreadExperimentalTest) + +BOOST_AUTO_TEST_CASE(testFixings) { BOOST_TEST_MESSAGE("Testing fixings of cms spread indices..."); TestData d; @@ -185,7 +188,7 @@ Real mcReferenceValue(const ext::shared_ptr& cpn1, } // mcReferenceValue } // namespace -void CmsSpreadTest::testCouponPricing() { +BOOST_AUTO_TEST_CASE(testCouponPricing) { BOOST_TEST_MESSAGE("Testing pricing of cms spread coupons..."); TestData d; @@ -344,9 +347,6 @@ void CmsSpreadTest::testCouponPricing() { tol); } -test_suite* CmsSpreadTest::suite() { - auto* suite = BOOST_TEST_SUITE("CmsSpreadTest"); - suite->add(QUANTLIB_TEST_CASE(&CmsSpreadTest::testFixings)); - suite->add(QUANTLIB_TEST_CASE(&CmsSpreadTest::testCouponPricing)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/cmsspread.hpp b/test-suite/cmsspread.hpp deleted file mode 100644 index 6fad0d59358..00000000000 --- a/test-suite/cmsspread.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2018 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_cmsspread_hpp -#define quantlib_test_cmsspread_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CmsSpreadTest { -public: - static void testFixings(); - static void testCouponPricing(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 0228dcc02d0..abeecf8ed51 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "cmsspread.hpp" #include "commodityunitofmeasure.hpp" #include "compiledboostversion.hpp" #include "compoundoption.hpp" @@ -296,7 +295,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CmsSpreadTest::suite()); test->add(CommodityUnitOfMeasureTest::suite()); test->add(CompiledBoostVersionTest::suite()); test->add(CreditRiskPlusTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 5b662499501..092342a6652 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 9c06fd7ef30..a19414f9e62 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From f770d36c17051330549194f50db7401237169027 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:03:51 +0800 Subject: [PATCH 038/132] Migrated commodityunitofmeasure.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/commodityunitofmeasure.cpp | 15 ++++++------ test-suite/commodityunitofmeasure.hpp | 35 --------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 test-suite/commodityunitofmeasure.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a8ca04d4eb1..31e8722a933 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - commodityunitofmeasure.hpp compiledboostversion.hpp compoundoption.hpp convertiblebonds.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 8a8775672bd..64c6703dfe3 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - commodityunitofmeasure.hpp \ compiledboostversion.hpp \ compoundoption.hpp \ convertiblebonds.hpp \ diff --git a/test-suite/commodityunitofmeasure.cpp b/test-suite/commodityunitofmeasure.cpp index 84b58b6e29e..a34acbe1169 100644 --- a/test-suite/commodityunitofmeasure.cpp +++ b/test-suite/commodityunitofmeasure.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "commodityunitofmeasure.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -25,7 +25,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CommodityUnitOfMeasureTest::testDirect() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CommodityUnitOfMeasureExperimentalTest) + +BOOST_AUTO_TEST_CASE(testDirect) { BOOST_TEST_MESSAGE("Testing direct commodity unit of measure conversions..."); @@ -133,9 +137,6 @@ void CommodityUnitOfMeasureTest::testDirect() { } } -test_suite* CommodityUnitOfMeasureTest::suite() { - auto* suite = BOOST_TEST_SUITE("Commodity Unit Of Measure tests"); - suite->add(QUANTLIB_TEST_CASE(&CommodityUnitOfMeasureTest::testDirect)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/commodityunitofmeasure.hpp b/test-suite/commodityunitofmeasure.hpp deleted file mode 100644 index b18473e10ec..00000000000 --- a/test-suite/commodityunitofmeasure.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2010 Manas Bhatt - - 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_commodity_unit_of_measure_hpp -#define quantlib_test_commodity_unit_of_measure_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CommodityUnitOfMeasureTest { - public: - static void testDirect(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index abeecf8ed51..8f6f81cc61c 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "commodityunitofmeasure.hpp" #include "compiledboostversion.hpp" #include "compoundoption.hpp" #include "convertiblebonds.hpp" @@ -295,7 +294,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CommodityUnitOfMeasureTest::suite()); test->add(CompiledBoostVersionTest::suite()); test->add(CreditRiskPlusTest::suite()); test->add(DoubleBarrierOptionTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 092342a6652..08bb8cab1be 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 a19414f9e62..a318a736c75 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From b3473d9e288dd4503a422b8e7a79343354416955 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:07:00 +0800 Subject: [PATCH 039/132] Migrated compiledboostversion.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/compiledboostversion.cpp | 16 +++++++------- test-suite/compiledboostversion.hpp | 33 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 test-suite/compiledboostversion.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 31e8722a933..8c88f4789de 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - compiledboostversion.hpp compoundoption.hpp convertiblebonds.hpp covariance.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 64c6703dfe3..ba08909d208 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - compiledboostversion.hpp \ compoundoption.hpp \ convertiblebonds.hpp \ covariance.hpp \ diff --git a/test-suite/compiledboostversion.cpp b/test-suite/compiledboostversion.cpp index 9a72f2366c3..aec138c9083 100644 --- a/test-suite/compiledboostversion.cpp +++ b/test-suite/compiledboostversion.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "compiledboostversion.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include @@ -27,7 +27,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CompiledBoostVersionTest::test() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CompiledBoostVersionExperimentalTest) + +BOOST_AUTO_TEST_CASE(test) { BOOST_TEST_MESSAGE("Testing compiled boost version..."); @@ -35,10 +39,6 @@ void CompiledBoostVersionTest::test() { BOOST_CHECK(QuantLib::compiledBoostVersion() == BOOST_VERSION); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CompiledBoostVersionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Compiled boost version test"); - suite->add(QUANTLIB_TEST_CASE(&CompiledBoostVersionTest::test)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/compiledboostversion.hpp b/test-suite/compiledboostversion.hpp deleted file mode 100644 index 8f59577cfc9..00000000000 --- a/test-suite/compiledboostversion.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2019 Aprexo Limited - - 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_compiledboostversion_test_hpp -#define quantlib_compiledboostversion_test_hpp - -#include - - -/* Simply ensures that compiledBoostVersion() returns BOOST_VERSION */ -class CompiledBoostVersionTest { - public: - static void test(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8f6f81cc61c..b03d63f98f7 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "compiledboostversion.hpp" #include "compoundoption.hpp" #include "convertiblebonds.hpp" #include "covariance.hpp" @@ -294,7 +293,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CompiledBoostVersionTest::suite()); test->add(CreditRiskPlusTest::suite()); test->add(DoubleBarrierOptionTest::suite(speed)); test->add(DoubleBinaryOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 08bb8cab1be..c0326ea9fda 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 a318a736c75..56f2b9511e9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 43384a1d418d871e8a4e3c3c255551da4e84cce5 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:09:51 +0800 Subject: [PATCH 040/132] Migrated compoundoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/compoundoption.cpp | 21 +++++++---------- test-suite/compoundoption.hpp | 35 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 56 deletions(-) delete mode 100644 test-suite/compoundoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 8c88f4789de..680a07fd35d 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - compoundoption.hpp convertiblebonds.hpp covariance.hpp creditdefaultswap.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ba08909d208..7c8b7c2743b 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - compoundoption.hpp \ convertiblebonds.hpp \ covariance.hpp \ creditdefaultswap.hpp \ diff --git a/test-suite/compoundoption.cpp b/test-suite/compoundoption.cpp index 98afeb6ce40..de7df293787 100644 --- a/test-suite/compoundoption.cpp +++ b/test-suite/compoundoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "compoundoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -78,8 +78,11 @@ namespace compound_option_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CompoundOptionTest::testPutCallParity(){ +BOOST_AUTO_TEST_SUITE(CompoundOptionTest) + +BOOST_AUTO_TEST_CASE(testPutCallParity){ BOOST_TEST_MESSAGE("Testing compound-option put-call parity..."); @@ -195,7 +198,7 @@ void CompoundOptionTest::testPutCallParity(){ } } -void CompoundOptionTest::testValues(){ +BOOST_AUTO_TEST_CASE(testValues){ BOOST_TEST_MESSAGE("Testing compound-option values and greeks..."); @@ -345,14 +348,6 @@ void CompoundOptionTest::testValues(){ } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CompoundOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Compound option tests"); - - suite->add(QUANTLIB_TEST_CASE(&CompoundOptionTest::testValues)); - suite->add(QUANTLIB_TEST_CASE(&CompoundOptionTest::testPutCallParity)); - - return suite; -} - - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/compoundoption.hpp b/test-suite/compoundoption.hpp deleted file mode 100644 index 3c1a009e777..00000000000 --- a/test-suite/compoundoption.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2009 Dimitri Reiswich - - 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_compound_option_test_hpp -#define quantlib_compound_option_test_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CompoundOptionTest { - public: - static void testValues(); - static void testPutCallParity(); - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index b03d63f98f7..e1c9de1935f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "compoundoption.hpp" #include "convertiblebonds.hpp" #include "covariance.hpp" #include "creditdefaultswap.hpp" @@ -185,7 +184,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CompoundOptionTest::suite()); test->add(ConvertibleBondTest::suite()); test->add(CovarianceTest::suite()); test->add(CPISwapTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index c0326ea9fda..f69c1e2ea2c 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 56f2b9511e9..01424074c08 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From ce04ccaab04ec2700bc8337257ef48949d69ff3d Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:16:09 +0800 Subject: [PATCH 041/132] Migrated convertiblebonds.cpp --- test-suite/CMakeLists.txt | 3 +-- test-suite/Makefile.am | 2 -- test-suite/convertiblebonds.cpp | 22 +++++++---------- test-suite/convertiblebonds.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/convertiblebonds.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 680a07fd35d..a9db6a44797 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - convertiblebonds.hpp covariance.hpp creditdefaultswap.hpp creditriskplus.hpp @@ -321,7 +320,7 @@ set(QL_BENCHMARK_SOURCES barrieroption.cpp basketoption.cpp batesmodel.cpp - convertiblebonds.cpp convertiblebonds.hpp + convertiblebonds.cpp digitaloption.cpp digitaloption.hpp dividendoption.cpp dividendoption.hpp europeanoption.cpp europeanoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 7c8b7c2743b..a4db42b60d0 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - convertiblebonds.hpp \ covariance.hpp \ creditdefaultswap.hpp \ creditriskplus.hpp \ @@ -341,7 +340,6 @@ QL_BENCHMARK_SRCS = \ QL_BENCHMARK_HDRS = \ doublebarrieroption.hpp \ - convertiblebonds.hpp \ digitaloption.hpp \ dividendoption.hpp \ europeanoption.hpp \ diff --git a/test-suite/convertiblebonds.cpp b/test-suite/convertiblebonds.cpp index 752c5b3ca3b..d85d4552154 100644 --- a/test-suite/convertiblebonds.cpp +++ b/test-suite/convertiblebonds.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "convertiblebonds.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -102,8 +102,11 @@ namespace convertible_bonds_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void ConvertibleBondTest::testBond() { +BOOST_AUTO_TEST_SUITE(ConvertibleBondTest) + +BOOST_AUTO_TEST_CASE(testBond) { /* when deeply out-of-the-money, the value of the convertible bond should equal that of the underlying plain-vanilla bond. */ @@ -292,7 +295,7 @@ void ConvertibleBondTest::testBond() { } } -void ConvertibleBondTest::testOption() { +BOOST_AUTO_TEST_CASE(testOption) { /* a zero-coupon convertible bond with no credit spread is equivalent to a call option. */ @@ -354,7 +357,7 @@ void ConvertibleBondTest::testOption() { } } -void ConvertibleBondTest::testRegression() { +BOOST_AUTO_TEST_CASE(testRegression) { BOOST_TEST_MESSAGE( "Testing fixed-coupon convertible bond in known regression case..."); @@ -444,13 +447,6 @@ void ConvertibleBondTest::testRegression() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* ConvertibleBondTest::suite() { - auto* suite = BOOST_TEST_SUITE("Convertible bond tests"); - - suite->add(QUANTLIB_TEST_CASE(&ConvertibleBondTest::testBond)); - suite->add(QUANTLIB_TEST_CASE(&ConvertibleBondTest::testOption)); - suite->add(QUANTLIB_TEST_CASE(&ConvertibleBondTest::testRegression)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/convertiblebonds.hpp b/test-suite/convertiblebonds.hpp deleted file mode 100644 index 1a5f589c6ea..00000000000 --- a/test-suite/convertiblebonds.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006, 2009 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_convertible_bonds_hpp -#define quantlib_test_convertible_bonds_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ConvertibleBondTest { - public: - static void testBond(); - static void testOption(); - static void testRegression(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 1623ad647bf..771e007e74d 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "convertiblebonds.hpp" #include "digitaloption.hpp" #include "dividendoption.hpp" #include "europeanoption.hpp" @@ -184,6 +183,11 @@ namespace QuantLibTest { struct testDAXCalibration: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace ConvertibleBondTest { + struct testBond: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -222,7 +226,7 @@ namespace { Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testTavellaValues::test_method, QuantLibTest::BasketOptionTest::testTavellaValues()), 933.80), Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testOddSamples::test_method, QuantLibTest::BasketOptionTest::testOddSamples()), 642.46), Benchmark("BatesModel::DAXCalibration", std::bind(&QuantLibTest::BatesModelTest::testDAXCalibration::test_method, QuantLibTest::BatesModelTest::testDAXCalibration()), 1993.35), - Benchmark("ConvertibleBondTest::testBond", &ConvertibleBondTest::testBond, 159.85), + Benchmark("ConvertibleBondTest::testBond", std::bind(&QuantLibTest::ConvertibleBondTest::testBond::test_method, QuantLibTest::ConvertibleBondTest::testBond()), 159.85), Benchmark("DigitalOption::MCCashAtHit", &DigitalOptionTest::testMCCashAtHit, 995.87), Benchmark("DividendOption::FdEuropeanGreeks", &DividendOptionTest::testFdEuropeanGreeks, 949.52), Benchmark("DividendOption::FdAmericanGreeks", &DividendOptionTest::testFdAmericanGreeks, 1113.74), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index e1c9de1935f..2e630be344e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "convertiblebonds.hpp" #include "covariance.hpp" #include "creditdefaultswap.hpp" #include "creditriskplus.hpp" @@ -184,7 +183,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(ConvertibleBondTest::suite()); test->add(CovarianceTest::suite()); test->add(CPISwapTest::suite()); test->add(CreditDefaultSwapTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f69c1e2ea2c..0685644e7b1 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 01424074c08..2bfb2a1cc8c 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 9be368b8fd1302795c4dc50bc1bfb7fd952a0b3a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:19:36 +0800 Subject: [PATCH 042/132] Migrated covariance.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/covariance.cpp | 24 +++++++----------- test-suite/covariance.hpp | 38 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 61 deletions(-) delete mode 100644 test-suite/covariance.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a9db6a44797..1661925e870 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - covariance.hpp creditdefaultswap.hpp creditriskplus.hpp crosscurrencyratehelpers.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index a4db42b60d0..197473227c9 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - covariance.hpp \ creditdefaultswap.hpp \ creditriskplus.hpp \ crosscurrencyratehelpers.hpp \ diff --git a/test-suite/covariance.cpp b/test-suite/covariance.cpp index 4a323b3d373..bf1f9428ad3 100644 --- a/test-suite/covariance.cpp +++ b/test-suite/covariance.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "covariance.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -39,8 +39,11 @@ namespace covariance_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CovarianceTest::testRankReduction() { +BOOST_AUTO_TEST_SUITE(CovarianceTest) + +BOOST_AUTO_TEST_CASE(testRankReduction) { BOOST_TEST_MESSAGE("Testing matrix rank reduction salvaging algorithms..."); @@ -98,7 +101,7 @@ void CovarianceTest::testRankReduction() { << "salvaged matrix:\n" << goodCov); } -void CovarianceTest::testSalvagingMatrix() { +BOOST_AUTO_TEST_CASE(testSalvagingMatrix) { BOOST_TEST_MESSAGE("Testing positive semi-definiteness salvaging " "algorithms..."); @@ -155,7 +158,7 @@ void CovarianceTest::testSalvagingMatrix() { << "salvaged matrix:\n" << goodCov); } -void CovarianceTest::testCovariance() { +BOOST_AUTO_TEST_CASE(testCovariance) { BOOST_TEST_MESSAGE("Testing covariance and correlation calculations..."); @@ -264,17 +267,8 @@ void CovarianceTest::testCovariance() { } } } - - - } +BOOST_AUTO_TEST_SUITE_END() -test_suite* CovarianceTest::suite() { - auto* suite = BOOST_TEST_SUITE("Covariance and correlation tests"); - suite->add(QUANTLIB_TEST_CASE(&CovarianceTest::testCovariance)); - suite->add(QUANTLIB_TEST_CASE(&CovarianceTest::testSalvagingMatrix)); - suite->add(QUANTLIB_TEST_CASE(&CovarianceTest::testRankReduction)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/covariance.hpp b/test-suite/covariance.hpp deleted file mode 100644 index 54bb4cd2a54..00000000000 --- a/test-suite/covariance.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Ferdinando Ametrano - 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_covariance_hpp -#define quantlib_test_covariance_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CovarianceTest { - public: - static void testCovariance(); - static void testSalvagingMatrix(); - static void testRankReduction(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2e630be344e..0125548c6ce 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "covariance.hpp" #include "creditdefaultswap.hpp" #include "creditriskplus.hpp" #include "crosscurrencyratehelpers.hpp" @@ -183,7 +182,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); - test->add(CovarianceTest::suite()); test->add(CPISwapTest::suite()); test->add(CreditDefaultSwapTest::suite()); test->add(CrossCurrencyRateHelpersTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0685644e7b1..ff809014e90 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 2bfb2a1cc8c..fd2a6c8eb40 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From efd50993a7dafa603db128483c0a8e0c5d508308 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:31:45 +0800 Subject: [PATCH 043/132] Migrated crosscurrencyratehelpers.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/crosscurrencyratehelpers.cpp | 59 +++++++------------------ test-suite/crosscurrencyratehelpers.hpp | 45 ------------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 17 insertions(+), 95 deletions(-) delete mode 100644 test-suite/crosscurrencyratehelpers.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 1661925e870..9d070d29f45 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -176,7 +176,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS creditdefaultswap.hpp creditriskplus.hpp - crosscurrencyratehelpers.hpp currency.hpp curvestates.hpp dates.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 197473227c9..2d56928dfc6 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -176,7 +176,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ creditdefaultswap.hpp \ creditriskplus.hpp \ - crosscurrencyratehelpers.hpp \ currency.hpp \ curvestates.hpp \ dates.hpp \ diff --git a/test-suite/crosscurrencyratehelpers.cpp b/test-suite/crosscurrencyratehelpers.cpp index eea6f75f7e3..f5f89d24119 100644 --- a/test-suite/crosscurrencyratehelpers.cpp +++ b/test-suite/crosscurrencyratehelpers.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "crosscurrencyratehelpers.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -323,8 +323,11 @@ void testResettingCrossCurrencySwaps(bool isFxBaseCurrencyCollateralCurrency, } } -void CrossCurrencyRateHelpersTest:: - testConstNotionalBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CrossCurrencyRateHelpersTest) + +BOOST_AUTO_TEST_CASE(testConstNotionalBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy) { BOOST_TEST_MESSAGE("Testing constant notional basis swaps with collateral in quote ccy and " "basis in base ccy..."); @@ -335,7 +338,7 @@ void CrossCurrencyRateHelpersTest:: isBasisOnFxBaseCurrencyLeg); } -void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy() { +BOOST_AUTO_TEST_CASE(testConstNotionalBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy) { BOOST_TEST_MESSAGE( "Testing constant notional basis swaps with collateral in base ccy and basis in quote ccy..."); @@ -346,7 +349,7 @@ void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralInBa isBasisOnFxBaseCurrencyLeg); } -void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralAndBasisInBaseCcy() { +BOOST_AUTO_TEST_CASE(testConstNotionalBasisSwapsWithCollateralAndBasisInBaseCcy) { BOOST_TEST_MESSAGE( "Testing constant notional basis swaps with collateral and basis in base ccy..."); @@ -357,7 +360,7 @@ void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralAndB isBasisOnFxBaseCurrencyLeg); } -void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralAndBasisInQuoteCcy() { +BOOST_AUTO_TEST_CASE(testConstNotionalBasisSwapsWithCollateralAndBasisInQuoteCcy) { BOOST_TEST_MESSAGE("Testing constant notional basis swaps with collateral and basis in quote ccy..."); bool isFxBaseCurrencyCollateralCurrency = false; @@ -367,8 +370,7 @@ void CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralAndB isBasisOnFxBaseCurrencyLeg); } -void CrossCurrencyRateHelpersTest:: - testResettingBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy() { +BOOST_AUTO_TEST_CASE(testResettingBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy) { BOOST_TEST_MESSAGE( "Testing resetting basis swaps with collateral in quote ccy and basis in base ccy..."); @@ -380,8 +382,7 @@ void CrossCurrencyRateHelpersTest:: isFxBaseCurrencyLegResettable); } -void CrossCurrencyRateHelpersTest:: - testResettingBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy() { +BOOST_AUTO_TEST_CASE(testResettingBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy) { BOOST_TEST_MESSAGE( "Testing resetting basis swaps with collateral in base ccy and basis in quote ccy..."); @@ -393,7 +394,7 @@ void CrossCurrencyRateHelpersTest:: isFxBaseCurrencyLegResettable); } -void CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasisInBaseCcy() { +BOOST_AUTO_TEST_CASE(testResettingBasisSwapsWithCollateralAndBasisInBaseCcy) { BOOST_TEST_MESSAGE("Testing resetting basis swaps with collateral and basis in base ccy..."); bool isFxBaseCurrencyCollateralCurrency = true; @@ -404,7 +405,7 @@ void CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasis isFxBaseCurrencyLegResettable); } -void CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasisInQuoteCcy() { +BOOST_AUTO_TEST_CASE(testResettingBasisSwapsWithCollateralAndBasisInQuoteCcy) { BOOST_TEST_MESSAGE("Testing resetting basis swaps with collateral and basis in quote ccy..."); bool isFxBaseCurrencyCollateralCurrency = false; @@ -415,7 +416,7 @@ void CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasis isFxBaseCurrencyLegResettable); } -void CrossCurrencyRateHelpersTest::testExceptionWhenInstrumentTenorShorterThanIndexFrequency() { +BOOST_AUTO_TEST_CASE(testExceptionWhenInstrumentTenorShorterThanIndexFrequency) { BOOST_TEST_MESSAGE( "Testing exception when instrument tenor is shorter than index frequency..."); @@ -432,32 +433,6 @@ void CrossCurrencyRateHelpersTest::testExceptionWhenInstrumentTenorShorterThanIn Error); } -test_suite* CrossCurrencyRateHelpersTest::suite() { - auto* suite = BOOST_TEST_SUITE("Cross currency rate helpers tests"); - - suite->add( - QUANTLIB_TEST_CASE(&CrossCurrencyRateHelpersTest:: - testConstNotionalBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy)); - suite->add( - QUANTLIB_TEST_CASE(&CrossCurrencyRateHelpersTest:: - testConstNotionalBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy)); - suite->add(QUANTLIB_TEST_CASE( - &CrossCurrencyRateHelpersTest::testConstNotionalBasisSwapsWithCollateralAndBasisInBaseCcy)); - suite->add(QUANTLIB_TEST_CASE(&CrossCurrencyRateHelpersTest:: - testConstNotionalBasisSwapsWithCollateralAndBasisInQuoteCcy)); - - suite->add( - QUANTLIB_TEST_CASE(&CrossCurrencyRateHelpersTest:: - testResettingBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy)); - suite->add( - QUANTLIB_TEST_CASE(&CrossCurrencyRateHelpersTest:: - testResettingBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy)); - suite->add(QUANTLIB_TEST_CASE( - &CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasisInBaseCcy)); - suite->add(QUANTLIB_TEST_CASE( - &CrossCurrencyRateHelpersTest::testResettingBasisSwapsWithCollateralAndBasisInQuoteCcy)); - - suite->add(QUANTLIB_TEST_CASE( - &CrossCurrencyRateHelpersTest::testExceptionWhenInstrumentTenorShorterThanIndexFrequency)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/crosscurrencyratehelpers.hpp b/test-suite/crosscurrencyratehelpers.hpp deleted file mode 100644 index a0f9ed14be6..00000000000 --- a/test-suite/crosscurrencyratehelpers.hpp +++ /dev/null @@ -1,45 +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_crosscurrencyratehelpers_hpp -#define quantlib_test_crosscurrencyratehelpers_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CrossCurrencyRateHelpersTest { - public: - static void testConstNotionalBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy(); - static void testConstNotionalBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy(); - static void testConstNotionalBasisSwapsWithCollateralAndBasisInBaseCcy(); - static void testConstNotionalBasisSwapsWithCollateralAndBasisInQuoteCcy(); - - static void testResettingBasisSwapsWithCollateralInQuoteAndBasisInBaseCcy(); - static void testResettingBasisSwapsWithCollateralInBaseAndBasisInQuoteCcy(); - static void testResettingBasisSwapsWithCollateralAndBasisInBaseCcy(); - static void testResettingBasisSwapsWithCollateralAndBasisInQuoteCcy(); - - static void testExceptionWhenInstrumentTenorShorterThanIndexFrequency(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 0125548c6ce..2dac2d344f6 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -18,7 +18,6 @@ #include "creditdefaultswap.hpp" #include "creditriskplus.hpp" -#include "crosscurrencyratehelpers.hpp" #include "currency.hpp" #include "curvestates.hpp" #include "dates.hpp" @@ -184,7 +183,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CPISwapTest::suite()); test->add(CreditDefaultSwapTest::suite()); - test->add(CrossCurrencyRateHelpersTest::suite()); test->add(CurrencyTest::suite()); test->add(CurveStatesTest::suite()); test->add(DateTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ff809014e90..7c783518a19 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 fd2a6c8eb40..d4c23c5dcfd 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -908,9 +908,6 @@ Header Files - - Header Files - Header Files From 42d394066596388bc593cf780323e6844eb2b4ac Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:35:39 +0800 Subject: [PATCH 044/132] Migrated creditdefaultswap.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/creditdefaultswap.cpp | 45 +++++++++++----------------- test-suite/creditdefaultswap.hpp | 43 -------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 17 insertions(+), 79 deletions(-) delete mode 100644 test-suite/creditdefaultswap.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9d070d29f45..5f0d8aab1de 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - creditdefaultswap.hpp creditriskplus.hpp currency.hpp curvestates.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 2d56928dfc6..e756630ebaa 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - creditdefaultswap.hpp \ creditriskplus.hpp \ currency.hpp \ curvestates.hpp \ diff --git a/test-suite/creditdefaultswap.cpp b/test-suite/creditdefaultswap.cpp index 568f0f1109b..86c9b167400 100644 --- a/test-suite/creditdefaultswap.cpp +++ b/test-suite/creditdefaultswap.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "creditdefaultswap.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -49,7 +49,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; using std::map; -void CreditDefaultSwapTest::testCachedValue() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CreditDefaultSwapTest) + +BOOST_AUTO_TEST_CASE(testCachedValue) { BOOST_TEST_MESSAGE("Testing credit-default swap against cached values..."); @@ -160,8 +164,7 @@ void CreditDefaultSwapTest::testCachedValue() { << " expected fair rate: " << fairRate); } - -void CreditDefaultSwapTest::testCachedMarketValue() { +BOOST_AUTO_TEST_CASE(testCachedMarketValue) { BOOST_TEST_MESSAGE( "Testing credit-default swap against cached market values..."); @@ -306,8 +309,7 @@ void CreditDefaultSwapTest::testCachedMarketValue() { << " Given fair rate: " << fairRate); } - -void CreditDefaultSwapTest::testImpliedHazardRate() { +BOOST_AUTO_TEST_CASE(testImpliedHazardRate) { BOOST_TEST_MESSAGE("Testing implied hazard-rate for credit-default swaps..."); @@ -411,8 +413,7 @@ void CreditDefaultSwapTest::testImpliedHazardRate() { } } - -void CreditDefaultSwapTest::testFairSpread() { +BOOST_AUTO_TEST_CASE(testFairSpread) { BOOST_TEST_MESSAGE( "Testing fair-spread calculation for credit-default swaps..."); @@ -475,7 +476,7 @@ void CreditDefaultSwapTest::testFairSpread() { << " calculated NPV: " << fairNPV); } -void CreditDefaultSwapTest::testFairUpfront() { +BOOST_AUTO_TEST_CASE(testFairUpfront) { BOOST_TEST_MESSAGE( "Testing fair-upfront calculation for credit-default swaps..."); @@ -562,7 +563,7 @@ void CreditDefaultSwapTest::testFairUpfront() { << " calculated NPV: " << fairNPV); } -void CreditDefaultSwapTest::testIsdaEngine() { +BOOST_AUTO_TEST_CASE(testIsdaEngine) { BOOST_TEST_MESSAGE( "Testing ISDA engine calculations for credit-default swaps..."); @@ -718,7 +719,7 @@ void CreditDefaultSwapTest::testIsdaEngine() { } } -void CreditDefaultSwapTest::testAccrualRebateAmounts() { +BOOST_AUTO_TEST_CASE(testAccrualRebateAmounts) { BOOST_TEST_MESSAGE("Testing accrual rebate amounts on credit default swaps..."); @@ -753,8 +754,7 @@ void CreditDefaultSwapTest::testAccrualRebateAmounts() { } } -void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleQuote () -{ +BOOST_AUTO_TEST_CASE(testIsdaCalculatorReconcileSingleQuote) { BOOST_TEST_MESSAGE( "Testing ISDA engine calculations for a single credit-default swap record (reconciliation)..."); @@ -857,8 +857,7 @@ void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleQuote () } -void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleWithIssueDateInThePast () -{ +BOOST_AUTO_TEST_CASE(testIsdaCalculatorReconcileSingleWithIssueDateInThePast) { BOOST_TEST_MESSAGE( "Testing ISDA engine calculations for a single credit-default swap with issue date in the past..."); @@ -956,16 +955,6 @@ void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleWithIssueDateInTheP QL_CHECK_CLOSE(calculated_accrual, expected_accrual, tolerance); } -test_suite* CreditDefaultSwapTest::suite() { - auto* suite = BOOST_TEST_SUITE("Credit-default swap tests"); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testCachedValue)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testCachedMarketValue)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testImpliedHazardRate)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testFairSpread)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testFairUpfront)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testIsdaEngine)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testAccrualRebateAmounts)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleQuote)); - suite->add(QUANTLIB_TEST_CASE(&CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleWithIssueDateInThePast)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/creditdefaultswap.hpp b/test-suite/creditdefaultswap.hpp deleted file mode 100644 index 5b1ec477335..00000000000 --- a/test-suite/creditdefaultswap.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008, 2009 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_credit_default_swaps_hpp -#define quantlib_test_credit_default_swaps_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CreditDefaultSwapTest { - public: - static void testCachedValue(); - static void testCachedMarketValue(); - static void testImpliedHazardRate(); - static void testFairSpread(); - static void testFairUpfront(); - static void testIsdaEngine(); - static void testAccrualRebateAmounts(); - static void testIsdaCalculatorReconcileSingleQuote(); - static void testIsdaCalculatorReconcileSingleWithIssueDateInThePast(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 2dac2d344f6..41d460cf093 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "creditdefaultswap.hpp" #include "creditriskplus.hpp" #include "currency.hpp" #include "curvestates.hpp" @@ -182,7 +181,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(CreditDefaultSwapTest::suite()); test->add(CurrencyTest::suite()); test->add(CurveStatesTest::suite()); test->add(DateTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 7c783518a19..a49b205a8be 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 d4c23c5dcfd..82da3b8bc90 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 07496962a2510beb42af4d19b588c9ec0000eaa6 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:37:52 +0800 Subject: [PATCH 045/132] Migrated creditriskplus.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/creditriskplus.cpp | 16 +++++++------ test-suite/creditriskplus.hpp | 34 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 test-suite/creditriskplus.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 5f0d8aab1de..75c663a284f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - creditriskplus.hpp currency.hpp curvestates.hpp dates.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e756630ebaa..e36460b23e5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - creditriskplus.hpp \ currency.hpp \ curvestates.hpp \ dates.hpp \ diff --git a/test-suite/creditriskplus.cpp b/test-suite/creditriskplus.cpp index 9d46993dab2..a57c3684be5 100644 --- a/test-suite/creditriskplus.cpp +++ b/test-suite/creditriskplus.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "creditriskplus.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -25,7 +25,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void CreditRiskPlusTest::testReferenceValues() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CreditRiskPlusExperimentalTest) + +BOOST_AUTO_TEST_CASE(testReferenceValues) { BOOST_TEST_MESSAGE( "Testing extended credit risk plus model against reference values..."); @@ -119,8 +123,6 @@ void CreditRiskPlusTest::testReferenceValues() { << cr.lossQuantile(0.99) << ", should be 250)"); } -test_suite *CreditRiskPlusTest::suite() { - auto* suite = BOOST_TEST_SUITE("Credit risk plus tests"); - suite->add(QUANTLIB_TEST_CASE(&CreditRiskPlusTest::testReferenceValues)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/creditriskplus.hpp b/test-suite/creditriskplus.hpp deleted file mode 100644 index bc25b8e335a..00000000000 --- a/test-suite/creditriskplus.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2013 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_creditriskplus_hpp -#define quantlib_test_creditriskplus_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CreditRiskPlusTest { - public: - static void testReferenceValues(); - static boost::unit_test_framework::test_suite *suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 41d460cf093..67f9b085fe3 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "creditriskplus.hpp" #include "currency.hpp" #include "curvestates.hpp" #include "dates.hpp" @@ -283,7 +282,6 @@ test_suite* init_unit_test_suite(int, char* []) { // tests for experimental classes test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(CreditRiskPlusTest::suite()); test->add(DoubleBarrierOptionTest::suite(speed)); test->add(DoubleBinaryOptionTest::suite()); test->add(EuropeanOptionTest::experimental()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index a49b205a8be..0ac05454c43 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 82da3b8bc90..94ea49ecdea 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d470e02b1d672358c478eb337f95fde05e03bbe6 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:39:55 +0800 Subject: [PATCH 046/132] Migrated currency.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/currency.cpp | 16 +++++++------- test-suite/currency.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/currency.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 75c663a284f..5e2ed8b1d6b 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - currency.hpp curvestates.hpp dates.hpp daycounters.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index e36460b23e5..ecbe2c72d19 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - currency.hpp \ curvestates.hpp \ dates.hpp \ daycounters.hpp \ diff --git a/test-suite/currency.cpp b/test-suite/currency.cpp index 7c0d6889b27..9e4980bf62e 100644 --- a/test-suite/currency.cpp +++ b/test-suite/currency.cpp @@ -16,14 +16,18 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "currency.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include using namespace QuantLib; using namespace boost::unit_test_framework; -void CurrencyTest::testBespokeConstructor() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(CurrencyTest) + +BOOST_AUTO_TEST_CASE(testBespokeConstructor) { BOOST_TEST_MESSAGE("Testing bespoke currency constructor..."); std::string name("Some Currency"); @@ -51,10 +55,6 @@ void CurrencyTest::testBespokeConstructor() { << " expected: " << symbol << "\n"); } -test_suite* CurrencyTest::suite() { - auto* suite = BOOST_TEST_SUITE("Currency tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&CurrencyTest::testBespokeConstructor)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/currency.hpp b/test-suite/currency.hpp deleted file mode 100644 index c0044645f15..00000000000 --- a/test-suite/currency.hpp +++ /dev/null @@ -1,32 +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_currency_hpp -#define quantlib_test_currency_hpp - -#include - -class CurrencyTest { - public: - static void testBespokeConstructor(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 67f9b085fe3..620f75b6813 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "currency.hpp" #include "curvestates.hpp" #include "dates.hpp" #include "daycounters.hpp" @@ -180,7 +179,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(CurrencyTest::suite()); test->add(CurveStatesTest::suite()); test->add(DateTest::suite(speed)); test->add(DayCounterTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0ac05454c43..f92fa023951 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 94ea49ecdea..be39d34aaf1 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -908,9 +908,6 @@ Header Files - - Header Files - Header Files From 5370fbd96530362541a2a18d9b82036ae35a0108 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 26 Oct 2023 17:47:48 +0800 Subject: [PATCH 047/132] Migrated curvestates.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/curvestates.cpp | 49 ++++++++++++++-------------- test-suite/curvestates.hpp | 38 --------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 24 insertions(+), 71 deletions(-) delete mode 100644 test-suite/curvestates.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 5e2ed8b1d6b..6c9f4a0821c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - curvestates.hpp dates.hpp daycounters.hpp defaultprobabilitycurves.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ecbe2c72d19..c1372e9660c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - curvestates.hpp \ dates.hpp \ daycounters.hpp \ defaultprobabilitycurves.hpp \ diff --git a/test-suite/curvestates.cpp b/test-suite/curvestates.cpp index 4d0a891fbe8..f76702a4af5 100644 --- a/test-suite/curvestates.cpp +++ b/test-suite/curvestates.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "curvestates.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -112,27 +112,31 @@ namespace curve_states_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void CurveStatesTest::testLMMCurveState() { +BOOST_AUTO_TEST_SUITE(CurveStatesTest) - BOOST_TEST_MESSAGE("Testing Libor-market-model curve state..."); +// Comment/uncomment the desired test case. - using namespace curve_states_test; - - CommonVars vars; -} +//BOOST_AUTO_TEST_CASE(testLMMCurveState) { +// +// BOOST_TEST_MESSAGE("Testing Libor-market-model curve state..."); +// +// using namespace curve_states_test; +// +// CommonVars vars; +//} -void CurveStatesTest::testCoterminalSwapCurveState() { +//BOOST_AUTO_TEST_CASE(testCoterminalSwapCurveState) { +// +// BOOST_TEST_MESSAGE("Testing coterminal-swap-market-model curve state..."); +// +// using namespace curve_states_test; +// +// CommonVars vars; +//} - BOOST_TEST_MESSAGE("Testing coterminal-swap-market-model curve state..."); - - using namespace curve_states_test; - - CommonVars vars; -} - - -void CurveStatesTest::testCMSwapCurveState() { +BOOST_AUTO_TEST_CASE(testCMSwapCurveState) { BOOST_TEST_MESSAGE("Testing constant-maturity-swap-market-model curve state..."); @@ -195,11 +199,6 @@ void CurveStatesTest::testCMSwapCurveState() { }*/ } -// --- Call the desired tests -test_suite* CurveStatesTest::suite() { - auto* suite = BOOST_TEST_SUITE("Curve States tests"); - //suite->add(QUANTLIB_TEST_CASE(&CurveStatesTest::testLMMCurveState)); - //suite->add(QUANTLIB_TEST_CASE(&CurveStatesTest::testCoterminalSwapCurveState)); - suite->add(QUANTLIB_TEST_CASE(&CurveStatesTest::testCMSwapCurveState)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/curvestates.hpp b/test-suite/curvestates.hpp deleted file mode 100644 index 541763b0359..00000000000 --- a/test-suite/curvestates.hpp +++ /dev/null @@ -1,38 +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_curve_states_hpp -#define quantlib_test_curve_states_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class CurveStatesTest { - public: - static void testLMMCurveState(); - static void testCMSwapCurveState(); - static void testCoterminalSwapCurveState(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 620f75b6813..e0ba55d3d8e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "curvestates.hpp" #include "dates.hpp" #include "daycounters.hpp" #include "defaultprobabilitycurves.hpp" @@ -179,7 +178,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(CurveStatesTest::suite()); test->add(DateTest::suite(speed)); test->add(DayCounterTest::suite()); test->add(DefaultProbabilityCurveTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f92fa023951..7f20501898a 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 be39d34aaf1..c3e3d69d3cd 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From ec1fb3fc79a4db1e9ce0471c0cb948c55842cec5 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 09:39:27 +0800 Subject: [PATCH 048/132] Bug fix --- test-suite/cdo.cpp | 2 +- test-suite/quantlibglobalfixture.cpp | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/test-suite/cdo.cpp b/test-suite/cdo.cpp index 239194cdcf3..0ebefb08711 100644 --- a/test-suite/cdo.cpp +++ b/test-suite/cdo.cpp @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_SUITE(CdoExperimentalTest) #ifndef QL_PATCH_SOLARIS -BOOST_AUTO_TEST_CASE(testHW) { +BOOST_AUTO_TEST_CASE(testHW, *precondition(if_speed(Slow))) { for (int dataSet{0}; dataSet < 5; dataSet++) { diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index e84b6fb4dd7..46d680c9a2f 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -36,11 +36,6 @@ # include #endif -#ifndef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER -#define BOOST_TEST_NO_MAIN -#define BOOST_TEST_ALTERNATIVE_INIT_API -#endif - #include "quantlibglobalfixture.hpp" #include "speedlevel.hpp" #include From b056daba30432be1a1582b976dcaf89ece323bcf Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 11:23:36 +0800 Subject: [PATCH 049/132] defined boost_test_no_main in global fixture if parallel processing is enabled --- test-suite/quantlibglobalfixture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 46d680c9a2f..7f01328feb1 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -25,6 +25,7 @@ #ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER #include "paralleltestrunner.hpp" +#define BOOST_TEST_NO_MAIN 1 #else #include #endif From f9912e49b3ae16dbf3ea6f0419fa5b921223b2a4 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:12:31 +0800 Subject: [PATCH 050/132] Migrated dates.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/dates.cpp | 46 +++++++++++----------------- test-suite/dates.hpp | 45 --------------------------- test-suite/quantlibglobalfixture.cpp | 4 ++- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 21 insertions(+), 82 deletions(-) delete mode 100644 test-suite/dates.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 6c9f4a0821c..fc910ddcc67 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - dates.hpp daycounters.hpp defaultprobabilitycurves.hpp digitalcoupon.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c1372e9660c..d06c938cd95 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - dates.hpp \ daycounters.hpp \ defaultprobabilitycurves.hpp \ digitalcoupon.hpp \ diff --git a/test-suite/dates.cpp b/test-suite/dates.cpp index 3a5cc5ed9d1..2f0eea0b043 100644 --- a/test-suite/dates.cpp +++ b/test-suite/dates.cpp @@ -23,7 +23,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "dates.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -38,7 +38,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void DateTest::ecbDates() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(DateTest) + +BOOST_AUTO_TEST_CASE(ecbDates) { BOOST_TEST_MESSAGE("Testing ECB dates..."); std::set knownDates = ECB::knownDates(); @@ -83,7 +87,7 @@ void DateTest::ecbDates() { BOOST_FAIL("unable to add an EBC date"); } -void DateTest::immDates() { +BOOST_AUTO_TEST_CASE(immDates) { BOOST_TEST_MESSAGE("Testing IMM dates..."); const std::string IMMcodes[] = { @@ -142,7 +146,7 @@ void DateTest::immDates() { } } -void DateTest::asxDates() { +BOOST_AUTO_TEST_CASE(asxDates) { BOOST_TEST_MESSAGE("Testing ASX dates..."); const std::string ASXcodes[] = { @@ -200,7 +204,7 @@ void DateTest::asxDates() { } } -void DateTest::testConsistency() { +BOOST_AUTO_TEST_CASE(testConsistency) { BOOST_TEST_MESSAGE("Testing dates..."); @@ -302,7 +306,7 @@ void DateTest::testConsistency() { } -void DateTest::isoDates() { +BOOST_AUTO_TEST_CASE(isoDates) { BOOST_TEST_MESSAGE("Testing ISO dates..."); std::string input_date("2006-01-15"); Date d = DateParser::parseISO(input_date); @@ -317,7 +321,8 @@ void DateTest::isoDates() { } } -void DateTest::parseDates() { +#ifndef QL_PATCH_SOLARIS +BOOST_AUTO_TEST_CASE(parseDates) { BOOST_TEST_MESSAGE("Testing parsing of dates..."); std::string input_date("2006-01-15"); @@ -350,9 +355,10 @@ void DateTest::parseDates() { << " parsed date: " << d); } } +#endif -void DateTest::intraday() { #ifdef QL_HIGH_RESOLUTION_DATE +BOOST_AUTO_TEST_CASE(intraday) { BOOST_TEST_MESSAGE("Testing intraday information of dates..."); @@ -422,10 +428,10 @@ void DateTest::intraday() { BOOST_CHECK_MESSAGE(d3 + Period(20, Microseconds) == Date(10, April, 2023, 11, 43, 13, 234, 273), "failed to add microseconds"); -#endif } +#endif -void DateTest::canHash() { +BOOST_AUTO_TEST_CASE(canHash) { BOOST_TEST_MESSAGE("Testing hashing of dates..."); Date start_date = Date(1, Jan, 2020); @@ -466,22 +472,6 @@ void DateTest::canHash() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* DateTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Date tests"); - - suite->add(QUANTLIB_TEST_CASE(&DateTest::testConsistency)); - suite->add(QUANTLIB_TEST_CASE(&DateTest::ecbDates)); - suite->add(QUANTLIB_TEST_CASE(&DateTest::immDates)); - suite->add(QUANTLIB_TEST_CASE(&DateTest::asxDates)); - suite->add(QUANTLIB_TEST_CASE(&DateTest::isoDates)); - #ifndef QL_PATCH_SOLARIS - suite->add(QUANTLIB_TEST_CASE(&DateTest::parseDates)); - #endif - #ifdef QL_HIGH_RESOLUTION_DATE - suite->add(QUANTLIB_TEST_CASE(&DateTest::intraday)); - #endif - suite->add(QUANTLIB_TEST_CASE(&DateTest::canHash)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/dates.hpp b/test-suite/dates.hpp deleted file mode 100644 index 83298ba478c..00000000000 --- a/test-suite/dates.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 RiskMap srl - Copyright (C) 2020 Leonardo Arcari - Copyright (C) 2020 Kline s.r.l. - - 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_dates_hpp -#define quantlib_test_dates_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DateTest { - public: - static void testConsistency(); - static void ecbDates(); - static void immDates(); - static void asxDates(); - static void isoDates(); - static void parseDates(); - static void intraday(); - static void canHash(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 7f01328feb1..0fd4d3afea9 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -25,7 +25,7 @@ #ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER #include "paralleltestrunner.hpp" -#define BOOST_TEST_NO_MAIN 1 +//#define BOOST_TEST_NO_MAIN 1 #else #include #endif @@ -37,6 +37,8 @@ # include #endif +#define BOOST_TEST_NO_MAIN +#define BOOST_TEST_ALTERNATIVE_INIT_API #include "quantlibglobalfixture.hpp" #include "speedlevel.hpp" #include diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index e0ba55d3d8e..0123c7c23dc 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "dates.hpp" #include "daycounters.hpp" #include "defaultprobabilitycurves.hpp" #include "digitalcoupon.hpp" @@ -178,7 +177,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DateTest::suite(speed)); test->add(DayCounterTest::suite()); test->add(DefaultProbabilityCurveTest::suite()); test->add(DigitalCouponTest::suite()); // might fail with QL_USE_INDEXED_COUPON diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 7f20501898a..4bfca387ba9 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 c3e3d69d3cd..b380ba6bd78 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 6bf0b5f4aa920da31daf9a7f60fb507ad95f1e6a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:21:12 +0800 Subject: [PATCH 051/132] Migrated daycounters.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/daycounters.cpp | 85 +++++++++------------------- test-suite/daycounters.hpp | 54 ------------------ test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 27 insertions(+), 120 deletions(-) delete mode 100644 test-suite/daycounters.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index fc910ddcc67..d818c4da944 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - daycounters.hpp defaultprobabilitycurves.hpp digitalcoupon.hpp digitaloption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index d06c938cd95..3887d4f487c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - daycounters.hpp \ defaultprobabilitycurves.hpp \ digitalcoupon.hpp \ digitaloption.hpp \ diff --git a/test-suite/daycounters.cpp b/test-suite/daycounters.cpp index 4248ff651fa..9da957a29db 100644 --- a/test-suite/daycounters.cpp +++ b/test-suite/daycounters.cpp @@ -21,7 +21,7 @@ */ -#include "daycounters.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -111,8 +111,11 @@ namespace day_counters_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void DayCounterTest::testActualActual() { +BOOST_AUTO_TEST_SUITE(DayCounterTest) + +BOOST_AUTO_TEST_CASE(testActualActual) { BOOST_TEST_MESSAGE("Testing actual/actual day counters..."); @@ -222,7 +225,7 @@ void DayCounterTest::testActualActual() { } } -void DayCounterTest::testActualActualIsma() +BOOST_AUTO_TEST_CASE(testActualActualIsma) { BOOST_TEST_MESSAGE("Testing actual/actual (ISMA) with odd last period..."); @@ -337,7 +340,7 @@ void DayCounterTest::testActualActualIsma() } } -void DayCounterTest::testActualActualWithSemiannualSchedule() { +BOOST_AUTO_TEST_CASE(testActualActualWithSemiannualSchedule) { BOOST_TEST_MESSAGE("Testing actual/actual with schedule " "for undefined semiannual reference periods..."); @@ -454,8 +457,7 @@ void DayCounterTest::testActualActualWithSemiannualSchedule() { } } - -void DayCounterTest::testActualActualWithAnnualSchedule(){ +BOOST_AUTO_TEST_CASE(testActualActualWithAnnualSchedule){ BOOST_TEST_MESSAGE("Testing actual/actual with schedule " "for undefined annual reference periods..."); @@ -497,7 +499,7 @@ void DayCounterTest::testActualActualWithAnnualSchedule(){ } } -void DayCounterTest::testActualActualWithSchedule() { +BOOST_AUTO_TEST_CASE(testActualActualWithSchedule) { BOOST_TEST_MESSAGE("Testing actual/actual day counter with schedule..."); @@ -649,7 +651,7 @@ void DayCounterTest::testActualActualWithSchedule() { } } -void DayCounterTest::testSimple() { +BOOST_AUTO_TEST_CASE(testSimple) { BOOST_TEST_MESSAGE("Testing simple day counter..."); @@ -675,7 +677,7 @@ void DayCounterTest::testSimple() { } } -void DayCounterTest::testOne() { +BOOST_AUTO_TEST_CASE(testOne) { BOOST_TEST_MESSAGE("Testing 1/1 day counter..."); @@ -701,7 +703,7 @@ void DayCounterTest::testOne() { } } -void DayCounterTest::testBusiness252() { +BOOST_AUTO_TEST_CASE(testBusiness252) { BOOST_TEST_MESSAGE("Testing business/252 day counter..."); @@ -769,7 +771,7 @@ void DayCounterTest::testBusiness252() { } } -void DayCounterTest::testThirty365() { +BOOST_AUTO_TEST_CASE(testThirty365) { BOOST_TEST_MESSAGE("Testing 30/365 day counter..."); @@ -793,7 +795,7 @@ void DayCounterTest::testThirty365() { } } -void DayCounterTest::testThirty360_BondBasis() { +BOOST_AUTO_TEST_CASE(testThirty360_BondBasis) { BOOST_TEST_MESSAGE("Testing 30/360 day counter (Bond Basis)..."); @@ -847,7 +849,7 @@ void DayCounterTest::testThirty360_BondBasis() { } } -void DayCounterTest::testThirty360_EurobondBasis() { +BOOST_AUTO_TEST_CASE(testThirty360_EurobondBasis) { BOOST_TEST_MESSAGE("Testing 30/360 day counter (Eurobond Basis)..."); @@ -907,8 +909,7 @@ void DayCounterTest::testThirty360_EurobondBasis() { } } - -void DayCounterTest::testThirty360_ISDA() { +BOOST_AUTO_TEST_CASE(testThirty360_ISDA) { BOOST_TEST_MESSAGE("Testing 30/360 day counter (ISDA)..."); @@ -999,8 +1000,7 @@ void DayCounterTest::testThirty360_ISDA() { } } - -void DayCounterTest::testActual365_Canadian() { +BOOST_AUTO_TEST_CASE(testActual365_Canadian) { BOOST_TEST_MESSAGE("Testing that Actual/365 (Canadian) throws when needed..."); @@ -1027,9 +1027,8 @@ void DayCounterTest::testActual365_Canadian() { } } - -void DayCounterTest::testIntraday() { #ifdef QL_HIGH_RESOLUTION_DATE +BOOST_AUTO_TEST_CASE(testIntraday) { BOOST_TEST_MESSAGE("Testing intraday behavior of day counter..."); @@ -1054,10 +1053,10 @@ void DayCounterTest::testIntraday() { std::fabs(dc.yearFraction(d2, d1) + expected) < tol, "can not reproduce result for day counter " << dc.name()); } -#endif } +#endif -void DayCounterTest::testActualActualOutOfScheduleRange() { +BOOST_AUTO_TEST_CASE(testActualActualOutOfScheduleRange) { BOOST_TEST_MESSAGE("Testing usage of actual/actual out of schedule..."); Date today = Date(10, November, 2020); @@ -1091,8 +1090,7 @@ void DayCounterTest::testActualActualOutOfScheduleRange() { Settings::instance().evaluationDate() = temp; } - -void DayCounterTest::testAct366() { +BOOST_AUTO_TEST_CASE(testAct366) { BOOST_TEST_MESSAGE("Testing Act/366 day counter..."); @@ -1147,7 +1145,7 @@ void DayCounterTest::testAct366() { } } -void DayCounterTest::testAct36525() { +BOOST_AUTO_TEST_CASE(testAct36525) { BOOST_TEST_MESSAGE("Testing Act/365.25 day counter..."); @@ -1202,8 +1200,7 @@ void DayCounterTest::testAct36525() { } } - -void DayCounterTest::testActualConsistency() { +BOOST_AUTO_TEST_CASE(testActualConsistency) { BOOST_TEST_MESSAGE("Testing consistency between different actual day-counters..."); const std::vector todayDates = { @@ -1251,8 +1248,7 @@ void DayCounterTest::testActualConsistency() { } } - -void DayCounterTest::testYearFraction2DateBulk() { +BOOST_AUTO_TEST_CASE(testYearFraction2DateBulk) { BOOST_TEST_MESSAGE("Testing bulk dates for YearFractionToDate ..."); const auto dayCounters = std::vector{ @@ -1304,7 +1300,7 @@ void DayCounterTest::testYearFraction2DateBulk() { } } -void DayCounterTest::testYearFraction2DateRounding() { +BOOST_AUTO_TEST_CASE(testYearFraction2DateRounding) { BOOST_TEST_MESSAGE("Testing YearFractionToDate rounding to closer date..."); const std::vector dayCounters @@ -1323,33 +1319,6 @@ void DayCounterTest::testYearFraction2DateRounding() { } } +BOOST_AUTO_TEST_SUITE_END() - -test_suite* DayCounterTest::suite() { - auto* suite = BOOST_TEST_SUITE("Day counter tests"); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActual)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActualIsma)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActualWithSemiannualSchedule)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActualWithAnnualSchedule)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActualWithSchedule)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testSimple)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testOne)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testBusiness252)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty365)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_BondBasis)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_EurobondBasis)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testThirty360_ISDA)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActual365_Canadian)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualActualOutOfScheduleRange)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testAct366)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testAct36525)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testActualConsistency)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testYearFraction2DateBulk)); - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testYearFraction2DateRounding)); - -#ifdef QL_HIGH_RESOLUTION_DATE - suite->add(QUANTLIB_TEST_CASE(&DayCounterTest::testIntraday)); -#endif - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/daycounters.hpp b/test-suite/daycounters.hpp deleted file mode 100644 index 70b7c1d2270..00000000000 --- a/test-suite/daycounters.hpp +++ /dev/null @@ -1,54 +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_day_counters_hpp -#define quantlib_test_day_counters_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DayCounterTest { - public: - static void testActualActual(); - static void testActualActualIsma(); - static void testActualActualWithSchedule(); - static void testActualActualWithAnnualSchedule(); - static void testActualActualWithSemiannualSchedule(); - static void testSimple(); - static void testOne(); - static void testBusiness252(); - static void testThirty365(); - static void testThirty360_BondBasis(); - static void testThirty360_EurobondBasis(); - static void testThirty360_ISDA(); - static void testActual365_Canadian(); - static void testIntraday(); - static void testActualActualOutOfScheduleRange(); - static void testAct366(); - static void testAct36525(); - static void testActualConsistency(); - static void testYearFraction2DateBulk(); - static void testYearFraction2DateRounding(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 0123c7c23dc..5060f1a6620 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "daycounters.hpp" #include "defaultprobabilitycurves.hpp" #include "digitalcoupon.hpp" #include "digitaloption.hpp" @@ -177,7 +176,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DayCounterTest::suite()); test->add(DefaultProbabilityCurveTest::suite()); test->add(DigitalCouponTest::suite()); // might fail with QL_USE_INDEXED_COUPON test->add(DigitalOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 4bfca387ba9..cf59c51562a 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 b380ba6bd78..bf52343da41 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 73d2a6e4fead1b69a6b24e6980e720bd006aa6ac Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:27:45 +0800 Subject: [PATCH 052/132] Migrated defaultprobabilitycurves.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/defaultprobabilitycurves.cpp | 50 +++++++++---------------- test-suite/defaultprobabilitycurves.hpp | 44 ---------------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 17 insertions(+), 85 deletions(-) delete mode 100644 test-suite/defaultprobabilitycurves.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d818c4da944..ee3a2de4e6f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - defaultprobabilitycurves.hpp digitalcoupon.hpp digitaloption.hpp distributions.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 3887d4f487c..15a100208bc 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - defaultprobabilitycurves.hpp \ digitalcoupon.hpp \ digitaloption.hpp \ distributions.hpp \ diff --git a/test-suite/defaultprobabilitycurves.cpp b/test-suite/defaultprobabilitycurves.cpp index 4cd75ee11ef..f1c7a20bd0a 100644 --- a/test-suite/defaultprobabilitycurves.cpp +++ b/test-suite/defaultprobabilitycurves.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "defaultprobabilitycurves.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -48,7 +48,11 @@ using std::map; using std::vector; using std::string; -void DefaultProbabilityCurveTest::testDefaultProbability() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(DefaultProbabilityCurveTest) + +BOOST_AUTO_TEST_CASE(testDefaultProbability) { BOOST_TEST_MESSAGE("Testing default-probability structure..."); @@ -111,8 +115,7 @@ void DefaultProbabilityCurveTest::testDefaultProbability() { } } - -void DefaultProbabilityCurveTest::testFlatHazardRate() { +BOOST_AUTO_TEST_CASE(testFlatHazardRate) { BOOST_TEST_MESSAGE("Testing flat hazard rate..."); @@ -317,31 +320,31 @@ namespace { } -void DefaultProbabilityCurveTest::testFlatHazardConsistency() { +BOOST_AUTO_TEST_CASE(testFlatHazardConsistency) { BOOST_TEST_MESSAGE("Testing piecewise-flat hazard-rate consistency..."); testBootstrapFromSpread(); testBootstrapFromUpfront(); } -void DefaultProbabilityCurveTest::testFlatDensityConsistency() { +BOOST_AUTO_TEST_CASE(testFlatDensityConsistency) { BOOST_TEST_MESSAGE("Testing piecewise-flat default-density consistency..."); testBootstrapFromSpread(); testBootstrapFromUpfront(); } -void DefaultProbabilityCurveTest::testLinearDensityConsistency() { +BOOST_AUTO_TEST_CASE(testLinearDensityConsistency) { BOOST_TEST_MESSAGE("Testing piecewise-linear default-density consistency..."); testBootstrapFromSpread(); testBootstrapFromUpfront(); } -void DefaultProbabilityCurveTest::testLogLinearSurvivalConsistency() { +BOOST_AUTO_TEST_CASE(testLogLinearSurvivalConsistency) { BOOST_TEST_MESSAGE("Testing log-linear survival-probability consistency..."); testBootstrapFromSpread(); testBootstrapFromUpfront(); } -void DefaultProbabilityCurveTest::testSingleInstrumentBootstrap() { +BOOST_AUTO_TEST_CASE(testSingleInstrumentBootstrap) { BOOST_TEST_MESSAGE("Testing single-instrument curve bootstrap..."); Calendar calendar = TARGET(); @@ -377,7 +380,7 @@ void DefaultProbabilityCurveTest::testSingleInstrumentBootstrap() { defaultCurve.recalculate(); } -void DefaultProbabilityCurveTest::testUpfrontBootstrap() { +BOOST_AUTO_TEST_CASE(testUpfrontBootstrap) { BOOST_TEST_MESSAGE("Testing bootstrap on upfront quotes..."); // Setting this to false would prevent the upfront from being used. @@ -400,7 +403,8 @@ void DefaultProbabilityCurveTest::testUpfrontBootstrap() { retries, the default curve building fails. Allowing retries, it expands the min survival probability bounds but still fails. We set dontThrow to true in IterativeBootstrap to use a fall back curve. */ -void DefaultProbabilityCurveTest::testIterativeBootstrapRetries() { + +BOOST_AUTO_TEST_CASE(testIterativeBootstrapRetries) { BOOST_TEST_MESSAGE("Testing iterative bootstrap with retries..."); @@ -526,26 +530,6 @@ void DefaultProbabilityCurveTest::testIterativeBootstrapRetries() { BOOST_CHECK_NO_THROW(dpts->survivalProbability(testDate)); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* DefaultProbabilityCurveTest::suite() { - auto* suite = BOOST_TEST_SUITE("Default-probability curve tests"); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testDefaultProbability)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testFlatHazardRate)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testFlatHazardConsistency)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testFlatDensityConsistency)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testLinearDensityConsistency)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testLogLinearSurvivalConsistency)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testSingleInstrumentBootstrap)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testUpfrontBootstrap)); - suite->add(QUANTLIB_TEST_CASE( - &DefaultProbabilityCurveTest::testIterativeBootstrapRetries)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/defaultprobabilitycurves.hpp b/test-suite/defaultprobabilitycurves.hpp deleted file mode 100644 index d2b3e41935f..00000000000 --- a/test-suite/defaultprobabilitycurves.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008, 2009 StatPro Italia srl - Copyright (C) 2009 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_default_curves_hpp -#define quantlib_test_default_curves_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DefaultProbabilityCurveTest { - public: - static void testDefaultProbability(); - static void testFlatHazardRate(); - static void testFlatHazardConsistency(); - static void testFlatDensityConsistency(); - static void testLinearDensityConsistency(); - static void testLogLinearSurvivalConsistency(); - static void testSingleInstrumentBootstrap(); - static void testUpfrontBootstrap(); - 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 5060f1a6620..8a32b647e24 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "defaultprobabilitycurves.hpp" #include "digitalcoupon.hpp" #include "digitaloption.hpp" #include "distributions.hpp" @@ -176,7 +175,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DefaultProbabilityCurveTest::suite()); test->add(DigitalCouponTest::suite()); // might fail with QL_USE_INDEXED_COUPON test->add(DigitalOptionTest::suite()); test->add(DistributionTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index cf59c51562a..5de14ff664e 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 bf52343da41..27429018214 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 819bb231982faa8732653eca3e752f5d91bf068c Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:30:48 +0800 Subject: [PATCH 053/132] Migrated digitalcoupon.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/digitalcoupon.cpp | 36 +++++++++-------------- test-suite/digitalcoupon.hpp | 43 ---------------------------- test-suite/quantlibtestsuite.cpp | 3 +- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 15 insertions(+), 73 deletions(-) delete mode 100644 test-suite/digitalcoupon.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index ee3a2de4e6f..a4f44f84a06 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - digitalcoupon.hpp digitaloption.hpp distributions.hpp dividendoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 15a100208bc..cf993d94cbd 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - digitalcoupon.hpp \ digitaloption.hpp \ distributions.hpp \ dividendoption.hpp \ diff --git a/test-suite/digitalcoupon.cpp b/test-suite/digitalcoupon.cpp index e02c0e9f94d..5675fda4487 100644 --- a/test-suite/digitalcoupon.cpp +++ b/test-suite/digitalcoupon.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "digitalcoupon.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -66,8 +66,11 @@ namespace digital_coupon_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) // might fail with QL_USE_INDEXED_COUPON -void DigitalCouponTest::testAssetOrNothing() { +BOOST_AUTO_TEST_SUITE(DigitalCouponTest) + +BOOST_AUTO_TEST_CASE(testAssetOrNothing) { BOOST_TEST_MESSAGE("Testing European asset-or-nothing digital coupon..."); @@ -254,7 +257,7 @@ void DigitalCouponTest::testAssetOrNothing() { } } -void DigitalCouponTest::testAssetOrNothingDeepInTheMoney() { +BOOST_AUTO_TEST_CASE(testAssetOrNothingDeepInTheMoney) { BOOST_TEST_MESSAGE("Testing European deep in-the-money asset-or-nothing " "digital coupon..."); @@ -363,7 +366,7 @@ void DigitalCouponTest::testAssetOrNothingDeepInTheMoney() { } } -void DigitalCouponTest::testAssetOrNothingDeepOutTheMoney() { +BOOST_AUTO_TEST_CASE(testAssetOrNothingDeepOutTheMoney) { BOOST_TEST_MESSAGE("Testing European deep out-the-money asset-or-nothing " "digital coupon..."); @@ -470,7 +473,7 @@ void DigitalCouponTest::testAssetOrNothingDeepOutTheMoney() { } } -void DigitalCouponTest::testCashOrNothing() { +BOOST_AUTO_TEST_CASE(testCashOrNothing) { BOOST_TEST_MESSAGE("Testing European cash-or-nothing digital coupon..."); @@ -623,7 +626,7 @@ void DigitalCouponTest::testCashOrNothing() { } } -void DigitalCouponTest::testCashOrNothingDeepInTheMoney() { +BOOST_AUTO_TEST_CASE(testCashOrNothingDeepInTheMoney) { BOOST_TEST_MESSAGE("Testing European deep in-the-money cash-or-nothing " "digital coupon..."); @@ -730,7 +733,7 @@ void DigitalCouponTest::testCashOrNothingDeepInTheMoney() { } } -void DigitalCouponTest::testCashOrNothingDeepOutTheMoney() { +BOOST_AUTO_TEST_CASE(testCashOrNothingDeepOutTheMoney) { BOOST_TEST_MESSAGE("Testing European deep out-the-money cash-or-nothing " "digital coupon..."); @@ -838,8 +841,7 @@ void DigitalCouponTest::testCashOrNothingDeepOutTheMoney() { } } - -void DigitalCouponTest::testCallPutParity() { +BOOST_AUTO_TEST_CASE(testCallPutParity) { BOOST_TEST_MESSAGE("Testing call/put parity for European digital coupon..."); @@ -934,7 +936,7 @@ void DigitalCouponTest::testCallPutParity() { } } -void DigitalCouponTest::testReplicationType() { +BOOST_AUTO_TEST_CASE(testReplicationType) { BOOST_TEST_MESSAGE("Testing replication type for European digital coupon..."); @@ -1111,16 +1113,6 @@ void DigitalCouponTest::testReplicationType() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* DigitalCouponTest::suite() { - auto* suite = BOOST_TEST_SUITE("Digital coupon tests"); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testAssetOrNothing)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testAssetOrNothingDeepInTheMoney)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testAssetOrNothingDeepOutTheMoney)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testCashOrNothing)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testCashOrNothingDeepInTheMoney)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testCashOrNothingDeepOutTheMoney)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testCallPutParity)); - suite->add(QUANTLIB_TEST_CASE(&DigitalCouponTest::testReplicationType)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/digitalcoupon.hpp b/test-suite/digitalcoupon.hpp deleted file mode 100644 index 00bd69218e5..00000000000 --- a/test-suite/digitalcoupon.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Cristina Duminuco - 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_digitalcoupon_hpp -#define quantlib_test_digitalcoupon_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DigitalCouponTest { - public: - static void testAssetOrNothing(); - static void testAssetOrNothingDeepInTheMoney(); - static void testAssetOrNothingDeepOutTheMoney(); - static void testCashOrNothing(); - static void testCashOrNothingDeepInTheMoney(); - static void testCashOrNothingDeepOutTheMoney(); - static void testCallPutParity(); - static void testReplicationType(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 8a32b647e24..054cbf98a6a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,7 @@ # include #endif -#include "digitalcoupon.hpp" + #include "digitaloption.hpp" #include "distributions.hpp" #include "dividendoption.hpp" @@ -175,7 +175,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DigitalCouponTest::suite()); // might fail with QL_USE_INDEXED_COUPON test->add(DigitalOptionTest::suite()); test->add(DistributionTest::suite(speed)); test->add(DividendOptionTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 5de14ff664e..de240305ded 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 27429018214..356af20513d 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 0c4d276b563699203e593fd4f8806dff4cdf06b4 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:48:39 +0800 Subject: [PATCH 054/132] Migrated digitaloption.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 2 -- test-suite/digitaloption.cpp | 47 +++++++++------------------- test-suite/digitaloption.hpp | 44 -------------------------- test-suite/quantlibbenchmark.cpp | 8 +++-- test-suite/quantlibtestsuite.cpp | 3 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 22 insertions(+), 89 deletions(-) delete mode 100644 test-suite/digitaloption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index a4f44f84a06..e05d2975a4e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - digitaloption.hpp distributions.hpp dividendoption.hpp doublebarrieroption.hpp @@ -311,7 +310,7 @@ set(QL_BENCHMARK_SOURCES basketoption.cpp batesmodel.cpp convertiblebonds.cpp - digitaloption.cpp digitaloption.hpp + digitaloption.cpp dividendoption.cpp dividendoption.hpp europeanoption.cpp europeanoption.hpp fdheston.cpp fdheston.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index cf993d94cbd..9bf42cad151 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - digitaloption.hpp \ distributions.hpp \ dividendoption.hpp \ doublebarrieroption.hpp \ @@ -329,7 +328,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - doublebarrieroption.hpp \ digitaloption.hpp \ dividendoption.hpp \ europeanoption.hpp \ diff --git a/test-suite/digitaloption.cpp b/test-suite/digitaloption.cpp index 1e0fee515f3..5016e9f0a22 100644 --- a/test-suite/digitaloption.cpp +++ b/test-suite/digitaloption.cpp @@ -20,7 +20,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "digitaloption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -72,8 +72,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void DigitalOptionTest::testCashOrNothingEuropeanValues() { +BOOST_AUTO_TEST_SUITE(DigitalOptionTest) + +BOOST_AUTO_TEST_CASE(testCashOrNothingEuropeanValues) { BOOST_TEST_MESSAGE("Testing European cash-or-nothing digital option..."); @@ -127,7 +130,7 @@ void DigitalOptionTest::testCashOrNothingEuropeanValues() { } } -void DigitalOptionTest::testAssetOrNothingEuropeanValues() { +BOOST_AUTO_TEST_CASE(testAssetOrNothingEuropeanValues) { BOOST_TEST_MESSAGE("Testing European asset-or-nothing digital option..."); @@ -181,7 +184,7 @@ void DigitalOptionTest::testAssetOrNothingEuropeanValues() { } } -void DigitalOptionTest::testGapEuropeanValues() { +BOOST_AUTO_TEST_CASE(testGapEuropeanValues) { BOOST_TEST_MESSAGE("Testing European gap digital option..."); @@ -234,7 +237,7 @@ void DigitalOptionTest::testGapEuropeanValues() { } } -void DigitalOptionTest::testCashAtHitOrNothingAmericanValues() { +BOOST_AUTO_TEST_CASE(testCashAtHitOrNothingAmericanValues) { BOOST_TEST_MESSAGE("Testing American cash-(at-hit)-or-nothing " "digital option..."); @@ -301,7 +304,7 @@ void DigitalOptionTest::testCashAtHitOrNothingAmericanValues() { } } -void DigitalOptionTest::testAssetAtHitOrNothingAmericanValues() { +BOOST_AUTO_TEST_CASE(testAssetAtHitOrNothingAmericanValues) { BOOST_TEST_MESSAGE("Testing American asset-(at-hit)-or-nothing " "digital option..."); @@ -366,7 +369,7 @@ void DigitalOptionTest::testAssetAtHitOrNothingAmericanValues() { } } -void DigitalOptionTest::testCashAtExpiryOrNothingAmericanValues() { +BOOST_AUTO_TEST_CASE(testCashAtExpiryOrNothingAmericanValues) { BOOST_TEST_MESSAGE("Testing American cash-(at-expiry)-or-nothing " "digital option..."); @@ -434,7 +437,7 @@ void DigitalOptionTest::testCashAtExpiryOrNothingAmericanValues() { } } -void DigitalOptionTest::testAssetAtExpiryOrNothingAmericanValues() { +BOOST_AUTO_TEST_CASE(testAssetAtExpiryOrNothingAmericanValues) { BOOST_TEST_MESSAGE("Testing American asset-(at-expiry)-or-nothing " "digital option..."); @@ -506,7 +509,7 @@ void DigitalOptionTest::testAssetAtExpiryOrNothingAmericanValues() { } } -void DigitalOptionTest::testCashAtHitOrNothingAmericanGreeks() { +BOOST_AUTO_TEST_CASE(testCashAtHitOrNothingAmericanGreeks) { BOOST_TEST_MESSAGE("Testing American cash-(at-hit)-or-nothing " "digital option greeks..."); @@ -661,8 +664,7 @@ void DigitalOptionTest::testCashAtHitOrNothingAmericanGreeks() { } } - -void DigitalOptionTest::testMCCashAtHit() { +BOOST_AUTO_TEST_CASE(testMCCashAtHit) { BOOST_TEST_MESSAGE("Testing Monte Carlo cash-(at-hit)-or-nothing " "American engine..."); @@ -728,25 +730,6 @@ void DigitalOptionTest::testMCCashAtHit() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* DigitalOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Digital option tests"); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testCashOrNothingEuropeanValues)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testAssetOrNothingEuropeanValues)); - suite->add(QUANTLIB_TEST_CASE(&DigitalOptionTest::testGapEuropeanValues)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testCashAtHitOrNothingAmericanValues)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testCashAtHitOrNothingAmericanGreeks)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testAssetAtHitOrNothingAmericanValues)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testCashAtExpiryOrNothingAmericanValues)); - suite->add(QUANTLIB_TEST_CASE( - &DigitalOptionTest::testAssetAtExpiryOrNothingAmericanValues)); - suite->add(QUANTLIB_TEST_CASE(&DigitalOptionTest::testMCCashAtHit)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/digitaloption.hpp b/test-suite/digitaloption.hpp deleted file mode 100644 index a297b4df52d..00000000000 --- a/test-suite/digitaloption.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003, 2004 Ferdinando Ametrano - Copyright (C) 2003 Neil Firth - - 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_digital_option_hpp -#define quantlib_test_digital_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DigitalOptionTest { - public: - static void testCashOrNothingEuropeanValues(); - static void testAssetOrNothingEuropeanValues(); - static void testGapEuropeanValues(); - static void testCashAtHitOrNothingAmericanValues(); - static void testAssetAtHitOrNothingAmericanValues(); - static void testCashAtExpiryOrNothingAmericanValues(); - static void testAssetAtExpiryOrNothingAmericanValues(); - static void testCashAtHitOrNothingAmericanGreeks(); - static void testMCCashAtHit(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 771e007e74d..ab94abae860 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "digitaloption.hpp" #include "dividendoption.hpp" #include "europeanoption.hpp" #include "fdheston.hpp" @@ -188,6 +187,11 @@ namespace QuantLibTest { struct testBond: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace DigitalOptionTest { + struct testMCCashAtHit: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -227,7 +231,7 @@ namespace { Benchmark("BasketOption::EuroTwoValues", std::bind(&QuantLibTest::BasketOptionTest::testOddSamples::test_method, QuantLibTest::BasketOptionTest::testOddSamples()), 642.46), Benchmark("BatesModel::DAXCalibration", std::bind(&QuantLibTest::BatesModelTest::testDAXCalibration::test_method, QuantLibTest::BatesModelTest::testDAXCalibration()), 1993.35), Benchmark("ConvertibleBondTest::testBond", std::bind(&QuantLibTest::ConvertibleBondTest::testBond::test_method, QuantLibTest::ConvertibleBondTest::testBond()), 159.85), - Benchmark("DigitalOption::MCCashAtHit", &DigitalOptionTest::testMCCashAtHit, 995.87), + Benchmark("DigitalOption::MCCashAtHit", std::bind(&QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, QuantLibTest::DigitalOptionTest::testMCCashAtHit()), 995.87), Benchmark("DividendOption::FdEuropeanGreeks", &DividendOptionTest::testFdEuropeanGreeks, 949.52), Benchmark("DividendOption::FdAmericanGreeks", &DividendOptionTest::testFdAmericanGreeks, 1113.74), Benchmark("EuropeanOption::FdMcEngines", &EuropeanOptionTest::testMcEngines, 1988.63), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 054cbf98a6a..58873d2af93 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,8 +16,6 @@ # include #endif - -#include "digitaloption.hpp" #include "distributions.hpp" #include "dividendoption.hpp" #include "doublebarrieroption.hpp" @@ -175,7 +173,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DigitalOptionTest::suite()); test->add(DistributionTest::suite(speed)); test->add(DividendOptionTest::suite(speed)); test->add(EquityIndexTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index de240305ded..b0c73754ec2 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 356af20513d..d744dcca4f4 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 59f991c8ab6a6a7309aaab8888a47f28e5a71fdc Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 14:55:16 +0800 Subject: [PATCH 055/132] Migrated distributions.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/distributions.cpp | 69 +++++++++++----------------- test-suite/distributions.hpp | 46 ------------------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 27 insertions(+), 96 deletions(-) delete mode 100644 test-suite/distributions.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index e05d2975a4e..b32f96c1532 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - distributions.hpp dividendoption.hpp doublebarrieroption.hpp doublebinaryoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 9bf42cad151..98847b2ec4f 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - distributions.hpp \ dividendoption.hpp \ doublebarrieroption.hpp \ doublebinaryoption.hpp \ diff --git a/test-suite/distributions.cpp b/test-suite/distributions.cpp index 09cdc42deb1..4cef523aec3 100644 --- a/test-suite/distributions.cpp +++ b/test-suite/distributions.cpp @@ -22,7 +22,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "distributions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -206,9 +206,24 @@ namespace distributions_test { Real result; }; + class InverseNonCentralChiSquared { + public: + InverseNonCentralChiSquared(Real df, Real ncp) + : dist_(df, ncp) {} + + Real operator()(Real x) const { + return boost::math::quantile(dist_, x); + } + private: + const boost::math::non_central_chi_squared_distribution dist_; + }; } -void DistributionTest::testNormal() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(DistributionTest) + +BOOST_AUTO_TEST_CASE(testNormal) { BOOST_TEST_MESSAGE("Testing normal distributions..."); @@ -298,7 +313,7 @@ void DistributionTest::testNormal() { } } -void DistributionTest::testBivariate() { +BOOST_AUTO_TEST_CASE(testBivariate) { BOOST_TEST_MESSAGE("Testing bivariate cumulative normal distribution..."); @@ -323,8 +338,7 @@ void DistributionTest::testBivariate() { "West 2004", 1.0e-8); } - -void DistributionTest::testPoisson() { +BOOST_AUTO_TEST_CASE(testPoisson) { BOOST_TEST_MESSAGE("Testing Poisson distribution..."); @@ -361,7 +375,7 @@ void DistributionTest::testPoisson() { } } -void DistributionTest::testCumulativePoisson() { +BOOST_AUTO_TEST_CASE(testCumulativePoisson) { BOOST_TEST_MESSAGE("Testing cumulative Poisson distribution..."); @@ -397,7 +411,7 @@ void DistributionTest::testCumulativePoisson() { } } -void DistributionTest::testInverseCumulativePoisson() { +BOOST_AUTO_TEST_CASE(testInverseCumulativePoisson) { BOOST_TEST_MESSAGE("Testing inverse cumulative Poisson distribution..."); @@ -428,8 +442,7 @@ void DistributionTest::testInverseCumulativePoisson() { } } - -void DistributionTest::testBivariateCumulativeStudent() { +BOOST_AUTO_TEST_CASE(testBivariateCumulativeStudent) { BOOST_TEST_MESSAGE( "Testing bivariate cumulative Student t distribution..."); @@ -587,7 +600,7 @@ void DistributionTest::testBivariateCumulativeStudent() { } } -void DistributionTest::testBivariateCumulativeStudentVsBivariate() { +BOOST_AUTO_TEST_CASE(testBivariateCumulativeStudentVsBivariate) { BOOST_TEST_MESSAGE( "Testing bivariate cumulative Student t distribution for large N..."); @@ -625,23 +638,8 @@ void DistributionTest::testBivariateCumulativeStudentVsBivariate() { "\n average error: " << avgDiff); } } - - -namespace distributions_test { - class InverseNonCentralChiSquared { - public: - InverseNonCentralChiSquared(Real df, Real ncp) - : dist_(df, ncp) {} - - Real operator()(Real x) const { - return boost::math::quantile(dist_, x); - } - private: - const boost::math::non_central_chi_squared_distribution dist_; - }; -} -void DistributionTest::testInvCDFviaStochasticCollocation() { +BOOST_AUTO_TEST_CASE(testInvCDFviaStochasticCollocation) { BOOST_TEST_MESSAGE( "Testing inverse CDF based on stochastic collocation..."); @@ -708,7 +706,7 @@ void DistributionTest::testInvCDFviaStochasticCollocation() { } } -void DistributionTest::testSankaranApproximation() { +BOOST_AUTO_TEST_CASE(testSankaranApproximation) { BOOST_TEST_MESSAGE("Testing Sankaran approximation for the " "non-central cumulative chi-square distribution..."); @@ -741,19 +739,6 @@ void DistributionTest::testSankaranApproximation() { } } -test_suite* DistributionTest::suite(SpeedLevel) { - auto* suite = BOOST_TEST_SUITE("Distribution tests"); - - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testNormal)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testBivariate)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testPoisson)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testCumulativePoisson)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testInverseCumulativePoisson)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testBivariateCumulativeStudent)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testInvCDFviaStochasticCollocation)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testSankaranApproximation)); - suite->add(QUANTLIB_TEST_CASE(&DistributionTest::testBivariateCumulativeStudentVsBivariate)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/distributions.hpp b/test-suite/distributions.hpp deleted file mode 100644 index 036fd176310..00000000000 --- a/test-suite/distributions.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2003 Ferdinando Ametrano - Copyright (C) 2003 RiskMap srl - 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_distributions_hpp -#define quantlib_test_distributions_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DistributionTest { - public: - static void testNormal(); - static void testBivariate(); - static void testPoisson(); - static void testCumulativePoisson(); - static void testInverseCumulativePoisson(); - static void testBivariateCumulativeStudent(); - static void testBivariateCumulativeStudentVsBivariate(); - static void testInvCDFviaStochasticCollocation(); - static void testSankaranApproximation(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 58873d2af93..f46ecbb191b 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "distributions.hpp" #include "dividendoption.hpp" #include "doublebarrieroption.hpp" #include "doublebinaryoption.hpp" @@ -173,7 +172,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DistributionTest::suite(speed)); test->add(DividendOptionTest::suite(speed)); test->add(EquityIndexTest::suite()); test->add(EquityCashFlowTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index b0c73754ec2..a348f756075 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 d744dcca4f4..3f3279beb7c 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From a6988e2839c1f2cd1e718e4236b5b5528254cc88 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 15:03:36 +0800 Subject: [PATCH 056/132] Migrated dividendoption.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 3 -- test-suite/dividendoption.cpp | 67 +++++++++------------------- test-suite/dividendoption.hpp | 50 --------------------- test-suite/quantlibbenchmark.cpp | 8 +++- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 8 files changed, 29 insertions(+), 108 deletions(-) delete mode 100644 test-suite/dividendoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index b32f96c1532..720a87e647f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - dividendoption.hpp doublebarrieroption.hpp doublebinaryoption.hpp equityindex.hpp @@ -310,7 +309,7 @@ set(QL_BENCHMARK_SOURCES batesmodel.cpp convertiblebonds.cpp digitaloption.cpp - dividendoption.cpp dividendoption.hpp + dividendoption.cpp europeanoption.cpp europeanoption.hpp fdheston.cpp fdheston.hpp hestonmodel.cpp hestonmodel.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 98847b2ec4f..17ecff0895b 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - dividendoption.hpp \ doublebarrieroption.hpp \ doublebinaryoption.hpp \ equityindex.hpp \ @@ -327,8 +326,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - digitaloption.hpp \ - dividendoption.hpp \ europeanoption.hpp \ fdheston.hpp \ hestonmodel.hpp \ diff --git a/test-suite/dividendoption.cpp b/test-suite/dividendoption.cpp index 4881f59b647..77e77ae9247 100644 --- a/test-suite/dividendoption.cpp +++ b/test-suite/dividendoption.cpp @@ -20,7 +20,8 @@ // TODO: Figure out why tests for options with both continuous and discrete // dividends fail. -#include "dividendoption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -56,7 +57,11 @@ using namespace boost::unit_test_framework; // tests -void DividendOptionTest::testEuropeanValues() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(DividendOptionTest) + +BOOST_AUTO_TEST_CASE(testEuropeanValues) { BOOST_TEST_MESSAGE( "Testing dividend European option values with no dividends..."); @@ -169,7 +174,7 @@ void DividendOptionTest::testEuropeanValues() { // Reference pg. 253 - Hull - Options, Futures, and Other Derivatives 5th ed // Exercise 12.8 -void DividendOptionTest::testEuropeanKnownValue() { +BOOST_AUTO_TEST_CASE(testEuropeanKnownValue) { BOOST_TEST_MESSAGE("Testing dividend European option against known value..."); @@ -245,8 +250,7 @@ void DividendOptionTest::testEuropeanKnownValue() { } } - -void DividendOptionTest::testEuropeanStartLimit() { +BOOST_AUTO_TEST_CASE(testEuropeanStartLimit) { BOOST_TEST_MESSAGE( "Testing dividend European option with a dividend on today's date..."); @@ -340,7 +344,7 @@ void DividendOptionTest::testEuropeanStartLimit() { } } -void DividendOptionTest::testEuropeanEndLimit() { +BOOST_AUTO_TEST_CASE(testEuropeanEndLimit) { BOOST_TEST_MESSAGE( "Testing dividend European option values with end limits..."); @@ -436,8 +440,7 @@ void DividendOptionTest::testEuropeanEndLimit() { } } - -void DividendOptionTest::testOldEuropeanGreeks() { +BOOST_AUTO_TEST_CASE(testOldEuropeanGreeks) { BOOST_TEST_MESSAGE("Testing old-style dividend European option greeks..."); @@ -571,7 +574,7 @@ void DividendOptionTest::testOldEuropeanGreeks() { } } -void DividendOptionTest::testEuropeanGreeks() { +BOOST_AUTO_TEST_CASE(testEuropeanGreeks) { BOOST_TEST_MESSAGE("Testing dividend European option greeks..."); @@ -703,8 +706,7 @@ void DividendOptionTest::testEuropeanGreeks() { } } - -void DividendOptionTest::testFdEuropeanValues() { +BOOST_AUTO_TEST_CASE(testFdEuropeanValues) { BOOST_TEST_MESSAGE( "Testing finite-difference dividend European option values..."); @@ -946,8 +948,7 @@ namespace { } - -void DividendOptionTest::testFdEuropeanGreeks() { +BOOST_AUTO_TEST_CASE(testFdEuropeanGreeks, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing finite-differences dividend European option greeks..."); Date today = Date::todaysDate(); @@ -962,7 +963,7 @@ void DividendOptionTest::testFdEuropeanGreeks() { } } -void DividendOptionTest::testFdAmericanGreeks() { +BOOST_AUTO_TEST_CASE(testFdAmericanGreeks) { BOOST_TEST_MESSAGE( "Testing finite-differences dividend American option greeks..."); @@ -1054,8 +1055,7 @@ namespace { } - -void DividendOptionTest::testFdEuropeanDegenerate() { +BOOST_AUTO_TEST_CASE(testFdEuropeanDegenerate) { BOOST_TEST_MESSAGE( "Testing degenerate finite-differences dividend European option..."); @@ -1070,7 +1070,7 @@ void DividendOptionTest::testFdEuropeanDegenerate() { testFdDegenerate(today,exercise,FdBlackScholesVanillaEngine::Escrowed); } -void DividendOptionTest::testFdAmericanDegenerate() { +BOOST_AUTO_TEST_CASE(testFdAmericanDegenerate) { BOOST_TEST_MESSAGE( "Testing degenerate finite-differences dividend American option..."); @@ -1183,8 +1183,7 @@ namespace { } } - -void DividendOptionTest::testFdEuropeanWithDividendToday() { +BOOST_AUTO_TEST_CASE(testFdEuropeanWithDividendToday) { BOOST_TEST_MESSAGE( "Testing finite-differences dividend European option with dividend on today's date..."); @@ -1199,7 +1198,7 @@ void DividendOptionTest::testFdEuropeanWithDividendToday() { testFdDividendAtTZero(today,exercise,FdBlackScholesVanillaEngine::Escrowed); } -void DividendOptionTest::testFdAmericanWithDividendToday() { +BOOST_AUTO_TEST_CASE(testFdAmericanWithDividendToday) { BOOST_TEST_MESSAGE( "Testing finite-differences dividend American option with dividend on today's date..."); @@ -1213,8 +1212,7 @@ void DividendOptionTest::testFdAmericanWithDividendToday() { testFdDividendAtTZero(today,exercise,FdBlackScholesVanillaEngine::Spot); } - -void DividendOptionTest::testEscrowedDividendModel() { +BOOST_AUTO_TEST_CASE(testEscrowedDividendModel) { BOOST_TEST_MESSAGE("Testing finite-difference European engine " "with the escrowed dividend model..."); @@ -1320,27 +1318,6 @@ void DividendOptionTest::testEscrowedDividendModel() { } } -test_suite* DividendOptionTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Dividend European option tests"); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEuropeanValues)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEuropeanKnownValue)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEuropeanStartLimit)); - // Doesn't quite work. Need to use discounted values - //suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEuropeanEndLimit)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testOldEuropeanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEuropeanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdEuropeanValues)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdAmericanGreeks)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdEuropeanDegenerate)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdAmericanDegenerate)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdEuropeanWithDividendToday)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdAmericanWithDividendToday)); - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testEscrowedDividendModel)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&DividendOptionTest::testFdEuropeanGreeks)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/dividendoption.hpp b/test-suite/dividendoption.hpp deleted file mode 100644 index d3b556b7755..00000000000 --- a/test-suite/dividendoption.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2004, 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_dividend_option_hpp -#define quantlib_test_dividend_option_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DividendOptionTest { - public: - static void testEuropeanValues(); - static void testEuropeanKnownValue(); - static void testEuropeanStartLimit(); - static void testEuropeanEndLimit(); - static void testOldEuropeanGreeks(); - static void testEuropeanGreeks(); - static void testFdEuropeanValues(); - static void testFdEuropeanGreeks(); - static void testFdAmericanGreeks(); - static void testFdEuropeanDegenerate(); - static void testFdAmericanDegenerate(); - static void testFdEuropeanWithDividendToday(); - static void testFdAmericanWithDividendToday(); - static void testEscrowedDividendModel(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index ab94abae860..ac21e8ecc1b 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "dividendoption.hpp" #include "europeanoption.hpp" #include "fdheston.hpp" #include "hestonmodel.hpp" @@ -192,6 +191,11 @@ namespace QuantLibTest { struct testMCCashAtHit: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace DividendOptionTest { + struct testFdAmericanGreeks: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -232,7 +236,7 @@ namespace { Benchmark("BatesModel::DAXCalibration", std::bind(&QuantLibTest::BatesModelTest::testDAXCalibration::test_method, QuantLibTest::BatesModelTest::testDAXCalibration()), 1993.35), Benchmark("ConvertibleBondTest::testBond", std::bind(&QuantLibTest::ConvertibleBondTest::testBond::test_method, QuantLibTest::ConvertibleBondTest::testBond()), 159.85), Benchmark("DigitalOption::MCCashAtHit", std::bind(&QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, QuantLibTest::DigitalOptionTest::testMCCashAtHit()), 995.87), - Benchmark("DividendOption::FdEuropeanGreeks", &DividendOptionTest::testFdEuropeanGreeks, 949.52), + Benchmark("DividendOption::FdEuropeanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdAmericanGreeks()), 949.52), Benchmark("DividendOption::FdAmericanGreeks", &DividendOptionTest::testFdAmericanGreeks, 1113.74), Benchmark("EuropeanOption::FdMcEngines", &EuropeanOptionTest::testMcEngines, 1988.63), Benchmark("EuropeanOption::ImpliedVol", &EuropeanOptionTest::testImpliedVol, 131.51), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index f46ecbb191b..7c59f24be52 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "dividendoption.hpp" #include "doublebarrieroption.hpp" #include "doublebinaryoption.hpp" #include "equitycashflow.hpp" @@ -172,7 +171,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(DividendOptionTest::suite(speed)); test->add(EquityIndexTest::suite()); test->add(EquityCashFlowTest::suite()); test->add(EquityTotalReturnSwapTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index a348f756075..bced7851db4 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 3f3279beb7c..185e67c329e 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From fe4c3de6157d52d1a61f1c423c4c12e6b109fa4a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 15:21:20 +0800 Subject: [PATCH 057/132] Migrated doublebarrieroption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/doublebarrieroption.cpp | 34 ++++++++++-------------- test-suite/doublebarrieroption.hpp | 39 ---------------------------- test-suite/quantlibtestsuite.cpp | 1 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 14 insertions(+), 66 deletions(-) delete mode 100644 test-suite/doublebarrieroption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 720a87e647f..d36803ae47c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - doublebarrieroption.hpp doublebinaryoption.hpp equityindex.hpp equitycashflow.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 17ecff0895b..5715a6703b0 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - doublebarrieroption.hpp \ doublebinaryoption.hpp \ equityindex.hpp \ equitycashflow.hpp \ diff --git a/test-suite/doublebarrieroption.cpp b/test-suite/doublebarrieroption.cpp index 52fb3dd700c..79537a3645e 100644 --- a/test-suite/doublebarrieroption.cpp +++ b/test-suite/doublebarrieroption.cpp @@ -18,7 +18,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "doublebarrieroption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -143,8 +144,11 @@ namespace double_barrier_option_test { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void DoubleBarrierOptionTest::testEuropeanHaugValues() { +BOOST_AUTO_TEST_SUITE(DoubleBarrierOptionTest) + +BOOST_AUTO_TEST_CASE(testEuropeanHaugValues) { BOOST_TEST_MESSAGE("Testing double barrier european options against Haug's values..."); @@ -383,7 +387,11 @@ void DoubleBarrierOptionTest::testEuropeanHaugValues() { } } -void DoubleBarrierOptionTest::testVannaVolgaDoubleBarrierValues() { +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(DoubleBarrierOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testVannaVolgaDoubleBarrierValues) { BOOST_TEST_MESSAGE( "Testing double-barrier FX options against Vanna/Volga values..."); @@ -525,7 +533,7 @@ void DoubleBarrierOptionTest::testVannaVolgaDoubleBarrierValues() { } } -void DoubleBarrierOptionTest::testMonteCarloDoubleBarrierWithAnalytical() { +BOOST_AUTO_TEST_CASE(testMonteCarloDoubleBarrierWithAnalytical, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing MC double-barrier options against analytical values..."); using namespace double_barrier_option_test; @@ -632,20 +640,6 @@ void DoubleBarrierOptionTest::testMonteCarloDoubleBarrierWithAnalytical() { } -test_suite* DoubleBarrierOptionTest::suite(SpeedLevel) { - auto* suite = BOOST_TEST_SUITE("DoubleBarrier"); - suite->add(QUANTLIB_TEST_CASE(&DoubleBarrierOptionTest::testEuropeanHaugValues)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() -test_suite* DoubleBarrierOptionTest::experimental(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("DoubleBarrier_experimental"); - suite->add(QUANTLIB_TEST_CASE(&DoubleBarrierOptionTest::testVannaVolgaDoubleBarrierValues)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&DoubleBarrierOptionTest::testMonteCarloDoubleBarrierWithAnalytical)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/doublebarrieroption.hpp b/test-suite/doublebarrieroption.hpp deleted file mode 100644 index 10d3bc4664a..00000000000 --- a/test-suite/doublebarrieroption.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2015 Thema Consulting SA - - 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_double_barrier_option_hpp -#define quantlib_test_double_barrier_option_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DoubleBarrierOptionTest { - public: - static void testEuropeanHaugValues(); - static void testVannaVolgaDoubleBarrierValues(); - static void testMonteCarloDoubleBarrierWithAnalytical(); - static boost::unit_test_framework::test_suite* suite(SpeedLevel); - static boost::unit_test_framework::test_suite* experimental(SpeedLevel); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 7c59f24be52..d061505ca28 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "doublebarrieroption.hpp" #include "doublebinaryoption.hpp" #include "equitycashflow.hpp" #include "equityindex.hpp" diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index bced7851db4..fe7cd671b32 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 185e67c329e..854d9e13b87 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 27a696f7ba8a34939d57904faff923bdf8644c8a Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 15:35:01 +0800 Subject: [PATCH 058/132] Migrated doublebinaryoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/doublebinaryoption.cpp | 17 +++++++------ test-suite/doublebinaryoption.hpp | 36 ---------------------------- test-suite/quantlibbenchmark.cpp | 7 ++++-- test-suite/quantlibtestsuite.cpp | 4 ---- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 13 insertions(+), 57 deletions(-) delete mode 100644 test-suite/doublebinaryoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d36803ae47c..4ec02878e80 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - doublebinaryoption.hpp equityindex.hpp equitycashflow.hpp equitytotalreturnswap.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 5715a6703b0..69630c9277c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - doublebinaryoption.hpp \ equityindex.hpp \ equitycashflow.hpp \ equitytotalreturnswap.hpp \ diff --git a/test-suite/doublebinaryoption.cpp b/test-suite/doublebinaryoption.cpp index 6fadd75eb17..03b9a5a9771 100644 --- a/test-suite/doublebinaryoption.cpp +++ b/test-suite/doublebinaryoption.cpp @@ -17,7 +17,7 @@ Copyright (C) 2015 Thema Consulting SA FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "doublebinaryoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -71,8 +71,11 @@ namespace { }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void DoubleBinaryOptionTest::testHaugValues() { +BOOST_AUTO_TEST_SUITE(DoubleBinaryOptionTest) + +BOOST_AUTO_TEST_CASE(testHaugValues) { BOOST_TEST_MESSAGE("Testing cash-or-nothing double barrier options against Haug's values..."); @@ -243,7 +246,7 @@ void DoubleBinaryOptionTest::testHaugValues() { } } -void DoubleBinaryOptionTest::testPdeDoubleBarrierWithAnalytical() { +BOOST_AUTO_TEST_CASE(testPdeDoubleBarrierWithAnalytical) { BOOST_TEST_MESSAGE("Testing cash-or-nothing double barrier options " "against PDE Heston version..."); @@ -323,10 +326,6 @@ void DoubleBinaryOptionTest::testPdeDoubleBarrierWithAnalytical() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* DoubleBinaryOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("DoubleBinary"); - suite->add(QUANTLIB_TEST_CASE(&DoubleBinaryOptionTest::testHaugValues)); - suite->add(QUANTLIB_TEST_CASE(&DoubleBinaryOptionTest::testPdeDoubleBarrierWithAnalytical)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/doublebinaryoption.hpp b/test-suite/doublebinaryoption.hpp deleted file mode 100644 index 82b95ace4fb..00000000000 --- a/test-suite/doublebinaryoption.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2015 Thema Consulting SA - - 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_double_binary_option_hpp -#define quantlib_test_double_binary_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class DoubleBinaryOptionTest { - public: - static void testHaugValues(); - static void testPdeDoubleBarrierWithAnalytical(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index ac21e8ecc1b..7a129c0af16 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -193,6 +193,9 @@ namespace QuantLibTest { } namespace DividendOptionTest { + struct testFdEuropeanGreeks: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } @@ -236,8 +239,8 @@ namespace { Benchmark("BatesModel::DAXCalibration", std::bind(&QuantLibTest::BatesModelTest::testDAXCalibration::test_method, QuantLibTest::BatesModelTest::testDAXCalibration()), 1993.35), Benchmark("ConvertibleBondTest::testBond", std::bind(&QuantLibTest::ConvertibleBondTest::testBond::test_method, QuantLibTest::ConvertibleBondTest::testBond()), 159.85), Benchmark("DigitalOption::MCCashAtHit", std::bind(&QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, QuantLibTest::DigitalOptionTest::testMCCashAtHit()), 995.87), - Benchmark("DividendOption::FdEuropeanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdAmericanGreeks()), 949.52), - Benchmark("DividendOption::FdAmericanGreeks", &DividendOptionTest::testFdAmericanGreeks, 1113.74), + Benchmark("DividendOption::FdEuropeanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdEuropeanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdEuropeanGreeks()), 949.52), + Benchmark("DividendOption::FdAmericanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdAmericanGreeks()), 1113.74), Benchmark("EuropeanOption::FdMcEngines", &EuropeanOptionTest::testMcEngines, 1988.63), Benchmark("EuropeanOption::ImpliedVol", &EuropeanOptionTest::testImpliedVol, 131.51), Benchmark("EuropeanOption::FdEngines", &EuropeanOptionTest::testFdEngines, 148.43), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index d061505ca28..a16028f28de 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -16,7 +16,6 @@ # include #endif -#include "doublebinaryoption.hpp" #include "equitycashflow.hpp" #include "equityindex.hpp" #include "equitytotalreturnswap.hpp" @@ -262,9 +261,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(DoubleBarrierOptionTest::experimental(speed)); - test->add(DoubleBarrierOptionTest::suite(speed)); - test->add(DoubleBinaryOptionTest::suite()); test->add(EuropeanOptionTest::experimental()); test->add(EverestOptionTest::suite()); test->add(ExtendedTreesTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index fe7cd671b32..55bd03269fb 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 854d9e13b87..f3e5c1b58b9 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 83a36bf533e78a6e19e6db5eb66543699c74a540 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 27 Oct 2023 15:42:15 +0800 Subject: [PATCH 059/132] Reviewed changes --- test-suite/quantlibtestsuite.cpp | 20 ++++++++++++++++++++ test-suite/testsuite.vcxproj | 2 +- test-suite/testsuite.vcxproj.filters | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index a16028f28de..a3adb8b4a3f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -1,3 +1,23 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + Copyright (C) 2004, 2005, 2006, 2007 Ferdinando Ametrano + Copyright (C) 2004, 2005, 2006, 2007, 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. +*/ + #include #include #include diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 55bd03269fb..d0c50c6bf38 100644 --- a/test-suite/testsuite.vcxproj +++ b/test-suite/testsuite.vcxproj @@ -763,7 +763,7 @@ - + diff --git a/test-suite/testsuite.vcxproj.filters b/test-suite/testsuite.vcxproj.filters index f3e5c1b58b9..d22a0cdca9f 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -335,9 +335,9 @@ Source Files - + Source Files - + Source Files From b355809d14651eb5e129325068200b2c86ce5ec1 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 1 Nov 2023 11:10:17 +0800 Subject: [PATCH 060/132] Migrated equitycashflow.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/equitycashflow.cpp | 38 +++++++++++---------------- test-suite/equitycashflow.hpp | 39 ---------------------------- 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/equitycashflow.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 4ec02878e80..520d06eaef3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -175,7 +175,6 @@ set(QL_TEST_SOURCES set(QL_TEST_HEADERS equityindex.hpp - equitycashflow.hpp equitytotalreturnswap.hpp europeanoption.hpp everestoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 69630c9277c..6d59ef334db 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ equityindex.hpp \ - equitycashflow.hpp \ equitytotalreturnswap.hpp \ europeanoption.hpp \ everestoption.hpp \ diff --git a/test-suite/equitycashflow.cpp b/test-suite/equitycashflow.cpp index 493fcf59899..bcf085734dc 100644 --- a/test-suite/equitycashflow.cpp +++ b/test-suite/equitycashflow.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "equitycashflow.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -165,7 +165,11 @@ namespace equitycashflow_test { } } -void EquityCashFlowTest::testSimpleEquityCashFlow() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(EquityCashFlowTest) + +BOOST_AUTO_TEST_CASE(testSimpleEquityCashFlow) { BOOST_TEST_MESSAGE("Testing simple equity cash flow..."); using namespace equitycashflow_test; @@ -191,7 +195,7 @@ void EquityCashFlowTest::testSimpleEquityCashFlow() { << " index end: " << indexEnd << "\n"); } -void EquityCashFlowTest::testQuantoCorrection() { +BOOST_AUTO_TEST_CASE(testQuantoCorrection) { BOOST_TEST_MESSAGE("Testing quanto correction..."); using namespace equitycashflow_test; @@ -204,7 +208,7 @@ void EquityCashFlowTest::testQuantoCorrection() { checkQuantoCorrection(false, true); } -void EquityCashFlowTest::testErrorWhenBaseDateAfterFixingDate() { +BOOST_AUTO_TEST_CASE(testErrorWhenBaseDateAfterFixingDate) { BOOST_TEST_MESSAGE("Testing error when base date after fixing date..."); using namespace equitycashflow_test; @@ -219,7 +223,7 @@ void EquityCashFlowTest::testErrorWhenBaseDateAfterFixingDate() { checkRaisedError(cf, "Fixing date cannot fall before base date."); } -void EquityCashFlowTest::testErrorWhenQuantoCurveHandleIsEmpty() { +BOOST_AUTO_TEST_CASE(testErrorWhenQuantoCurveHandleIsEmpty) { BOOST_TEST_MESSAGE("Testing error when quanto currency curve handle is empty..."); using namespace equitycashflow_test; @@ -233,7 +237,7 @@ void EquityCashFlowTest::testErrorWhenQuantoCurveHandleIsEmpty() { checkRaisedError(cf, "Quanto currency term structure handle cannot be empty."); } -void EquityCashFlowTest::testErrorWhenEquityVolHandleIsEmpty() { +BOOST_AUTO_TEST_CASE(testErrorWhenEquityVolHandleIsEmpty) { BOOST_TEST_MESSAGE("Testing error when equity vol handle is empty..."); using namespace equitycashflow_test; @@ -247,7 +251,7 @@ void EquityCashFlowTest::testErrorWhenEquityVolHandleIsEmpty() { checkRaisedError(cf, "Equity volatility term structure handle cannot be empty."); } -void EquityCashFlowTest::testErrorWhenFXVolHandleIsEmpty() { +BOOST_AUTO_TEST_CASE(testErrorWhenFXVolHandleIsEmpty) { BOOST_TEST_MESSAGE("Testing error when FX vol handle is empty..."); using namespace equitycashflow_test; @@ -261,7 +265,7 @@ void EquityCashFlowTest::testErrorWhenFXVolHandleIsEmpty() { checkRaisedError(cf, "FX volatility term structure handle cannot be empty."); } -void EquityCashFlowTest::testErrorWhenCorrelationHandleIsEmpty() { +BOOST_AUTO_TEST_CASE(testErrorWhenCorrelationHandleIsEmpty) { BOOST_TEST_MESSAGE("Testing error when correlation handle is empty..."); using namespace equitycashflow_test; @@ -275,7 +279,7 @@ void EquityCashFlowTest::testErrorWhenCorrelationHandleIsEmpty() { checkRaisedError(cf, "Correlation handle cannot be empty."); } -void EquityCashFlowTest::testErrorWhenInconsistentMarketDataReferenceDate() { +BOOST_AUTO_TEST_CASE(testErrorWhenInconsistentMarketDataReferenceDate) { BOOST_TEST_MESSAGE("Testing error when market data reference dates are inconsistent..."); using namespace equitycashflow_test; @@ -291,18 +295,6 @@ void EquityCashFlowTest::testErrorWhenInconsistentMarketDataReferenceDate() { "reference date."); } -test_suite* EquityCashFlowTest::suite() { - auto* suite = BOOST_TEST_SUITE("Equity cash flow tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testSimpleEquityCashFlow)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testQuantoCorrection)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenBaseDateAfterFixingDate)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenQuantoCurveHandleIsEmpty)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenEquityVolHandleIsEmpty)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenFXVolHandleIsEmpty)); - suite->add(QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenCorrelationHandleIsEmpty)); - suite->add( - QUANTLIB_TEST_CASE(&EquityCashFlowTest::testErrorWhenInconsistentMarketDataReferenceDate)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/equitycashflow.hpp b/test-suite/equitycashflow.hpp deleted file mode 100644 index 4b950f4daa6..00000000000 --- a/test-suite/equitycashflow.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2023 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_equitycashflow_hpp -#define quantlib_test_equitycashflow_hpp - -#include - -class EquityCashFlowTest { - public: - static void testSimpleEquityCashFlow(); - static void testQuantoCorrection(); - static void testErrorWhenBaseDateAfterFixingDate(); - static void testErrorWhenQuantoCurveHandleIsEmpty(); - static void testErrorWhenEquityVolHandleIsEmpty(); - static void testErrorWhenFXVolHandleIsEmpty(); - static void testErrorWhenCorrelationHandleIsEmpty(); - static void testErrorWhenInconsistentMarketDataReferenceDate(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index a3adb8b4a3f..59a273fd721 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "equitycashflow.hpp" #include "equityindex.hpp" #include "equitytotalreturnswap.hpp" #include "europeanoption.hpp" @@ -190,7 +189,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CPISwapTest::suite()); test->add(EquityIndexTest::suite()); - test->add(EquityCashFlowTest::suite()); test->add(EquityTotalReturnSwapTest::suite()); test->add(EuropeanOptionTest::suite()); test->add(ExchangeRateTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index d0c50c6bf38..0a690f08fc6 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 d22a0cdca9f..417723ad4ff 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -887,8 +887,5 @@ Header Files - - Header Files - From eb6f83cd7109a659945bcb43ceeff1359088e9c3 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Wed, 1 Nov 2023 11:19:00 +0800 Subject: [PATCH 061/132] Migrated equityindex.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/equityindex.cpp | 52 +++++++++++----------------- test-suite/equityindex.hpp | 43 ----------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 20 insertions(+), 83 deletions(-) delete mode 100644 test-suite/equityindex.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 520d06eaef3..c7b1658b321 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - equityindex.hpp equitytotalreturnswap.hpp europeanoption.hpp everestoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6d59ef334db..816a91cb412 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - equityindex.hpp \ equitytotalreturnswap.hpp \ europeanoption.hpp \ everestoption.hpp \ diff --git a/test-suite/equityindex.cpp b/test-suite/equityindex.cpp index 856855b9ef3..d80ed895f3e 100644 --- a/test-suite/equityindex.cpp +++ b/test-suite/equityindex.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "equityindex.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -65,7 +65,11 @@ namespace equityindex_test { }; } -void EquityIndexTest::testTodaysFixing() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(EquityIndexTest) + +BOOST_AUTO_TEST_CASE(testTodaysFixing) { BOOST_TEST_MESSAGE("Testing today's fixing..."); using namespace equityindex_test; @@ -90,7 +94,7 @@ void EquityIndexTest::testTodaysFixing() { << " expected forecast: " << spot << "\n"); } -void EquityIndexTest::testTodaysFixingWithSpotAsProxy() { +BOOST_AUTO_TEST_CASE(testTodaysFixingWithSpotAsProxy) { BOOST_TEST_MESSAGE("Testing today's fixing with spot as proxy..."); using namespace equityindex_test; @@ -107,7 +111,7 @@ void EquityIndexTest::testTodaysFixingWithSpotAsProxy() { << " expected fixing: " << spot << "\n"); } -void EquityIndexTest::testFixingForecast() { +BOOST_AUTO_TEST_CASE(testFixingForecast) { BOOST_TEST_MESSAGE("Testing fixing forecast..."); using namespace equityindex_test; @@ -128,7 +132,7 @@ void EquityIndexTest::testFixingForecast() { << " expected forecast: " << expectedForecast << "\n"); } -void EquityIndexTest::testFixingForecastWithoutDividend() { +BOOST_AUTO_TEST_CASE(testFixingForecastWithoutDividend) { BOOST_TEST_MESSAGE("Testing fixing forecast without dividend..."); using namespace equityindex_test; @@ -151,7 +155,7 @@ void EquityIndexTest::testFixingForecastWithoutDividend() { << " expected forecast: " << expectedForecast << "\n"); } -void EquityIndexTest::testFixingForecastWithoutSpot() { +BOOST_AUTO_TEST_CASE(testFixingForecastWithoutSpot) { BOOST_TEST_MESSAGE("Testing fixing forecast without spot handle..."); using namespace equityindex_test; @@ -175,7 +179,7 @@ void EquityIndexTest::testFixingForecastWithoutSpot() { << " expected forecast: " << expectedForecast << "\n"); } -void EquityIndexTest::testFixingForecastWithoutSpotAndHistoricalFixing() { +BOOST_AUTO_TEST_CASE(testFixingForecastWithoutSpotAndHistoricalFixing) { BOOST_TEST_MESSAGE("Testing fixing forecast without spot handle and historical fixing..."); using namespace equityindex_test; @@ -193,7 +197,7 @@ void EquityIndexTest::testFixingForecastWithoutSpotAndHistoricalFixing() { "Cannot forecast equity index, missing both spot and historical index")); } -void EquityIndexTest::testSpotChange() { +BOOST_AUTO_TEST_CASE(testSpotChange) { BOOST_TEST_MESSAGE("Testing spot change..."); using namespace equityindex_test; @@ -217,7 +221,7 @@ void EquityIndexTest::testSpotChange() { << " expected spot: " << vars.spot->value() << "\n"); } -void EquityIndexTest::testErrorWhenInvalidFixingDate() { +BOOST_AUTO_TEST_CASE(testErrorWhenInvalidFixingDate) { BOOST_TEST_MESSAGE("Testing error when invalid fixing date is used..."); using namespace equityindex_test; @@ -229,7 +233,7 @@ void EquityIndexTest::testErrorWhenInvalidFixingDate() { ExpectedErrorMessage("Fixing date January 1st, 2023 is not valid")); } -void EquityIndexTest::testErrorWhenFixingMissing() { +BOOST_AUTO_TEST_CASE(testErrorWhenFixingMissing) { BOOST_TEST_MESSAGE("Testing error when required fixing is missing..."); using namespace equityindex_test; @@ -241,7 +245,7 @@ void EquityIndexTest::testErrorWhenFixingMissing() { ExpectedErrorMessage("Missing eqIndex fixing for January 2nd, 2023")); } -void EquityIndexTest::testErrorWhenInterestHandleMissing() { +BOOST_AUTO_TEST_CASE(testErrorWhenInterestHandleMissing) { BOOST_TEST_MESSAGE("Testing error when interest handle is missing..."); using namespace equityindex_test; @@ -259,7 +263,7 @@ void EquityIndexTest::testErrorWhenInterestHandleMissing() { "null interest rate term structure set to this instance of eqIndex")); } -void EquityIndexTest::testFixingObservability() { +BOOST_AUTO_TEST_CASE(testFixingObservability) { BOOST_TEST_MESSAGE("Testing observability of index fixings..."); using namespace equityindex_test; @@ -281,7 +285,7 @@ void EquityIndexTest::testFixingObservability() { BOOST_FAIL("Observer was not notified of added equity index fixing"); } -void EquityIndexTest::testNoErrorIfTodayIsNotBusinessDay() { +BOOST_AUTO_TEST_CASE(testNoErrorIfTodayIsNotBusinessDay) { BOOST_TEST_MESSAGE("Testing that no error is thrown if today is not a business day..."); using namespace equityindex_test; @@ -299,22 +303,6 @@ void EquityIndexTest::testNoErrorIfTodayIsNotBusinessDay() { BOOST_REQUIRE_NO_THROW(vars.equityIndex->fixing(forecastedDate)); } -test_suite* EquityIndexTest::suite() { - auto* suite = BOOST_TEST_SUITE("Equity index tests"); - - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testTodaysFixing)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testTodaysFixingWithSpotAsProxy)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testFixingForecast)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testFixingForecastWithoutDividend)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testFixingForecastWithoutSpot)); - suite->add( - QUANTLIB_TEST_CASE(&EquityIndexTest::testFixingForecastWithoutSpotAndHistoricalFixing)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testSpotChange)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testErrorWhenInvalidFixingDate)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testErrorWhenFixingMissing)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testErrorWhenInterestHandleMissing)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testFixingObservability)); - suite->add(QUANTLIB_TEST_CASE(&EquityIndexTest::testNoErrorIfTodayIsNotBusinessDay)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/equityindex.hpp b/test-suite/equityindex.hpp deleted file mode 100644 index 2c03e5cfc73..00000000000 --- a/test-suite/equityindex.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2023 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_equityindex_hpp -#define quantlib_test_equityindex_hpp - -#include - -class EquityIndexTest { - public: - static void testTodaysFixing(); - static void testTodaysFixingWithSpotAsProxy(); - static void testFixingForecast(); - static void testFixingForecastWithoutDividend(); - static void testFixingForecastWithoutSpot(); - static void testFixingForecastWithoutSpotAndHistoricalFixing(); - static void testSpotChange(); - static void testErrorWhenInvalidFixingDate(); - static void testErrorWhenFixingMissing(); - static void testErrorWhenInterestHandleMissing(); - static void testFixingObservability(); - static void testNoErrorIfTodayIsNotBusinessDay(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 59a273fd721..daf336bc41f 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "equityindex.hpp" #include "equitytotalreturnswap.hpp" #include "europeanoption.hpp" #include "everestoption.hpp" @@ -188,7 +187,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(EquityIndexTest::suite()); test->add(EquityTotalReturnSwapTest::suite()); test->add(EuropeanOptionTest::suite()); test->add(ExchangeRateTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0a690f08fc6..0ecc9986c9c 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 417723ad4ff..b017fbd2496 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -881,9 +881,6 @@ Header Files - - Header Files - Header Files From d3e3e040d612f1c275c366e74156c8150fbec3ff Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 10:05:16 +0800 Subject: [PATCH 062/132] Added auto test case template in basketoption.cpp --- test-suite/basketoption.cpp | 135 +++++++++++++----------- test-suite/dividendoption.cpp | 190 +++++++++++++++++----------------- 2 files changed, 168 insertions(+), 157 deletions(-) diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index 4a44e9bcce8..3e02cd7ef5f 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace QuantLib; using namespace boost::unit_test_framework; @@ -94,6 +95,9 @@ using namespace boost::unit_test_framework; namespace { + auto from = data::make ({0, 5, 11, 17, 23}); + auto to = data::make ({5, 11, 17, 23, 29}); + enum BasketType { MinBasket, MaxBasket, SpreadBasket }; std::string basketTypeToString(BasketType basketType) { @@ -741,85 +745,92 @@ BOOST_AUTO_TEST_CASE(testTavellaValues) { } } -BOOST_AUTO_TEST_CASE(testOneDAmericanValues) { - std::size_t from{0}, to{5}; +struct sliceOne { static const int from{0}, to{5}; }; +struct sliceTwo { static const int from{5}, to{11}; }; +struct sliceThree { static const int from{11}, to{17}; }; +struct sliceFour { static const int from{17}, to{23}; }; +struct sliceFive { static const int from{23}, to{29}; }; - for (int iter{0}; iter < 5; iter++) { +using slices = boost::mpl::vector; - BOOST_TEST_MESSAGE("Testing basket American options against 1-D case " - "from " << from << " to " << to - 1 << "..."); +BOOST_AUTO_TEST_CASE_TEMPLATE(testOneDAmericanValues, T, slices) { + const int from = T::from; + const int to = T::to; - DayCounter dc = Actual360(); - Date today = Date::todaysDate(); - ext::shared_ptr spot1(new SimpleQuote(0.0)); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - ext::shared_ptr qTS = flatRate(today, qRate, dc); + BOOST_TEST_MESSAGE("Testing basket American options against 1-D case " + "from " << from << " to " << to - 1 << "..."); - ext::shared_ptr rRate(new SimpleQuote(0.05)); - ext::shared_ptr rTS = flatRate(today, rRate, dc); + DayCounter dc = Actual360(); + Date today = Date::todaysDate(); - ext::shared_ptr vol1(new SimpleQuote(0.0)); - ext::shared_ptr volTS1 = flatVol(today, vol1, dc); + ext::shared_ptr spot1(new SimpleQuote(0.0)); - Size requiredSamples = 10000; - Size timeSteps = 52; - BigNatural seed = 0; + ext::shared_ptr qRate(new SimpleQuote(0.0)); + ext::shared_ptr qTS = flatRate(today, qRate, dc); - ext::shared_ptr stochProcess1(new - BlackScholesMertonProcess(Handle(spot1), - Handle(qTS), - Handle(rTS), - Handle(volTS1))); + ext::shared_ptr rRate(new SimpleQuote(0.05)); + ext::shared_ptr rTS = flatRate(today, rRate, dc); - std::vector> procs = {stochProcess1}; + ext::shared_ptr vol1(new SimpleQuote(0.0)); + ext::shared_ptr volTS1 = flatVol(today, vol1, dc); - Matrix correlation(1, 1, 1.0); + Size requiredSamples = 10000; + Size timeSteps = 52; + BigNatural seed = 0; - ext::shared_ptr process( - new StochasticProcessArray(procs, correlation)); + ext::shared_ptr stochProcess1(new + BlackScholesMertonProcess(Handle(spot1), + Handle(qTS), + Handle(rTS), + Handle(volTS1))); - ext::shared_ptr mcLSMCEngine = - MakeMCAmericanBasketEngine<>(process) - .withSteps(timeSteps) - .withAntitheticVariate() - .withSamples(requiredSamples) - .withCalibrationSamples(requiredSamples / 4) - .withSeed(seed); - - for (Size i = from; i < to; i++) { - ext::shared_ptr payoff( - new PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike)); - - Date exDate = today + timeToDays(oneDataValues[i].t); - ext::shared_ptr exercise(new AmericanExercise(today, exDate)); - - spot1 ->setValue(oneDataValues[i].s); - vol1 ->setValue(oneDataValues[i].v); - rRate ->setValue(oneDataValues[i].r); - qRate ->setValue(oneDataValues[i].q); - - BasketOption basketOption( // process, - basketTypeToPayoff(MaxBasket, payoff), exercise); - basketOption.setPricingEngine(mcLSMCEngine); - - Real calculated = basketOption.NPV(); - Real expected = oneDataValues[i].result; - // Real errorEstimate = basketOption.errorEstimate(); - Real relError = relativeError(calculated, expected, oneDataValues[i].s); - // Real error = std::fabs(calculated-expected); - - if (relError > oneDataValues[i].tol) { - BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n" - << "calculated: " << calculated); - } + std::vector> procs = {stochProcess1}; + + Matrix correlation(1, 1, 1.0); + + ext::shared_ptr process( + new StochasticProcessArray(procs, correlation)); + + ext::shared_ptr mcLSMCEngine = + MakeMCAmericanBasketEngine<>(process) + .withSteps(timeSteps) + .withAntitheticVariate() + .withSamples(requiredSamples) + .withCalibrationSamples(requiredSamples / 4) + .withSeed(seed); + + for (Size i = from; i < to; i++) { + ext::shared_ptr payoff( + new PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike)); + + Date exDate = today + timeToDays(oneDataValues[i].t); + ext::shared_ptr exercise(new AmericanExercise(today, exDate)); + + spot1 ->setValue(oneDataValues[i].s); + vol1 ->setValue(oneDataValues[i].v); + rRate ->setValue(oneDataValues[i].r); + qRate ->setValue(oneDataValues[i].q); + + BasketOption basketOption( // process, + basketTypeToPayoff(MaxBasket, payoff), exercise); + basketOption.setPricingEngine(mcLSMCEngine); + + Real calculated = basketOption.NPV(); + Real expected = oneDataValues[i].result; + // Real errorEstimate = basketOption.errorEstimate(); + Real relError = relativeError(calculated, expected, oneDataValues[i].s); + // Real error = std::fabs(calculated-expected); + + if (relError > oneDataValues[i].tol) { + BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n" + << "calculated: " << calculated); } - from = to; to += 6; } } -/* This unit test is a a regression test to check for a crash in +/* This unit test is a regression test to check for a crash in monte carlo if the required sample is odd. The crash occurred because the samples array size was off by one when antithetic paths were added. diff --git a/test-suite/dividendoption.cpp b/test-suite/dividendoption.cpp index 77e77ae9247..e535998d368 100644 --- a/test-suite/dividendoption.cpp +++ b/test-suite/dividendoption.cpp @@ -344,101 +344,101 @@ BOOST_AUTO_TEST_CASE(testEuropeanStartLimit) { } } -BOOST_AUTO_TEST_CASE(testEuropeanEndLimit) { - - BOOST_TEST_MESSAGE( - "Testing dividend European option values with end limits..."); - - Real tolerance = 1.0e-5; - Real dividendValue = 10.0; - - Option::Type types[] = { Option::Call, Option::Put }; - Real strikes[] = { 50.0, 99.5, 100.0, 100.5, 150.0 }; - Real underlyings[] = { 100.0 }; - Rate qRates[] = { 0.00, 0.10, 0.30 }; - Rate rRates[] = { 0.01, 0.05, 0.15 }; - Integer lengths[] = { 1, 2 }; - Volatility vols[] = { 0.05, 0.20, 0.70 }; - - DayCounter dc = Actual360(); - Date today = Date::todaysDate(); - Settings::instance().evaluationDate() = today; - - ext::shared_ptr spot(new SimpleQuote(0.0)); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - Handle qTS(flatRate(qRate, dc)); - ext::shared_ptr rRate(new SimpleQuote(0.0)); - Handle rTS(flatRate(rRate, dc)); - ext::shared_ptr vol(new SimpleQuote(0.0)); - Handle volTS(flatVol(vol, dc)); - - for (auto& type : types) { - for (Real strike : strikes) { - for (int length : lengths) { - Date exDate = today + length * Years; - ext::shared_ptr exercise(new EuropeanExercise(exDate)); - - ext::shared_ptr stochProcess( - new BlackScholesMertonProcess(Handle(spot), qTS, rTS, volTS)); - - std::vector dividendDates = {exercise->lastDate()}; - std::vector dividends = {dividendValue}; - - ext::shared_ptr payoff(new PlainVanillaPayoff(type, strike)); - - ext::shared_ptr refPayoff( - new PlainVanillaPayoff(type, strike + dividendValue)); - - ext::shared_ptr ref_engine(new AnalyticEuropeanEngine(stochProcess)); - - VanillaOption ref_option(refPayoff, exercise); - ref_option.setPricingEngine(ref_engine); - - QL_DEPRECATED_DISABLE_WARNING - ext::shared_ptr engine1( - new AnalyticDividendEuropeanEngine(stochProcess)); - - DividendVanillaOption option1(payoff, exercise, dividendDates, dividends); - QL_DEPRECATED_ENABLE_WARNING - option1.setPricingEngine(engine1); - - auto engine2 = ext::make_shared( - stochProcess, DividendVector(dividendDates, dividends)); - - VanillaOption option2(payoff, exercise); - option2.setPricingEngine(engine2); - - for (Real u : underlyings) { - for (Real m : qRates) { - for (Real n : rRates) { - for (Real v : vols) { - Rate q = m, r = n; - spot->setValue(u); - qRate->setValue(q); - rRate->setValue(r); - vol->setValue(v); - - Real expected = ref_option.NPV(); - Real calculated = option1.NPV(); - Real error = std::fabs(calculated - expected); - if (error > tolerance) { - REPORT_FAILURE("value", payoff, exercise, u, q, r, today, v, - expected, calculated, error, tolerance); - } - calculated = option2.NPV(); - error = std::fabs(calculated - expected); - if (error > tolerance) { - REPORT_FAILURE("value", payoff, exercise, u, q, r, today, v, - expected, calculated, error, tolerance); - } - } - } - } - } - } - } - } -} +//BOOST_AUTO_TEST_CASE(testEuropeanEndLimit) { +// +// BOOST_TEST_MESSAGE( +// "Testing dividend European option values with end limits..."); +// +// Real tolerance = 1.0e-5; +// Real dividendValue = 10.0; +// +// Option::Type types[] = { Option::Call, Option::Put }; +// Real strikes[] = { 50.0, 99.5, 100.0, 100.5, 150.0 }; +// Real underlyings[] = { 100.0 }; +// Rate qRates[] = { 0.00, 0.10, 0.30 }; +// Rate rRates[] = { 0.01, 0.05, 0.15 }; +// Integer lengths[] = { 1, 2 }; +// Volatility vols[] = { 0.05, 0.20, 0.70 }; +// +// DayCounter dc = Actual360(); +// Date today = Date::todaysDate(); +// Settings::instance().evaluationDate() = today; +// +// ext::shared_ptr spot(new SimpleQuote(0.0)); +// ext::shared_ptr qRate(new SimpleQuote(0.0)); +// Handle qTS(flatRate(qRate, dc)); +// ext::shared_ptr rRate(new SimpleQuote(0.0)); +// Handle rTS(flatRate(rRate, dc)); +// ext::shared_ptr vol(new SimpleQuote(0.0)); +// Handle volTS(flatVol(vol, dc)); +// +// for (auto& type : types) { +// for (Real strike : strikes) { +// for (int length : lengths) { +// Date exDate = today + length * Years; +// ext::shared_ptr exercise(new EuropeanExercise(exDate)); +// +// ext::shared_ptr stochProcess( +// new BlackScholesMertonProcess(Handle(spot), qTS, rTS, volTS)); +// +// std::vector dividendDates = {exercise->lastDate()}; +// std::vector dividends = {dividendValue}; +// +// ext::shared_ptr payoff(new PlainVanillaPayoff(type, strike)); +// +// ext::shared_ptr refPayoff( +// new PlainVanillaPayoff(type, strike + dividendValue)); +// +// ext::shared_ptr ref_engine(new AnalyticEuropeanEngine(stochProcess)); +// +// VanillaOption ref_option(refPayoff, exercise); +// ref_option.setPricingEngine(ref_engine); +// +// QL_DEPRECATED_DISABLE_WARNING +// ext::shared_ptr engine1( +// new AnalyticDividendEuropeanEngine(stochProcess)); +// +// DividendVanillaOption option1(payoff, exercise, dividendDates, dividends); +// QL_DEPRECATED_ENABLE_WARNING +// option1.setPricingEngine(engine1); +// +// auto engine2 = ext::make_shared( +// stochProcess, DividendVector(dividendDates, dividends)); +// +// VanillaOption option2(payoff, exercise); +// option2.setPricingEngine(engine2); +// +// for (Real u : underlyings) { +// for (Real m : qRates) { +// for (Real n : rRates) { +// for (Real v : vols) { +// Rate q = m, r = n; +// spot->setValue(u); +// qRate->setValue(q); +// rRate->setValue(r); +// vol->setValue(v); +// +// Real expected = ref_option.NPV(); +// Real calculated = option1.NPV(); +// Real error = std::fabs(calculated - expected); +// if (error > tolerance) { +// REPORT_FAILURE("value", payoff, exercise, u, q, r, today, v, +// expected, calculated, error, tolerance); +// } +// calculated = option2.NPV(); +// error = std::fabs(calculated - expected); +// if (error > tolerance) { +// REPORT_FAILURE("value", payoff, exercise, u, q, r, today, v, +// expected, calculated, error, tolerance); +// } +// } +// } +// } +// } +// } +// } +// } +//} BOOST_AUTO_TEST_CASE(testOldEuropeanGreeks) { From a6781ed7aff3925a710f61c86033b24f5ea846e9 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 10:55:42 +0800 Subject: [PATCH 063/132] Added auto test case template in cdo.cpp --- test-suite/basketoption.cpp | 4 - test-suite/cdo.cpp | 498 ++++++++++++++++++------------------ 2 files changed, 253 insertions(+), 249 deletions(-) diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index 3e02cd7ef5f..31a896bee58 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -37,7 +37,6 @@ #include #include #include -#include using namespace QuantLib; using namespace boost::unit_test_framework; @@ -95,9 +94,6 @@ using namespace boost::unit_test_framework; namespace { - auto from = data::make ({0, 5, 11, 17, 23}); - auto to = data::make ({5, 11, 17, 23, 29}); - enum BasketType { MinBasket, MaxBasket, SpreadBasket }; std::string basketTypeToString(BasketType basketType) { diff --git a/test-suite/cdo.cpp b/test-suite/cdo.cpp index 0ebefb08711..b0c9a75a940 100644 --- a/test-suite/cdo.cpp +++ b/test-suite/cdo.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -93,256 +94,263 @@ namespace cdo_test { BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -BOOST_AUTO_TEST_SUITE(CdoExperimentalTest) +BOOST_AUTO_TEST_SUITE(CdoExperimentalTest, *precondition(if_speed(Slow))) #ifndef QL_PATCH_SOLARIS -BOOST_AUTO_TEST_CASE(testHW, *precondition(if_speed(Slow))) { - - for (int dataSet{0}; dataSet < 5; dataSet++) { - - BOOST_TEST_MESSAGE("Testing CDO premiums against Hull-White values" - " for data set " - << dataSet << "..."); - - using namespace cdo_test; - - Size poolSize = 100; - Real lambda = 0.01; - - // nBuckets and period determine the computation time - Size nBuckets = 200; - // Period period = 1*Months; - // for MC engines - Size numSims = 5000; - - Real rate = 0.05; - DayCounter daycount = Actual360(); - Compounding cmp = Continuous; // Simple; - - Real recovery = 0.4; - std::vector nominals(poolSize, 100.0); - Real premium = 0.02; - Period maxTerm(5, Years); - Schedule schedule = MakeSchedule() - .from(Date(1, September, 2006)) - .to(Date(1, September, 2011)) - .withTenor(Period(3, Months)) - .withCalendar(TARGET()); - - Date asofDate = Date(31, August, 2006); - - Settings::instance().evaluationDate() = asofDate; - - ext::shared_ptr yieldPtr( - new FlatForward(asofDate, rate, daycount, cmp)); - Handle yieldHandle(yieldPtr); - - Handle hazardRate(ext::shared_ptr(new SimpleQuote(lambda))); - std::vector> basket; - ext::shared_ptr ptr( - new FlatHazardRate(asofDate, hazardRate, ActualActual(ActualActual::ISDA))); - ext::shared_ptr pool(new Pool()); - std::vector names; - // probability key items - std::vector issuers; - std::vector>> - probabilities; - probabilities.emplace_back( - NorthAmericaCorpDefaultKey(EURCurrency(), SeniorSec, Period(0, Weeks), 10.), - Handle(ptr)); - - for (Size i = 0; i < poolSize; ++i) { - std::ostringstream o; - o << "issuer-" << i; - names.push_back(o.str()); - basket.emplace_back(ptr); - issuers.emplace_back(probabilities); - pool->add(names.back(), issuers.back(), - NorthAmericaCorpDefaultKey(EURCurrency(), QuantLib::SeniorSec, Period(), 1.)); - } +struct dataSetOne { static const int dataset{0}; }; +struct dataSetTwo { static const int dataset{1}; }; +struct dataSetThree { static const int dataset{2}; }; +struct dataSetFour { static const int dataset{3}; }; +struct dataSetFive { static const int dataset{4}; }; + +using dataSets = boost::mpl::vector; + +BOOST_AUTO_TEST_CASE_TEMPLATE(testHW, T, dataSets) { + + const int dataSet = T::dataset; + + BOOST_TEST_MESSAGE("Testing CDO premiums against Hull-White values" + " for data set " + << dataSet << "..."); + + using namespace cdo_test; + + Size poolSize = 100; + Real lambda = 0.01; + + // nBuckets and period determine the computation time + Size nBuckets = 200; + // Period period = 1*Months; + // for MC engines + Size numSims = 5000; + + Real rate = 0.05; + DayCounter daycount = Actual360(); + Compounding cmp = Continuous; // Simple; + + Real recovery = 0.4; + std::vector nominals(poolSize, 100.0); + Real premium = 0.02; + Period maxTerm(5, Years); + Schedule schedule = MakeSchedule() + .from(Date(1, September, 2006)) + .to(Date(1, September, 2011)) + .withTenor(Period(3, Months)) + .withCalendar(TARGET()); + + Date asofDate = Date(31, August, 2006); + + Settings::instance().evaluationDate() = asofDate; + + ext::shared_ptr yieldPtr( + new FlatForward(asofDate, rate, daycount, cmp)); + Handle yieldHandle(yieldPtr); + + Handle hazardRate(ext::shared_ptr(new SimpleQuote(lambda))); + std::vector> basket; + ext::shared_ptr ptr( + new FlatHazardRate(asofDate, hazardRate, ActualActual(ActualActual::ISDA))); + ext::shared_ptr pool(new Pool()); + std::vector names; + // probability key items + std::vector issuers; + std::vector>> + probabilities; + probabilities.emplace_back( + NorthAmericaCorpDefaultKey(EURCurrency(), SeniorSec, Period(0, Weeks), 10.), + Handle(ptr)); + + for (Size i = 0; i < poolSize; ++i) { + std::ostringstream o; + o << "issuer-" << i; + names.push_back(o.str()); + basket.emplace_back(ptr); + issuers.emplace_back(probabilities); + pool->add(names.back(), issuers.back(), + NorthAmericaCorpDefaultKey(EURCurrency(), QuantLib::SeniorSec, Period(), 1.)); + } - ext::shared_ptr correlation(new SimpleQuote(0.0)); - Handle hCorrelation(correlation); - QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwDetachment), "data length does not match"); - - ext::shared_ptr midPCDOEngine(new MidPointCDOEngine(yieldHandle)); - ext::shared_ptr integralCDOEngine(new IntegralCDOEngine(yieldHandle)); - - const Size i = dataSet; - correlation->setValue(hwData7[i].correlation); - QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwData7[i].trancheSpread), - "data length does not match"); - std::vector> basketModels; - std::vector modelNames; - std::vector relativeToleranceMidp, relativeTolerancePeriod, absoluteTolerance; - - if (hwData7[i].nm == -1 && hwData7[i].nz == -1) { - ext::shared_ptr gaussKtLossLM( - new GaussianConstantLossLM(hCorrelation, std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, poolSize, - GaussianCopulaPolicy::initTraits())); - - // 1.-Inhomogeneous gaussian - modelNames.emplace_back("Inhomogeneous gaussian"); - basketModels.push_back(ext::shared_ptr( - new IHGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous gaussian - modelNames.emplace_back("Homogeneous gaussian"); - basketModels.push_back(ext::shared_ptr( - new HomogGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default gaussian - modelNames.emplace_back("Random default gaussian"); - basketModels.push_back(ext::shared_ptr( - new RandomDefaultLM(gaussKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // gaussian LHP - modelNames.emplace_back("Gaussian LHP"); - basketModels.push_back(ext::shared_ptr( - new GaussianLHPLossModel(hCorrelation, std::vector(poolSize, recovery)))); - absoluteTolerance.push_back(10.); - relativeToleranceMidp.push_back(0.5); - relativeTolerancePeriod.push_back(0.5); - // Binomial... - // Saddle point... - // Recursive ... - } else if (hwData7[i].nm > 0 && hwData7[i].nz > 0) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(hwData7[i].nm); - initTG.tOrders.push_back(hwData7[i].nz); - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); - // 1.-inhomogeneous studentT - modelNames.emplace_back("Inhomogeneous student"); - basketModels.push_back(ext::shared_ptr( - new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous student T - modelNames.emplace_back("Homogeneous student"); - basketModels.push_back(ext::shared_ptr( - new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default student T - modelNames.emplace_back("Random default studentT"); - basketModels.push_back(ext::shared_ptr( - new RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } else if (hwData7[i].nm > 0 && hwData7[i].nz == -1) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(hwData7[i].nm); - initTG.tOrders.push_back(45); - /* T_{55} is pretty close to a gaussian. Probably theres no need to - be this conservative as the polynomial convolution gets shorter and - faster as the order decreases. - */ - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); - // 1.-inhomogeneous - modelNames.emplace_back("Inhomogeneous student-gaussian"); - basketModels.push_back(ext::shared_ptr( - new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous - modelNames.emplace_back("Homogeneous student-gaussian"); - basketModels.push_back(ext::shared_ptr( - new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default - modelNames.emplace_back("Random default student-gaussian"); - basketModels.push_back(ext::shared_ptr( - new RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } else if (hwData7[i].nm == -1 && hwData7[i].nz > 0) { - TCopulaPolicy::initTraits initTG; - initTG.tOrders.push_back(45); // pretty close to gaussian - initTG.tOrders.push_back(hwData7[i].nz); - ext::shared_ptr TKtLossLM(new TConstantLossLM( - hCorrelation, std::vector(poolSize, recovery), - LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); - // 1.-inhomogeneous gaussian - modelNames.emplace_back("Inhomogeneous gaussian-student"); - basketModels.push_back(ext::shared_ptr( - new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 2.-homogeneous gaussian - modelNames.emplace_back("Homogeneous gaussian-student"); - basketModels.push_back(ext::shared_ptr( - new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.04); - relativeTolerancePeriod.push_back(0.04); - // 3.-random default gaussian - modelNames.emplace_back("Random default gaussian-student"); - basketModels.push_back(ext::shared_ptr( - new RandomDefaultLM(TKtLossLM, numSims))); - absoluteTolerance.push_back(1.); - relativeToleranceMidp.push_back(0.07); - relativeTolerancePeriod.push_back(0.07); - // SECOND MC - // Binomial... - // Saddle point... - // Recursive ... - } else { - return; - } + ext::shared_ptr correlation(new SimpleQuote(0.0)); + Handle hCorrelation(correlation); + QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwDetachment), "data length does not match"); + + ext::shared_ptr midPCDOEngine(new MidPointCDOEngine(yieldHandle)); + ext::shared_ptr integralCDOEngine(new IntegralCDOEngine(yieldHandle)); + + const Size i = dataSet; + correlation->setValue(hwData7[i].correlation); + QL_REQUIRE(LENGTH(hwAttachment) == LENGTH(hwData7[i].trancheSpread), + "data length does not match"); + std::vector> basketModels; + std::vector modelNames; + std::vector relativeToleranceMidp, relativeTolerancePeriod, absoluteTolerance; + + if (hwData7[i].nm == -1 && hwData7[i].nz == -1) { + ext::shared_ptr gaussKtLossLM( + new GaussianConstantLossLM(hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, + GaussianCopulaPolicy::initTraits())); + + // 1.-Inhomogeneous gaussian + modelNames.emplace_back("Inhomogeneous gaussian"); + basketModels.push_back(ext::shared_ptr( + new IHGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous gaussian + modelNames.emplace_back("Homogeneous gaussian"); + basketModels.push_back(ext::shared_ptr( + new HomogGaussPoolLossModel(gaussKtLossLM, nBuckets, 5., -5, 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default gaussian + modelNames.emplace_back("Random default gaussian"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(gaussKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // gaussian LHP + modelNames.emplace_back("Gaussian LHP"); + basketModels.push_back(ext::shared_ptr( + new GaussianLHPLossModel(hCorrelation, std::vector(poolSize, recovery)))); + absoluteTolerance.push_back(10.); + relativeToleranceMidp.push_back(0.5); + relativeTolerancePeriod.push_back(0.5); + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm > 0 && hwData7[i].nz > 0) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(hwData7[i].nm); + initTG.tOrders.push_back(hwData7[i].nz); + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous studentT + modelNames.emplace_back("Inhomogeneous student"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous student T + modelNames.emplace_back("Homogeneous student"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default student T + modelNames.emplace_back("Random default studentT"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm > 0 && hwData7[i].nz == -1) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(hwData7[i].nm); + initTG.tOrders.push_back(45); + /* T_{55} is pretty close to a gaussian. Probably theres no need to + be this conservative as the polynomial convolution gets shorter and + faster as the order decreases. + */ + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous + modelNames.emplace_back("Inhomogeneous student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous + modelNames.emplace_back("Homogeneous student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default + modelNames.emplace_back("Random default student-gaussian"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else if (hwData7[i].nm == -1 && hwData7[i].nz > 0) { + TCopulaPolicy::initTraits initTG; + initTG.tOrders.push_back(45); // pretty close to gaussian + initTG.tOrders.push_back(hwData7[i].nz); + ext::shared_ptr TKtLossLM(new TConstantLossLM( + hCorrelation, std::vector(poolSize, recovery), + LatentModelIntegrationType::GaussianQuadrature, poolSize, initTG)); + // 1.-inhomogeneous gaussian + modelNames.emplace_back("Inhomogeneous gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new IHStudentPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 2.-homogeneous gaussian + modelNames.emplace_back("Homogeneous gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new HomogTPoolLossModel(TKtLossLM, nBuckets, 5., -5., 15))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.04); + relativeTolerancePeriod.push_back(0.04); + // 3.-random default gaussian + modelNames.emplace_back("Random default gaussian-student"); + basketModels.push_back(ext::shared_ptr( + new RandomDefaultLM(TKtLossLM, numSims))); + absoluteTolerance.push_back(1.); + relativeToleranceMidp.push_back(0.07); + relativeTolerancePeriod.push_back(0.07); + // SECOND MC + // Binomial... + // Saddle point... + // Recursive ... + } else { + return; + } - for (Size j = 0; j < LENGTH(hwAttachment); j++) { - ext::shared_ptr basketPtr( - new Basket(asofDate, names, nominals, pool, hwAttachment[j], hwDetachment[j])); - std::ostringstream trancheId; - trancheId << "[" << hwAttachment[j] << " , " << hwDetachment[j] << "]"; - SyntheticCDO cdoe(basketPtr, Protection::Seller, schedule, 0.0, premium, daycount, - Following); - - for (Size im = 0; im < basketModels.size(); im++) { - - basketPtr->setLossModel(basketModels[im]); - - cdoe.setPricingEngine(midPCDOEngine); - check(i, j, - modelNames[im] + std::string(" with midp integration on ") + trancheId.str(), - cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], - relativeToleranceMidp[im]); - - cdoe.setPricingEngine(integralCDOEngine); - check(i, j, - modelNames[im] + std::string(" with step integration on ") + trancheId.str(), - cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], - relativeTolerancePeriod[im]); - } + for (Size j = 0; j < LENGTH(hwAttachment); j++) { + ext::shared_ptr basketPtr( + new Basket(asofDate, names, nominals, pool, hwAttachment[j], hwDetachment[j])); + std::ostringstream trancheId; + trancheId << "[" << hwAttachment[j] << " , " << hwDetachment[j] << "]"; + SyntheticCDO cdoe(basketPtr, Protection::Seller, schedule, 0.0, premium, daycount, + Following); + + for (Size im = 0; im < basketModels.size(); im++) { + + basketPtr->setLossModel(basketModels[im]); + + cdoe.setPricingEngine(midPCDOEngine); + check(i, j, + modelNames[im] + std::string(" with midp integration on ") + trancheId.str(), + cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], + relativeToleranceMidp[im]); + + cdoe.setPricingEngine(integralCDOEngine); + check(i, j, + modelNames[im] + std::string(" with step integration on ") + trancheId.str(), + cdoe.fairPremium() * 1e4, hwData7[i].trancheSpread[j], absoluteTolerance[im], + relativeTolerancePeriod[im]); } } } From 985aaebff17f054c32e5a27b50cc8a29aa731d09 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 10:56:51 +0800 Subject: [PATCH 064/132] Migrated equitytotalreturnswap.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/basketoption.cpp | 2 -- test-suite/equitytotalreturnswap.cpp | 28 ++++++++++------------ test-suite/equitytotalreturnswap.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 test-suite/equitytotalreturnswap.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index c7b1658b321..36541f0dd2e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - equitytotalreturnswap.hpp europeanoption.hpp everestoption.hpp exchangerate.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 816a91cb412..1e34cc82dab 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - equitytotalreturnswap.hpp \ europeanoption.hpp \ everestoption.hpp \ exchangerate.hpp \ diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index 31a896bee58..c4ffd30f06b 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -753,8 +753,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(testOneDAmericanValues, T, slices) { const int from = T::from; const int to = T::to; - - BOOST_TEST_MESSAGE("Testing basket American options against 1-D case " "from " << from << " to " << to - 1 << "..."); diff --git a/test-suite/equitytotalreturnswap.cpp b/test-suite/equitytotalreturnswap.cpp index f6f09e8261f..e96136e9bc3 100644 --- a/test-suite/equitytotalreturnswap.cpp +++ b/test-suite/equitytotalreturnswap.cpp @@ -16,7 +16,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "equitytotalreturnswap.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -210,7 +210,11 @@ namespace equitytotalreturnswap_test { } } -void EquityTotalReturnSwapTest::testFairMargin() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(EquityTotalReturnSwapTest) + +BOOST_AUTO_TEST_CASE(testFairMargin) { BOOST_TEST_MESSAGE("Testing fair margin..."); using namespace equitytotalreturnswap_test; @@ -232,7 +236,7 @@ void EquityTotalReturnSwapTest::testFairMargin() { -0.005, 1.0, 2); } -void EquityTotalReturnSwapTest::testErrorWhenNegativeNominal() { +BOOST_AUTO_TEST_CASE(testErrorWhenNegativeNominal) { BOOST_TEST_MESSAGE("Testing error when negative nominal..."); using namespace equitytotalreturnswap_test; @@ -246,7 +250,7 @@ void EquityTotalReturnSwapTest::testErrorWhenNegativeNominal() { ExpectedErrorMessage("Nominal cannot be negative")); } -void EquityTotalReturnSwapTest::testErrorWhenNoPaymentCalendar() { +BOOST_AUTO_TEST_CASE(testErrorWhenNoPaymentCalendar) { BOOST_TEST_MESSAGE("Testing error when payment calendar is missing..."); using namespace equitytotalreturnswap_test; @@ -261,7 +265,7 @@ void EquityTotalReturnSwapTest::testErrorWhenNoPaymentCalendar() { ExpectedErrorMessage("Calendar in schedule cannot be empty")); } -void EquityTotalReturnSwapTest::testEquityLegNPV() { +BOOST_AUTO_TEST_CASE(testEquityLegNPV) { BOOST_TEST_MESSAGE("Testing equity leg NPV replication..."); using namespace equitytotalreturnswap_test; @@ -287,7 +291,7 @@ void EquityTotalReturnSwapTest::testEquityLegNPV() { << " expected NPV: " << expectedEquityLegNPV << "\n"); } -void EquityTotalReturnSwapTest::testTRSNPV() { +BOOST_AUTO_TEST_CASE(testTRSNPV) { BOOST_TEST_MESSAGE("Testing TRS NPV..."); using namespace equitytotalreturnswap_test; @@ -308,14 +312,6 @@ void EquityTotalReturnSwapTest::testTRSNPV() { -0.005, 1.0, 2); } -test_suite* EquityTotalReturnSwapTest::suite() { - auto* suite = BOOST_TEST_SUITE("Equity total return swap tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&EquityTotalReturnSwapTest::testFairMargin)); - suite->add(QUANTLIB_TEST_CASE(&EquityTotalReturnSwapTest::testErrorWhenNegativeNominal)); - suite->add(QUANTLIB_TEST_CASE(&EquityTotalReturnSwapTest::testErrorWhenNoPaymentCalendar)); - suite->add(QUANTLIB_TEST_CASE(&EquityTotalReturnSwapTest::testEquityLegNPV)); - suite->add(QUANTLIB_TEST_CASE(&EquityTotalReturnSwapTest::testTRSNPV)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/equitytotalreturnswap.hpp b/test-suite/equitytotalreturnswap.hpp deleted file mode 100644 index 0a64fad1f25..00000000000 --- a/test-suite/equitytotalreturnswap.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2023 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_equitytotalreturnswap_hpp -#define quantlib_test_equitytotalreturnswap_hpp - -#include - -class EquityTotalReturnSwapTest { - public: - static void testFairMargin(); - static void testErrorWhenNegativeNominal(); - static void testErrorWhenNoPaymentCalendar(); - static void testEquityLegNPV(); - static void testTRSNPV(); - - static boost::unit_test_framework::test_suite* suite(); -}; - -#endif \ No newline at end of file diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index daf336bc41f..798a5fb197a 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "equitytotalreturnswap.hpp" #include "europeanoption.hpp" #include "everestoption.hpp" #include "exchangerate.hpp" @@ -187,7 +186,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(EquityTotalReturnSwapTest::suite()); test->add(EuropeanOptionTest::suite()); test->add(ExchangeRateTest::suite()); test->add(FastFourierTransformTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 0ecc9986c9c..131d1084a36 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 b017fbd2496..834bc4ebf2f 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -881,8 +881,5 @@ Header Files - - Header Files - From bc67995f572877c77ea388ae6923db4c73a3b6f6 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 11:25:18 +0800 Subject: [PATCH 065/132] Migrated europeanoption.cpp --- test-suite/CMakeLists.txt | 3 +- test-suite/Makefile.am | 2 - test-suite/europeanoption.cpp | 317 ++++++++++++--------------- test-suite/europeanoption.hpp | 61 ------ test-suite/quantlibbenchmark.cpp | 18 +- test-suite/quantlibtestsuite.cpp | 3 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 8 files changed, 157 insertions(+), 251 deletions(-) delete mode 100644 test-suite/europeanoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 36541f0dd2e..3d86236ea4f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - europeanoption.hpp everestoption.hpp exchangerate.hpp extendedtrees.hpp @@ -305,7 +304,7 @@ set(QL_BENCHMARK_SOURCES convertiblebonds.cpp digitaloption.cpp dividendoption.cpp - europeanoption.cpp europeanoption.hpp + europeanoption.cpp fdheston.cpp fdheston.hpp hestonmodel.cpp hestonmodel.hpp interpolations.cpp interpolations.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1e34cc82dab..6f2b73ed832 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - europeanoption.hpp \ everestoption.hpp \ exchangerate.hpp \ extendedtrees.hpp \ @@ -321,7 +320,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - europeanoption.hpp \ fdheston.hpp \ hestonmodel.hpp \ interpolations.hpp \ diff --git a/test-suite/europeanoption.cpp b/test-suite/europeanoption.cpp index 5c0a24f4efe..8e0113b2e5d 100644 --- a/test-suite/europeanoption.cpp +++ b/test-suite/europeanoption.cpp @@ -19,7 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "europeanoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -189,8 +189,106 @@ namespace european_option_test { } +// different engines + +namespace { + + void testEngineConsistency(european_option_test::EngineType engine, + Size binomialSteps, + Size samples, + std::map tolerance, + bool testGreeks = false) { + + using namespace european_option_test; + + std::map calculated, expected; + + // test options + Option::Type types[] = { Option::Call, Option::Put }; + Real strikes[] = { 75.0, 100.0, 125.0 }; + Integer lengths[] = { 1 }; + + // test data + Real underlyings[] = { 100.0 }; + Rate qRates[] = { 0.00, 0.05 }; + Rate rRates[] = { 0.01, 0.05, 0.15 }; + Volatility vols[] = { 0.11, 0.50, 1.20 }; + + DayCounter dc = Actual360(); + Date today = Date::todaysDate(); + + ext::shared_ptr spot(new SimpleQuote(0.0)); + ext::shared_ptr vol(new SimpleQuote(0.0)); + ext::shared_ptr volTS = flatVol(today,vol,dc); + ext::shared_ptr qRate(new SimpleQuote(0.0)); + ext::shared_ptr qTS = flatRate(today,qRate,dc); + ext::shared_ptr rRate(new SimpleQuote(0.0)); + ext::shared_ptr rTS = flatRate(today,rRate,dc); + + for (auto& type : types) { + for (Real strike : strikes) { + for (int length : lengths) { + Date exDate = today + length * 360; + ext::shared_ptr exercise(new EuropeanExercise(exDate)); + ext::shared_ptr payoff(new PlainVanillaPayoff(type, strike)); + // reference option + ext::shared_ptr refOption = + makeOption(payoff, exercise, spot, qTS, rTS, volTS, Analytic, Null(), + Null()); + // option to check + ext::shared_ptr option = makeOption( + payoff, exercise, spot, qTS, rTS, volTS, engine, binomialSteps, samples); + + for (Real u : underlyings) { + for (Real m : qRates) { + for (Real n : rRates) { + for (Real v : vols) { + Rate q = m, r = n; + spot->setValue(u); + qRate->setValue(q); + rRate->setValue(r); + vol->setValue(v); + + expected.clear(); + calculated.clear(); + + expected["value"] = refOption->NPV(); + calculated["value"] = option->NPV(); -void EuropeanOptionTest::testValues() { + if (testGreeks && option->NPV() > spot->value() * 1.0e-5) { + expected["delta"] = refOption->delta(); + expected["gamma"] = refOption->gamma(); + expected["theta"] = refOption->theta(); + calculated["delta"] = option->delta(); + calculated["gamma"] = option->gamma(); + calculated["theta"] = option->theta(); + } + std::map::iterator it; + for (it = calculated.begin(); it != calculated.end(); ++it) { + std::string greek = it->first; + Real expct = expected[greek], calcl = calculated[greek], + tol = tolerance[greek]; + Real error = relativeError(expct, calcl, u); + if (error > tol) { + REPORT_FAILURE(greek, payoff, exercise, u, q, r, today, + v, expct, calcl, error, tol); + } + } + } + } + } + } + } + } + } + } +} + +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(EuropeanOptionTest) + +BOOST_AUTO_TEST_CASE(testValues) { BOOST_TEST_MESSAGE("Testing European option values..."); @@ -304,9 +402,7 @@ void EuropeanOptionTest::testValues() { } } - - -void EuropeanOptionTest::testGreekValues() { +BOOST_AUTO_TEST_CASE(testGreekValues) { BOOST_TEST_MESSAGE("Testing European option greek values..."); @@ -595,7 +691,7 @@ void EuropeanOptionTest::testGreekValues() { } -void EuropeanOptionTest::testGreeks() { +BOOST_AUTO_TEST_CASE(testGreeks) { BOOST_TEST_MESSAGE("Testing analytic European option greeks..."); @@ -746,7 +842,7 @@ void EuropeanOptionTest::testGreeks() { } } -void EuropeanOptionTest::testImpliedVol() { +BOOST_AUTO_TEST_CASE(testImpliedVol) { BOOST_TEST_MESSAGE("Testing European option implied volatility..."); @@ -861,8 +957,7 @@ void EuropeanOptionTest::testImpliedVol() { } } - -void EuropeanOptionTest::testImpliedVolWithDividends() { +BOOST_AUTO_TEST_CASE(testImpliedVolWithDividends) { BOOST_TEST_MESSAGE("Testing European option implied volatility with dividends..."); @@ -978,8 +1073,7 @@ void EuropeanOptionTest::testImpliedVolWithDividends() { } } - -void EuropeanOptionTest::testImpliedVolContainment() { +BOOST_AUTO_TEST_CASE(testImpliedVolContainment) { BOOST_TEST_MESSAGE("Testing self-containment of " "implied volatility calculation..."); @@ -1052,105 +1146,7 @@ void EuropeanOptionTest::testImpliedVolContainment() { } - -// different engines - -namespace { - - void testEngineConsistency(european_option_test::EngineType engine, - Size binomialSteps, - Size samples, - std::map tolerance, - bool testGreeks = false) { - - using namespace european_option_test; - - std::map calculated, expected; - - // test options - Option::Type types[] = { Option::Call, Option::Put }; - Real strikes[] = { 75.0, 100.0, 125.0 }; - Integer lengths[] = { 1 }; - - // test data - Real underlyings[] = { 100.0 }; - Rate qRates[] = { 0.00, 0.05 }; - Rate rRates[] = { 0.01, 0.05, 0.15 }; - Volatility vols[] = { 0.11, 0.50, 1.20 }; - - DayCounter dc = Actual360(); - Date today = Date::todaysDate(); - - ext::shared_ptr spot(new SimpleQuote(0.0)); - ext::shared_ptr vol(new SimpleQuote(0.0)); - ext::shared_ptr volTS = flatVol(today,vol,dc); - ext::shared_ptr qRate(new SimpleQuote(0.0)); - ext::shared_ptr qTS = flatRate(today,qRate,dc); - ext::shared_ptr rRate(new SimpleQuote(0.0)); - ext::shared_ptr rTS = flatRate(today,rRate,dc); - - for (auto& type : types) { - for (Real strike : strikes) { - for (int length : lengths) { - Date exDate = today + length * 360; - ext::shared_ptr exercise(new EuropeanExercise(exDate)); - ext::shared_ptr payoff(new PlainVanillaPayoff(type, strike)); - // reference option - ext::shared_ptr refOption = - makeOption(payoff, exercise, spot, qTS, rTS, volTS, Analytic, Null(), - Null()); - // option to check - ext::shared_ptr option = makeOption( - payoff, exercise, spot, qTS, rTS, volTS, engine, binomialSteps, samples); - - for (Real u : underlyings) { - for (Real m : qRates) { - for (Real n : rRates) { - for (Real v : vols) { - Rate q = m, r = n; - spot->setValue(u); - qRate->setValue(q); - rRate->setValue(r); - vol->setValue(v); - - expected.clear(); - calculated.clear(); - - expected["value"] = refOption->NPV(); - calculated["value"] = option->NPV(); - - if (testGreeks && option->NPV() > spot->value() * 1.0e-5) { - expected["delta"] = refOption->delta(); - expected["gamma"] = refOption->gamma(); - expected["theta"] = refOption->theta(); - calculated["delta"] = option->delta(); - calculated["gamma"] = option->gamma(); - calculated["theta"] = option->theta(); - } - std::map::iterator it; - for (it = calculated.begin(); it != calculated.end(); ++it) { - std::string greek = it->first; - Real expct = expected[greek], calcl = calculated[greek], - tol = tolerance[greek]; - Real error = relativeError(expct, calcl, u); - if (error > tol) { - REPORT_FAILURE(greek, payoff, exercise, u, q, r, today, - v, expct, calcl, error, tol); - } - } - } - } - } - } - } - } - } - } - -} - - -void EuropeanOptionTest::testJRBinomialEngines() { +BOOST_AUTO_TEST_CASE(testJRBinomialEngines) { BOOST_TEST_MESSAGE("Testing JR binomial European engines " "against analytic results..."); @@ -1168,7 +1164,7 @@ void EuropeanOptionTest::testJRBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testCRRBinomialEngines() { +BOOST_AUTO_TEST_CASE(testCRRBinomialEngines) { BOOST_TEST_MESSAGE("Testing CRR binomial European engines " "against analytic results..."); @@ -1186,7 +1182,7 @@ void EuropeanOptionTest::testCRRBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testEQPBinomialEngines() { +BOOST_AUTO_TEST_CASE(testEQPBinomialEngines) { BOOST_TEST_MESSAGE("Testing EQP binomial European engines " "against analytic results..."); @@ -1204,7 +1200,7 @@ void EuropeanOptionTest::testEQPBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testTGEOBinomialEngines() { +BOOST_AUTO_TEST_CASE(testTGEOBinomialEngines) { BOOST_TEST_MESSAGE("Testing TGEO binomial European engines " "against analytic results..."); @@ -1222,7 +1218,7 @@ void EuropeanOptionTest::testTGEOBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testTIANBinomialEngines() { +BOOST_AUTO_TEST_CASE(testTIANBinomialEngines) { BOOST_TEST_MESSAGE("Testing TIAN binomial European engines " "against analytic results..."); @@ -1240,7 +1236,7 @@ void EuropeanOptionTest::testTIANBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testLRBinomialEngines() { +BOOST_AUTO_TEST_CASE(testLRBinomialEngines) { BOOST_TEST_MESSAGE("Testing LR binomial European engines " "against analytic results..."); @@ -1258,7 +1254,7 @@ void EuropeanOptionTest::testLRBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testJOSHIBinomialEngines() { +BOOST_AUTO_TEST_CASE(testJOSHIBinomialEngines) { BOOST_TEST_MESSAGE("Testing Joshi binomial European engines " "against analytic results..."); @@ -1276,7 +1272,7 @@ void EuropeanOptionTest::testJOSHIBinomialEngines() { testEngineConsistency(engine,steps,samples,relativeTol,true); } -void EuropeanOptionTest::testFdEngines() { +BOOST_AUTO_TEST_CASE(testFdEngines) { BOOST_TEST_MESSAGE("Testing finite-difference European engines " "against analytic results..."); @@ -1294,7 +1290,7 @@ void EuropeanOptionTest::testFdEngines() { testEngineConsistency(engine,timeSteps,gridPoints,relativeTol,true); } -void EuropeanOptionTest::testIntegralEngines() { +BOOST_AUTO_TEST_CASE(testIntegralEngines) { BOOST_TEST_MESSAGE("Testing integral engines against analytic results..."); @@ -1308,7 +1304,7 @@ void EuropeanOptionTest::testIntegralEngines() { testEngineConsistency(engine,timeSteps,gridPoints,relativeTol); } -void EuropeanOptionTest::testMcEngines() { +BOOST_AUTO_TEST_CASE(testMcEngines) { BOOST_TEST_MESSAGE("Testing Monte Carlo European engines " "against analytic results..."); @@ -1323,7 +1319,7 @@ void EuropeanOptionTest::testMcEngines() { testEngineConsistency(engine,steps,samples,relativeTol); } -void EuropeanOptionTest::testQmcEngines() { +BOOST_AUTO_TEST_CASE(testQmcEngines) { BOOST_TEST_MESSAGE("Testing Quasi Monte Carlo European engines " "against analytic results..."); @@ -1338,23 +1334,7 @@ void EuropeanOptionTest::testQmcEngines() { testEngineConsistency(engine,steps,samples,relativeTol); } -void EuropeanOptionTest::testFFTEngines() { - - BOOST_TEST_MESSAGE("Testing FFT European engines " - "against analytic results..."); - - using namespace european_option_test; - - EngineType engine = FFT; - Size steps = Null(); - Size samples = Null(); - std::map relativeTol; - relativeTol["value"] = 0.01; - testEngineConsistency(engine,steps,samples,relativeTol); -} - - -void EuropeanOptionTest::testLocalVolatility() { +BOOST_AUTO_TEST_CASE(testLocalVolatility) { BOOST_TEST_MESSAGE("Testing finite-differences with local volatility..."); using namespace european_option_test; @@ -1494,7 +1474,7 @@ void EuropeanOptionTest::testLocalVolatility() { } } -void EuropeanOptionTest::testAnalyticEngineDiscountCurve() { +BOOST_AUTO_TEST_CASE(testAnalyticEngineDiscountCurve) { BOOST_TEST_MESSAGE( "Testing separate discount curve for analytic European engine..."); @@ -1540,8 +1520,7 @@ void EuropeanOptionTest::testAnalyticEngineDiscountCurve() { BOOST_CHECK_NE(npvSingleCurve, npvMultiCurve); } - -void EuropeanOptionTest::testPDESchemes() { +BOOST_AUTO_TEST_CASE(testPDESchemes) { BOOST_TEST_MESSAGE("Testing different PDE schemes to solve Black-Scholes PDEs..."); const DayCounter dc = Actual365Fixed(); @@ -1640,7 +1619,7 @@ void EuropeanOptionTest::testPDESchemes() { } } -void EuropeanOptionTest::testFdEngineWithNonConstantParameters() { +BOOST_AUTO_TEST_CASE(testFdEngineWithNonConstantParameters) { BOOST_TEST_MESSAGE("Testing finite-difference European engine " "with non-constant parameters..."); @@ -1695,7 +1674,7 @@ void EuropeanOptionTest::testFdEngineWithNonConstantParameters() { } } -void EuropeanOptionTest::testDouglasVsCrankNicolson() { +BOOST_AUTO_TEST_CASE(testDouglasVsCrankNicolson) { BOOST_TEST_MESSAGE("Testing Douglas vs Crank-Nicolson scheme " "for finite-difference European PDE engines..."); @@ -1761,7 +1740,7 @@ void EuropeanOptionTest::testDouglasVsCrankNicolson() { } } -void EuropeanOptionTest::testVanillaAndDividendEngine() { +BOOST_AUTO_TEST_CASE(testVanillaAndDividendEngine) { BOOST_TEST_MESSAGE("Testing the use of a single engine for vanilla and dividend options..."); auto today = Date(1, January, 2023); @@ -1802,37 +1781,25 @@ void EuropeanOptionTest::testVanillaAndDividendEngine() { } } -test_suite* EuropeanOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("European option tests"); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testValues)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testGreekValues)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testGreeks)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testImpliedVol)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testImpliedVolWithDividends)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testImpliedVolContainment)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testJRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testCRRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testEQPBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testTGEOBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testTIANBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testLRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testJOSHIBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testFdEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testIntegralEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testMcEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testQmcEngines)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testLocalVolatility)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testAnalyticEngineDiscountCurve)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testPDESchemes)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testFdEngineWithNonConstantParameters)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testDouglasVsCrankNicolson)); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testVanillaAndDividendEngine)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(EuropeanOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testFFTEngines) { + + BOOST_TEST_MESSAGE("Testing FFT European engines " + "against analytic results..."); -test_suite* EuropeanOptionTest::experimental() { - auto* suite = BOOST_TEST_SUITE("European option experimental tests"); - suite->add(QUANTLIB_TEST_CASE(&EuropeanOptionTest::testFFTEngines)); - return suite; + using namespace european_option_test; + + EngineType engine = FFT; + Size steps = Null(); + Size samples = Null(); + std::map relativeTol; + relativeTol["value"] = 0.01; + testEngineConsistency(engine,steps,samples,relativeTol); } + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/europeanoption.hpp b/test-suite/europeanoption.hpp deleted file mode 100644 index 6b4a004624c..00000000000 --- a/test-suite/europeanoption.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2007 Ferdinando Ametrano - Copyright (C) 2003 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_european_option_hpp -#define quantlib_test_european_option_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class EuropeanOptionTest { - public: - static void testValues(); - static void testGreekValues(); - static void testGreeks(); - static void testImpliedVol(); - static void testImpliedVolWithDividends(); - static void testImpliedVolContainment(); - static void testJRBinomialEngines(); - static void testCRRBinomialEngines(); - static void testEQPBinomialEngines(); - static void testTGEOBinomialEngines(); - static void testTIANBinomialEngines(); - static void testLRBinomialEngines(); - static void testJOSHIBinomialEngines(); - static void testFdEngines(); - static void testIntegralEngines(); - static void testQmcEngines(); - static void testMcEngines(); - static void testFFTEngines(); - static void testLocalVolatility(); - static void testAnalyticEngineDiscountCurve(); - static void testPDESchemes(); - static void testDouglasVsCrankNicolson(); - static void testFdEngineWithNonConstantParameters(); - static void testVanillaAndDividendEngine(); - - static boost::unit_test_framework::test_suite* suite(); - static boost::unit_test_framework::test_suite* experimental(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 7a129c0af16..72b929f7c41 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "europeanoption.hpp" #include "fdheston.hpp" #include "hestonmodel.hpp" #include "interpolations.hpp" @@ -199,6 +198,17 @@ namespace QuantLibTest { struct testFdAmericanGreeks: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace EuropeanOptionTest { + struct testMcEngines: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + + struct testImpliedVol: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + + struct testFdEngines: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -241,9 +251,9 @@ namespace { Benchmark("DigitalOption::MCCashAtHit", std::bind(&QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, QuantLibTest::DigitalOptionTest::testMCCashAtHit()), 995.87), Benchmark("DividendOption::FdEuropeanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdEuropeanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdEuropeanGreeks()), 949.52), Benchmark("DividendOption::FdAmericanGreeks", std::bind(&QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::DividendOptionTest::testFdAmericanGreeks()), 1113.74), - Benchmark("EuropeanOption::FdMcEngines", &EuropeanOptionTest::testMcEngines, 1988.63), - Benchmark("EuropeanOption::ImpliedVol", &EuropeanOptionTest::testImpliedVol, 131.51), - Benchmark("EuropeanOption::FdEngines", &EuropeanOptionTest::testFdEngines, 148.43), + Benchmark("EuropeanOption::FdMcEngines", std::bind(&QuantLibTest::EuropeanOptionTest::testMcEngines::test_method, QuantLibTest::EuropeanOptionTest::testMcEngines()), 1988.63), + Benchmark("EuropeanOption::ImpliedVol", std::bind(&QuantLibTest::EuropeanOptionTest::testImpliedVol::test_method, QuantLibTest::EuropeanOptionTest::testImpliedVol()), 131.51), + Benchmark("EuropeanOption::FdEngines", std::bind(&QuantLibTest::EuropeanOptionTest::testFdEngines::test_method, QuantLibTest::EuropeanOptionTest::testFdEngines()), 148.43), Benchmark("FdHestonTest::testFdmHestonAmerican", &FdHestonTest::testFdmHestonAmerican, 234.21), Benchmark("HestonModel::DAXCalibration", &HestonModelTest::testDAXCalibration, 555.19), Benchmark("InterpolationTest::testSabrInterpolation", &InterpolationTest::testSabrInterpolation, 2266.06), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 798a5fb197a..2c4ba5a8e97 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "europeanoption.hpp" #include "everestoption.hpp" #include "exchangerate.hpp" #include "extendedtrees.hpp" @@ -186,7 +185,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(EuropeanOptionTest::suite()); test->add(ExchangeRateTest::suite()); test->add(FastFourierTransformTest::suite()); test->add(FdHestonTest::suite(speed)); @@ -275,7 +273,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(EuropeanOptionTest::experimental()); test->add(EverestOptionTest::suite()); test->add(ExtendedTreesTest::suite()); test->add(ExtensibleOptionsTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 131d1084a36..5278caa1833 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 834bc4ebf2f..3aab98037dc 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From e4d320edf0df7a265b3b4aa9308b8f636d16e0b9 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 13:23:24 +0800 Subject: [PATCH 066/132] removed boost test no main redefinition --- test-suite/quantlibglobalfixture.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 0fd4d3afea9..79d46e34d5d 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -37,8 +37,7 @@ # include #endif -#define BOOST_TEST_NO_MAIN -#define BOOST_TEST_ALTERNATIVE_INIT_API + #include "quantlibglobalfixture.hpp" #include "speedlevel.hpp" #include From 896f012c3380576d8d0b356aa1126171f47452d8 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 13:37:23 +0800 Subject: [PATCH 067/132] Migrated everestoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/everestoption.cpp | 16 +++++++------- test-suite/everestoption.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/everestoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 3d86236ea4f..9a922bb4149 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - everestoption.hpp exchangerate.hpp extendedtrees.hpp extensibleoptions.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6f2b73ed832..ed5becd4a4f 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - everestoption.hpp \ exchangerate.hpp \ extendedtrees.hpp \ extensibleoptions.hpp \ diff --git a/test-suite/everestoption.cpp b/test-suite/everestoption.cpp index 2bfd4aa193f..910f161379d 100644 --- a/test-suite/everestoption.cpp +++ b/test-suite/everestoption.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "everestoption.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -28,7 +28,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void EverestOptionTest::testCached() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(EverestOptionExperimentalTest) + +BOOST_AUTO_TEST_CASE(testCached) { BOOST_TEST_MESSAGE("Testing Everest option against cached values..."); @@ -129,10 +133,6 @@ void EverestOptionTest::testCached() { << " expected: " << tolerance); } +BOOST_AUTO_TEST_SUITE_END() -test_suite* EverestOptionTest::suite() { - auto* suite = BOOST_TEST_SUITE("Everest-option tests"); - suite->add(QUANTLIB_TEST_CASE(&EverestOptionTest::testCached)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/everestoption.hpp b/test-suite/everestoption.hpp deleted file mode 100644 index 24897e2909b..00000000000 --- a/test-suite/everestoption.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_everest_option_hpp -#define quantlib_test_everest_option_hpp - -#include - -class EverestOptionTest { - 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 2c4ba5a8e97..613189b3d3d 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "everestoption.hpp" #include "exchangerate.hpp" #include "extendedtrees.hpp" #include "extensibleoptions.hpp" @@ -273,7 +272,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(EverestOptionTest::suite()); test->add(ExtendedTreesTest::suite()); test->add(ExtensibleOptionsTest::suite()); test->add(GaussianQuadraturesTest::experimental()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 5278caa1833..610e8b0c518 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 3aab98037dc..199b2566045 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 2355b5b369a683864bce3ac76daf0f75ae148de7 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 13:40:36 +0800 Subject: [PATCH 068/132] Migrated exchangerate.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/exchangerate.cpp | 27 +++++++++---------- test-suite/exchangerate.hpp | 39 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 test-suite/exchangerate.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 9a922bb4149..7ba16c26b97 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - exchangerate.hpp extendedtrees.hpp extensibleoptions.hpp fastfouriertransform.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index ed5becd4a4f..2b507631760 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - exchangerate.hpp \ extendedtrees.hpp \ extensibleoptions.hpp \ fastfouriertransform.hpp \ diff --git a/test-suite/exchangerate.cpp b/test-suite/exchangerate.cpp index c224d597028..d9577338031 100644 --- a/test-suite/exchangerate.cpp +++ b/test-suite/exchangerate.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "exchangerate.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -28,7 +28,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void ExchangeRateTest::testDirect() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ExchangeRateTest) + +BOOST_AUTO_TEST_CASE(testDirect) { BOOST_TEST_MESSAGE("Testing direct exchange rates..."); @@ -60,7 +64,7 @@ void ExchangeRateTest::testDirect() { } } -void ExchangeRateTest::testDerived() { +BOOST_AUTO_TEST_CASE(testDerived) { BOOST_TEST_MESSAGE("Testing derived exchange rates..."); @@ -95,7 +99,7 @@ void ExchangeRateTest::testDerived() { } } -void ExchangeRateTest::testDirectLookup() { +BOOST_AUTO_TEST_CASE(testDirectLookup) { BOOST_TEST_MESSAGE("Testing lookup of direct exchange rates..."); @@ -165,7 +169,7 @@ void ExchangeRateTest::testDirectLookup() { } } -void ExchangeRateTest::testTriangulatedLookup() { +BOOST_AUTO_TEST_CASE(testTriangulatedLookup) { BOOST_TEST_MESSAGE("Testing lookup of triangulated exchange rates..."); @@ -231,7 +235,7 @@ void ExchangeRateTest::testTriangulatedLookup() { } } -void ExchangeRateTest::testSmartLookup() { +BOOST_AUTO_TEST_CASE(testSmartLookup) { BOOST_TEST_MESSAGE("Testing lookup of derived exchange rates..."); @@ -374,13 +378,6 @@ void ExchangeRateTest::testSmartLookup() { } } -test_suite* ExchangeRateTest::suite() { - auto* suite = BOOST_TEST_SUITE("Exchange-rate tests"); - suite->add(QUANTLIB_TEST_CASE(&ExchangeRateTest::testDirect)); - suite->add(QUANTLIB_TEST_CASE(&ExchangeRateTest::testDerived)); - suite->add(QUANTLIB_TEST_CASE(&ExchangeRateTest::testDirectLookup)); - suite->add(QUANTLIB_TEST_CASE(&ExchangeRateTest::testTriangulatedLookup)); - suite->add(QUANTLIB_TEST_CASE(&ExchangeRateTest::testSmartLookup)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/exchangerate.hpp b/test-suite/exchangerate.hpp deleted file mode 100644 index c91e59828cf..00000000000 --- a/test-suite/exchangerate.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_exchange_rate_hpp -#define quantlib_test_exchange_rate_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ExchangeRateTest { - public: - static void testDirect(); - static void testDerived(); - static void testDirectLookup(); - static void testTriangulatedLookup(); - static void testSmartLookup(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 613189b3d3d..c2c7534e99d 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "exchangerate.hpp" #include "extendedtrees.hpp" #include "extensibleoptions.hpp" #include "fastfouriertransform.hpp" @@ -184,7 +183,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(ExchangeRateTest::suite()); test->add(FastFourierTransformTest::suite()); test->add(FdHestonTest::suite(speed)); test->add(FdmLinearOpTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 610e8b0c518..f4425824f5a 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 199b2566045..2f2e18963ec 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From 7bd925125a43e2d9b967ce6dab7f5d6ad6c379fc Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 15:30:56 +0800 Subject: [PATCH 069/132] Added condition for unity builds in quantlibbenchmark.cpp --- test-suite/quantlibbenchmark.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 72b929f7c41..77224a24e8d 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -239,6 +239,7 @@ namespace { // point operations (not per sec!) }; +#ifndef UNITY_BUILD std::vector bm = { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), @@ -265,6 +266,34 @@ namespace { Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) }; +#elif + std::vector bm = { + Benchmark("AmericanOption::FdAmericanGreeks", &QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, 518.31), + Benchmark("AsianOption::MCArithmeticAveragePrice", &QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, 5186.13), + Benchmark("BarrierOption::BabsiriValues", &QuantLibTest::BarrierOptionTest::testBabsiriValues::test_method, 880.8), + Benchmark("BasketOption::EuroTwoValues", &QuantLibTest::BasketOptionTest::testEuroTwoValues::test_method, 340.04), + Benchmark("BasketOption::TavellaValues", &QuantLibTest::BasketOptionTest::testTavellaValues::test_method, 933.80), + Benchmark("BasketOption::OddSamples", &QuantLibTest::BasketOptionTest::testOddSamples::test_method, 642.46), + Benchmark("BatesModel::DAXCalibration", &QuantLibTest::BatesModelTest::testDAXCalibration::test_method, 1993.35), + Benchmark("ConvertibleBondTest::testBond", &QuantLibTest::ConvertibleBondTest::testBond::test_method, 159.85), + Benchmark("DigitalOption::MCCashAtHit", &QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, 995.87), + Benchmark("DividendOption::FdEuropeanGreeks", &QuantLibTest::DividendOptionTest::testFdEuropeanGreeks::test_method, 949.52), + Benchmark("DividendOption::FdAmericanGreeks", &QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, 1113.74), + Benchmark("EuropeanOption::FdMcEngines", &QuantLibTest::EuropeanOptionTest::testMcEngines::test_method, 1988.63), + Benchmark("EuropeanOption::ImpliedVol", &QuantLibTest::EuropeanOptionTest::testImpliedVol::test_method, 131.51), + Benchmark("EuropeanOption::FdEngines", &QuantLibTest::EuropeanOptionTest::testFdEngines::test_method, 148.43), + Benchmark("FdHestonTest::testFdmHestonAmerican", &FdHestonTest::testFdmHestonAmerican, 234.21), + Benchmark("HestonModel::DAXCalibration", &HestonModelTest::testDAXCalibration, 555.19), + Benchmark("InterpolationTest::testSabrInterpolation", &InterpolationTest::testSabrInterpolation, 2266.06), + Benchmark("JumpDiffusion::Greeks", &JumpDiffusionTest::testGreeks, 433.77), + Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", &MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions, 11497.73), + Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", &MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions, 11244.95), + Benchmark("QuantoOption::ForwardGreeks", &QuantoOptionTest::testForwardGreeks, 90.98), + Benchmark("RandomNumber::MersenneTwisterDescrepancy", &LowDiscrepancyTest::testMersenneTwisterDiscrepancy, 951.98), + Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), + Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) + }; +#endif /* PAPI code float real_time, proc_time, mflops; From ec5525f6f619648dae79905d5615a032de434693 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 15:45:55 +0800 Subject: [PATCH 070/132] Migrated extendedtrees.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/extendedtrees.cpp | 34 +++++++++-------------- test-suite/extendedtrees.hpp | 41 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 -- 7 files changed, 13 insertions(+), 70 deletions(-) delete mode 100644 test-suite/extendedtrees.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 7ba16c26b97..cd12c594d18 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - extendedtrees.hpp extensibleoptions.hpp fastfouriertransform.hpp fdcev.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 2b507631760..aab733bf5de 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - extendedtrees.hpp \ extensibleoptions.hpp \ fastfouriertransform.hpp \ fdheston.hpp \ diff --git a/test-suite/extendedtrees.cpp b/test-suite/extendedtrees.cpp index e47514f29da..293c5e1693b 100644 --- a/test-suite/extendedtrees.cpp +++ b/test-suite/extendedtrees.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "extendedtrees.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -230,8 +230,11 @@ namespace { } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) -void ExtendedTreesTest::testJRBinomialEngines() { +BOOST_AUTO_TEST_SUITE(ExtendedTreesExperimentalTest) + +BOOST_AUTO_TEST_CASE(testJRBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent JR binomial European engines " "against analytic results..."); @@ -248,7 +251,7 @@ void ExtendedTreesTest::testJRBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testCRRBinomialEngines() { +BOOST_AUTO_TEST_CASE(testCRRBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent CRR binomial European engines " "against analytic results..."); @@ -265,7 +268,7 @@ void ExtendedTreesTest::testCRRBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testEQPBinomialEngines() { +BOOST_AUTO_TEST_CASE(testEQPBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent EQP binomial European engines " "against analytic results..."); @@ -282,7 +285,7 @@ void ExtendedTreesTest::testEQPBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testTGEOBinomialEngines() { +BOOST_AUTO_TEST_CASE(testTGEOBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent TGEO binomial European engines " "against analytic results..."); @@ -299,7 +302,7 @@ void ExtendedTreesTest::testTGEOBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testTIANBinomialEngines() { +BOOST_AUTO_TEST_CASE(testTIANBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent TIAN binomial European engines " "against analytic results..."); @@ -316,7 +319,7 @@ void ExtendedTreesTest::testTIANBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testLRBinomialEngines() { +BOOST_AUTO_TEST_CASE(testLRBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent LR binomial European engines " "against analytic results..."); @@ -333,7 +336,7 @@ void ExtendedTreesTest::testLRBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -void ExtendedTreesTest::testJOSHIBinomialEngines() { +BOOST_AUTO_TEST_CASE(testJOSHIBinomialEngines) { BOOST_TEST_MESSAGE("Testing time-dependent Joshi binomial European engines " "against analytic results..."); @@ -350,17 +353,6 @@ void ExtendedTreesTest::testJOSHIBinomialEngines() { testEngineConsistency(engine, steps, relativeTol); } -test_suite* ExtendedTreesTest::suite() { - auto* suite = BOOST_TEST_SUITE("European option extended trees tests"); - - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testJRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testCRRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testEQPBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testTGEOBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testTIANBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE(&ExtendedTreesTest::testLRBinomialEngines)); - suite->add(QUANTLIB_TEST_CASE( - &ExtendedTreesTest::testJOSHIBinomialEngines)); +BOOST_AUTO_TEST_SUITE_END() - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/extendedtrees.hpp b/test-suite/extendedtrees.hpp deleted file mode 100644 index 85552285fdb..00000000000 --- a/test-suite/extendedtrees.hpp +++ /dev/null @@ -1,41 +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_extended_trees_hpp -#define quantlib_test_extended_trees_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ExtendedTreesTest { - public: - static void testJRBinomialEngines(); - static void testCRRBinomialEngines(); - static void testEQPBinomialEngines(); - static void testTGEOBinomialEngines(); - static void testTIANBinomialEngines(); - static void testLRBinomialEngines(); - static void testJOSHIBinomialEngines(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index c2c7534e99d..9a100c4d0cd 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "extendedtrees.hpp" #include "extensibleoptions.hpp" #include "fastfouriertransform.hpp" #include "fdcev.hpp" @@ -270,7 +269,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(ExtendedTreesTest::suite()); test->add(ExtensibleOptionsTest::suite()); test->add(GaussianQuadraturesTest::experimental()); test->add(HestonModelTest::experimental()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f4425824f5a..6717eec4e34 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 2f2e18963ec..f98c19dd310 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From d057548ea7b62fac84114a2510f19207081fa39f Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 15:48:17 +0800 Subject: [PATCH 071/132] Migrated extensibleoptions.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/extensibleoptions.cpp | 22 +++++++---------- test-suite/extensibleoptions.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 57 deletions(-) delete mode 100644 test-suite/extensibleoptions.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index cd12c594d18..240c7cd582c 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - extensibleoptions.hpp fastfouriertransform.hpp fdcev.hpp fdcir.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index aab733bf5de..eba277674dc 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - extensibleoptions.hpp \ fastfouriertransform.hpp \ fdheston.hpp \ fdcir.hpp \ diff --git a/test-suite/extensibleoptions.cpp b/test-suite/extensibleoptions.cpp index 9675cecdc9d..7795f735ae0 100644 --- a/test-suite/extensibleoptions.cpp +++ b/test-suite/extensibleoptions.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "extensibleoptions.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -31,7 +31,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void ExtensibleOptionsTest::testAnalyticHolderExtensibleOptionEngine() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(ExtensibleOptionsExperimentalTest) + +BOOST_AUTO_TEST_CASE(testAnalyticHolderExtensibleOptionEngine) { BOOST_TEST_MESSAGE( "Testing analytic engine for holder-extensible option..."); @@ -83,8 +87,7 @@ void ExtensibleOptionsTest::testAnalyticHolderExtensibleOptionEngine() { << "\n error: " << error); } - -void ExtensibleOptionsTest::testAnalyticWriterExtensibleOptionEngine() { +BOOST_AUTO_TEST_CASE(testAnalyticWriterExtensibleOptionEngine) { BOOST_TEST_MESSAGE("Testing analytic engine for writer-extensible option..."); // What we need for the option (tests): @@ -148,13 +151,6 @@ void ExtensibleOptionsTest::testAnalyticWriterExtensibleOptionEngine() { << "\n error: " << error); } -test_suite* ExtensibleOptionsTest::suite() { - auto* suite = BOOST_TEST_SUITE("Extensible option tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE( - &ExtensibleOptionsTest::testAnalyticHolderExtensibleOptionEngine)); - suite->add(QUANTLIB_TEST_CASE( - &ExtensibleOptionsTest::testAnalyticWriterExtensibleOptionEngine)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/extensibleoptions.hpp b/test-suite/extensibleoptions.hpp deleted file mode 100644 index 02802c81ea3..00000000000 --- a/test-suite/extensibleoptions.hpp +++ /dev/null @@ -1,36 +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_extensible_options_hpp -#define quantlib_test_extensible_options_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class ExtensibleOptionsTest { - public: - static void testAnalyticHolderExtensibleOptionEngine(); - static void testAnalyticWriterExtensibleOptionEngine(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 9a100c4d0cd..69e198f466c 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "extensibleoptions.hpp" #include "fastfouriertransform.hpp" #include "fdcev.hpp" #include "fdcir.hpp" @@ -269,7 +268,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(ZeroCouponSwapTest::suite()); // tests for experimental classes - test->add(ExtensibleOptionsTest::suite()); test->add(GaussianQuadraturesTest::experimental()); test->add(HestonModelTest::experimental()); test->add(HimalayaOptionTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 6717eec4e34..ed79a9e5263 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 f98c19dd310..a99e858bafd 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -527,9 +527,6 @@ - - Header Files - Header Files From acec033066a8a63779e29c6607eeb3ab5fa82a99 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 15:51:57 +0800 Subject: [PATCH 072/132] Migrated fastfouriertransform.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fastfouriertransform.cpp | 20 +++++++-------- test-suite/fastfouriertransform.hpp | 37 ---------------------------- test-suite/quantlibbenchmark.cpp | 3 ++- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 8 files changed, 11 insertions(+), 57 deletions(-) delete mode 100644 test-suite/fastfouriertransform.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 240c7cd582c..52864780f96 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fastfouriertransform.hpp fdcev.hpp fdcir.hpp fdheston.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index eba277674dc..1d986e248b5 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - fastfouriertransform.hpp \ fdheston.hpp \ fdcir.hpp \ fdmlinearop.hpp \ diff --git a/test-suite/fastfouriertransform.cpp b/test-suite/fastfouriertransform.cpp index ad5fc13ae33..0651e9e7060 100644 --- a/test-suite/fastfouriertransform.cpp +++ b/test-suite/fastfouriertransform.cpp @@ -18,7 +18,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fastfouriertransform.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -29,7 +29,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void FastFourierTransformTest::testSimple() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FastFourierTransformTest) + +BOOST_AUTO_TEST_CASE(testSimple) { BOOST_TEST_MESSAGE("Testing complex direct FFT..."); typedef std::complex cx; cx a[] = { cx(0,0), cx(1,1), cx(3,3), cx(4,4), @@ -51,7 +55,7 @@ void FastFourierTransformTest::testSimple() { } } -void FastFourierTransformTest::testInverse() { +BOOST_AUTO_TEST_CASE(testInverse) { BOOST_TEST_MESSAGE("Testing convolution via inverse FFT..."); Array x(3); x[0] = 1; @@ -101,12 +105,6 @@ void FastFourierTransformTest::testInverse() { } +BOOST_AUTO_TEST_SUITE_END() - -test_suite* FastFourierTransformTest::suite() { - auto* suite = BOOST_TEST_SUITE("fast fourier transform tests"); - suite->add(QUANTLIB_TEST_CASE(&FastFourierTransformTest::testSimple)); - suite->add(QUANTLIB_TEST_CASE(&FastFourierTransformTest::testInverse)); - return suite; -} - +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fastfouriertransform.hpp b/test-suite/fastfouriertransform.hpp deleted file mode 100644 index 4e6ebfd26bd..00000000000 --- a/test-suite/fastfouriertransform.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2006 Joseph Wang - Copyright (C) 2009 Liquidnet Holdings, Inc. - - 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_fast_fourier_transform_hpp -#define quantlib_test_fast_fourier_transform_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FastFourierTransformTest { - public: - static void testSimple(); - static void testInverse(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 77224a24e8d..65e69e1558c 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -148,7 +148,7 @@ #include "riskstats.hpp" #include "shortratemodels.hpp" - +#ifndef UNITY_BUILD namespace QuantLibTest { namespace AmericanOptionTest { struct testFdAmericanGreeks: @@ -210,6 +210,7 @@ namespace QuantLibTest { public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } } +#endif namespace { diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 69e198f466c..5d4918bb399 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fastfouriertransform.hpp" #include "fdcev.hpp" #include "fdcir.hpp" #include "fdheston.hpp" @@ -181,7 +180,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(FastFourierTransformTest::suite()); test->add(FdHestonTest::suite(speed)); test->add(FdmLinearOpTest::suite(speed)); test->add(FdCevTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index ed79a9e5263..f67c8bd2e13 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 a99e858bafd..75e25f7ea9b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -530,9 +530,6 @@ Header Files - - Header Files - Header Files From 97fd015f640ce9fb0e3aad7a3d92d2e28a19fcd1 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Thu, 2 Nov 2023 16:30:07 +0800 Subject: [PATCH 073/132] Added conditions for unity build --- test-suite/quantlibbenchmark.cpp | 4 ++-- test-suite/quantlibglobalfixture.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 65e69e1558c..3f7d2440b11 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -148,7 +148,7 @@ #include "riskstats.hpp" #include "shortratemodels.hpp" -#ifndef UNITY_BUILD +#ifndef CMAKE_UNITY_BUILD namespace QuantLibTest { namespace AmericanOptionTest { struct testFdAmericanGreeks: @@ -240,7 +240,7 @@ namespace { // point operations (not per sec!) }; -#ifndef UNITY_BUILD +#ifndef CMAKE_UNITY_BUILD std::vector bm = { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), diff --git a/test-suite/quantlibglobalfixture.cpp b/test-suite/quantlibglobalfixture.cpp index 79d46e34d5d..d5295923475 100644 --- a/test-suite/quantlibglobalfixture.cpp +++ b/test-suite/quantlibglobalfixture.cpp @@ -25,7 +25,7 @@ #ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER #include "paralleltestrunner.hpp" -//#define BOOST_TEST_NO_MAIN 1 +#define BOOST_TEST_NO_MAIN 1 #else #include #endif From 3c3230f4602446326f52d0cb4e562cf300977888 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 14:21:23 +0800 Subject: [PATCH 074/132] Removed conditions for unity build --- test-suite/quantlibbenchmark.cpp | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index 3f7d2440b11..cdd5bc2fe19 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -148,7 +148,6 @@ #include "riskstats.hpp" #include "shortratemodels.hpp" -#ifndef CMAKE_UNITY_BUILD namespace QuantLibTest { namespace AmericanOptionTest { struct testFdAmericanGreeks: @@ -210,7 +209,6 @@ namespace QuantLibTest { public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } } -#endif namespace { @@ -240,7 +238,6 @@ namespace { // point operations (not per sec!) }; -#ifndef CMAKE_UNITY_BUILD std::vector bm = { Benchmark("AmericanOption::FdAmericanGreeks", std::bind(&QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, QuantLibTest::AmericanOptionTest::testFdAmericanGreeks()), 518.31), Benchmark("AsianOption::MCArithmeticAveragePrice", std::bind(&QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice()), 5186.13), @@ -267,34 +264,6 @@ namespace { Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) }; -#elif - std::vector bm = { - Benchmark("AmericanOption::FdAmericanGreeks", &QuantLibTest::AmericanOptionTest::testFdAmericanGreeks::test_method, 518.31), - Benchmark("AsianOption::MCArithmeticAveragePrice", &QuantLibTest::AsianOptionTest::testMCDiscreteArithmeticAveragePrice::test_method, 5186.13), - Benchmark("BarrierOption::BabsiriValues", &QuantLibTest::BarrierOptionTest::testBabsiriValues::test_method, 880.8), - Benchmark("BasketOption::EuroTwoValues", &QuantLibTest::BasketOptionTest::testEuroTwoValues::test_method, 340.04), - Benchmark("BasketOption::TavellaValues", &QuantLibTest::BasketOptionTest::testTavellaValues::test_method, 933.80), - Benchmark("BasketOption::OddSamples", &QuantLibTest::BasketOptionTest::testOddSamples::test_method, 642.46), - Benchmark("BatesModel::DAXCalibration", &QuantLibTest::BatesModelTest::testDAXCalibration::test_method, 1993.35), - Benchmark("ConvertibleBondTest::testBond", &QuantLibTest::ConvertibleBondTest::testBond::test_method, 159.85), - Benchmark("DigitalOption::MCCashAtHit", &QuantLibTest::DigitalOptionTest::testMCCashAtHit::test_method, 995.87), - Benchmark("DividendOption::FdEuropeanGreeks", &QuantLibTest::DividendOptionTest::testFdEuropeanGreeks::test_method, 949.52), - Benchmark("DividendOption::FdAmericanGreeks", &QuantLibTest::DividendOptionTest::testFdAmericanGreeks::test_method, 1113.74), - Benchmark("EuropeanOption::FdMcEngines", &QuantLibTest::EuropeanOptionTest::testMcEngines::test_method, 1988.63), - Benchmark("EuropeanOption::ImpliedVol", &QuantLibTest::EuropeanOptionTest::testImpliedVol::test_method, 131.51), - Benchmark("EuropeanOption::FdEngines", &QuantLibTest::EuropeanOptionTest::testFdEngines::test_method, 148.43), - Benchmark("FdHestonTest::testFdmHestonAmerican", &FdHestonTest::testFdmHestonAmerican, 234.21), - Benchmark("HestonModel::DAXCalibration", &HestonModelTest::testDAXCalibration, 555.19), - Benchmark("InterpolationTest::testSabrInterpolation", &InterpolationTest::testSabrInterpolation, 2266.06), - Benchmark("JumpDiffusion::Greeks", &JumpDiffusionTest::testGreeks, 433.77), - Benchmark("MarketModelCmsTest::testCmSwapsSwaptions", &MarketModelCmsTest::testMultiStepCmSwapsAndSwaptions, 11497.73), - Benchmark("MarketModelSmmTest::testMultiSmmSwaptions", &MarketModelSmmTest::testMultiStepCoterminalSwapsAndSwaptions, 11244.95), - Benchmark("QuantoOption::ForwardGreeks", &QuantoOptionTest::testForwardGreeks, 90.98), - Benchmark("RandomNumber::MersenneTwisterDescrepancy", &LowDiscrepancyTest::testMersenneTwisterDiscrepancy, 951.98), - Benchmark("RiskStatistics::Results", &RiskStatisticsTest::testResults, 300.28), - Benchmark("ShortRateModel::Swaps", &ShortRateModelTest::testSwaps, 454.73) - }; -#endif /* PAPI code float real_time, proc_time, mflops; From 21b75a911b94144c8d040c916e351a87432eb95b Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 15:07:36 +0800 Subject: [PATCH 075/132] Migrated fdcev.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fdcev.cpp | 21 +++++++--------- test-suite/fdcev.hpp | 37 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 9 insertions(+), 57 deletions(-) delete mode 100644 test-suite/fdcev.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 52864780f96..c7c20c7b63a 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fdcev.hpp fdcir.hpp fdheston.hpp fdmlinearop.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 1d986e248b5..aa4168f1034 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -177,7 +177,6 @@ QL_TEST_HDRS = \ fdheston.hpp \ fdcir.hpp \ fdmlinearop.hpp \ - fdcev.hpp \ fdsabr.hpp \ fittedbonddiscountcurve.hpp \ forwardoption.hpp \ diff --git a/test-suite/fdcev.cpp b/test-suite/fdcev.cpp index fe748b2cef9..0030693c269 100644 --- a/test-suite/fdcev.cpp +++ b/test-suite/fdcev.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fdcev.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -45,7 +45,11 @@ namespace { }; } -void FdCevTest::testLocalMartingale() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FdCevTest) + +BOOST_AUTO_TEST_CASE(testLocalMartingale) { BOOST_TEST_MESSAGE( "Testing local martingale property of CEV process with PDF..."); @@ -123,7 +127,7 @@ void FdCevTest::testLocalMartingale() { } } -void FdCevTest::testFdmCevOp() { +BOOST_AUTO_TEST_CASE(testFdmCevOp) { BOOST_TEST_MESSAGE( "Testing FDM constant elasticity of variance (CEV) operator..."); @@ -201,13 +205,6 @@ void FdCevTest::testFdmCevOp() { } } +BOOST_AUTO_TEST_SUITE_END() -test_suite* FdCevTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Finite Difference CEV tests"); - - - suite->add(QUANTLIB_TEST_CASE(&FdCevTest::testLocalMartingale)); - suite->add(QUANTLIB_TEST_CASE(&FdCevTest::testFdmCevOp)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fdcev.hpp b/test-suite/fdcev.hpp deleted file mode 100644 index f45aeb918bb..00000000000 --- a/test-suite/fdcev.hpp +++ /dev/null @@ -1,37 +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_fd_vec_hpp -#define quantlib_test_fd_vec_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FdCevTest { - public: - static void testLocalMartingale(); - static void testFdmCevOp(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel speed); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 5d4918bb399..b8c59e43137 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fdcev.hpp" #include "fdcir.hpp" #include "fdheston.hpp" #include "fdmlinearop.hpp" @@ -182,7 +181,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CPISwapTest::suite()); test->add(FdHestonTest::suite(speed)); test->add(FdmLinearOpTest::suite(speed)); - test->add(FdCevTest::suite(speed)); test->add(FdCIRTest::suite(speed)); test->add(FdSabrTest::suite(speed)); test->add(FittedBondDiscountCurveTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index f67c8bd2e13..3a698334530 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 75e25f7ea9b..4b3f40c6a4b 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -842,9 +842,6 @@ Header Files - - Header Files - Header Files From 43511ea9556076b2791f2c4ba32dda760b171310 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 15:10:35 +0800 Subject: [PATCH 076/132] Migrated fdcir.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fdcir.cpp | 16 ++++++------- test-suite/fdcir.hpp | 36 ---------------------------- test-suite/quantlibtestsuite.cpp | 2 -- test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 --- 7 files changed, 8 insertions(+), 52 deletions(-) delete mode 100644 test-suite/fdcir.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index c7c20c7b63a..fa588b6077f 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fdcir.hpp fdheston.hpp fdmlinearop.hpp fdsabr.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index aa4168f1034..8e6531d6550 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -175,7 +175,6 @@ QL_TEST_SRCS = \ QL_TEST_HDRS = \ fdheston.hpp \ - fdcir.hpp \ fdmlinearop.hpp \ fdsabr.hpp \ fittedbonddiscountcurve.hpp \ diff --git a/test-suite/fdcir.cpp b/test-suite/fdcir.cpp index ca2aff9f695..55a196ccb4f 100644 --- a/test-suite/fdcir.cpp +++ b/test-suite/fdcir.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fdcir.hpp" +#include "toplevelfixture.hpp" #include "fdheston.hpp" #include "utilities.hpp" #include @@ -35,7 +35,11 @@ using namespace QuantLib; using boost::unit_test_framework::test_suite; -void FdCIRTest::testFdmCIRConvergence() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FdCIRTest) + +BOOST_AUTO_TEST_CASE(testFdmCIRConvergence) { BOOST_TEST_MESSAGE("Testing FDM CIR convergence..."); FdmSchemeDesc schemes[] = { @@ -108,11 +112,7 @@ void FdCIRTest::testFdmCIRConvergence() { } } -test_suite* FdCIRTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Finite Difference CIR tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&FdCIRTest::testFdmCIRConvergence)); - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() diff --git a/test-suite/fdcir.hpp b/test-suite/fdcir.hpp deleted file mode 100644 index 12e454e983a..00000000000 --- a/test-suite/fdcir.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2020 Lew Wei Hao - - 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_fd_cir_hpp -#define quantlib_test_fd_cir_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FdCIRTest { -public: - static void testFdmCIRConvergence(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index b8c59e43137..bcd0a23a04e 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fdcir.hpp" #include "fdheston.hpp" #include "fdmlinearop.hpp" #include "fdsabr.hpp" @@ -181,7 +180,6 @@ test_suite* init_unit_test_suite(int, char* []) { test->add(CPISwapTest::suite()); test->add(FdHestonTest::suite(speed)); test->add(FdmLinearOpTest::suite(speed)); - test->add(FdCIRTest::suite(speed)); test->add(FdSabrTest::suite(speed)); test->add(FittedBondDiscountCurveTest::suite()); test->add(ForwardOptionTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 3a698334530..63762feef4f 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 4b3f40c6a4b..69a96b037a2 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -533,9 +533,6 @@ Header Files - - Header Files - Header Files From 3e2498c32b00275894b779d24c5ffd46a151b040 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 15:21:51 +0800 Subject: [PATCH 077/132] Migrated fdheston.cpp --- test-suite/CMakeLists.txt | 5 +- test-suite/Makefile.am | 2 - test-suite/fdcir.cpp | 1 - test-suite/fdheston.cpp | 90 +++++++++++----------------- test-suite/fdheston.hpp | 48 --------------- test-suite/quantlibbenchmark.cpp | 8 ++- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 9 files changed, 42 insertions(+), 118 deletions(-) delete mode 100644 test-suite/fdheston.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index fa588b6077f..e2bc59e4010 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fdheston.hpp fdmlinearop.hpp fdsabr.hpp fittedbonddiscountcurve.hpp @@ -298,8 +297,8 @@ set(QL_BENCHMARK_SOURCES digitaloption.cpp dividendoption.cpp europeanoption.cpp - fdheston.cpp fdheston.hpp - hestonmodel.cpp hestonmodel.hpp + fdheston.cpp + hestonmodel.cpp hestonmodel.hpp interpolations.cpp interpolations.hpp jumpdiffusion.cpp jumpdiffusion.hpp lowdiscrepancysequences.cpp lowdiscrepancysequences.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 8e6531d6550..cc4f62b7fce 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - fdheston.hpp \ fdmlinearop.hpp \ fdsabr.hpp \ fittedbonddiscountcurve.hpp \ @@ -313,7 +312,6 @@ QL_BENCHMARK_SRCS = \ utilities.cpp QL_BENCHMARK_HDRS = \ - fdheston.hpp \ hestonmodel.hpp \ interpolations.hpp \ jumpdiffusion.hpp \ diff --git a/test-suite/fdcir.cpp b/test-suite/fdcir.cpp index 55a196ccb4f..189a0f095d5 100644 --- a/test-suite/fdcir.cpp +++ b/test-suite/fdcir.cpp @@ -18,7 +18,6 @@ */ #include "toplevelfixture.hpp" -#include "fdheston.hpp" #include "utilities.hpp" #include #include diff --git a/test-suite/fdheston.cpp b/test-suite/fdheston.cpp index 8dc40325f0a..0db15c41067 100644 --- a/test-suite/fdheston.cpp +++ b/test-suite/fdheston.cpp @@ -18,9 +18,9 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fdheston.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" - #include #include #include @@ -44,7 +44,7 @@ #include using namespace QuantLib; -using boost::unit_test_framework::test_suite; +using namespace boost::unit_test_framework; namespace fd_heston_test { @@ -89,7 +89,23 @@ namespace fd_heston_test { }; } -void FdHestonTest::testFdmHestonVarianceMesher() { +namespace { + struct HestonTestData { + Real kappa; + Real theta; + Real sigma; + Real rho; + Real r; + Real q; + Real T; + Real K; + }; +} +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FdHestonTest) + +BOOST_AUTO_TEST_CASE(testFdmHestonVarianceMesher) { BOOST_TEST_MESSAGE("Testing FDM Heston variance mesher..."); using namespace fd_heston_test; @@ -187,7 +203,7 @@ void FdHestonTest::testFdmHestonVarianceMesher() { } } -void FdHestonTest::testFdmHestonBarrierVsBlackScholes() { +BOOST_AUTO_TEST_CASE(testFdmHestonBarrierVsBlackScholes, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing FDM with barrier option in Heston model..."); @@ -336,7 +352,7 @@ void FdHestonTest::testFdmHestonBarrierVsBlackScholes() { } } -void FdHestonTest::testFdmHestonBarrier() { +BOOST_AUTO_TEST_CASE(testFdmHestonBarrier) { BOOST_TEST_MESSAGE("Testing FDM with barrier option for Heston model vs " "Black-Scholes model..."); @@ -388,7 +404,7 @@ void FdHestonTest::testFdmHestonBarrier() { } } -void FdHestonTest::testFdmHestonAmerican() { +BOOST_AUTO_TEST_CASE(testFdmHestonAmerican) { BOOST_TEST_MESSAGE("Testing FDM with American option in Heston model..."); @@ -439,8 +455,7 @@ void FdHestonTest::testFdmHestonAmerican() { } } - -void FdHestonTest::testFdmHestonIkonenToivanen() { +BOOST_AUTO_TEST_CASE(testFdmHestonIkonenToivanen) { BOOST_TEST_MESSAGE("Testing FDM Heston for Ikonen and Toivanen tests..."); @@ -487,7 +502,7 @@ void FdHestonTest::testFdmHestonIkonenToivanen() { } } -void FdHestonTest::testFdmHestonBlackScholes() { +BOOST_AUTO_TEST_CASE(testFdmHestonBlackScholes) { BOOST_TEST_MESSAGE("Testing FDM Heston with Black Scholes model..."); @@ -552,9 +567,7 @@ void FdHestonTest::testFdmHestonBlackScholes() { } } - - -void FdHestonTest::testFdmHestonEuropeanWithDividends() { +BOOST_AUTO_TEST_CASE(testFdmHestonEuropeanWithDividends) { BOOST_TEST_MESSAGE("Testing FDM with European option with dividends in Heston model..."); @@ -635,20 +648,7 @@ void FdHestonTest::testFdmHestonEuropeanWithDividends() { } } -namespace { - struct HestonTestData { - Real kappa; - Real theta; - Real sigma; - Real rho; - Real r; - Real q; - Real T; - Real K; - }; -} - -void FdHestonTest::testFdmHestonConvergence() { +BOOST_AUTO_TEST_CASE(testFdmHestonConvergence, *precondition(if_speed(Fast))) { /* convergence tests based on ADI finite difference schemes for option pricing in the @@ -726,8 +726,8 @@ void FdHestonTest::testFdmHestonConvergence() { } } -void FdHestonTest::testFdmHestonIntradayPricing() { #ifdef QL_HIGH_RESOLUTION_DATE +BOOST_AUTO_TEST_CASE(testFdmHestonIntradayPricing) { BOOST_TEST_MESSAGE("Testing FDM Heston intraday pricing..."); @@ -785,10 +785,10 @@ void FdHestonTest::testFdmHestonIntradayPricing() { << "\n calculated: "<< gammaCalculated); } } -#endif } +#endif -void FdHestonTest::testMethodOfLinesAndCN() { +BOOST_AUTO_TEST_CASE(testMethodOfLinesAndCN) { BOOST_TEST_MESSAGE("Testing method of lines to solve Heston PDEs..."); const DayCounter dc = Actual365Fixed(); @@ -904,7 +904,7 @@ void FdHestonTest::testMethodOfLinesAndCN() { } } -void FdHestonTest::testSpuriousOscillations() { +BOOST_AUTO_TEST_CASE(testSpuriousOscillations) { BOOST_TEST_MESSAGE("Testing for spurious oscillations when " "solving the Heston PDEs..."); @@ -981,8 +981,7 @@ void FdHestonTest::testSpuriousOscillations() { } } - -void FdHestonTest::testAmericanCallPutParity() { +BOOST_AUTO_TEST_CASE(testAmericanCallPutParity) { BOOST_TEST_MESSAGE("Testing call/put parity for American options " "under the Heston model..."); @@ -1090,27 +1089,6 @@ void FdHestonTest::testAmericanCallPutParity() { } } -test_suite* FdHestonTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Finite Difference Heston tests"); - - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonVarianceMesher)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonBarrier)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonAmerican)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonIkonenToivanen)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonEuropeanWithDividends)); - #ifdef QL_HIGH_RESOLUTION_DATE - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonIntradayPricing)); - #endif - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testMethodOfLinesAndCN)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testSpuriousOscillations)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testAmericanCallPutParity)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonBlackScholes)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonConvergence)); - suite->add(QUANTLIB_TEST_CASE(&FdHestonTest::testFdmHestonBarrierVsBlackScholes)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fdheston.hpp b/test-suite/fdheston.hpp deleted file mode 100644 index e0bdcccee3c..00000000000 --- a/test-suite/fdheston.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008 Klaus Spanderen - Copyright (C) 2014 Johannes Göttker-Schnetmann - - 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_fd_heston_hpp -#define quantlib_test_fd_heston_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FdHestonTest { -public: - static void testFdmHestonVarianceMesher(); - static void testFdmHestonBarrier(); - static void testFdmHestonBarrierVsBlackScholes(); - static void testFdmHestonAmerican(); - static void testFdmHestonIkonenToivanen(); - static void testFdmHestonEuropeanWithDividends(); - static void testFdmHestonConvergence(); - static void testFdmHestonBlackScholes(); - static void testFdmHestonIntradayPricing(); - static void testMethodOfLinesAndCN(); - static void testSpuriousOscillations(); - static void testAmericanCallPutParity(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibbenchmark.cpp b/test-suite/quantlibbenchmark.cpp index cdd5bc2fe19..6013c4d0b6f 100644 --- a/test-suite/quantlibbenchmark.cpp +++ b/test-suite/quantlibbenchmark.cpp @@ -137,7 +137,6 @@ #endif #include "utilities.hpp" -#include "fdheston.hpp" #include "hestonmodel.hpp" #include "interpolations.hpp" #include "jumpdiffusion.hpp" @@ -208,6 +207,11 @@ namespace QuantLibTest { struct testFdEngines: public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; } + + namespace FdHestonTest { + struct testFdmHestonAmerican: + public BOOST_AUTO_TEST_CASE_FIXTURE { void test_method(); }; + } } namespace { @@ -253,7 +257,7 @@ namespace { Benchmark("EuropeanOption::FdMcEngines", std::bind(&QuantLibTest::EuropeanOptionTest::testMcEngines::test_method, QuantLibTest::EuropeanOptionTest::testMcEngines()), 1988.63), Benchmark("EuropeanOption::ImpliedVol", std::bind(&QuantLibTest::EuropeanOptionTest::testImpliedVol::test_method, QuantLibTest::EuropeanOptionTest::testImpliedVol()), 131.51), Benchmark("EuropeanOption::FdEngines", std::bind(&QuantLibTest::EuropeanOptionTest::testFdEngines::test_method, QuantLibTest::EuropeanOptionTest::testFdEngines()), 148.43), - Benchmark("FdHestonTest::testFdmHestonAmerican", &FdHestonTest::testFdmHestonAmerican, 234.21), + Benchmark("FdHestonTest::testFdmHestonAmerican", std::bind(&QuantLibTest::FdHestonTest::testFdmHestonAmerican::test_method, QuantLibTest::FdHestonTest::testFdmHestonAmerican()), 234.21), Benchmark("HestonModel::DAXCalibration", &HestonModelTest::testDAXCalibration, 555.19), Benchmark("InterpolationTest::testSabrInterpolation", &InterpolationTest::testSabrInterpolation, 2266.06), Benchmark("JumpDiffusion::Greeks", &JumpDiffusionTest::testGreeks, 433.77), diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index bcd0a23a04e..72e199c6bd2 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fdheston.hpp" #include "fdmlinearop.hpp" #include "fdsabr.hpp" #include "fittedbonddiscountcurve.hpp" @@ -178,7 +177,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(FdHestonTest::suite(speed)); test->add(FdmLinearOpTest::suite(speed)); test->add(FdSabrTest::suite(speed)); test->add(FittedBondDiscountCurveTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 63762feef4f..5b955013580 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 69a96b037a2..e1b6bb47ecb 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -530,9 +530,6 @@ Header Files - - Header Files - Header Files From 3a38262e18fb4e556ea97fa45c341adb30bc1825 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 15:32:45 +0800 Subject: [PATCH 078/132] Migrated fdmlinearop.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fdmlinearop.cpp | 360 ++++++++++++--------------- test-suite/fdmlinearop.hpp | 56 ----- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 162 insertions(+), 262 deletions(-) delete mode 100644 test-suite/fdmlinearop.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index e2bc59e4010..72031ce1eef 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fdmlinearop.hpp fdsabr.hpp fittedbonddiscountcurve.hpp forwardoption.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index cc4f62b7fce..896e0f74231 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - fdmlinearop.hpp \ fdsabr.hpp \ fittedbonddiscountcurve.hpp \ forwardoption.hpp \ diff --git a/test-suite/fdmlinearop.cpp b/test-suite/fdmlinearop.cpp index a8ef6f9a9f3..997de4d8cb7 100644 --- a/test-suite/fdmlinearop.cpp +++ b/test-suite/fdmlinearop.cpp @@ -19,9 +19,9 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fdmlinearop.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" - #include #include #include @@ -133,7 +133,145 @@ namespace { } -void FdmLinearOpTest::testFdmLinearOpLayout() { +namespace { + + ext::shared_ptr createHestonHullWhite( + Time maturity) { + + DayCounter dc = Actual365Fixed(); + const Date today = Settings::instance().evaluationDate(); + Handle s0(ext::shared_ptr(new SimpleQuote(100.0))); + + std::vector dates; + std::vector rates, divRates; + + for (Size i=0; i <= 25; ++i) { + dates.push_back(today+Period(i, Years)); + rates.push_back(0.05); + divRates.push_back(0.02); + } + + const Handle rTS( + ext::shared_ptr(new ZeroCurve(dates, rates, dc))); + const Handle qTS( + ext::shared_ptr( + new ZeroCurve(dates, divRates, dc))); + + const Real v0 = 0.04; + ext::shared_ptr hestonProcess( + new HestonProcess(rTS, qTS, s0, v0, 1.0, v0*0.75, 0.4, -0.7)); + + ext::shared_ptr hwFwdProcess( + new HullWhiteForwardProcess(rTS, 0.00883, 0.01)); + hwFwdProcess->setForwardMeasureTime(maturity); + + const Real equityShortRateCorr = -0.7; + + return ext::make_shared( + hestonProcess, hwFwdProcess, + equityShortRateCorr); + } + + FdmSolverDesc createSolverDesc( + const std::vector& dim, + const ext::shared_ptr& process) { + + const Time maturity + = process->hullWhiteProcess()->getForwardMeasureTime(); + + ext::shared_ptr layout(new FdmLinearOpLayout(dim)); + + std::vector > mesher1d = { + ext::shared_ptr( + new Uniform1dMesher(std::log(22.0), std::log(440.0), dim[0])), + ext::shared_ptr( + new FdmHestonVarianceMesher(dim[1], process->hestonProcess(), + maturity)), + ext::shared_ptr( + new Uniform1dMesher(-0.15, 0.15, dim[2])) + }; + + const ext::shared_ptr mesher( + new FdmMesherComposite(mesher1d)); + + const FdmBoundaryConditionSet boundaries; + + std::list > stoppingTimes; + std::list > > stepConditions; + + ext::shared_ptr conditions( + new FdmStepConditionComposite( + std::list >(), + FdmStepConditionComposite::Conditions())); + + ext::shared_ptr payoff( + new PlainVanillaPayoff(Option::Call, 160.0)); + + ext::shared_ptr calculator( + new FdmLogInnerValue(payoff, mesher, 0)); + + const Size tGrid = 100; + const Size dampingSteps = 0; + + FdmSolverDesc desc = { mesher, boundaries, + conditions, calculator, + maturity, tGrid, dampingSteps }; + + return desc; + } + + Array axpy(const boost::numeric::ublas::compressed_matrix& A, + const Array& x) { + + boost::numeric::ublas::vector tmpX(x.size()), y(x.size()); + std::copy(x.begin(), x.end(), tmpX.begin()); + boost::numeric::ublas::axpy_prod(A, tmpX, y); + + return Array(y.begin(), y.end()); + } + + boost::numeric::ublas::compressed_matrix createTestMatrix( + Size n, Size m, Real theta) { + + boost::numeric::ublas::compressed_matrix a(n*m, n*m); + + for (Size i=0; i < n; ++i) { + for (Size j=0; j < m; ++j) { + const Size k = i*m+j; + a(k,k)=1.0; + + if (i > 0 && j > 0 && i mesherX( @@ -537,7 +671,7 @@ void FdmLinearOpTest::testDerivativeWeightsOnNonUniformGrids() { } } -void FdmLinearOpTest::testSecondOrderMixedDerivativesMapApply() { +BOOST_AUTO_TEST_CASE(testSecondOrderMixedDerivativesMapApply) { BOOST_TEST_MESSAGE( "Testing application of second-order mixed-derivatives map..."); @@ -628,11 +762,9 @@ void FdmLinearOpTest::testSecondOrderMixedDerivativesMapApply() { << "\n value " << std::fabs(t[i]-u[i])); } } - - } -void FdmLinearOpTest::testTripleBandMapSolve() { +BOOST_AUTO_TEST_CASE(testTripleBandMapSolve) { BOOST_TEST_MESSAGE("Testing triple-band map solution..."); @@ -711,8 +843,7 @@ void FdmLinearOpTest::testTripleBandMapSolve() { } } - -void FdmLinearOpTest::testFdmHestonBarrier() { +BOOST_AUTO_TEST_CASE(testFdmHestonBarrier) { BOOST_TEST_MESSAGE("Testing FDM with barrier option in Heston model..."); @@ -798,7 +929,7 @@ void FdmLinearOpTest::testFdmHestonBarrier() { } } -void FdmLinearOpTest::testFdmHestonAmerican() { +BOOST_AUTO_TEST_CASE(testFdmHestonAmerican) { BOOST_TEST_MESSAGE("Testing FDM with American option in Heston model..."); @@ -869,7 +1000,7 @@ void FdmLinearOpTest::testFdmHestonAmerican() { } } -void FdmLinearOpTest::testFdmHestonExpress() { +BOOST_AUTO_TEST_CASE(testFdmHestonExpress) { BOOST_TEST_MESSAGE("Testing FDM with express certificate in Heston model..."); @@ -959,96 +1090,7 @@ void FdmLinearOpTest::testFdmHestonExpress() { } } - -namespace { - - ext::shared_ptr createHestonHullWhite( - Time maturity) { - - DayCounter dc = Actual365Fixed(); - const Date today = Settings::instance().evaluationDate(); - Handle s0(ext::shared_ptr(new SimpleQuote(100.0))); - - std::vector dates; - std::vector rates, divRates; - - for (Size i=0; i <= 25; ++i) { - dates.push_back(today+Period(i, Years)); - rates.push_back(0.05); - divRates.push_back(0.02); - } - - const Handle rTS( - ext::shared_ptr(new ZeroCurve(dates, rates, dc))); - const Handle qTS( - ext::shared_ptr( - new ZeroCurve(dates, divRates, dc))); - - const Real v0 = 0.04; - ext::shared_ptr hestonProcess( - new HestonProcess(rTS, qTS, s0, v0, 1.0, v0*0.75, 0.4, -0.7)); - - ext::shared_ptr hwFwdProcess( - new HullWhiteForwardProcess(rTS, 0.00883, 0.01)); - hwFwdProcess->setForwardMeasureTime(maturity); - - const Real equityShortRateCorr = -0.7; - - return ext::make_shared( - hestonProcess, hwFwdProcess, - equityShortRateCorr); - } - - FdmSolverDesc createSolverDesc( - const std::vector& dim, - const ext::shared_ptr& process) { - - const Time maturity - = process->hullWhiteProcess()->getForwardMeasureTime(); - - ext::shared_ptr layout(new FdmLinearOpLayout(dim)); - - std::vector > mesher1d = { - ext::shared_ptr( - new Uniform1dMesher(std::log(22.0), std::log(440.0), dim[0])), - ext::shared_ptr( - new FdmHestonVarianceMesher(dim[1], process->hestonProcess(), - maturity)), - ext::shared_ptr( - new Uniform1dMesher(-0.15, 0.15, dim[2])) - }; - - const ext::shared_ptr mesher( - new FdmMesherComposite(mesher1d)); - - const FdmBoundaryConditionSet boundaries; - - std::list > stoppingTimes; - std::list > > stepConditions; - - ext::shared_ptr conditions( - new FdmStepConditionComposite( - std::list >(), - FdmStepConditionComposite::Conditions())); - - ext::shared_ptr payoff( - new PlainVanillaPayoff(Option::Call, 160.0)); - - ext::shared_ptr calculator( - new FdmLogInnerValue(payoff, mesher, 0)); - - const Size tGrid = 100; - const Size dampingSteps = 0; - - FdmSolverDesc desc = { mesher, boundaries, - conditions, calculator, - maturity, tGrid, dampingSteps }; - - return desc; - } -} - -void FdmLinearOpTest::testFdmHestonHullWhiteOp() { +BOOST_AUTO_TEST_CASE(testFdmHestonHullWhiteOp, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing FDM with Heston Hull-White model..."); const Date today = Date(28, March, 2004); @@ -1164,47 +1206,7 @@ void FdmLinearOpTest::testFdmHestonHullWhiteOp() { } } -namespace { - Array axpy(const boost::numeric::ublas::compressed_matrix& A, - const Array& x) { - - boost::numeric::ublas::vector tmpX(x.size()), y(x.size()); - std::copy(x.begin(), x.end(), tmpX.begin()); - boost::numeric::ublas::axpy_prod(A, tmpX, y); - - return Array(y.begin(), y.end()); - } - - boost::numeric::ublas::compressed_matrix createTestMatrix( - Size n, Size m, Real theta) { - - boost::numeric::ublas::compressed_matrix a(n*m, n*m); - - for (Size i=0; i < n; ++i) { - for (Size j=0; j < m; ++j) { - const Size k = i*m+j; - a(k,k)=1.0; - - if (i > 0 && j > 0 && i mesher( @@ -1514,7 +1503,7 @@ void FdmLinearOpTest::testFdmMesherIntegral() { } } -void FdmLinearOpTest::testHighInterestRateBlackScholesMesher() { +BOOST_AUTO_TEST_CASE(testHighInterestRateBlackScholesMesher) { BOOST_TEST_MESSAGE("Testing Black-Scholes mesher in a " "high interest rate scenario..."); @@ -1577,7 +1566,7 @@ void FdmLinearOpTest::testHighInterestRateBlackScholesMesher() { } } -void FdmLinearOpTest::testLowVolatilityHighDiscreteDividendBlackScholesMesher() { +BOOST_AUTO_TEST_CASE(testLowVolatilityHighDiscreteDividendBlackScholesMesher) { BOOST_TEST_MESSAGE("Testing Black-Scholes mesher in a low volatility and " "high discrete dividend scenario..."); @@ -1651,31 +1640,6 @@ void FdmLinearOpTest::testLowVolatilityHighDiscreteDividendBlackScholesMesher() } } -test_suite* FdmLinearOpTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("linear operator tests"); - - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmLinearOpLayout)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testUniformGridMesher)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFirstDerivativesMapApply)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testSecondDerivativesMapApply)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testDerivativeWeightsOnNonUniformGrids)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testSecondOrderMixedDerivativesMapApply)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testTripleBandMapSolve)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmHestonBarrier)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmHestonAmerican)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmHestonExpress)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testBiCGstab)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testGMRES)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testCrankNicolsonWithDamping)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testSpareMatrixReference)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testSparseMatrixZeroAssignment)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmMesherIntegral)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testHighInterestRateBlackScholesMesher)); - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testLowVolatilityHighDiscreteDividendBlackScholesMesher)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&FdmLinearOpTest::testFdmHestonHullWhiteOp)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fdmlinearop.hpp b/test-suite/fdmlinearop.hpp deleted file mode 100644 index 2292ea842fa..00000000000 --- a/test-suite/fdmlinearop.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2008 Andreas Gaida - Copyright (C) 2008 Ralph Schreyer - Copyright (C) 2008, 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_fdm_linear_op_hpp -#define quantlib_test_fdm_linear_op_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FdmLinearOpTest { -public: - static void testFdmLinearOpLayout(); - static void testUniformGridMesher(); - static void testFirstDerivativesMapApply(); - static void testSecondDerivativesMapApply(); - static void testDerivativeWeightsOnNonUniformGrids(); - static void testSecondOrderMixedDerivativesMapApply(); - static void testTripleBandMapSolve(); - static void testFdmHestonBarrier(); - static void testFdmHestonAmerican(); - static void testFdmHestonExpress(); - static void testFdmHestonHullWhiteOp(); - static void testBiCGstab(); - static void testGMRES(); - static void testCrankNicolsonWithDamping(); - static void testSpareMatrixReference(); - static void testSparseMatrixZeroAssignment(); - static void testFdmMesherIntegral(); - static void testHighInterestRateBlackScholesMesher(); - static void testLowVolatilityHighDiscreteDividendBlackScholesMesher(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 72e199c6bd2..365b14535e8 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fdmlinearop.hpp" #include "fdsabr.hpp" #include "fittedbonddiscountcurve.hpp" #include "forwardoption.hpp" @@ -177,7 +176,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(FdmLinearOpTest::suite(speed)); test->add(FdSabrTest::suite(speed)); test->add(FittedBondDiscountCurveTest::suite()); test->add(ForwardOptionTest::suite(speed)); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 5b955013580..058914181b0 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 e1b6bb47ecb..cb3773e53dd 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -530,9 +530,6 @@ Header Files - - Header Files - Header Files From 68e0e4e904bd4bc6dcfcc3c56946eea59b7ba027 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 15:37:36 +0800 Subject: [PATCH 079/132] Migrated fdsabr.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fdsabr.cpp | 103 ++++++++++++--------------- test-suite/fdsabr.hpp | 40 ----------- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 46 insertions(+), 105 deletions(-) delete mode 100644 test-suite/fdsabr.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 72031ce1eef..adf883816c3 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fdsabr.hpp fittedbonddiscountcurve.hpp forwardoption.hpp forwardrateagreement.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 896e0f74231..db7c4d5338a 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - fdsabr.hpp \ fittedbonddiscountcurve.hpp \ forwardoption.hpp \ forwardrateagreement.hpp \ diff --git a/test-suite/fdsabr.cpp b/test-suite/fdsabr.cpp index 8060f7f82fd..50b3ed7c119 100644 --- a/test-suite/fdsabr.cpp +++ b/test-suite/fdsabr.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fdsabr.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -36,7 +37,7 @@ #include using namespace QuantLib; -using boost::unit_test_framework::test_suite; +using namespace boost::unit_test_framework; namespace { class SabrMonteCarloPricer { @@ -101,10 +102,46 @@ namespace { const Real alpha_, beta_, nu_, rho_; }; + /* + * Example and reference values are taken from + * B. Chen, C.W. Oosterlee, H. Weide, + * Efficient unbiased simulation scheme for the SABR stochastic volatility model. + * https://http://ta.twi.tudelft.nl/mf/users/oosterle/oosterlee/SABRMC.pdf + */ + + class OsterleeReferenceResults { + public: + explicit OsterleeReferenceResults(Size i) : i_(i) { } + + Real operator()(Real t) const { + Size i; + if (close_enough(t, 1/16.)) + i = 0; + else if (close_enough(t, 1/32.)) + i = 1; + else + QL_FAIL("unmatched reference result lookup"); + + return data_[i_][i]; + } + + private: + const Size i_; + static Real data_[9][3]; + }; + + Real OsterleeReferenceResults::data_[9][3] = { + { 0.0610, 0.0604 }, { 0.0468, 0.0463 }, { 0.0347, 0.0343 }, + { 0.0632, 0.0625 }, { 0.0512, 0.0506 }, { 0.0406, 0.0400 }, + { 0.0635, 0.0630 }, { 0.0523, 0.0520 }, { 0.0422, 0.0421 } + }; } +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FdSabrTest) -void FdSabrTest::testFdmSabrOp() { +BOOST_AUTO_TEST_CASE(testFdmSabrOp, *precondition(if_speed(Fast))) { BOOST_TEST_MESSAGE("Testing FDM SABR operator..."); const Date today = Date(22, February, 2018); @@ -198,7 +235,7 @@ void FdSabrTest::testFdmSabrOp() { } } -void FdSabrTest::testFdmSabrCevPricing() { +BOOST_AUTO_TEST_CASE(testFdmSabrCevPricing) { BOOST_TEST_MESSAGE("Testing FDM CEV pricing with trivial SABR model..."); const Date today = Date(3, January, 2019); @@ -261,7 +298,7 @@ void FdSabrTest::testFdmSabrCevPricing() { } } -void FdSabrTest::testFdmSabrVsVolApproximation() { +BOOST_AUTO_TEST_CASE(testFdmSabrVsVolApproximation) { BOOST_TEST_MESSAGE("Testing FDM SABR vs approximations..."); const Date today = Date(8, January, 2019); @@ -321,44 +358,7 @@ void FdSabrTest::testFdmSabrVsVolApproximation() { } } - -namespace { - /* - * Example and reference values are taken from - * B. Chen, C.W. Oosterlee, H. Weide, - * Efficient unbiased simulation scheme for the SABR stochastic volatility model. - * https://http://ta.twi.tudelft.nl/mf/users/oosterle/oosterlee/SABRMC.pdf - */ - - class OsterleeReferenceResults { - public: - explicit OsterleeReferenceResults(Size i) : i_(i) { } - - Real operator()(Real t) const { - Size i; - if (close_enough(t, 1/16.)) - i = 0; - else if (close_enough(t, 1/32.)) - i = 1; - else - QL_FAIL("unmatched reference result lookup"); - - return data_[i_][i]; - } - - private: - const Size i_; - static Real data_[9][3]; - }; - - Real OsterleeReferenceResults::data_[9][3] = { - { 0.0610, 0.0604 }, { 0.0468, 0.0463 }, { 0.0347, 0.0343 }, - { 0.0632, 0.0625 }, { 0.0512, 0.0506 }, { 0.0406, 0.0400 }, - { 0.0635, 0.0630 }, { 0.0523, 0.0520 }, { 0.0422, 0.0421 } - }; -} - -void FdSabrTest::testOosterleeTestCaseIV() { +BOOST_AUTO_TEST_CASE(testOosterleeTestCaseIV) { BOOST_TEST_MESSAGE("Testing Chen, Oosterlee and Weide test case IV..."); const Date today = Date(8, January, 2019); @@ -423,7 +423,7 @@ void FdSabrTest::testOosterleeTestCaseIV() { } } -void FdSabrTest::testBenchOpSabrCase() { +BOOST_AUTO_TEST_CASE(testBenchOpSabrCase) { BOOST_TEST_MESSAGE("Testing SABR BenchOp problem..."); /* @@ -508,17 +508,6 @@ void FdSabrTest::testBenchOpSabrCase() { } } -test_suite* FdSabrTest::suite(SpeedLevel speed) { - auto* suite = BOOST_TEST_SUITE("Finite Difference SABR tests"); +BOOST_AUTO_TEST_SUITE_END() - suite->add(QUANTLIB_TEST_CASE(&FdSabrTest::testFdmSabrCevPricing)); - suite->add(QUANTLIB_TEST_CASE(&FdSabrTest::testFdmSabrVsVolApproximation)); - suite->add(QUANTLIB_TEST_CASE(&FdSabrTest::testOosterleeTestCaseIV)); - suite->add(QUANTLIB_TEST_CASE(&FdSabrTest::testBenchOpSabrCase)); - - if (speed <= Fast) { - suite->add(QUANTLIB_TEST_CASE(&FdSabrTest::testFdmSabrOp)); - } - - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fdsabr.hpp b/test-suite/fdsabr.hpp deleted file mode 100644 index d2da8c7fa03..00000000000 --- a/test-suite/fdsabr.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2019 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_fd_sabr_hpp -#define quantlib_test_fd_sabr_hpp - -#include -#include "speedlevel.hpp" - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FdSabrTest { - public: - static void testFdmSabrOp(); - static void testFdmSabrCevPricing(); - static void testFdmSabrVsVolApproximation(); - static void testOosterleeTestCaseIV(); - static void testBenchOpSabrCase(); - - static boost::unit_test_framework::test_suite* suite(SpeedLevel speed); -}; - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 365b14535e8..3ca7230bc81 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fdsabr.hpp" #include "fittedbonddiscountcurve.hpp" #include "forwardoption.hpp" #include "forwardrateagreement.hpp" @@ -176,7 +175,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(FdSabrTest::suite(speed)); test->add(FittedBondDiscountCurveTest::suite()); test->add(ForwardOptionTest::suite(speed)); test->add(ForwardRateAgreementTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 058914181b0..22558d2849a 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 cb3773e53dd..dcba7c41be1 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -833,9 +833,6 @@ Header Files - - Header Files - Header Files From 5fc4c7fa7dc9d69d18a127532e9d54c7c3e3933b Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 16:37:32 +0800 Subject: [PATCH 080/132] Migrated fittedbonddiscountcurve.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/fittedbonddiscountcurve.cpp | 18 ++++++------- test-suite/fittedbonddiscountcurve.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/fittedbonddiscountcurve.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index adf883816c3..8fc4535bcae 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - fittedbonddiscountcurve.hpp forwardoption.hpp forwardrateagreement.hpp functions.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index db7c4d5338a..b47cfefa6ca 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - fittedbonddiscountcurve.hpp \ forwardoption.hpp \ forwardrateagreement.hpp \ functions.hpp \ diff --git a/test-suite/fittedbonddiscountcurve.cpp b/test-suite/fittedbonddiscountcurve.cpp index 4c81cd8e65f..ccbe22d6b6d 100644 --- a/test-suite/fittedbonddiscountcurve.cpp +++ b/test-suite/fittedbonddiscountcurve.cpp @@ -17,7 +17,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "fittedbonddiscountcurve.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -33,7 +33,11 @@ using namespace QuantLib; using namespace boost::unit_test_framework; -void FittedBondDiscountCurveTest::testEvaluation() { +BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) + +BOOST_AUTO_TEST_SUITE(FittedBondDiscountCurveTest) + +BOOST_AUTO_TEST_CASE(testEvaluation) { BOOST_TEST_MESSAGE("Testing that fitted bond curves work as evaluators..."); @@ -65,7 +69,7 @@ void FittedBondDiscountCurveTest::testEvaluation() { BOOST_CHECK_NO_THROW(curve.discount(3.0)); } -void FittedBondDiscountCurveTest::testFlatExtrapolation() { +BOOST_AUTO_TEST_CASE(testFlatExtrapolation) { BOOST_TEST_MESSAGE("Testing fitted bond curve with flat extrapolation..."); @@ -193,10 +197,6 @@ void FittedBondDiscountCurveTest::testFlatExtrapolation() { } +BOOST_AUTO_TEST_SUITE_END() -test_suite* FittedBondDiscountCurveTest::suite() { - auto* suite = BOOST_TEST_SUITE("Fitted bond discount curve tests"); - suite->add(QUANTLIB_TEST_CASE(&FittedBondDiscountCurveTest::testEvaluation)); - suite->add(QUANTLIB_TEST_CASE(&FittedBondDiscountCurveTest::testFlatExtrapolation)); - return suite; -} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test-suite/fittedbonddiscountcurve.hpp b/test-suite/fittedbonddiscountcurve.hpp deleted file mode 100644 index 62f12748ca5..00000000000 --- a/test-suite/fittedbonddiscountcurve.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -/* - Copyright (C) 2019 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_fitted_bond_discount_curve_hpp -#define quantlib_test_fitted_bond_discount_curve_hpp - -#include - -/* remember to document new and/or updated tests in the Doxygen - comment block of the corresponding class */ - -class FittedBondDiscountCurveTest { - public: - static void testEvaluation(); - static void testFlatExtrapolation(); - static boost::unit_test_framework::test_suite* suite(); -}; - - -#endif diff --git a/test-suite/quantlibtestsuite.cpp b/test-suite/quantlibtestsuite.cpp index 3ca7230bc81..2da079314dd 100644 --- a/test-suite/quantlibtestsuite.cpp +++ b/test-suite/quantlibtestsuite.cpp @@ -36,7 +36,6 @@ # include #endif -#include "fittedbonddiscountcurve.hpp" #include "forwardoption.hpp" #include "forwardrateagreement.hpp" #include "functions.hpp" @@ -175,7 +174,6 @@ test_suite* init_unit_test_suite(int, char* []) { auto* test = BOOST_TEST_SUITE("QuantLib test suite"); test->add(CPISwapTest::suite()); - test->add(FittedBondDiscountCurveTest::suite()); test->add(ForwardOptionTest::suite(speed)); test->add(ForwardRateAgreementTest::suite()); test->add(FunctionsTest::suite()); diff --git a/test-suite/testsuite.vcxproj b/test-suite/testsuite.vcxproj index 22558d2849a..0c430bead1b 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 dcba7c41be1..682623cd2a5 100644 --- a/test-suite/testsuite.vcxproj.filters +++ b/test-suite/testsuite.vcxproj.filters @@ -833,9 +833,6 @@ Header Files - - Header Files - Header Files From 1d2da6b5d365cbe6cf4ef6fb3c53a023080c48b4 Mon Sep 17 00:00:00 2001 From: siddharthmehrotra Date: Fri, 3 Nov 2023 16:42:37 +0800 Subject: [PATCH 081/132] Migrated forwardoption.cpp --- test-suite/CMakeLists.txt | 1 - test-suite/Makefile.am | 1 - test-suite/forwardoption.cpp | 293 ++++++++++++--------------- test-suite/forwardoption.hpp | 43 ---- test-suite/quantlibtestsuite.cpp | 2 - test-suite/testsuite.vcxproj | 1 - test-suite/testsuite.vcxproj.filters | 3 - 7 files changed, 134 insertions(+), 210 deletions(-) delete mode 100644 test-suite/forwardoption.hpp diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index 8fc4535bcae..8beeb879ab5 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -174,7 +174,6 @@ set(QL_TEST_SOURCES ) set(QL_TEST_HEADERS - forwardoption.hpp forwardrateagreement.hpp functions.hpp garch.hpp diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index b47cfefa6ca..74df477e56c 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -174,7 +174,6 @@ QL_TEST_SRCS = \ zerocouponswap.cpp QL_TEST_HDRS = \ - forwardoption.hpp \ forwardrateagreement.hpp \ functions.hpp \ garch.hpp \ diff --git a/test-suite/forwardoption.cpp b/test-suite/forwardoption.cpp index 1d5a4cb600e..9ab88635e12 100644 --- a/test-suite/forwardoption.cpp +++ b/test-suite/forwardoption.cpp @@ -17,7 +17,8 @@ FOR A PARTICULAR PURPOSE. See the license for more details. */ -#include "forwardoption.hpp" +#include "speedlevel.hpp" +#include "toplevelfixture.hpp" #include "utilities.hpp" #include #include @@ -75,133 +76,6 @@ namespace { Real tol; // tolerance }; -} - - -void ForwardOptionTest::testValues() { - - BOOST_TEST_MESSAGE("Testing forward option values..."); - - /* The data below are from - "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 - */ - ForwardOptionData values[] = { - // type, moneyness, spot, div, rate,start, t, vol, result, tol - // "Option pricing formulas", pag. 37 - { Option::Call, 1.1, 60.0, 0.04, 0.08, 0.25, 1.0, 0.30, 4.4064, 1.0e-4 }, - // "Option pricing formulas", VBA code - { Option::Put, 1.1, 60.0, 0.04, 0.08, 0.25, 1.0, 0.30, 8.2971, 1.0e-4 } - }; - - DayCounter dc = Actual360(); - Date today = Settings::instance().evaluationDate(); - - 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 stochProcess( - new BlackScholesMertonProcess(Handle(spot), - Handle(qTS), - Handle(rTS), - Handle(volTS))); - - ext::shared_ptr engine( - new ForwardVanillaEngine(stochProcess)); - - for (auto& value : values) { - - ext::shared_ptr payoff(new PlainVanillaPayoff(value.type, 0.0)); - Date exDate = today + timeToDays(value.t); - ext::shared_ptr exercise(new EuropeanExercise(exDate)); - Date reset = today + timeToDays(value.start); - - spot->setValue(value.s); - qRate->setValue(value.q); - rRate->setValue(value.r); - vol->setValue(value.v); - - ForwardVanillaOption option(value.moneyness, reset, payoff, exercise); - option.setPricingEngine(engine); - - Real calculated = option.NPV(); - Real error = std::fabs(calculated - value.result); - Real tolerance = 1e-4; - if (error>tolerance) { - REPORT_FAILURE("value", payoff, exercise, value.s, value.q, value.r, today, value.v, - value.moneyness, reset, value.result, calculated, error, tolerance); - } - } -} - - -void ForwardOptionTest::testPerformanceValues() { - - BOOST_TEST_MESSAGE("Testing forward performance option values..."); - - /* The data below are the performance equivalent of the - forward options tested above and taken from - "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 - */ - ForwardOptionData values[] = { - // type, moneyness, spot, div, rate,start, maturity, vol, result, tol - { Option::Call, 1.1, 60.0, 0.04, 0.08, 0.25, 1.0, 0.30, 4.4064/60*std::exp(-0.04*0.25), 1.0e-4 }, - { Option::Put, 1.1, 60.0, 0.04, 0.08, 0.25, 1.0, 0.30, 8.2971/60*std::exp(-0.04*0.25), 1.0e-4 } - }; - - DayCounter dc = Actual360(); - Date today = Settings::instance().evaluationDate(); - - 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 stochProcess( - new BlackScholesMertonProcess(Handle(spot), - Handle(qTS), - Handle(rTS), - Handle(volTS))); - - ext::shared_ptr engine( - new ForwardPerformanceVanillaEngine( - stochProcess)); - - for (auto& value : values) { - - ext::shared_ptr payoff(new PlainVanillaPayoff(value.type, 0.0)); - Date exDate = today + timeToDays(value.t); - ext::shared_ptr exercise(new EuropeanExercise(exDate)); - Date reset = today + timeToDays(value.start); - - spot->setValue(value.s); - qRate->setValue(value.q); - rRate->setValue(value.r); - vol->setValue(value.v); - - ForwardVanillaOption option(value.moneyness, reset, payoff, exercise); - option.setPricingEngine(engine); - - Real calculated = option.NPV(); - Real error = std::fabs(calculated - value.result); - Real tolerance = 1e-4; - if (error>tolerance) { - REPORT_FAILURE("value", payoff, exercise, value.s, value.q, value.r, today, value.v, - value.moneyness, reset, value.result, calculated, error, tolerance); - } - } -} - - -namespace { - template