26#include <boost/make_shared.hpp>
37 const vector<string>& creditCurveIds,
38 const boost::optional<string>& overrideCurve,
39 Real recoveryRate,
const bool inCcyDiscountCurve) {
40 vector<string> res{ccy.code()};
41 res.insert(res.end(), creditCurveIds.begin(), creditCurveIds.end());
42 res.push_back(creditCurveId);
43 res.push_back(overrideCurve ? *overrideCurve :
"");
44 if (recoveryRate != Null<Real>())
46 res.push_back(inCcyDiscountCurve ?
"1" :
"0");
51 const Currency& ccy,
const string& creditCurveId,
const vector<string>& creditCurveIds,
52 const boost::optional<string>& overrideCurve, Real recoveryRate,
const bool inCcyDiscountCurve) {
54 std::string curve = overrideCurve ? *overrideCurve :
engineParameter(
"Curve", {},
false,
"Underlying");
56 if (curve ==
"Index") {
59 Real recovery = recoveryRate != Null<Real>() ? recoveryRate : mktRecovery->value();
60 return QuantLib::ext::make_shared<QuantExt::MidPointIndexCdsEngine>(
61 creditCurve->curve(), recovery,
64 }
else if (curve ==
"Underlying") {
65 std::vector<Handle<DefaultProbabilityTermStructure>> dpts;
66 std::vector<Real> recovery;
67 for (
auto& c : creditCurveIds) {
70 dpts.push_back(tmp->curve());
71 recovery.push_back(recoveryRate != Null<Real>() ? recoveryRate : tmp2->value());
73 return QuantLib::ext::make_shared<QuantExt::MidPointIndexCdsEngine>(
78 QL_FAIL(
"MidPointIndexCdsEngineBuilder: Curve Parameter value \""
79 <<
engineParameter(
"Curve") <<
"\" not recognised, expected Underlying or Index");
QuantLib::ext::shared_ptr< Market > market_
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
CreditPortfolioSensitivityDecomposition sensitivityDecomposition()
vector< string > keyImpl(const Currency &ccy, const string &creditCurveId, const vector< string > &creditCurveIds, const boost::optional< string > &overrideCurve, Real recoveryRate=Null< Real >(), const bool inCcyDiscountCurve=false) override
QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &ccy, const string &creditCurveId, const vector< string > &creditCurveIds, const boost::optional< string > &overrideCurve, Real recoveryRate=Null< Real >(), const bool inCcyDiscountCurve=false) override
Classes and functions for log message handling.
market data related utilties
QuantLib::Handle< QuantExt::CreditCurve > indexCdsDefaultCurve(const QuantLib::ext::shared_ptr< Market > &market, const std::string &creditCurveId, const std::string &config)
CreditPortfolioSensitivityDecomposition parseCreditPortfolioSensitivityDecomposition(const std::string &s)
Convert text to CreditPortfolioSensitivitiyDecomposition.
std::string to_string(const LocationInfo &l)
CreditPortfolioSensitivityDecomposition
Enumeration CreditPortfolioSensitivityDecomposition.
Serializable Credit Default Swap.
string conversion utilities