Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
indexcreditdefaultswap.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
21
25
26#include <boost/make_shared.hpp>
27
28namespace ore {
29namespace data {
30
33 engineParameter("SensitivityDecomposition", {}, false, "Underlying"));
34}
35
36vector<string> IndexCreditDefaultSwapEngineBuilder::keyImpl(const Currency& ccy, const string& creditCurveId,
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>())
45 res.push_back(to_string(recoveryRate));
46 res.push_back(inCcyDiscountCurve ? "1" : "0");
47 return res;
48}
49
50QuantLib::ext::shared_ptr<PricingEngine> MidPointIndexCdsEngineBuilder::engineImpl(
51 const Currency& ccy, const string& creditCurveId, const vector<string>& creditCurveIds,
52 const boost::optional<string>& overrideCurve, Real recoveryRate, const bool inCcyDiscountCurve) {
53
54 std::string curve = overrideCurve ? *overrideCurve : engineParameter("Curve", {}, false, "Underlying");
55
56 if (curve == "Index") {
57 auto creditCurve = indexCdsDefaultCurve(market_, creditCurveId, configuration(MarketContext::pricing));
58 Handle<Quote> mktRecovery = market_->recoveryRate(creditCurveId, configuration(MarketContext::pricing));
59 Real recovery = recoveryRate != Null<Real>() ? recoveryRate : mktRecovery->value();
60 return QuantLib::ext::make_shared<QuantExt::MidPointIndexCdsEngine>(
61 creditCurve->curve(), recovery,
62 market_->discountCurve(
63 ccy.code(), configuration(inCcyDiscountCurve ? MarketContext::irCalibration : MarketContext::pricing)));
64 } else if (curve == "Underlying") {
65 std::vector<Handle<DefaultProbabilityTermStructure>> dpts;
66 std::vector<Real> recovery;
67 for (auto& c : creditCurveIds) {
68 auto tmp = market_->defaultCurve(c, configuration(MarketContext::pricing));
69 auto tmp2 = market_->recoveryRate(c, configuration(MarketContext::pricing));
70 dpts.push_back(tmp->curve());
71 recovery.push_back(recoveryRate != Null<Real>() ? recoveryRate : tmp2->value());
72 }
73 return QuantLib::ext::make_shared<QuantExt::MidPointIndexCdsEngine>(
74 dpts, recovery,
75 market_->discountCurve(
76 ccy.code(), configuration(inCcyDiscountCurve ? MarketContext::irCalibration : MarketContext::pricing)));
77 } else {
78 QL_FAIL("MidPointIndexCdsEngineBuilder: Curve Parameter value \""
79 << engineParameter("Curve") << "\" not recognised, expected Underlying or Index");
80 }
81}
82
83} // namespace data
84} // namespace ore
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.
@ data
Definition: log.hpp:77
market data related utilties
QuantLib::Handle< QuantExt::CreditCurve > indexCdsDefaultCurve(const QuantLib::ext::shared_ptr< Market > &market, const std::string &creditCurveId, const std::string &config)
Definition: marketdata.cpp:243
CreditPortfolioSensitivityDecomposition parseCreditPortfolioSensitivityDecomposition(const std::string &s)
Convert text to CreditPortfolioSensitivitiyDecomposition.
Definition: parsers.cpp:1374
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
CreditPortfolioSensitivityDecomposition
Enumeration CreditPortfolioSensitivityDecomposition.
Definition: parsers.hpp:568
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string conversion utilities