1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2005, 2006, 2007 Ferdinando Ametrano
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/types.hpp>
22#include <ql/settings.hpp>
23#include <ql/utilities/dataparsers.hpp>
24#include <ql/version.hpp>
25
26#ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
27#include "paralleltestrunner.hpp"
28#else
29#include <boost/test/included/unit_test.hpp>
30#endif
31
32/* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks,
33 for example) also #define _MSC_VER
34*/
35#if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC)
36# include <ql/auto_link.hpp>
37#endif
38
39#include "americanoption.hpp"
40#include "amortizingbond.hpp"
41#include "andreasenhugevolatilityinterpl.hpp"
42#include "array.hpp"
43#include "asianoptions.hpp"
44#include "assetswap.hpp"
45#include "autocovariances.hpp"
46#include "barrieroption.hpp"
47#include "basismodels.hpp"
48#include "basisswapratehelpers.hpp"
49#include "basketoption.hpp"
50#include "batesmodel.hpp"
51#include "bermudanswaption.hpp"
52#include "binaryoption.hpp"
53#include "blackdeltacalculator.hpp"
54#include "blackformula.hpp"
55#include "bondforward.hpp"
56#include "bonds.hpp"
57#include "brownianbridge.hpp"
58#include "businessdayconventions.hpp"
59#include "calendars.hpp"
60#include "callablebonds.hpp"
61#include "capfloor.hpp"
62#include "capflooredcoupon.hpp"
63#include "cashflows.hpp"
64#include "catbonds.hpp"
65#include "cdo.hpp"
66#include "cdsoption.hpp"
67#include "chooseroption.hpp"
68#include "cliquetoption.hpp"
69#include "cms.hpp"
70#include "cms_normal.hpp"
71#include "cmsspread.hpp"
72#include "commodityunitofmeasure.hpp"
73#include "compiledboostversion.hpp"
74#include "compoundoption.hpp"
75#include "convertiblebonds.hpp"
76#include "covariance.hpp"
77#include "creditdefaultswap.hpp"
78#include "creditriskplus.hpp"
79#include "crosscurrencyratehelpers.hpp"
80#include "currency.hpp"
81#include "curvestates.hpp"
82#include "dates.hpp"
83#include "daycounters.hpp"
84#include "defaultprobabilitycurves.hpp"
85#include "digitalcoupon.hpp"
86#include "digitaloption.hpp"
87#include "distributions.hpp"
88#include "dividendoption.hpp"
89#include "doublebarrieroption.hpp"
90#include "doublebinaryoption.hpp"
91#include "equitycashflow.hpp"
92#include "equityindex.hpp"
93#include "equitytotalreturnswap.hpp"
94#include "europeanoption.hpp"
95#include "everestoption.hpp"
96#include "exchangerate.hpp"
97#include "extendedtrees.hpp"
98#include "extensibleoptions.hpp"
99#include "fastfouriertransform.hpp"
100#include "fdcev.hpp"
101#include "fdcir.hpp"
102#include "fdheston.hpp"
103#include "fdmlinearop.hpp"
104#include "fdsabr.hpp"
105#include "fittedbonddiscountcurve.hpp"
106#include "forwardoption.hpp"
107#include "forwardrateagreement.hpp"
108#include "functions.hpp"
109#include "garch.hpp"
110#include "gaussianquadratures.hpp"
111#include "gjrgarchmodel.hpp"
112#include "gsr.hpp"
113#include "hestonmodel.hpp"
114#include "hestonslvmodel.hpp"
115#include "himalayaoption.hpp"
116#include "hybridhestonhullwhiteprocess.hpp"
117#include "indexes.hpp"
118#include "inflation.hpp"
119#include "inflationcapfloor.hpp"
120#include "inflationcapflooredcoupon.hpp"
121#include "inflationcpibond.hpp"
122#include "inflationcpicapfloor.hpp"
123#include "inflationcpiswap.hpp"
124#include "inflationvolatility.hpp"
125#include "instruments.hpp"
126#include "integrals.hpp"
127#include "interestrates.hpp"
128#include "interpolations.hpp"
129#include "jumpdiffusion.hpp"
130#include "lazyobject.hpp"
131#include "libormarketmodel.hpp"
132#include "libormarketmodelprocess.hpp"
133#include "linearleastsquaresregression.hpp"
134#include "lookbackoptions.hpp"
135#include "lowdiscrepancysequences.hpp"
136#include "margrabeoption.hpp"
137#include "marketmodel.hpp"
138#include "marketmodel_cms.hpp"
139#include "marketmodel_smm.hpp"
140#include "marketmodel_smmcapletalphacalibration.hpp"
141#include "marketmodel_smmcapletcalibration.hpp"
142#include "marketmodel_smmcaplethomocalibration.hpp"
143#include "markovfunctional.hpp"
144#include "matrices.hpp"
145#include "mclongstaffschwartzengine.hpp"
146#include "mersennetwister.hpp"
147#include "money.hpp"
148#include "noarbsabr.hpp"
149#include "normalclvmodel.hpp"
150#include "nthorderderivativeop.hpp"
151#include "nthtodefault.hpp"
152#include "numericaldifferentiation.hpp"
153#include "observable.hpp"
154#include "ode.hpp"
155#include "operators.hpp"
156#include "optimizers.hpp"
157#include "optionletstripper.hpp"
158#include "overnightindexedcoupon.hpp"
159#include "overnightindexedswap.hpp"
160#include "pagodaoption.hpp"
161#include "partialtimebarrieroption.hpp"
162#include "pathgenerator.hpp"
163#include "period.hpp"
164#include "piecewiseyieldcurve.hpp"
165#include "piecewisezerospreadedtermstructure.hpp"
166#include "quantooption.hpp"
167#include "quotes.hpp"
168#include "rangeaccrual.hpp"
169#include "riskneutraldensitycalculator.hpp"
170#include "riskstats.hpp"
171#include "rngtraits.hpp"
172#include "rounding.hpp"
173#include "sampledcurve.hpp"
174#include "schedule.hpp"
175#include "settings.hpp"
176#include "shortratemodels.hpp"
177#include "sofrfutures.hpp"
178#include "solvers.hpp"
179#include "speedlevel.hpp"
180#include "spreadoption.hpp"
181#include "squarerootclvmodel.hpp"
182#include "stats.hpp"
183#include "subperiodcoupons.hpp"
184#include "svivolatility.hpp"
185#include "swap.hpp"
186#include "swapforwardmappings.hpp"
187#include "swaption.hpp"
188#include "swaptionvolatilitycube.hpp"
189#include "swaptionvolatilitymatrix.hpp"
190#include "swingoption.hpp"
191#include "termstructures.hpp"
192#include "timegrid.hpp"
193#include "timeseries.hpp"
194#include "tqreigendecomposition.hpp"
195#include "tracing.hpp"
196#include "transformedgrid.hpp"
197#include "twoassetbarrieroption.hpp"
198#include "twoassetcorrelationoption.hpp"
199#include "ultimateforwardtermstructure.hpp"
200#include "utilities.hpp"
201#include "variancegamma.hpp"
202#include "varianceoption.hpp"
203#include "varianceswaps.hpp"
204#include "volatilitymodels.hpp"
205#include "vpp.hpp"
206#include "xoshiro256starstar.hpp"
207#include "zabr.hpp"
208#include "zerocouponswap.hpp"
209#include <chrono>
210#include <iomanip>
211#include <iostream>
212
213using namespace boost::unit_test_framework;
214
215namespace {
216
217 decltype(std::chrono::steady_clock::now()) start;
218
219 void startTimer() {
220 start = std::chrono::steady_clock::now();
221 }
222
223 void stopTimer() {
224 auto stop = std::chrono::steady_clock::now();
225
226 double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(d: stop - start).count() * 1e-3;
227 int hours = int(seconds/3600);
228 seconds -= hours * 3600;
229 int minutes = int(seconds/60);
230 seconds -= minutes * 60;
231
232 std::cout << "\nTests completed in ";
233 if (hours > 0)
234 std::cout << hours << " h ";
235 if (hours > 0 || minutes > 0)
236 std::cout << minutes << " m ";
237 std::cout << std::fixed << std::setprecision(0)
238 << seconds << " s\n" << std::endl;
239 }
240
241 void configure(QuantLib::Date evaluationDate) {
242 /* if needed, a subset of the lines below can be
243 uncommented and/or changed to run the test suite with a
244 different configuration. In the future, we'll need a
245 mechanism that doesn't force us to recompile (possibly a
246 couple of command-line flags for the test suite?)
247 */
248
249 // QuantLib::Settings::instance().includeReferenceDateCashFlows() = true;
250 // QuantLib::Settings::instance().includeTodaysCashFlows() = ext::nullopt;
251
252 QuantLib::Settings::instance().evaluationDate() = evaluationDate;
253 }
254
255}
256
257QuantLib::Date evaluation_date(int argc, char** argv) {
258 /*! Dead simple parser:
259 - passing --date=YYYY-MM-DD causes the test suite to run on
260 that date;
261 - passing --date=today causes it to run on today's date;
262 - passing nothing causes it to run on a known date for which
263 there should be no date-dependent errors as far as we know.
264
265 Dates that should eventually be checked include:
266 - 2015-08-29 causes three tests to fail;
267 - 2016-02-29 causes two tests to fail.
268 */
269
270 QuantLib::Date knownGoodDefault =
271 QuantLib::Date(16, QuantLib::September, 2015);
272
273 for (int i=1; i<argc; ++i) {
274 std::string arg = argv[i];
275 if (arg == "--date=today")
276 return QuantLib::Date::todaysDate();
277 else if (arg.substr(pos: 0, n: 7) == "--date=")
278 return QuantLib::DateParser::parseISO(str: arg.substr(pos: 7));
279 }
280 return knownGoodDefault;
281}
282
283
284SpeedLevel speed_level(int argc, char** argv) {
285 /*! Again, dead simple parser:
286 - passing --slow causes all tests to be run;
287 - passing --fast causes most tests to be run, except the slowest;
288 - passing --faster causes only the faster tests to be run;
289 - passing nothing is the same as --slow
290 */
291
292 for (int i=1; i<argc; ++i) {
293 std::string arg = argv[i];
294 if (arg == "--slow")
295 return Slow;
296 else if (arg == "--fast")
297 return Fast;
298 else if (arg == "--faster")
299 return Faster;
300 }
301 return Slow;
302}
303
304
305test_suite* init_unit_test_suite(int, char* []) {
306
307 int argc = boost::unit_test::framework::master_test_suite().argc;
308 char **argv = boost::unit_test::framework::master_test_suite().argv;
309 configure(evaluationDate: evaluation_date(argc, argv));
310 SpeedLevel speed = speed_level(argc, argv);
311
312 const QuantLib::Settings& settings = QuantLib::Settings::instance();
313 std::ostringstream header;
314 header <<
315 " Testing "
316 "QuantLib " QL_VERSION
317 "\n QL_EXTRA_SAFETY_CHECKS "
318 #ifdef QL_EXTRA_SAFETY_CHECKS
319 " defined"
320 #else
321 "undefined"
322 #endif
323 "\n QL_USE_INDEXED_COUPON "
324 #ifdef QL_USE_INDEXED_COUPON
325 " defined"
326 #else
327 " undefined"
328 #endif
329 "\n"
330 << "evaluation date is " << settings.evaluationDate() << ",\n"
331 << (settings.includeReferenceDateEvents()
332 ? "reference date events are included,\n"
333 : "reference date events are excluded,\n")
334 << (settings.includeTodaysCashFlows()
335 ? (*settings.includeTodaysCashFlows()
336 ? "today's cashflows are included,\n"
337 : "today's cashflows are excluded,\n")
338 : "")
339 << (settings.enforcesTodaysHistoricFixings()
340 ? "today's historic fixings are enforced."
341 : "today's historic fixings are not enforced.")
342 << "\nRunning "
343 << (speed == Faster ? "faster" :
344 (speed == Fast ? "fast" : "all"))
345 << " tests.";
346
347 std::string rule = std::string(41, '=');
348
349 BOOST_TEST_MESSAGE(rule);
350 BOOST_TEST_MESSAGE(header.str());
351 BOOST_TEST_MESSAGE(rule);
352 auto* test = BOOST_TEST_SUITE("QuantLib test suite");
353
354 test->add(QUANTLIB_TEST_CASE(startTimer));
355
356 test->add(tu: AmericanOptionTest::suite(speed));
357 test->add(tu: AmortizingBondTest::suite());
358 test->add(tu: AndreasenHugeVolatilityInterplTest::suite(speed));
359 test->add(tu: ArrayTest::suite());
360 test->add(tu: AsianOptionTest::suite(speed));
361 test->add(tu: AssetSwapTest::suite()); // fails with QL_USE_INDEXED_COUPON
362 test->add(tu: AutocovariancesTest::suite());
363 test->add(tu: BarrierOptionTest::suite());
364 test->add(tu: BasketOptionTest::suite(speed));
365 test->add(tu: BatesModelTest::suite());
366 test->add(tu: BermudanSwaptionTest::suite(speed));
367 test->add(tu: BinaryOptionTest::suite());
368 test->add(tu: BlackFormulaTest::suite());
369 test->add(tu: BondTest::suite());
370 test->add(tu: BondForwardTest::suite());
371 test->add(tu: BrownianBridgeTest::suite());
372 test->add(tu: BusinessDayConventionTest::suite());
373 test->add(tu: CalendarTest::suite());
374 test->add(tu: CapFloorTest::suite());
375 test->add(tu: CapFlooredCouponTest::suite());
376 test->add(tu: CashFlowsTest::suite());
377 test->add(tu: ChooserOptionTest::suite());
378 test->add(tu: CliquetOptionTest::suite());
379 test->add(tu: CmsTest::suite());
380 test->add(tu: CmsNormalTest::suite());
381 test->add(tu: CompoundOptionTest::suite());
382 test->add(tu: ConvertibleBondTest::suite());
383 test->add(tu: CovarianceTest::suite());
384 test->add(tu: CPISwapTest::suite());
385 test->add(tu: CreditDefaultSwapTest::suite());
386 test->add(tu: CrossCurrencyRateHelpersTest::suite());
387 test->add(tu: CurrencyTest::suite());
388 test->add(tu: CurveStatesTest::suite());
389 test->add(tu: DateTest::suite(speed));
390 test->add(tu: DayCounterTest::suite());
391 test->add(tu: DefaultProbabilityCurveTest::suite());
392 test->add(tu: DigitalCouponTest::suite()); // might fail with QL_USE_INDEXED_COUPON
393 test->add(tu: DigitalOptionTest::suite());
394 test->add(tu: DistributionTest::suite(speed));
395 test->add(tu: DividendOptionTest::suite(speed));
396 test->add(tu: EquityIndexTest::suite());
397 test->add(tu: EquityCashFlowTest::suite());
398 test->add(tu: EquityTotalReturnSwapTest::suite());
399 test->add(tu: EuropeanOptionTest::suite());
400 test->add(tu: ExchangeRateTest::suite());
401 test->add(tu: FastFourierTransformTest::suite());
402 test->add(tu: FdHestonTest::suite(speed));
403 test->add(tu: FdmLinearOpTest::suite(speed));
404 test->add(tu: FdCevTest::suite(speed));
405 test->add(tu: FdCIRTest::suite(speed));
406 test->add(tu: FdSabrTest::suite(speed));
407 test->add(tu: FittedBondDiscountCurveTest::suite());
408 test->add(tu: ForwardOptionTest::suite(speed));
409 test->add(tu: ForwardRateAgreementTest::suite());
410 test->add(tu: FunctionsTest::suite());
411 test->add(tu: GARCHTest::suite());
412 test->add(tu: GaussianQuadraturesTest::suite());
413 test->add(tu: GJRGARCHModelTest::suite(speed));
414 test->add(tu: GsrTest::suite());
415 test->add(tu: HestonModelTest::suite(speed));
416 test->add(tu: HestonSLVModelTest::suite(speed));
417 test->add(tu: HybridHestonHullWhiteProcessTest::suite(speed));
418 test->add(tu: IndexTest::suite());
419 test->add(tu: InflationTest::suite());
420 test->add(tu: InflationCapFloorTest::suite());
421 test->add(tu: InflationCapFlooredCouponTest::suite());
422 test->add(tu: InflationCPIBondTest::suite());
423 test->add(tu: InstrumentTest::suite());
424 test->add(tu: IntegralTest::suite());
425 test->add(tu: InterestRateTest::suite());
426 test->add(tu: InterpolationTest::suite(speed));
427 test->add(tu: JumpDiffusionTest::suite());
428 test->add(tu: LazyObjectTest::suite());
429 test->add(tu: LinearLeastSquaresRegressionTest::suite());
430 test->add(tu: LookbackOptionTest::suite(speed));
431 test->add(tu: LowDiscrepancyTest::suite());
432 test->add(tu: MargrabeOptionTest::suite());
433 test->add(tu: MarketModelTest::suite(speed));
434 test->add(tu: MarketModelCmsTest::suite(speed));
435 test->add(tu: MarketModelSmmTest::suite(speed));
436 test->add(tu: MarketModelSmmCapletAlphaCalibrationTest::suite());
437 test->add(tu: MarketModelSmmCapletCalibrationTest::suite());
438 test->add(tu: MarketModelSmmCapletHomoCalibrationTest::suite());
439 test->add(tu: MarkovFunctionalTest::suite(speed));
440 test->add(tu: MatricesTest::suite());
441 test->add(tu: MCLongstaffSchwartzEngineTest::suite(speed));
442 test->add(tu: MersenneTwisterTest::suite());
443 test->add(tu: MoneyTest::suite());
444 test->add(tu: NumericalDifferentiationTest::suite());
445 test->add(tu: NthOrderDerivativeOpTest::suite(speed));
446 test->add(tu: ObservableTest::suite());
447 test->add(tu: OdeTest::suite());
448 test->add(tu: OperatorTest::suite());
449 test->add(tu: OptimizersTest::suite(speed));
450 test->add(tu: OptionletStripperTest::suite());
451 test->add(tu: OvernightIndexedCouponTest::suite());
452 test->add(tu: OvernightIndexedSwapTest::suite());
453 test->add(tu: PathGeneratorTest::suite());
454 test->add(tu: PeriodTest::suite());
455 test->add(tu: PiecewiseYieldCurveTest::suite());
456 test->add(tu: PiecewiseZeroSpreadedTermStructureTest::suite());
457 test->add(tu: QuantoOptionTest::suite());
458 test->add(tu: QuoteTest::suite());
459 test->add(tu: RangeAccrualTest::suite());
460 test->add(tu: RiskStatisticsTest::suite());
461 test->add(tu: RngTraitsTest::suite());
462 test->add(tu: RoundingTest::suite());
463 test->add(tu: SampledCurveTest::suite());
464 test->add(tu: ScheduleTest::suite());
465 test->add(tu: SettingsTest::suite());
466 test->add(tu: ShortRateModelTest::suite(speed)); // fails with QL_USE_INDEXED_COUPON
467 test->add(tu: SofrFuturesTest::suite());
468 test->add(tu: Solver1DTest::suite());
469 test->add(tu: StatisticsTest::suite());
470 test->add(tu: SubPeriodsCouponTest::suite());
471 test->add(tu: SwapTest::suite());
472 test->add(tu: SwapForwardMappingsTest::suite());
473 test->add(tu: SwaptionTest::suite(speed));
474 test->add(tu: SwaptionVolatilityCubeTest::suite());
475 test->add(tu: SwaptionVolatilityMatrixTest::suite());
476 test->add(tu: TermStructureTest::suite());
477 test->add(tu: TimeGridTest::suite());
478 test->add(tu: TimeSeriesTest::suite());
479 test->add(tu: TqrEigenDecompositionTest::suite());
480 test->add(tu: TracingTest::suite());
481 test->add(tu: TransformedGridTest::suite());
482 test->add(tu: UltimateForwardTermStructureTest::suite());
483 test->add(tu: VarianceSwapTest::suite());
484 test->add(tu: VolatilityModelsTest::suite());
485 test->add(tu: Xoshiro256StarStarTest::suite());
486 test->add(tu: ZeroCouponSwapTest::suite());
487
488 // tests for experimental classes
489 test->add(tu: AsianOptionTest::experimental(speed));
490 test->add(tu: BasismodelsTest::suite());
491 test->add(tu: BasisSwapRateHelpersTest::suite());
492 test->add(tu: BarrierOptionTest::experimental());
493 test->add(tu: DoubleBarrierOptionTest::experimental(speed));
494 test->add(tu: BlackDeltaCalculatorTest::suite());
495 test->add(tu: CallableBondTest::suite());
496 test->add(tu: CatBondTest::suite());
497 test->add(tu: CdoTest::suite(speed));
498 test->add(tu: CdsOptionTest::suite());
499 test->add(tu: CmsSpreadTest::suite());
500 test->add(tu: CommodityUnitOfMeasureTest::suite());
501 test->add(tu: CompiledBoostVersionTest::suite());
502 test->add(tu: CreditRiskPlusTest::suite());
503 test->add(tu: DoubleBarrierOptionTest::suite(speed));
504 test->add(tu: DoubleBinaryOptionTest::suite());
505 test->add(tu: EuropeanOptionTest::experimental());
506 test->add(tu: EverestOptionTest::suite());
507 test->add(tu: ExtendedTreesTest::suite());
508 test->add(tu: ExtensibleOptionsTest::suite());
509 test->add(tu: GaussianQuadraturesTest::experimental());
510 test->add(tu: HestonModelTest::experimental());
511 test->add(tu: HimalayaOptionTest::suite());
512 test->add(tu: InflationCPICapFloorTest::suite());
513 test->add(tu: InflationVolTest::suite());
514 test->add(tu: NoArbSabrTest::suite());
515 test->add(tu: NormalCLVModelTest::experimental(speed));
516 test->add(tu: NthToDefaultTest::suite(speed));
517 test->add(tu: PagodaOptionTest::suite());
518 test->add(tu: PartialTimeBarrierOptionTest::suite());
519 test->add(tu: QuantoOptionTest::experimental());
520 test->add(tu: RiskNeutralDensityCalculatorTest::experimental(speed));
521 test->add(tu: SpreadOptionTest::suite());
522 test->add(tu: SquareRootCLVModelTest::experimental());
523 test->add(tu: SviVolatilityTest::experimental());
524 test->add(tu: SwingOptionTest::suite(speed));
525 test->add(tu: TwoAssetBarrierOptionTest::suite());
526 test->add(tu: TwoAssetCorrelationOptionTest::suite());
527 test->add(tu: VarianceGammaTest::suite());
528 test->add(tu: VarianceOptionTest::suite());
529 test->add(tu: VPPTest::suite(speed));
530 test->add(tu: ZabrTest::suite(speed));
531
532 // tests for deprecated classes
533 test->add(tu: LiborMarketModelTest::suite(speed));
534 test->add(tu: LiborMarketModelProcessTest::suite(speed));
535
536 test->add(QUANTLIB_TEST_CASE(stopTimer));
537
538 return test;
539}
540

source code of quantlib/test-suite/quantlibtestsuite.cpp

Morty Proxy This is a proxified and sanitized view of the page, visit original site.