Skip to content

Commit

Permalink
Merge 2560d5d into e607238
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Feb 17, 2021
2 parents e607238 + 2560d5d commit a8bb91e
Show file tree
Hide file tree
Showing 50 changed files with 256 additions and 611 deletions.
7 changes: 2 additions & 5 deletions ql/cashflows/conundrumpricer.cpp
Expand Up @@ -257,10 +257,7 @@ namespace QuantLib {

}

Real NumericHaganPricer::integrate(Real a,
Real b, const ConundrumIntegrand& integrand) const {

using namespace ext::placeholders;
Real NumericHaganPricer::integrate(Real a, Real b, const ConundrumIntegrand& integrand) const {

Real result =.0;
//double abserr =.0;
Expand Down Expand Up @@ -292,7 +289,7 @@ namespace QuantLib {
Size k = 3;
ext::function<Real (Real)> temp = ext::cref(integrand);
VariableChange variableChange(temp, a, upperBoundary, k);
f = ext::bind(&VariableChange::value, &variableChange, _1);
f = [&](Real _x) { return variableChange.value(_x); };
result = gaussKronrodNonAdaptive(f, .0, 1.0);
} else {
f = ext::cref(integrand);
Expand Down
44 changes: 10 additions & 34 deletions ql/experimental/credit/binomiallossmodel.hpp
Expand Up @@ -25,7 +25,6 @@
#include <ql/experimental/credit/defaultlossmodel.hpp>
#include <ql/functional.hpp>
#include <ql/handle.hpp>
#include <ql/math/functional.hpp>
#include <algorithm>
#include <numeric>
#include <utility>
Expand Down Expand Up @@ -81,7 +80,6 @@ namespace QuantLib {
*/
Disposable<std::vector<Real> >
expectedDistribution(const Date& date) const {
using namespace ext::placeholders;
// precal date conditional magnitudes:
std::vector<Real> notionals = basket_->remainingNotionals(date);
std::vector<Probability> invProbs =
Expand All @@ -90,18 +88,10 @@ namespace QuantLib {
invProbs[iName] =
copula_->inverseCumulativeY(invProbs[iName], iName);

return copula_->integratedExpectedValue(
ext::function<Disposable<std::vector<Real> > (
const std::vector<Real>& v1)>(
ext::bind(
&BinomialLossModel<LLM>::lossProbability,
this,
ext::cref(date), //d,
ext::cref(notionals),
ext::cref(invProbs),
_1)
)
);
return copula_->integratedExpectedValueV(
[&](const std::vector<Real>& v1) {
return lossProbability(date, notionals, invProbs, v1);
});
}
//! attainable loss points this model provides
Disposable<std::vector<Real> > lossPoints(const Date&) const;
Expand Down Expand Up @@ -286,19 +276,12 @@ namespace QuantLib {
Disposable<std::vector<Real> >
BinomialLossModel<LLM>::lossPoints(const Date& d) const
{
using namespace ext::placeholders;
std::vector<Real> notionals = basket_->remainingNotionals(d);

Real aveLossFrct = copula_->integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&BinomialLossModel<LLM>::averageLoss,
this,
ext::cref(d),
ext::cref(notionals),
_1)
)
);
[&](const std::vector<Real>& v1) {
return averageLoss(d, notionals, v1);
});

std::vector<Real> data;
Size dataSize = basket_->remainingSize() + 1;
Expand Down Expand Up @@ -332,7 +315,6 @@ namespace QuantLib {

template< class LLM>
Real BinomialLossModel<LLM>::expectedTrancheLoss(const Date& d) const {
using namespace ext::placeholders;
std::vector<Real> lossVals = lossPoints(d);
std::vector<Real> notionals = basket_->remainingNotionals(d);
std::vector<Probability> invProbs =
Expand All @@ -342,15 +324,9 @@ namespace QuantLib {
copula_->inverseCumulativeY(invProbs[iName], iName);

return copula_->integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(&BinomialLossModel<LLM>::condTrancheLoss,
this,
ext::cref(d),
ext::cref(lossVals),
ext::cref(notionals),
ext::cref(invProbs),
_1))
);
[&](const std::vector<Real>& v1) {
return condTrancheLoss(d, lossVals, notionals, invProbs, v1);
});
}


Expand Down
31 changes: 9 additions & 22 deletions ql/experimental/credit/defaultprobabilitylatentmodel.hpp
Expand Up @@ -218,15 +218,10 @@ namespace QuantLib {
if (pUncond < 1.e-10) return 0.;

return integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&DefaultLatentModel<copulaPolicy>
::conditionalDefaultProbabilityInvP,
this,
inverseCumulativeY(pUncond, iName),
iName,
ext::placeholders::_1)
));
[&](const std::vector<Real>& v1) {
return conditionalDefaultProbabilityInvP(
inverseCumulativeY(pUncond, iName), iName, v1);
});
}
/*! Pearsons' default probability correlation.
Users should consider specialization on the copula type for specific
Expand All @@ -241,14 +236,9 @@ namespace QuantLib {
*/
Probability probAtLeastNEvents(Size n, const Date& date) const {
return integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&DefaultLatentModel<copulaPolicy>::conditionalProbAtLeastNEvents,
this,
n,
ext::cref(date),
ext::placeholders::_1)
));
[&](const std::vector<Real>& v1) {
return conditionalProbAtLeastNEvents(n, date, v1);
});
}
};

