Skip to content

Commit

Permalink
Removed usage of Disposable and of relative configure flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Apr 12, 2022
1 parent 5e59b56 commit 08159d9
Show file tree
Hide file tree
Showing 269 changed files with 1,376 additions and 2,058 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/linux-full-tests.yml
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/linux.yml
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions Docs/pages/config.docs
Expand Up @@ -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<T>` is
still available but is just an alias to `T`.

\code
#define QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
\endcode
Expand Down
12 changes: 6 additions & 6 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -65,7 +65,7 @@ Real ackley(const Array& x) {
return M_E + 20.0 - 20.0*std::exp(p1)-std::exp(p2);
}

Disposable<Array> 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];
Expand All @@ -81,7 +81,7 @@ Real sphere(const Array& x) {
return DotProduct(x, x);
}

Disposable<Array> 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];
Expand Down Expand Up @@ -110,7 +110,7 @@ Real easom(const Array& x) {
return -p1*std::exp(-p2);
}

Disposable<Array> 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]);
Expand Down Expand Up @@ -141,14 +141,14 @@ Real printFunction(Problem& p, const Array& x) {
class TestFunction : public CostFunction {
public:
typedef ext::function<Real(const Array&)> RealFunc;
typedef ext::function<Disposable<Array>(const Array&)> ArrayFunc;
typedef ext::function<Array(const Array&)> ArrayFunc;
explicit TestFunction(RealFunc f, ArrayFunc fs = ArrayFunc())
: f_(std::move(f)), fs_(std::move(fs)) {}
explicit TestFunction(Real (*f)(const Array&), Disposable<Array> (*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<Array> values(const Array& x) const override {
Array values(const Array& x) const override {
if(!fs_)
throw std::runtime_error("Invalid function");
return fs_(x);
Expand Down
1 change: 1 addition & 0 deletions cmake/GenerateHeaders.cmake
Expand Up @@ -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 "^\\..*")
Expand Down
17 changes: 0 additions & 17 deletions configure.ac
Expand Up @@ -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*)
Expand Down
1 change: 0 additions & 1 deletion ql/config.hpp.cfg
Expand Up @@ -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
Expand Down
23 changes: 8 additions & 15 deletions ql/experimental/credit/basket.cpp
Expand Up @@ -106,7 +106,7 @@ namespace QuantLib {
return std::accumulate(notionals_.begin(), notionals_.end(), 0.0);
}

Disposable<vector<Real> > Basket::probabilities(const Date& d) const {
vector<Real> Basket::probabilities(const Date& d) const {
vector<Real> prob(size());
vector<DefaultProbKey> defKeys = defaultKeys();
for (Size j = 0; j < size(); j++)
Expand Down Expand Up @@ -168,8 +168,7 @@ namespace QuantLib {
return evalDateRemainingNot_;
}

Disposable<std::vector<Size> >
Basket::liveList(const Date& endDate) const {
std::vector<Size> Basket::liveList(const Date& endDate) const {
std::vector<Size> calcBufferLiveList;
for (Size i = 0; i < size(); i++)
if (!pool_->get(pool_->names()[i]).defaultedBetween(
Expand All @@ -193,8 +192,7 @@ namespace QuantLib {
return notional;
}

Disposable<vector<Real> >
Basket::remainingNotionals(const Date& endDate) const
vector<Real> Basket::remainingNotionals(const Date& endDate) const
{
QL_REQUIRE(endDate >= refDate_,
"Target date lies before basket inception");
Expand All @@ -208,8 +206,7 @@ namespace QuantLib {
return calcBufferNotionals;
}

Disposable<std::vector<Probability> >
Basket::remainingProbabilities(const Date& d) const
std::vector<Probability> Basket::remainingProbabilities(const Date& d) const
{
QL_REQUIRE(d >= refDate_, "Target date lies before basket inception");
vector<Real> prob;
Expand Down Expand Up @@ -245,8 +242,7 @@ namespace QuantLib {
//return positions_[position]->expectedExposure(d);
}

Disposable<std::vector<std::string> >
Basket::remainingNames(const Date& endDate) const
std::vector<std::string> Basket::remainingNames(const Date& endDate) const
{
// maybe return zero directly instead?:
QL_REQUIRE(endDate >= refDate_,
Expand All @@ -260,8 +256,7 @@ namespace QuantLib {
return calcBufferNames;
}

Disposable<vector<DefaultProbKey> >
Basket::remainingDefaultKeys(const Date& endDate) const
vector<DefaultProbKey> Basket::remainingDefaultKeys(const Date& endDate) const
{
QL_REQUIRE(endDate >= refDate_,
"Target date lies before basket inception");
Expand Down Expand Up @@ -329,8 +324,7 @@ namespace QuantLib {
return cumulatedLoss() + lossModel_->expectedTrancheLoss(d);
}

Disposable<std::vector<Real> >
Basket::splitVaRLevel(const Date& date, Real loss) const {
std::vector<Real> Basket::splitVaRLevel(const Date& date, Real loss) const {
calculate();
return lossModel_->splitVaRLevel(date, loss);
}
Expand All @@ -340,8 +334,7 @@ namespace QuantLib {
return lossModel_->expectedShortfall(d, prob);
}

Disposable<std::map<Real, Probability> >
Basket::lossDistribution(const Date& d) const {
std::map<Real, Probability> Basket::lossDistribution(const Date& d) const {
calculate();
return lossModel_->lossDistribution(d);
}
Expand Down
28 changes: 10 additions & 18 deletions ql/experimental/credit/basket.hpp
Expand Up @@ -33,7 +33,6 @@
#include <ql/experimental/credit/recoveryratemodel.hpp>
#include <ql/experimental/credit/pool.hpp>
#include <ql/experimental/credit/loss.hpp>
#include <ql/utilities/disposable.hpp>

namespace QuantLib {

Expand Down Expand Up @@ -103,7 +102,7 @@ namespace QuantLib {
//! Underlying pool
const ext::shared_ptr<Pool>& pool() const;
//! The keys each counterparty enters the basket with (sensitive to)
Disposable<std::vector<DefaultProbKey> > defaultKeys() const;
std::vector<DefaultProbKey> defaultKeys() const;
/*! Loss Given Default for all issuers/notionals based on
expected recovery rates for the respective issuers.
*/
Expand All @@ -128,8 +127,7 @@ namespace QuantLib {
/*! Vector of cumulative default probability to date d for all
issuers in the basket.
*/
Disposable<std::vector<Probability> >
probabilities(const Date& d) const;
std::vector<Probability> 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.
Expand Down Expand Up @@ -165,26 +163,23 @@ namespace QuantLib {
reference date and the given date, recovery ignored.
*/
const std::vector<Real>& remainingNotionals() const;
Disposable<std::vector<Real> > remainingNotionals(const Date&) const;
std::vector<Real> remainingNotionals(const Date&) const;
/*! Vector of surviving issuers after defaults between the reference
basket date and the given (or evaluation) date.
*/
const std::vector<std::string>& remainingNames() const;
Disposable<std::vector<std::string> >
remainingNames(const Date&) const;
std::vector<std::string> remainingNames(const Date&) const;
/*! Default keys of non defaulted counterparties
*/
const std::vector<DefaultProbKey>& remainingDefaultKeys() const;
Disposable<std::vector<DefaultProbKey> > remainingDefaultKeys(
const Date&) const;
std::vector<DefaultProbKey> 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<std::vector<Probability> >
remainingProbabilities(const Date& d) const;
std::vector<Probability> remainingProbabilities(const Date& d) const;
/*!
Attachment amount of the equivalent (after defaults) remaining basket
The remaining attachment amount is
Expand Down Expand Up @@ -222,7 +217,7 @@ namespace QuantLib {
}
//!Indexes of remaining names. Notice these are names and not positions.
const std::vector<Size>& liveList() const;
Disposable<std::vector<Size> > liveList(const Date&) const;//?? keep?
std::vector<Size> liveList(const Date&) const;//?? keep?
//! Assigns the default loss model to this basket. Resets calculations.
void setLossModel(
const ext::shared_ptr<DefaultLossModel>& lossModel);
Expand All @@ -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<std::vector<Real> >
splitVaRLevel(const Date& date, Real loss) const;
std::vector<Real> splitVaRLevel(const Date& date, Real loss) const;
/*! Full loss distribution
*/
Disposable<std::map<Real, Probability> > lossDistribution(
const Date&) const;
std::map<Real, Probability> 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
Expand Down Expand Up @@ -329,8 +322,7 @@ namespace QuantLib {
return notionals_;
}

inline Disposable<std::vector<DefaultProbKey> >
Basket::defaultKeys() const {
inline std::vector<DefaultProbKey> Basket::defaultKeys() const {
return pool_->defaultKeys();
}

Expand Down
23 changes: 9 additions & 14 deletions ql/experimental/credit/binomiallossmodel.hpp
Expand Up @@ -78,8 +78,7 @@ namespace QuantLib {
/*! Returns the probability of the default loss values given by the
method lossPoints.
*/
Disposable<std::vector<Real> >
expectedDistribution(const Date& date) const {
std::vector<Real> expectedDistribution(const Date& date) const {
// precal date conditional magnitudes:
std::vector<Real> notionals = basket_->remainingNotionals(date);
std::vector<Probability> invProbs =
Expand All @@ -94,9 +93,9 @@ namespace QuantLib {
});
}
//! attainable loss points this model provides
Disposable<std::vector<Real> > lossPoints(const Date&) const;
std::vector<Real> lossPoints(const Date&) const;
//! Returns the cumulative full loss distribution
Disposable<std::map<Real, Probability> > lossDistribution(const Date& d) const override;
std::map<Real, Probability> 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;
Expand All @@ -111,9 +110,8 @@ namespace QuantLib {
const std::vector<Probability>& uncondDefProbs,
const std::vector<Real>&) const;
// expected as in time-value, not average, see literature
Disposable<std::vector<Real> >
expConditionalLgd(const Date& d,
const std::vector<Real>& mktFactors) const
std::vector<Real> expConditionalLgd(const Date& d,
const std::vector<Real>& mktFactors) const
{
std::vector<Real> condLgds;
const std::vector<Size>& evalDateLives = basket_->liveList();
Expand All @@ -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<std::vector<Real> >
lossProbability(
std::vector<Real> lossProbability(
const Date& date,
// expected exposures at the passed date, no wrong way means
// no dependence of the exposure with the mkt factor
Expand All @@ -148,7 +145,7 @@ namespace QuantLib {
distribution of a given number of defaults.
*/
template< class LLM>
Disposable<std::vector<Real> > BinomialLossModel<LLM>::lossProbability(
std::vector<Real> BinomialLossModel<LLM>::lossProbability(
const Date& date,
const std::vector<Real>& bsktNots,
const std::vector<Real>& uncondDefProbInv,
Expand Down Expand Up @@ -273,8 +270,7 @@ namespace QuantLib {
}

template< class LLM>
Disposable<std::vector<Real> >
BinomialLossModel<LLM>::lossPoints(const Date& d) const
std::vector<Real> BinomialLossModel<LLM>::lossPoints(const Date& d) const
{
std::vector<Real> notionals = basket_->remainingNotionals(d);

Expand Down Expand Up @@ -331,8 +327,7 @@ namespace QuantLib {


template< class LLM>
Disposable<std::map<Real, Probability> >
BinomialLossModel<LLM>::lossDistribution(const Date& d) const
std::map<Real, Probability> BinomialLossModel<LLM>::lossDistribution(const Date& d) const
{
std::map<Real, Probability> distrib;
std::vector<Real> lossPts = lossPoints(d);
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/constantlosslatentmodel.hpp
Expand Up @@ -140,7 +140,7 @@ namespace QuantLib {
integralType, nVariables,ini) {}

protected:
//Disposable<std::vector<Probability> > probsBeingNthEvent(
//std::vector<Probability> probsBeingNthEvent(
// Size n, const Date& d) const {
// return
// ConstantLossLatentmodel<copulaPolicy>::probsBeingNthEvent(n, d);
Expand Down

0 comments on commit 08159d9

Please sign in to comment.