Skip to content

Commit 65ec85e

Browse files
authored
Merge pull request #3 from Sidsky/automated-test-registration
Updates to use automated registration
2 parents 82f71c2 + 677a73e commit 65ec85e

17 files changed

+227
-237
lines changed

test-suite/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ set(QL_TEST_SOURCES
126126
period.cpp
127127
piecewiseyieldcurve.cpp
128128
piecewisezerospreadedtermstructure.cpp
129+
quantlibglobalfixture.cpp
129130
quantlibtestsuite.cpp
130131
quantooption.cpp
131132
quotes.cpp
@@ -140,6 +141,7 @@ set(QL_TEST_SOURCES
140141
shortratemodels.cpp
141142
sofrfutures.cpp
142143
solvers.cpp
144+
speedlevel.cpp
143145
spreadoption.cpp
144146
squarerootclvmodel.cpp
145147
stats.cpp
@@ -172,7 +174,6 @@ set(QL_TEST_SOURCES
172174
)
173175

174176
set(QL_TEST_HEADERS
175-
americanoption.hpp
176177
amortizingbond.hpp
177178
andreasenhugevolatilityinterpl.hpp
178179
array.hpp
@@ -258,7 +259,6 @@ set(QL_TEST_HEADERS
258259
inflationcpicapfloor.hpp
259260
inflationcpiswap.hpp
260261
inflationvolatility.hpp
261-
instruments.hpp
262262
integrals.hpp
263263
interestrates.hpp
264264
interpolations.hpp
@@ -300,6 +300,7 @@ set(QL_TEST_HEADERS
300300
period.hpp
301301
piecewiseyieldcurve.hpp
302302
piecewisezerospreadedtermstructure.hpp
303+
quantlibglobalfixture.hpp
303304
quantooption.hpp
304305
quotes.hpp
305306
rangeaccrual.hpp
@@ -330,6 +331,7 @@ set(QL_TEST_HEADERS
330331
timegrid.hpp
331332
timeseries.hpp
332333
tqreigendecomposition.hpp
334+
toplevelfixture.hpp
333335
tracing.hpp
334336
transformedgrid.hpp
335337
twoassetbarrieroption.hpp
@@ -349,7 +351,7 @@ set(QL_TEST_HEADERS
349351
set(QL_BENCHMARK_SOURCES
350352
quantlibbenchmark.cpp
351353

352-
americanoption.cpp americanoption.hpp
354+
# americanoption.cpp
353355
asianoptions.cpp asianoptions.hpp
354356
barrieroption.cpp barrieroption.hpp
355357
basketoption.cpp basketoption.hpp

test-suite/Makefile.am

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ QL_TEST_SRCS = \
128128
period.cpp \
129129
piecewiseyieldcurve.cpp \
130130
piecewisezerospreadedtermstructure.cpp \
131+
quantlibglobalfixture.cpp \
131132
quantooption.cpp \
132133
quotes.cpp \
133134
rangeaccrual.cpp \
@@ -141,6 +142,7 @@ QL_TEST_SRCS = \
141142
shortratemodels.cpp \
142143
sofrfutures.cpp \
143144
solvers.cpp \
145+
speedlevel.cpp \
144146
spreadoption.cpp \
145147
squarerootclvmodel.cpp \
146148
stats.cpp \
@@ -173,7 +175,6 @@ QL_TEST_SRCS = \
173175

174176
QL_TEST_HDRS = \
175177
speedlevel.hpp \
176-
americanoption.hpp \
177178
amortizingbond.hpp \
178179
andreasenhugevolatilityinterpl.hpp \
179180
array.hpp \
@@ -259,7 +260,6 @@ QL_TEST_HDRS = \
259260
inflationcpicapfloor.hpp \
260261
inflationcpiswap.hpp \
261262
inflationvolatility.hpp \
262-
instruments.hpp \
263263
integrals.hpp \
264264
interestrates.hpp \
265265
interpolations.hpp \
@@ -300,6 +300,7 @@ QL_TEST_HDRS = \
300300
period.hpp \
301301
piecewiseyieldcurve.hpp \
302302
piecewisezerospreadedtermstructure.hpp \
303+
quantlibglobalfixture.hpp \
303304
quantooption.hpp \
304305
quotes.hpp \
305306
rangeaccrual.hpp \
@@ -330,6 +331,7 @@ QL_TEST_HDRS = \
330331
timeseries.hpp \
331332
transformedgrid.hpp \
332333
tqreigendecomposition.hpp \
334+
toplevelfixture.hpp \
333335
tracing.hpp \
334336
twoassetbarrieroption.hpp \
335337
twoassetcorrelationoption.hpp \
@@ -348,7 +350,6 @@ QL_TESTS = ${QL_TEST_SRCS} ${QL_TEST_HDRS}
348350

349351
QL_BENCHMARK_SRCS = \
350352
quantlibbenchmark.cpp \
351-
americanoption.cpp \
352353
asianoptions.cpp \
353354
barrieroption.cpp \
354355
doublebarrieroption.cpp \
@@ -371,7 +372,6 @@ QL_BENCHMARK_SRCS = \
371372
utilities.cpp
372373

373374
QL_BENCHMARK_HDRS = \
374-
americanoption.hpp \
375375
asianoptions.hpp \
376376
barrieroption.hpp \
377377
doublebarrieroption.hpp \

test-suite/americanoption.cpp

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
FOR A PARTICULAR PURPOSE. See the license for more details.
2020
*/
2121

22-
#include "americanoption.hpp"
22+
#include "speedlevel.hpp"
23+
#include "toplevelfixture.hpp"
2324
#include "utilities.hpp"
2425
#include <ql/any.hpp>
2526
#include <ql/time/daycounters/actual360.hpp>
@@ -83,8 +84,11 @@ namespace {
8384

8485
}
8586

87+
BOOST_FIXTURE_TEST_SUITE(QuantLibTest, QuantLib::TopLevelFixture)
8688

87-
void AmericanOptionTest::testBaroneAdesiWhaleyValues() {
89+
BOOST_AUTO_TEST_SUITE(AmericanOptionTest)
90+
91+
BOOST_AUTO_TEST_CASE(testBaroneAdesiWhaleyValues) {
8892

8993
BOOST_TEST_MESSAGE("Testing Barone-Adesi and Whaley approximation "
9094
"for American options...");
@@ -184,8 +188,7 @@ void AmericanOptionTest::testBaroneAdesiWhaleyValues() {
184188
}
185189
}
186190

187-
188-
void AmericanOptionTest::testBjerksundStenslandValues() {
191+
BOOST_AUTO_TEST_CASE(testBjerksundStenslandValues) {
189192

190193
BOOST_TEST_MESSAGE("Testing Bjerksund and Stensland approximation "
191194
"for American options...");
@@ -330,8 +333,7 @@ namespace {
330333

331334
}
332335

333-
334-
void AmericanOptionTest::testJuValues() {
336+
BOOST_AUTO_TEST_CASE(testJuValues) {
335337

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

@@ -381,8 +383,7 @@ void AmericanOptionTest::testJuValues() {
381383
}
382384
}
383385

384-
385-
void AmericanOptionTest::testFdValues() {
386+
BOOST_AUTO_TEST_CASE(testFdValues) {
386387

387388
BOOST_TEST_MESSAGE("Testing finite-difference and QR+ engine "
388389
"for American options...");
@@ -563,18 +564,17 @@ namespace {
563564

564565
}
565566

566-
567-
void AmericanOptionTest::testFdAmericanGreeks() {
567+
BOOST_AUTO_TEST_CASE(testFdAmericanGreeks) {
568568
BOOST_TEST_MESSAGE("Testing finite-differences American option greeks...");
569569
testFdGreeks<FdBlackScholesVanillaEngine>();
570570
}
571571

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

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

580580
const auto dc = Actual365Fixed();
@@ -631,7 +631,7 @@ void AmericanOptionTest::testFDShoutNPV() {
631631
}
632632
}
633633

634-
void AmericanOptionTest::testZeroVolFDShoutNPV() {
634+
BOOST_AUTO_TEST_CASE(testZeroVolFDShoutNPV) {
635635
BOOST_TEST_MESSAGE("Testing zero volatility shout option pricing with discrete dividends...");
636636

637637
const auto dc = Actual365Fixed();
@@ -710,7 +710,7 @@ void AmericanOptionTest::testZeroVolFDShoutNPV() {
710710
}
711711
}
712712

713-
void AmericanOptionTest::testLargeDividendShoutNPV() {
713+
BOOST_AUTO_TEST_CASE(testLargeDividendShoutNPV) {
714714
BOOST_TEST_MESSAGE("Testing zero strike shout option pricing with discrete dividends...");
715715

716716
const auto dc = Actual365Fixed();
@@ -792,7 +792,7 @@ void AmericanOptionTest::testLargeDividendShoutNPV() {
792792
}
793793
}
794794

795-
void AmericanOptionTest::testEscrowedVsSpotAmericanOption() {
795+
BOOST_AUTO_TEST_CASE(testEscrowedVsSpotAmericanOption) {
796796
BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model for American options...");
797797

798798
const auto dc = Actual360();
@@ -863,8 +863,7 @@ void AmericanOptionTest::testEscrowedVsSpotAmericanOption() {
863863
}
864864
}
865865

866-
867-
void AmericanOptionTest::testTodayIsDividendDate() {
866+
BOOST_AUTO_TEST_CASE(testTodayIsDividendDate) {
868867
BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model on dividend dates for American options...");
869868

870869
const auto dc = Actual360();
@@ -982,8 +981,7 @@ void AmericanOptionTest::testTodayIsDividendDate() {
982981
}
983982
}
984983

985-
986-
void AmericanOptionTest::testCallPutParity() {
984+
BOOST_AUTO_TEST_CASE(testCallPutParity) {
987985
BOOST_TEST_MESSAGE("Testing call/put parity for American options...");
988986

989987
// R.L. McDonald, M.D. Schroder: A parity result for American option
@@ -1071,7 +1069,7 @@ void AmericanOptionTest::testCallPutParity() {
10711069
}
10721070
}
10731071

1074-
void AmericanOptionTest::testQdPlusBoundaryValues() {
1072+
BOOST_AUTO_TEST_CASE(testQdPlusBoundaryValues) {
10751073
BOOST_TEST_MESSAGE("Testing QD+ boundary approximation...");
10761074

10771075
const DayCounter dc = Actual365Fixed();
@@ -1122,7 +1120,7 @@ void AmericanOptionTest::testQdPlusBoundaryValues() {
11221120
}
11231121
}
11241122

1125-
void AmericanOptionTest::testQdPlusBoundaryConvergence() {
1123+
BOOST_AUTO_TEST_CASE(testQdPlusBoundaryConvergence) {
11261124
BOOST_TEST_MESSAGE("Testing QD+ boundary convergence...");
11271125

11281126
const DayCounter dc = Actual365Fixed();
@@ -1187,7 +1185,7 @@ void AmericanOptionTest::testQdPlusBoundaryConvergence() {
11871185
}
11881186
}
11891187

1190-
void AmericanOptionTest::testQdAmericanEngines() {
1188+
BOOST_AUTO_TEST_CASE(testQdAmericanEngines) {
11911189
BOOST_TEST_MESSAGE("Testing QD+ American option pricing...");
11921190

11931191
const DayCounter dc = Actual365Fixed();
@@ -1432,7 +1430,7 @@ void AmericanOptionTest::testQdAmericanEngines() {
14321430
};
14331431
}
14341432

1435-
void AmericanOptionTest::testQdFpIterationScheme() {
1433+
BOOST_AUTO_TEST_CASE(testQdFpIterationScheme) {
14361434
BOOST_TEST_MESSAGE("Testing Legendre and tanh-sinh iteration "
14371435
"scheme for QD+ fixed-point American engine...");
14381436

@@ -1459,8 +1457,7 @@ void AmericanOptionTest::testQdFpIterationScheme() {
14591457
}
14601458
}
14611459

1462-
1463-
void AmericanOptionTest::testAndersenLakeHighPrecisionExample() {
1460+
BOOST_AUTO_TEST_CASE(testAndersenLakeHighPrecisionExample) {
14641461
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
14651462
"high precision example...");
14661463

@@ -1556,8 +1553,7 @@ void AmericanOptionTest::testAndersenLakeHighPrecisionExample() {
15561553
}
15571554
}
15581555

1559-
1560-
void AmericanOptionTest::testQdEngineStandardExample() {
1556+
BOOST_AUTO_TEST_CASE(testQdEngineStandardExample) {
15611557
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
15621558
"standard example...");
15631559

@@ -1649,7 +1645,7 @@ namespace {
16491645
};
16501646
}
16511647

1652-
void AmericanOptionTest::testBulkQdFpAmericanEngine() {
1648+
BOOST_AUTO_TEST_CASE(testBulkQdFpAmericanEngine) {
16531649
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
16541650
"bulk examples...");
16551651

@@ -1758,7 +1754,7 @@ void AmericanOptionTest::testBulkQdFpAmericanEngine() {
17581754
<< "\n tol : " << tolMax);
17591755
}
17601756

1761-
void AmericanOptionTest::testQdEngineWithLobattoIntegral() {
1757+
BOOST_AUTO_TEST_CASE(testQdEngineWithLobattoIntegral) {
17621758
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
17631759
"with high precision Gauss-Lobatto integration...");
17641760

@@ -1825,7 +1821,7 @@ void AmericanOptionTest::testQdEngineWithLobattoIntegral() {
18251821
}
18261822
}
18271823

1828-
void AmericanOptionTest::testQdNegativeDividendYield() {
1824+
BOOST_AUTO_TEST_CASE(testQdNegativeDividendYield) {
18291825
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
18301826
"with positive or zero interest rate and "
18311827
"negative dividend yield...");
@@ -1896,7 +1892,7 @@ void AmericanOptionTest::testQdNegativeDividendYield() {
18961892
}
18971893
}
18981894

1899-
void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() {
1895+
BOOST_AUTO_TEST_CASE(testBjerksundStenslandEuropeanGreeks) {
19001896
BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland greeks when early "
19011897
"exercise is not optimal...");
19021898

@@ -1973,8 +1969,7 @@ void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() {
19731969
}
19741970
}
19751971

1976-
1977-
void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() {
1972+
BOOST_AUTO_TEST_CASE(testBjerksundStenslandAmericanGreeks) {
19781973
BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland American greeks...");
19791974

19801975
const Date today = Date(5, December, 2022);
@@ -2164,8 +2159,7 @@ void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() {
21642159
}
21652160
}
21662161

2167-
2168-
void AmericanOptionTest::testSingleBjerksundStenslandGreeks() {
2162+
BOOST_AUTO_TEST_CASE(testSingleBjerksundStenslandGreeks) {
21692163
BOOST_TEST_MESSAGE("Testing a single Bjerksund-Stensland greeks set...");
21702164

21712165
const Date today = Date(20, January, 2023);
@@ -2248,39 +2242,6 @@ void AmericanOptionTest::testSingleBjerksundStenslandGreeks() {
22482242
BOOST_FAIL("American exercise type expected");
22492243
}
22502244

2245+
BOOST_AUTO_TEST_SUITE_END()
22512246

2252-
test_suite* AmericanOptionTest::suite(SpeedLevel speed) {
2253-
auto* suite = BOOST_TEST_SUITE("American option tests");
2254-
2255-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBaroneAdesiWhaleyValues));
2256-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandValues));
2257-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testJuValues));
2258-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdValues));
2259-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdAmericanGreeks));
2260-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFDShoutNPV));
2261-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testZeroVolFDShoutNPV));
2262-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testLargeDividendShoutNPV));
2263-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testEscrowedVsSpotAmericanOption));
2264-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testTodayIsDividendDate));
2265-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testCallPutParity));
2266-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdPlusBoundaryValues));
2267-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdPlusBoundaryConvergence));
2268-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdAmericanEngines));
2269-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdFpIterationScheme));
2270-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testAndersenLakeHighPrecisionExample));
2271-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdEngineStandardExample));
2272-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBulkQdFpAmericanEngine));
2273-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdEngineWithLobattoIntegral));
2274-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testQdNegativeDividendYield));
2275-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandEuropeanGreeks));
2276-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testBjerksundStenslandAmericanGreeks));
2277-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testSingleBjerksundStenslandGreeks));
2278-
2279-
2280-
if (speed <= Fast) {
2281-
suite->add(QUANTLIB_TEST_CASE(&AmericanOptionTest::testFdShoutGreeks));
2282-
}
2283-
2284-
return suite;
2285-
}
2286-
2247+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)