Expand Down Expand Up @@ -276,11 +266,8 @@ namespace QuantLib {
Real E1i1j; // joint default covariance term
if(iNamei !=iNamej) {
E1i1j = integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&DefaultLatentModel<CP>::condProbProduct,
this, invPi, invPj, iNamei, iNamej,
ext::placeholders::_1) ));
[&](const std::vector<Real>& v1) {
return condProbProduct(invPi, invPj, iNamei, iNamej, v1); });
}else{
E1i1j = pi;
}
Expand Down
7 changes: 3 additions & 4 deletions ql/experimental/credit/pool.cpp
Expand Up @@ -75,11 +75,10 @@ namespace QuantLib {
}

Disposable<std::vector<DefaultProbKey> > Pool::defaultKeys() const {
using namespace ext::placeholders;
std::vector<DefaultProbKey> defaultKeys;
std::transform(defaultKeys_.begin(), defaultKeys_.end(),
std::back_inserter(defaultKeys), ext::bind(
&std::map<std::string, DefaultProbKey>::value_type::second, _1));
defaultKeys.reserve(defaultKeys_.size());
for (const auto & i : defaultKeys_)
defaultKeys.push_back(i.second);
return defaultKeys;
}

Expand Down
41 changes: 10 additions & 31 deletions ql/experimental/credit/recursivelossmodel.hpp
Expand Up @@ -22,7 +22,6 @@

#include <ql/experimental/credit/constantlosslatentmodel.hpp>
#include <ql/experimental/credit/defaultlossmodel.hpp>
#include <ql/functional.hpp>
#include <map>
#include <algorithm>

Expand Down Expand Up @@ -160,17 +159,10 @@ namespace QuantLib {
basket_->remainingProbabilities(date);
return copula_->integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&RecursiveLossModel::expectedConditionalLoss,
this,
ext::cref(uncDefProb),
_1)
)
);
[&](const std::vector<Real>& v1) {
return expectedConditionalLoss(uncDefProb, v1);
});
*/
/**/
using namespace ext::placeholders;

std::vector<Probability> uncDefProb =
basket_->remainingProbabilities(date);
Expand All @@ -179,34 +171,21 @@ namespace QuantLib {
invProb.push_back(copula_->inverseCumulativeY(uncDefProb[i], i));
/// invProb.push_back(CP::inverseCumulativeY(uncDefProb[i], i));//<-static call
return copula_->integratedExpectedValue(
ext::function<Real (const std::vector<Real>& v1)>(
ext::bind(
&RecursiveLossModel::expectedConditionalLossInvP,
this,
ext::cref(invProb),
_1)
)
);

[&](const std::vector<Real>& v1) {
return expectedConditionalLossInvP(invProb, v1);
});
}

template<class CP>
inline Disposable<std::vector<Real> >
RecursiveLossModel<CP>::lossProbability(const Date& date) const {

using namespace ext::placeholders;

std::vector<Probability> uncDefProb =
basket_->remainingProbabilities(date);
return copula_->integratedExpectedValue(
ext::function<Disposable<std::vector<Real> > (const std::vector<Real>& v1)>(
ext::bind(
&RecursiveLossModel::conditionalLossProb,
this,
ext::cref(uncDefProb),
_1)
)
);
return copula_->integratedExpectedValueV(
[&](const std::vector<Real>& v1) {
return conditionalLossProb(uncDefProb, v1);
});
}

// -------------------------------------------------------------------
Expand Down

0 comments on commit a8bb91e

Please sign in to comment.