28#include <ql/pricingengine.hpp>
30#include <boost/make_shared.hpp>
42std::vector<std::string>
44 const std::string& volCurveId,
45 const std::vector<std::string>& creditCurveIds) {
47 std::vector<std::string> res{ccy.code()};
48 res.insert(res.end(), creditCurveIds.begin(), creditCurveIds.end());
49 res.push_back(creditCurveId);
50 res.push_back(volCurveId);
55template <
class ENGINE>
56QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
57genericEngineImpl(
const std::string& curve,
const QuantLib::ext::shared_ptr<Market> market,
58 const std::string& configurationInCcy,
const std::string& configurationPricing,
59 const QuantLib::Currency& ccy,
const std::string& creditCurveId,
const std::string& volCurveId,
60 const std::vector<std::string>& creditCurveIds) {
62 QuantLib::Handle<QuantLib::YieldTermStructure> ytsInCcy = market->discountCurve(ccy.code(), configurationInCcy);
63 QuantLib::Handle<QuantLib::YieldTermStructure> ytsPricing = market->discountCurve(ccy.code(), configurationPricing);
64 QuantLib::Handle<QuantExt::CreditVolCurve> vol = market->cdsVol(volCurveId, configurationPricing);
66 if (curve ==
"Index") {
67 auto creditCurve = market->defaultCurve(creditCurveId, configurationPricing);
68 QuantLib::Handle<QuantLib::Quote> recovery = market->recoveryRate(creditCurveId, configurationPricing);
69 return QuantLib::ext::make_shared<ENGINE>(creditCurve->curve(), recovery->value(), ytsInCcy, ytsPricing, vol);
70 }
else if (curve ==
"Underlying") {
71 std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>> dpts;
72 std::vector<QuantLib::Real> recovery;
73 for (
auto& c : creditCurveIds) {
74 auto tmp = market->defaultCurve(c, configurationPricing);
75 dpts.push_back(tmp->curve());
76 recovery.push_back(market->recoveryRate(c, configurationPricing)->value());
78 QuantLib::Real indexRecovery = QuantLib::Null<QuantLib::Real>();
80 indexRecovery = market->recoveryRate(creditCurveId, configurationPricing)->value();
83 return QuantLib::ext::make_shared<ENGINE>(dpts, recovery, ytsInCcy, ytsPricing, vol, indexRecovery);
85 QL_FAIL(
"IndexCdsOptionEngineBuilder: Curve Parameter value \""
86 << curve <<
"\" not recognised, expected Underlying or Index");
91QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
93 const std::string& volCurveId,
94 const std::vector<std::string>& creditCurveIds) {
95 std::string curve =
engineParameter(
"FepCurve", {},
false,
"Underlying");
96 return genericEngineImpl<QuantExt::BlackIndexCdsOptionEngine>(
102 const QuantLib::Currency& ccy,
const std::string& creditCurveId,
const std::string& volCurveId,
103 const std::vector<std::string>& creditCurveIds) {
104 std::string curve =
engineParameter(
"FepCurve", {},
false,
"Underlying");
105 return genericEngineImpl<QuantExt::NumericalIntegrationIndexCdsOptionEngine>(
Abstract template engine builder class.
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const QuantLib::Currency &ccy, const std::string &creditCurveId, const std::string &volCurveId, const std::vector< std::string > &creditCurveIds) override
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)
std::vector< std::string > keyImpl(const QuantLib::Currency &ccy, const std::string &creditCurveId, const std::string &volCurveId, const std::vector< std::string > &creditCurveIds) override
CreditPortfolioSensitivityDecomposition sensitivityDecomposition()
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const QuantLib::Currency &ccy, const std::string &creditCurveId, const std::string &volCurveId, const std::vector< std::string > &creditCurveIds) override
Classes and functions for log message handling.
CreditPortfolioSensitivityDecomposition parseCreditPortfolioSensitivityDecomposition(const std::string &s)
Convert text to CreditPortfolioSensitivitiyDecomposition.
CreditPortfolioSensitivityDecomposition
Enumeration CreditPortfolioSensitivityDecomposition.
Serializable Credit Default Swap.
string conversion utilities