Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
indexcreditdefaultswapoption.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
24
27
28#include <ql/pricingengine.hpp>
29
30#include <boost/make_shared.hpp>
31
32namespace ore {
33namespace data {
34
35using namespace QuantLib;
36
39 engineParameter("SensitivityDecomposition", {}, false, "Underlying"));
40}
41
42std::vector<std::string>
43IndexCreditDefaultSwapOptionEngineBuilder::keyImpl(const QuantLib::Currency& ccy, const std::string& creditCurveId,
44 const std::string& volCurveId,
45 const std::vector<std::string>& creditCurveIds) {
46
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);
51 return res;
52}
53
54namespace {
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) {
61
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);
65
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());
77 }
78 QuantLib::Real indexRecovery = QuantLib::Null<QuantLib::Real>();
79 try {
80 indexRecovery = market->recoveryRate(creditCurveId, configurationPricing)->value();
81 } catch (...) {
82 }
83 return QuantLib::ext::make_shared<ENGINE>(dpts, recovery, ytsInCcy, ytsPricing, vol, indexRecovery);
84 } else {
85 QL_FAIL("IndexCdsOptionEngineBuilder: Curve Parameter value \""
86 << curve << "\" not recognised, expected Underlying or Index");
87 }
88}
89} // namespace
90
91QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
92BlackIndexCdsOptionEngineBuilder::engineImpl(const QuantLib::Currency& ccy, const std::string& creditCurveId,
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>(
98 configuration(ore::data::MarketContext::pricing), ccy, creditCurveId, volCurveId, creditCurveIds);
99}
100
101QuantLib::ext::shared_ptr<QuantLib::PricingEngine> NumericalIntegrationIndexCdsOptionEngineBuilder::engineImpl(
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>(
107 configuration(ore::data::MarketContext::pricing), ccy, creditCurveId, volCurveId, creditCurveIds);
108}
109
110} // namespace data
111} // namespace ore
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
Pricing Engine Factory.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
CreditPortfolioSensitivityDecomposition parseCreditPortfolioSensitivityDecomposition(const std::string &s)
Convert text to CreditPortfolioSensitivitiyDecomposition.
Definition: parsers.cpp:1374
CreditPortfolioSensitivityDecomposition
Enumeration CreditPortfolioSensitivityDecomposition.
Definition: parsers.hpp:568
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string conversion utilities