Skip to content

Commit

Permalink
Merge pull request #3 from Sidsky/automated-test-registration
Browse files Browse the repository at this point in the history
Updates to use automated registration
  • Loading branch information
Sidsky authored Oct 12, 2023
2 parents 82f71c2 + 677a73e commit 65ec85e
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 237 deletions.
8 changes: 5 additions & 3 deletions test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ set(QL_TEST_SOURCES
period.cpp
piecewiseyieldcurve.cpp
piecewisezerospreadedtermstructure.cpp
quantlibglobalfixture.cpp
quantlibtestsuite.cpp
quantooption.cpp
quotes.cpp
Expand All @@ -140,6 +141,7 @@ set(QL_TEST_SOURCES
shortratemodels.cpp
sofrfutures.cpp
solvers.cpp
speedlevel.cpp
spreadoption.cpp
squarerootclvmodel.cpp
stats.cpp
Expand Down Expand Up @@ -172,7 +174,6 @@ set(QL_TEST_SOURCES
)

set(QL_TEST_HEADERS
americanoption.hpp
amortizingbond.hpp
andreasenhugevolatilityinterpl.hpp
array.hpp
Expand Down Expand Up @@ -258,7 +259,6 @@ set(QL_TEST_HEADERS
inflationcpicapfloor.hpp
inflationcpiswap.hpp
inflationvolatility.hpp
instruments.hpp
integrals.hpp
interestrates.hpp
interpolations.hpp
Expand Down Expand Up @@ -300,6 +300,7 @@ set(QL_TEST_HEADERS
period.hpp
piecewiseyieldcurve.hpp
piecewisezerospreadedtermstructure.hpp
quantlibglobalfixture.hpp
quantooption.hpp
quotes.hpp
rangeaccrual.hpp
Expand Down Expand Up @@ -330,6 +331,7 @@ set(QL_TEST_HEADERS
timegrid.hpp
timeseries.hpp
tqreigendecomposition.hpp
toplevelfixture.hpp
tracing.hpp
transformedgrid.hpp
twoassetbarrieroption.hpp
Expand All @@ -349,7 +351,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
Expand Down
8 changes: 4 additions & 4 deletions test-suite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ QL_TEST_SRCS = \
period.cpp \
piecewiseyieldcurve.cpp \
piecewisezerospreadedtermstructure.cpp \
quantlibglobalfixture.cpp \
quantooption.cpp \
quotes.cpp \
rangeaccrual.cpp \
Expand All @@ -141,6 +142,7 @@ QL_TEST_SRCS = \
shortratemodels.cpp \
sofrfutures.cpp \
solvers.cpp \
speedlevel.cpp \
spreadoption.cpp \
squarerootclvmodel.cpp \
stats.cpp \
Expand Down Expand Up @@ -173,7 +175,6 @@ QL_TEST_SRCS = \

QL_TEST_HDRS = \
speedlevel.hpp \
americanoption.hpp \
amortizingbond.hpp \
andreasenhugevolatilityinterpl.hpp \
array.hpp \
Expand Down Expand Up @@ -259,7 +260,6 @@ QL_TEST_HDRS = \
inflationcpicapfloor.hpp \
inflationcpiswap.hpp \
inflationvolatility.hpp \
instruments.hpp \
integrals.hpp \
interestrates.hpp \
interpolations.hpp \
Expand Down Expand Up @@ -300,6 +300,7 @@ QL_TEST_HDRS = \
period.hpp \
piecewiseyieldcurve.hpp \
piecewisezerospreadedtermstructure.hpp \
quantlibglobalfixture.hpp \
quantooption.hpp \
quotes.hpp \
rangeaccrual.hpp \
Expand Down Expand Up @@ -330,6 +331,7 @@ QL_TEST_HDRS = \
timeseries.hpp \
transformedgrid.hpp \
tqreigendecomposition.hpp \
toplevelfixture.hpp \
tracing.hpp \
twoassetbarrieroption.hpp \
twoassetcorrelationoption.hpp \
Expand All @@ -348,7 +350,6 @@ QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS}

QL_BENCHMARK_SRCS = \
quantlibbenchmark.cpp \
americanoption.cpp \
asianoptions.cpp \
barrieroption.cpp \
doublebarrieroption.cpp \
Expand All @@ -371,7 +372,6 @@ QL_BENCHMARK_SRCS = \
utilities.cpp

QL_BENCHMARK_HDRS = \
americanoption.hpp \
asianoptions.hpp \
barrieroption.hpp \
doublebarrieroption.hpp \
Expand Down
101 changes: 31 additions & 70 deletions test-suite/americanoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ql/any.hpp>
#include <ql/time/daycounters/actual360.hpp>
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -330,8 +333,7 @@ namespace {

}


void AmericanOptionTest::testJuValues() {
BOOST_AUTO_TEST_CASE(testJuValues) {

BOOST_TEST_MESSAGE("Testing Ju approximation for American options...");

Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -563,18 +564,17 @@ namespace {

}


void AmericanOptionTest::testFdAmericanGreeks() {
BOOST_AUTO_TEST_CASE(testFdAmericanGreeks) {
BOOST_TEST_MESSAGE("Testing finite-differences American option greeks...");
testFdGreeks<FdBlackScholesVanillaEngine>();
}

void AmericanOptionTest::testFdShoutGreeks() {
BOOST_AUTO_TEST_CASE(testFdShoutGreeks, *precondition(if_speed(Fast))) {
BOOST_TEST_MESSAGE("Testing finite-differences shout option greeks...");
testFdGreeks<FdBlackScholesShoutEngine>();
}

void AmericanOptionTest::testFDShoutNPV() {
BOOST_AUTO_TEST_CASE(testFDShoutNPV) {
BOOST_TEST_MESSAGE("Testing finite-differences shout option pricing...");

const auto dc = Actual365Fixed();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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...");

Expand All @@ -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...");

Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -1649,7 +1645,7 @@ namespace {
};
}

void AmericanOptionTest::testBulkQdFpAmericanEngine() {
BOOST_AUTO_TEST_CASE(testBulkQdFpAmericanEngine) {
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
"bulk examples...");

Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Loading

0 comments on commit 65ec85e

Please sign in to comment.