Skip to content

Commit b3a753b

Browse files
committed
Restore settings after every test
Instead of adding SavedSettings into every test that changes settings, use it in quantlib_test_case so it applies to every test. This is cheap and makes writing tests easier.
1 parent b1f41c3 commit b3a753b

File tree

91 files changed

+4
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4
-710
lines changed

test-suite/americanoption.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ namespace {
461461
template <class Engine>
462462
void testFdGreeks() {
463463

464-
SavedSettings backup;
465-
466464
std::map<std::string,Real> calculated, expected, tolerance;
467465
tolerance["delta"] = 7.0e-4;
468466
tolerance["gamma"] = 2.0e-4;
@@ -579,8 +577,6 @@ void AmericanOptionTest::testFdShoutGreeks() {
579577
void AmericanOptionTest::testFDShoutNPV() {
580578
BOOST_TEST_MESSAGE("Testing finite-differences shout option pricing...");
581579

582-
SavedSettings backup;
583-
584580
const auto dc = Actual365Fixed();
585581
const auto today = Date(4, February, 2021);
586582
Settings::instance().evaluationDate() = today;
@@ -638,8 +634,6 @@ void AmericanOptionTest::testFDShoutNPV() {
638634
void AmericanOptionTest::testZeroVolFDShoutNPV() {
639635
BOOST_TEST_MESSAGE("Testing zero volatility shout option pricing with discrete dividends...");
640636

641-
SavedSettings backup;
642-
643637
const auto dc = Actual365Fixed();
644638
const auto today = Date(14, February, 2021);
645639
Settings::instance().evaluationDate() = today;
@@ -719,8 +713,6 @@ void AmericanOptionTest::testZeroVolFDShoutNPV() {
719713
void AmericanOptionTest::testLargeDividendShoutNPV() {
720714
BOOST_TEST_MESSAGE("Testing zero strike shout option pricing with discrete dividends...");
721715

722-
SavedSettings backup;
723-
724716
const auto dc = Actual365Fixed();
725717
const auto today = Date(21, February, 2021);
726718
Settings::instance().evaluationDate() = today;
@@ -803,8 +795,6 @@ void AmericanOptionTest::testLargeDividendShoutNPV() {
803795
void AmericanOptionTest::testEscrowedVsSpotAmericanOption() {
804796
BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model for American options...");
805797

806-
SavedSettings backup;
807-
808798
const auto dc = Actual360();
809799
const auto today = Date(27, February, 2021);
810800
Settings::instance().evaluationDate() = today;
@@ -877,8 +867,6 @@ void AmericanOptionTest::testEscrowedVsSpotAmericanOption() {
877867
void AmericanOptionTest::testTodayIsDividendDate() {
878868
BOOST_TEST_MESSAGE("Testing escrowed vs spot dividend model on dividend dates for American options...");
879869

880-
SavedSettings backup;
881-
882870
const auto dc = Actual360();
883871
const auto today = Date(27, February, 2021);
884872
Settings::instance().evaluationDate() = today;
@@ -1000,8 +988,6 @@ void AmericanOptionTest::testCallPutParity() {
1000988

1001989
// R.L. McDonald, M.D. Schroder: A parity result for American option
1002990

1003-
SavedSettings backup;
1004-
1005991
const DayCounter dc = Actual365Fixed();
1006992
const Date today = Date(8, April, 2022);
1007993
Settings::instance().evaluationDate() = today;
@@ -1204,8 +1190,6 @@ void AmericanOptionTest::testQdPlusBoundaryConvergence() {
12041190
void AmericanOptionTest::testQdAmericanEngines() {
12051191
BOOST_TEST_MESSAGE("Testing QD+ American option pricing...");
12061192

1207-
SavedSettings backup;
1208-
12091193
const DayCounter dc = Actual365Fixed();
12101194
const Date today = Date(1, June, 2022);
12111195
Settings::instance().evaluationDate() = today;
@@ -1480,8 +1464,6 @@ void AmericanOptionTest::testAndersenLakeHighPrecisionExample() {
14801464
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
14811465
"high precision example...");
14821466

1483-
SavedSettings backup;
1484-
14851467
// Example and results are taken from
14861468
// Leif Andersen, Mark Lake and Dimitri Offengenden (2015)
14871469
// "High Performance American Option Pricing",
@@ -1579,8 +1561,6 @@ void AmericanOptionTest::testQdEngineStandardExample() {
15791561
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
15801562
"standard example...");
15811563

1582-
SavedSettings backup;
1583-
15841564
const DayCounter dc = Actual365Fixed();
15851565
const Date today = Date(1, June, 2022);
15861566
Settings::instance().evaluationDate() = today;
@@ -1678,8 +1658,6 @@ void AmericanOptionTest::testBulkQdFpAmericanEngine() {
16781658
// "High Performance American Option Pricing",
16791659
// https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2547027
16801660

1681-
SavedSettings backup;
1682-
16831661
const DayCounter dc = Actual365Fixed();
16841662
const Date today = Date(1, June, 2022);
16851663
Settings::instance().evaluationDate() = today;
@@ -1784,8 +1762,6 @@ void AmericanOptionTest::testQdEngineWithLobattoIntegral() {
17841762
BOOST_TEST_MESSAGE("Testing Andersen, Lake and Offengenden "
17851763
"with high precision Gauss-Lobatto integration...");
17861764

1787-
SavedSettings backup;
1788-
17891765
const DayCounter dc = Actual365Fixed();
17901766
const Date today = Date(5, November, 2022);
17911767
Settings::instance().evaluationDate() = today;
@@ -1854,8 +1830,6 @@ void AmericanOptionTest::testQdNegativeDividendYield() {
18541830
"with positive or zero interest rate and "
18551831
"negative dividend yield...");
18561832

1857-
SavedSettings backup;
1858-
18591833
const DayCounter dc = Actual365Fixed();
18601834
const Date today = Date(5, December, 2022);
18611835
Settings::instance().evaluationDate() = today;
@@ -1926,8 +1900,6 @@ void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() {
19261900
BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland greeks when early "
19271901
"exercise is not optimal...");
19281902

1929-
SavedSettings backup;
1930-
19311903
const Date today = Date(5, November, 2022);
19321904
Settings::instance().evaluationDate() = today;
19331905

@@ -2005,8 +1977,6 @@ void AmericanOptionTest::testBjerksundStenslandEuropeanGreeks() {
20051977
void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() {
20061978
BOOST_TEST_MESSAGE("Testing Bjerksund-Stensland American greeks...");
20071979

2008-
SavedSettings backup;
2009-
20101980
const Date today = Date(5, December, 2022);
20111981
Settings::instance().evaluationDate() = today;
20121982

@@ -2198,8 +2168,6 @@ void AmericanOptionTest::testBjerksundStenslandAmericanGreeks() {
21982168
void AmericanOptionTest::testSingleBjerksundStenslandGreeks() {
21992169
BOOST_TEST_MESSAGE("Testing a single Bjerksund-Stensland greeks set...");
22002170

2201-
SavedSettings backup;
2202-
22032171
const Date today = Date(20, January, 2023);
22042172
Settings::instance().evaluationDate() = today;
22052173

test-suite/andreasenhugevolatilityinterpl.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ namespace andreasen_huge_volatility_interpl_test {
150150
void testAndreasenHugeVolatilityInterpolation(
151151
const CalibrationData& data, const CalibrationResults& expected) {
152152

153-
SavedSettings backup;
154-
155153
const Handle<YieldTermStructure> rTS = data.rTS;
156154
const Handle<YieldTermStructure> qTS = data.qTS;
157155

@@ -448,8 +446,6 @@ void AndreasenHugeVolatilityInterplTest::testTimeDependentInterestRates() {
448446

449447
using namespace andreasen_huge_volatility_interpl_test;
450448

451-
SavedSettings backup;
452-
453449
const CalibrationData data = AndreasenHugeExampleData();
454450

455451
const DayCounter dc = data.rTS->dayCounter();
@@ -533,8 +529,6 @@ void AndreasenHugeVolatilityInterplTest::testSingleOptionCalibration() {
533529
"Testing Andreasen-Huge volatility interpolation with "
534530
"a single option...");
535531

536-
SavedSettings backup;
537-
538532
const DayCounter dc = Actual365Fixed();
539533
const Date today = Date(4, January, 2018);
540534

@@ -596,8 +590,6 @@ void AndreasenHugeVolatilityInterplTest::testArbitrageFree() {
596590

597591
using namespace andreasen_huge_volatility_interpl_test;
598592

599-
SavedSettings backup;
600-
601593
CalibrationData data[] = { BorovkovaExampleData(), arbitrageData() };;
602594

603595
for (auto& i : data) {
@@ -685,8 +677,6 @@ void AndreasenHugeVolatilityInterplTest::testBarrierOptionPricing() {
685677
"Testing Barrier option pricing with Andreasen-Huge "
686678
"local volatility surface...");
687679

688-
SavedSettings backup;
689-
690680
const DayCounter dc = Actual365Fixed();
691681
const Date today = Date(4, January, 2018);
692682

@@ -838,8 +828,6 @@ void AndreasenHugeVolatilityInterplTest::testPeterAndFabiensExample() {
838828

839829
using namespace andreasen_huge_volatility_interpl_test;
840830

841-
SavedSettings backup;
842-
843831
const std::pair<CalibrationData, std::vector<Real> > sd = sabrData();
844832
const CalibrationData& data = sd.first;
845833
const std::vector<Real>& parameter = sd.second;
@@ -916,8 +904,6 @@ void AndreasenHugeVolatilityInterplTest::testMovingReferenceDate() {
916904
"Testing that reference date of adapter surface moves along with "
917905
"evaluation date...");
918906

919-
SavedSettings backup;
920-
921907
const Date today = Date(4, January, 2018);
922908
Settings::instance().evaluationDate() = today;
923909

@@ -994,8 +980,6 @@ void AndreasenHugeVolatilityInterplTest::testFlatVolCalibration() {
994980

995981
using namespace andreasen_huge_volatility_interpl_test;
996982

997-
SavedSettings backup;
998-
999983
const Date ref(1, November, 2019);
1000984
const DayCounter dc = Actual365Fixed();
1001985
Settings::instance().evaluationDate() = ref;

test-suite/asianoptions.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ void AsianOptionTest::testAnalyticContinuousGeometricAveragePriceGreeks() {
178178
BOOST_TEST_MESSAGE(
179179
"Testing analytic continuous geometric average-price Asian greeks...");
180180

181-
SavedSettings backup;
182-
183181
std::map<std::string,Real> calculated, expected, tolerance;
184182
tolerance["delta"] = 1.0e-5;
185183
tolerance["gamma"] = 1.0e-5;
@@ -1323,8 +1321,6 @@ void AsianOptionTest::testAnalyticDiscreteGeometricAveragePriceGreeks() {
13231321

13241322
BOOST_TEST_MESSAGE("Testing discrete-averaging geometric Asian greeks...");
13251323

1326-
SavedSettings backup;
1327-
13281324
std::map<std::string,Real> calculated, expected, tolerance;
13291325
tolerance["delta"] = 1.0e-5;
13301326
tolerance["gamma"] = 1.0e-5;
@@ -1864,8 +1860,6 @@ void AsianOptionTest::testAllFixingsInThePast() {
18641860

18651861
// also check with the evaluation date on last fixing
18661862

1867-
SavedSettings backup;
1868-
18691863
Settings::instance().evaluationDate() = fixingDates.back();
18701864

18711865
raised = false;

test-suite/assetswap.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ namespace asset_swap_test {
7171
Compounding compounding;
7272
RelinkableHandle<YieldTermStructure> termStructure;
7373

74-
// clean-up
75-
SavedSettings backup;
76-
7774
// initial setup
7875
CommonVars() {
7976
Natural swapSettlementDays = 2;

test-suite/barrieroption.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,6 @@ void BarrierOptionTest::testLocalVolAndHestonComparison() {
805805
BOOST_TEST_MESSAGE("Testing local volatility and Heston FD engines "
806806
"for barrier options...");
807807

808-
SavedSettings backup;
809-
810808
const Date settlementDate(5, July, 2002);
811809
Settings::instance().evaluationDate() = settlementDate;
812810

@@ -944,8 +942,6 @@ void BarrierOptionTest::testVannaVolgaSimpleBarrierValues() {
944942

945943
using namespace barrier_option_test;
946944

947-
SavedSettings backup;
948-
949945
BarrierFxOptionData values[] = {
950946

951947
//barrierType,barrier,rebate,type,strike,s,q,r,t,vol25Put,volAtm,vol25Call,vol, result, tol
@@ -1167,8 +1163,6 @@ void BarrierOptionTest::testVannaVolgaSimpleBarrierValues() {
11671163
void BarrierOptionTest::testOldDividendBarrierOption() {
11681164
BOOST_TEST_MESSAGE("Testing old-style barrier option pricing with discrete dividends...");
11691165

1170-
SavedSettings backup;
1171-
11721166
const DayCounter dc = Actual365Fixed();
11731167

11741168
const Date today(11, February, 2018);
@@ -1284,8 +1278,6 @@ void BarrierOptionTest::testOldDividendBarrierOption() {
12841278
void BarrierOptionTest::testDividendBarrierOption() {
12851279
BOOST_TEST_MESSAGE("Testing barrier option pricing with discrete dividends...");
12861280

1287-
SavedSettings backup;
1288-
12891281
DayCounter dc = Actual365Fixed();
12901282

12911283
Date today(11, February, 2018);
@@ -1393,8 +1385,6 @@ void BarrierOptionTest::testDividendBarrierOption() {
13931385
void BarrierOptionTest::testDividendBarrierOptionWithDividendsPastMaturity() {
13941386
BOOST_TEST_MESSAGE("Testing barrier option pricing with discrete dividends past maturity...");
13951387

1396-
SavedSettings backup;
1397-
13981388
DayCounter dc = Actual365Fixed();
13991389

14001390
Date today(11, February, 2018);
@@ -1479,8 +1469,6 @@ void BarrierOptionTest::testDividendBarrierOptionWithDividendsPastMaturity() {
14791469
void BarrierOptionTest::testBarrierAndDividendEngine() {
14801470
BOOST_TEST_MESSAGE("Testing the use of a single engine for barrier and dividend options...");
14811471

1482-
SavedSettings backup;
1483-
14841472
auto today = Date(1, January, 2023);
14851473
Settings::instance().evaluationDate() = today;
14861474

@@ -1521,8 +1509,6 @@ void BarrierOptionTest::testBarrierAndDividendEngine() {
15211509
void BarrierOptionTest::testImpliedVolatility() {
15221510
BOOST_TEST_MESSAGE("Testing implied volatility for barrier options...");
15231511

1524-
SavedSettings backup;
1525-
15261512
DayCounter dc = Actual365Fixed();
15271513

15281514
Date today(11, February, 2018);
@@ -1602,8 +1588,6 @@ void BarrierOptionTest::testImpliedVolatility() {
16021588
void BarrierOptionTest::testLowVolatility() {
16031589
BOOST_TEST_MESSAGE("Testing barrier options with low volatility value...");
16041590

1605-
SavedSettings backup;
1606-
16071591
DayCounter dc = Actual365Fixed();
16081592

16091593
Date today(11, February, 2018);

test-suite/batesmodel.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ void BatesModelTest::testAnalyticVsBlack() {
6161

6262
BOOST_TEST_MESSAGE("Testing analytic Bates engine against Black formula...");
6363

64-
SavedSettings backup;
65-
6664
Date settlementDate = Date::todaysDate();
6765
Settings::instance().evaluationDate() = settlementDate;
6866

@@ -174,8 +172,6 @@ void BatesModelTest::testAnalyticAndMcVsJumpDiffusion() {
174172

175173
BOOST_TEST_MESSAGE("Testing analytic Bates engine against Merton-76 engine...");
176174

177-
SavedSettings backup;
178-
179175
Date settlementDate = Date::todaysDate();
180176
Settings::instance().evaluationDate() = settlementDate;
181177

@@ -302,8 +298,6 @@ void BatesModelTest::testAnalyticVsMCPricing() {
302298

303299
using namespace bates_model_test;
304300

305-
SavedSettings backup;
306-
307301
Date settlementDate(30, March, 2007);
308302
Settings::instance().evaluationDate() = settlementDate;
309303

@@ -383,8 +377,6 @@ void BatesModelTest::testDAXCalibration() {
383377

384378
using namespace bates_model_test;
385379

386-
SavedSettings backup;
387-
388380
Date settlementDate(5, July, 2002);
389381
Settings::instance().evaluationDate() = settlementDate;
390382

test-suite/bermudanswaption.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ namespace bermudan_swaption_test {
5959

6060
RelinkableHandle<YieldTermStructure> termStructure;
6161

62-
// cleanup
63-
SavedSettings backup;
64-
6562
// setup
6663
CommonVars() {
6764
startYears = 1;
@@ -318,7 +315,6 @@ void BermudanSwaptionTest::testTreeEngineTimeSnapping() {
318315
BOOST_TEST_MESSAGE("Testing snap of exercise dates for discretized swaption...");
319316

320317
Date today = Date(8, Jul, 2021);
321-
SavedSettings backup;
322318
Settings::instance().evaluationDate() = today;
323319

324320
RelinkableHandle<YieldTermStructure> termStructure;

0 commit comments

Comments
 (0)