23#include <ql/math/interpolations/backwardflatinterpolation.hpp>
24#include <ql/math/interpolations/loginterpolation.hpp>
25#include <ql/termstructures/credit/flathazardrate.hpp>
41 std::vector<Handle<DefaultProbabilityTermStructure>> dpts;
42 Handle<DefaultProbabilityTermStructure> clientCurve;
43 Handle<DefaultProbabilityTermStructure> baseCurve;
44 vector<Time> baseCurveTimes;
46 for (
const auto& targetCurve : curves) {
54 std::sort(targetCurveTimes.begin(), targetCurveTimes.end());
56 if (targetCurve == curves.front()) {
57 baseCurve = targetCurve;
58 clientCurve = baseCurve;
59 baseCurveTimes = targetCurveTimes;
61 std::vector<Time> times;
62 std::set_union(baseCurveTimes.begin(), baseCurveTimes.end(), targetCurveTimes.begin(),
63 targetCurveTimes.end(), std::back_inserter(times));
64 vector<Handle<Quote>> spreads(times.size());
65 std::transform(times.begin(), times.end(), spreads.begin(), [&baseCurve, &targetCurve](Time t) {
67 targetCurve->survivalProbability(t, true) / baseCurve->survivalProbability(t, true);
68 if (close_enough(spread, 0.0)) {
71 return Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(spread));
73 clientCurve = Handle<DefaultProbabilityTermStructure>(
74 QuantLib::ext::make_shared<SpreadedSurvivalProbabilityTermStructure>(baseCurve, times, spreads));
75 if (baseCurve->allowsExtrapolation())
76 clientCurve->enableExtrapolation();
78 dpts.push_back(clientCurve);
84 const Currency& ccy,
bool isIndexCDS,
const vector<string>& creditCurves,
85 const QuantLib::ext::shared_ptr<SimpleQuote>& calibrationFactor,
86 const QuantLib::Real fixedRecovery) {
89 std::vector<Handle<DefaultProbabilityTermStructure>> dpts;
90 std::vector<Real> recovery;
91 for (
auto& c : creditCurves) {
93 Handle<DefaultProbabilityTermStructure> targetCurve;
103 recovery.push_back(fixedRecovery != Null<Real>() ? fixedRecovery : recoveryRate);
104 dpts.push_back(targetCurve);
109 return QuantLib::ext::make_shared<QuantExt::MidPointIndexCdsEngine>(dpts, recovery, yts);
112 return QuantLib::ext::make_shared<QuantExt::IndexCdsTrancheEngine>(yts);
Mid point CDO engines cached by currency.
bool optimizedSensitivityCalculation() const
bool calibrateConstituentCurve() const
QuantLib::ext::shared_ptr< Market > market_
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
std::map< std::string, std::string > globalParameters_
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &ccy, bool isIndexCDS, const vector< string > &creditCurves, const QuantLib::ext::shared_ptr< QuantLib::SimpleQuote > &calibrationFactor, const QuantLib::Real fixedRecovery=QuantLib::Null< QuantLib::Real >()) override
static vector< Time > extractTimeGridDefaultCurve(const QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > &dpts)
static QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > buildCalibratedConstiuentCurve(const QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > &curve, const QuantLib::ext::shared_ptr< SimpleQuote > &calibrationFactor)
std::vector< Handle< DefaultProbabilityTermStructure > > buildPerformanceOptimizedDefaultCurves(const std::vector< Handle< DefaultProbabilityTermStructure > > &curves)
Serializable Credit Default Swap.