diff --git a/.github/workflows/linux-full-tests.yml b/.github/workflows/linux-full-tests.yml index a99062e8d57..162f6288370 100644 --- a/.github/workflows/linux-full-tests.yml +++ b/.github/workflows/linux-full-tests.yml @@ -147,12 +147,6 @@ jobs: cxx: g++ cxxflags: "-Wno-deprecated-declarations" configureflags: --disable-std-unique-ptr - - name: "Disposable re-enabled" - shortname: disposable - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-disposable - name: "Thread-safe observer enabled" shortname: threadsafe tag: rolling diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index ae669c7933b..5505dea78bf 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -153,13 +153,6 @@ jobs: cxxflags: "-Wno-deprecated-declarations" configureflags: --disable-std-unique-ptr tests: true - - name: "Disposable re-enabled" - shortname: disposable - tag: rolling - cc: gcc - cxx: g++ - configureflags: --enable-disposable - tests: true - name: "Thread-safe observer enabled" shortname: threadsafe tag: rolling diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b93131110b..4d368d27483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,6 @@ option(QL_INSTALL_EXAMPLES "Install examples" ON) option(QL_INSTALL_TEST_SUITE "Install test suite" ON) option(QL_TAGGED_LAYOUT "Library names use layout tags" ${MSVC}) option(QL_USE_CLANG_TIDY "Use clang-tidy when building" OFF) -option(QL_USE_DISPOSABLE "Use the Disposable class template. Not needed for C++11" OFF) option(QL_USE_INDEXED_COUPON "Use indexed coupons instead of par coupons" OFF) option(QL_USE_STD_CLASSES "Enable all QL_USE_STD_ options" OFF) option(QL_USE_STD_SHARED_PTR "Use standard smart pointers instead of Boost ones" OFF) diff --git a/Docs/pages/config.docs b/Docs/pages/config.docs index aab2fb8b4ae..4fa8a3f4063 100644 --- a/Docs/pages/config.docs +++ b/Docs/pages/config.docs @@ -133,14 +133,6 @@ are used instead of `boost::tuple`. If disabled (the default) the Boost facilities are used. - \code - #define QL_USE_DISPOSABLE - \endcode - If defined, the old `Disposable` class template is used; this - should be no longer necessary in C++11 and might interfere with - compiler optimizations. If disabled (the default) `Disposable` is - still available but is just an alias to `T`. - \code #define QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER \endcode diff --git a/Examples/GlobalOptimizer/GlobalOptimizer.cpp b/Examples/GlobalOptimizer/GlobalOptimizer.cpp index dc973f3adac..daffe148e3a 100644 --- a/Examples/GlobalOptimizer/GlobalOptimizer.cpp +++ b/Examples/GlobalOptimizer/GlobalOptimizer.cpp @@ -65,7 +65,7 @@ Real ackley(const Array& x) { return M_E + 20.0 - 20.0*std::exp(p1)-std::exp(p2); } -Disposable ackleyValues(const Array& x) { +Array ackleyValues(const Array& x) { Array y(x.size()); for (Size i = 0; i < x.size(); i++) { Real p1 = x[i] * x[i]; @@ -81,7 +81,7 @@ Real sphere(const Array& x) { return DotProduct(x, x); } -Disposable sphereValues(const Array& x) { +Array sphereValues(const Array& x) { Array y(x.size()); for (Size i = 0; i < x.size(); i++) { y[i] = x[i]*x[i]; @@ -110,7 +110,7 @@ Real easom(const Array& x) { return -p1*std::exp(-p2); } -Disposable easomValues(const Array& x) { +Array easomValues(const Array& x) { Array y(x.size()); for (Size i = 0; i < x.size(); i++) { Real p1 = std::cos(x[i]); @@ -141,14 +141,14 @@ Real printFunction(Problem& p, const Array& x) { class TestFunction : public CostFunction { public: typedef ext::function RealFunc; - typedef ext::function(const Array&)> ArrayFunc; + typedef ext::function ArrayFunc; explicit TestFunction(RealFunc f, ArrayFunc fs = ArrayFunc()) : f_(std::move(f)), fs_(std::move(fs)) {} - explicit TestFunction(Real (*f)(const Array&), Disposable (*fs)(const Array&) = nullptr) + explicit TestFunction(Real (*f)(const Array&), Array (*fs)(const Array&) = nullptr) : f_(f), fs_(fs) {} ~TestFunction() override = default; Real value(const Array& x) const override { return f_(x); } - Disposable values(const Array& x) const override { + Array values(const Array& x) const override { if(!fs_) throw std::runtime_error("Invalid function"); return fs_(x); diff --git a/cmake/GenerateHeaders.cmake b/cmake/GenerateHeaders.cmake index b050eb1db51..b25f7e8ce51 100644 --- a/cmake/GenerateHeaders.cmake +++ b/cmake/GenerateHeaders.cmake @@ -37,6 +37,7 @@ function(generate_dir_headers source_dir binary_dir) set(children_all "") file(GLOB children_hpp RELATIVE ${source_dir} "${source_dir}/*.hpp") list(FILTER children_hpp EXCLUDE REGEX "all.hpp") + list(FILTER children_hpp EXCLUDE REGEX "disposable.hpp") file(GLOB children_dir RELATIVE ${source_dir} "${source_dir}/*") list(FILTER children_dir EXCLUDE REGEX "CMakeFiles") list(FILTER children_dir EXCLUDE REGEX "^\\..*") diff --git a/configure.ac b/configure.ac index 5168c4ed463..bd1c3884b43 100644 --- a/configure.ac +++ b/configure.ac @@ -444,23 +444,6 @@ fi AC_MSG_RESULT([$ql_use_std_classes]) -AC_MSG_CHECKING([whether to enable the Disposable class template]) -AC_ARG_ENABLE([disposable], - AS_HELP_STRING([--enable-disposable], - [If enabled, the Disposable class template will be used; - this should be no longer necessary in C++11 - and might interfere with compiler optimizations. - If disabled (the default) the class will only - be an alias for the underlying type.]), - [ql_use_disposable=$enableval], - [ql_use_disposable=no]) -if test "$ql_use_disposable" = "yes" ; then - AC_DEFINE([QL_USE_DISPOSABLE],[1], - [Define this if you want to use the Disposable class template.]) -fi -AC_MSG_RESULT([$ql_use_disposable]) - - # manual configurations for specific hosts case $host in powerpc-apple-darwin*) diff --git a/ql/config.hpp.cfg b/ql/config.hpp.cfg index 53de8c0e95d..1a61f1fa98b 100644 --- a/ql/config.hpp.cfg +++ b/ql/config.hpp.cfg @@ -36,7 +36,6 @@ #cmakedefine QL_ERROR_LINES #cmakedefine QL_EXTRA_SAFETY_CHECKS #cmakedefine QL_HIGH_RESOLUTION_DATE -#cmakedefine QL_USE_DISPOSABLE #cmakedefine QL_USE_INDEXED_COUPON #cmakedefine QL_USE_STD_SHARED_PTR #cmakedefine QL_USE_STD_UNIQUE_PTR diff --git a/ql/experimental/credit/basket.cpp b/ql/experimental/credit/basket.cpp index 5e6f268dfdb..7c06aa3daf6 100644 --- a/ql/experimental/credit/basket.cpp +++ b/ql/experimental/credit/basket.cpp @@ -106,7 +106,7 @@ namespace QuantLib { return std::accumulate(notionals_.begin(), notionals_.end(), 0.0); } - Disposable > Basket::probabilities(const Date& d) const { + vector Basket::probabilities(const Date& d) const { vector prob(size()); vector defKeys = defaultKeys(); for (Size j = 0; j < size(); j++) @@ -168,8 +168,7 @@ namespace QuantLib { return evalDateRemainingNot_; } - Disposable > - Basket::liveList(const Date& endDate) const { + std::vector Basket::liveList(const Date& endDate) const { std::vector calcBufferLiveList; for (Size i = 0; i < size(); i++) if (!pool_->get(pool_->names()[i]).defaultedBetween( @@ -193,8 +192,7 @@ namespace QuantLib { return notional; } - Disposable > - Basket::remainingNotionals(const Date& endDate) const + vector Basket::remainingNotionals(const Date& endDate) const { QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception"); @@ -208,8 +206,7 @@ namespace QuantLib { return calcBufferNotionals; } - Disposable > - Basket::remainingProbabilities(const Date& d) const + std::vector Basket::remainingProbabilities(const Date& d) const { QL_REQUIRE(d >= refDate_, "Target date lies before basket inception"); vector prob; @@ -245,8 +242,7 @@ namespace QuantLib { //return positions_[position]->expectedExposure(d); } - Disposable > - Basket::remainingNames(const Date& endDate) const + std::vector Basket::remainingNames(const Date& endDate) const { // maybe return zero directly instead?: QL_REQUIRE(endDate >= refDate_, @@ -260,8 +256,7 @@ namespace QuantLib { return calcBufferNames; } - Disposable > - Basket::remainingDefaultKeys(const Date& endDate) const + vector Basket::remainingDefaultKeys(const Date& endDate) const { QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception"); @@ -329,8 +324,7 @@ namespace QuantLib { return cumulatedLoss() + lossModel_->expectedTrancheLoss(d); } - Disposable > - Basket::splitVaRLevel(const Date& date, Real loss) const { + std::vector Basket::splitVaRLevel(const Date& date, Real loss) const { calculate(); return lossModel_->splitVaRLevel(date, loss); } @@ -340,8 +334,7 @@ namespace QuantLib { return lossModel_->expectedShortfall(d, prob); } - Disposable > - Basket::lossDistribution(const Date& d) const { + std::map Basket::lossDistribution(const Date& d) const { calculate(); return lossModel_->lossDistribution(d); } diff --git a/ql/experimental/credit/basket.hpp b/ql/experimental/credit/basket.hpp index 973176f0d8d..3b768553b46 100644 --- a/ql/experimental/credit/basket.hpp +++ b/ql/experimental/credit/basket.hpp @@ -33,7 +33,6 @@ #include #include #include -#include namespace QuantLib { @@ -103,7 +102,7 @@ namespace QuantLib { //! Underlying pool const ext::shared_ptr& pool() const; //! The keys each counterparty enters the basket with (sensitive to) - Disposable > defaultKeys() const; + std::vector defaultKeys() const; /*! Loss Given Default for all issuers/notionals based on expected recovery rates for the respective issuers. */ @@ -128,8 +127,7 @@ namespace QuantLib { /*! Vector of cumulative default probability to date d for all issuers in the basket. */ - Disposable > - probabilities(const Date& d) const; + std::vector probabilities(const Date& d) const; /*! Realized basket losses between the reference date and the calculation date, taking the actual recovery rates of loss events into account. @@ -165,26 +163,23 @@ namespace QuantLib { reference date and the given date, recovery ignored. */ const std::vector& remainingNotionals() const; - Disposable > remainingNotionals(const Date&) const; + std::vector remainingNotionals(const Date&) const; /*! Vector of surviving issuers after defaults between the reference basket date and the given (or evaluation) date. */ const std::vector& remainingNames() const; - Disposable > - remainingNames(const Date&) const; + std::vector remainingNames(const Date&) const; /*! Default keys of non defaulted counterparties */ const std::vector& remainingDefaultKeys() const; - Disposable > remainingDefaultKeys( - const Date&) const; + std::vector remainingDefaultKeys(const Date&) const; //! Number of counterparties alive on the requested date. Size remainingSize() const; Size remainingSize(const Date&) const; /*! Vector of cumulative default probability to date d for all issuers still (at the evaluation date) alive in the basket. */ - Disposable > - remainingProbabilities(const Date& d) const; + std::vector remainingProbabilities(const Date& d) const; /*! Attachment amount of the equivalent (after defaults) remaining basket The remaining attachment amount is @@ -222,7 +217,7 @@ namespace QuantLib { } //!Indexes of remaining names. Notice these are names and not positions. const std::vector& liveList() const; - Disposable > liveList(const Date&) const;//?? keep? + std::vector liveList(const Date&) const;//?? keep? //! Assigns the default loss model to this basket. Resets calculations. void setLossModel( const ext::shared_ptr& lossModel); @@ -246,12 +241,10 @@ namespace QuantLib { Real expectedShortfall(const Date& d, Probability prob) const; /* Split a portfolio loss along counterparties. Typically loss corresponds to some percentile.*/ - Disposable > - splitVaRLevel(const Date& date, Real loss) const; + std::vector splitVaRLevel(const Date& date, Real loss) const; /*! Full loss distribution */ - Disposable > lossDistribution( - const Date&) const; + std::map lossDistribution(const Date&) const; Real densityTrancheLoss(const Date& d, Real lossFraction) const; Real defaultCorrelation(const Date& d, Size iName, Size jName) const; /*! Probability vector that each of the remaining live names (at eval @@ -329,8 +322,7 @@ namespace QuantLib { return notionals_; } - inline Disposable > - Basket::defaultKeys() const { + inline std::vector Basket::defaultKeys() const { return pool_->defaultKeys(); } diff --git a/ql/experimental/credit/binomiallossmodel.hpp b/ql/experimental/credit/binomiallossmodel.hpp index aac4e1ed625..902237a7450 100644 --- a/ql/experimental/credit/binomiallossmodel.hpp +++ b/ql/experimental/credit/binomiallossmodel.hpp @@ -78,8 +78,7 @@ namespace QuantLib { /*! Returns the probability of the default loss values given by the method lossPoints. */ - Disposable > - expectedDistribution(const Date& date) const { + std::vector expectedDistribution(const Date& date) const { // precal date conditional magnitudes: std::vector notionals = basket_->remainingNotionals(date); std::vector invProbs = @@ -94,9 +93,9 @@ namespace QuantLib { }); } //! attainable loss points this model provides - Disposable > lossPoints(const Date&) const; + std::vector lossPoints(const Date&) const; //! Returns the cumulative full loss distribution - Disposable > lossDistribution(const Date& d) const override; + std::map lossDistribution(const Date& d) const override; //! Loss level for this percentile Real percentile(const Date& d, Real percentile) const override; Real expectedShortfall(const Date& d, Real percentile) const override; @@ -111,9 +110,8 @@ namespace QuantLib { const std::vector& uncondDefProbs, const std::vector&) const; // expected as in time-value, not average, see literature - Disposable > - expConditionalLgd(const Date& d, - const std::vector& mktFactors) const + std::vector expConditionalLgd(const Date& d, + const std::vector& mktFactors) const { std::vector condLgds; const std::vector& evalDateLives = basket_->liveList(); @@ -125,8 +123,7 @@ namespace QuantLib { //! Loss probability density conditional on the market factor value. // Heres where the burden of the algorithm setup lies. - Disposable > - lossProbability( + std::vector lossProbability( const Date& date, // expected exposures at the passed date, no wrong way means // no dependence of the exposure with the mkt factor @@ -148,7 +145,7 @@ namespace QuantLib { distribution of a given number of defaults. */ template< class LLM> - Disposable > BinomialLossModel::lossProbability( + std::vector BinomialLossModel::lossProbability( const Date& date, const std::vector& bsktNots, const std::vector& uncondDefProbInv, @@ -273,8 +270,7 @@ namespace QuantLib { } template< class LLM> - Disposable > - BinomialLossModel::lossPoints(const Date& d) const + std::vector BinomialLossModel::lossPoints(const Date& d) const { std::vector notionals = basket_->remainingNotionals(d); @@ -331,8 +327,7 @@ namespace QuantLib { template< class LLM> - Disposable > - BinomialLossModel::lossDistribution(const Date& d) const + std::map BinomialLossModel::lossDistribution(const Date& d) const { std::map distrib; std::vector lossPts = lossPoints(d); diff --git a/ql/experimental/credit/constantlosslatentmodel.hpp b/ql/experimental/credit/constantlosslatentmodel.hpp index 1b93e335479..c289d2ba041 100644 --- a/ql/experimental/credit/constantlosslatentmodel.hpp +++ b/ql/experimental/credit/constantlosslatentmodel.hpp @@ -140,7 +140,7 @@ namespace QuantLib { integralType, nVariables,ini) {} protected: - //Disposable > probsBeingNthEvent( + //std::vector probsBeingNthEvent( // Size n, const Date& d) const { // return // ConstantLossLatentmodel::probsBeingNthEvent(n, d); diff --git a/ql/experimental/credit/defaultlossmodel.hpp b/ql/experimental/credit/defaultlossmodel.hpp index c545e3f31ce..4cb44b5ba70 100644 --- a/ql/experimental/credit/defaultlossmodel.hpp +++ b/ql/experimental/credit/defaultlossmodel.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -87,21 +86,18 @@ namespace QuantLib { QL_FAIL("eSF Not implemented for this model."); } //! Associated VaR fraction to each counterparty. - virtual Disposable > - splitVaRLevel(const Date& d, Real loss) const { + virtual std::vector splitVaRLevel(const Date& d, Real loss) const { QL_FAIL("splitVaRLevel Not implemented for this model."); } //! Associated ESF fraction to each counterparty. - virtual Disposable > - splitESFLevel(const Date& d, Real loss) const { + virtual std::vector splitESFLevel(const Date& d, Real loss) const { QL_FAIL("splitESFLevel Not implemented for this model."); } // \todo Add splits by instrument position. //! Full loss distribution. - virtual Disposable > - lossDistribution(const Date&) const { + virtual std::map lossDistribution(const Date&) const { QL_FAIL("lossDistribution Not implemented for this model."); } //! Probability density of a given loss fraction of the basket notional. @@ -116,8 +112,7 @@ namespace QuantLib { The the probabilities ordering in the vector coincides with the pool order. */ - virtual Disposable > probsBeingNthEvent( - Size n, const Date& d) const { + virtual std::vector probsBeingNthEvent(Size n, const Date& d) const { QL_FAIL("probsBeingNthEvent Not implemented for this model."); } //! Pearsons' default probability correlation. diff --git a/ql/experimental/credit/pool.cpp b/ql/experimental/credit/pool.cpp index 9ec546627c0..7f6dd363f7b 100644 --- a/ql/experimental/credit/pool.cpp +++ b/ql/experimental/credit/pool.cpp @@ -74,7 +74,7 @@ namespace QuantLib { return names_; } - Disposable > Pool::defaultKeys() const { + std::vector Pool::defaultKeys() const { std::vector defaultKeys; defaultKeys.reserve(defaultKeys_.size()); for (const auto & i : defaultKeys_) diff --git a/ql/experimental/credit/pool.hpp b/ql/experimental/credit/pool.hpp index 157fdc9b875..e9f3c0f5b10 100644 --- a/ql/experimental/credit/pool.hpp +++ b/ql/experimental/credit/pool.hpp @@ -24,7 +24,6 @@ #ifndef quantlib_pool_hpp #define quantlib_pool_hpp -#include #include #include @@ -44,7 +43,7 @@ namespace QuantLib { void setTime(const std::string& name, Real time); Real getTime (const std::string& name) const; const std::vector& names() const; - Disposable > defaultKeys() const; + std::vector defaultKeys() const; private: // \todo: needs to cehck all defaul TS have the same ref date? here or // where used? e.g. simulations. diff --git a/ql/experimental/credit/randomdefaultlatentmodel.hpp b/ql/experimental/credit/randomdefaultlatentmodel.hpp index 63ca1a654d3..ff3eac7f5f7 100644 --- a/ql/experimental/credit/randomdefaultlatentmodel.hpp +++ b/ql/experimental/credit/randomdefaultlatentmodel.hpp @@ -170,14 +170,13 @@ namespace QuantLib { Chen, Z., Glasserman, P. 'Fast pricing of basket default swaps' in Operations Research Vol. 56, No. 2, March/April 2008, pp. 286-303 */ - Disposable > probsBeingNthEvent(Size n, - const Date& d) const override; + std::vector probsBeingNthEvent(Size n, const Date& d) const override; //! Pearsons' default probability correlation. Real defaultCorrelation(const Date& d, Size iName, Size jName) const override; Real expectedTrancheLoss(const Date& d) const override; virtual std::pair expectedTrancheLossInterval(const Date& d, Probability confidencePerc) const; - Disposable > lossDistribution(const Date& d) const override; + std::map lossDistribution(const Date& d) const override; virtual Histogram computeHistogram(const Date& d) const; Real expectedShortfall(const Date& d, Real percent) const override; Real percentile(const Date& d, Real percentile) const override; @@ -188,7 +187,7 @@ namespace QuantLib { /*! Distributes the total VaR amount along the portfolio counterparties. The passed loss amount is in loss units. */ - Disposable > splitVaRLevel(const Date& date, Real loss) const override; + std::vector splitVaRLevel(const Date& date, Real loss) const override; /*! Distributes the total VaR amount along the portfolio counterparties. @@ -197,7 +196,7 @@ namespace QuantLib { The passed loss amount is in loss units. */ - virtual Disposable > > splitVaRAndError( + virtual std::vector > splitVaRAndError( const Date& date, Real loss, Probability confInterval) const; //@} public: @@ -253,9 +252,8 @@ namespace QuantLib { } template