Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bondoption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
19/*! \file ored/portfolio/builders/bondoption.hpp
20\brief Engine builder for bond option
21\ingroup builders
22*/
23
24#pragma once
25
27
32
34
35#include <ql/processes/blackscholesprocess.hpp>
36
37#include <boost/make_shared.hpp>
38
39namespace ore {
40namespace data {
41
42//! Engine builder for bond option
43/*! Pricing engines are cached by currency, creditCurve, securityId and referenceCurve
44-
45\ingroup builders
46*/
48 : public CachingPricingEngineBuilder<string, const string&, const Currency&, const string&, const bool,
49 const string&, const string&, const string&> {
50public:
51 BondOptionEngineBuilder() : CachingEngineBuilder("Black", "BlackBondOptionEngine", {"BondOption"}) {}
52
53protected:
54 virtual std::string keyImpl(const string& id, const Currency& ccy, const string& creditCurveId,
55 const bool hasCreditRisk, const string& securityId, const string& referenceCurveId,
56 const string& volatilityCurveId) override {
57 // id is _not_ part of the key
58 return ccy.code() + "_" + creditCurveId + "_" + (hasCreditRisk ? "1_" : "0_") + securityId + "_" +
59 referenceCurveId + "_" + volatilityCurveId + "_" + "BondOption";
60 }
61
62 virtual QuantLib::ext::shared_ptr<QuantLib::PricingEngine>
63 engineImpl(const string& id, const Currency& ccy, const string& creditCurveId, const bool hasCreditRisk,
64 const string& securityId, const string& referenceCurveId, const string& volatilityCurveId) override {
65
66 Handle<YieldTermStructure> discountCurve =
67 market_->discountCurve(ccy.code(), configuration(MarketContext::pricing));
68 QL_REQUIRE(!volatilityCurveId.empty(), "BondOptionEngineBuilder: volatility curve ID for trade id '"
69 << id << "', security id '" << securityId << "' not given");
70 Handle<QuantLib::SwaptionVolatilityStructure> yieldVola =
71 market_->yieldVol(volatilityCurveId, configuration(MarketContext::pricing));
72 Handle<YieldTermStructure> yts = market_->yieldCurve(referenceCurveId, configuration(MarketContext::pricing));
73 Handle<DefaultProbabilityTermStructure> dpts;
74 // credit curve may not always be used. If credit curve ID is empty proceed without it
75 if (!creditCurveId.empty())
76 dpts =
78 ->curve();
79 Handle<Quote> recovery;
80 try {
81 // try security recovery first
82 recovery = market_->recoveryRate(securityId, configuration(MarketContext::pricing));
83 } catch (...) {
84 // otherwise fall back on curve recovery
85 ALOG("security specific recovery rate not found for security ID "
86 << securityId << ", falling back on the recovery rate for credit curve Id " << creditCurveId);
87 if (!creditCurveId.empty())
88 recovery = market_->recoveryRate(creditCurveId, configuration(MarketContext::pricing));
89 }
90 Handle<Quote> spread;
91 try {
92 // spread is optional, pass empty handle to engine if not given (will be treated as 0 spread there)
93 spread = market_->securitySpread(securityId, configuration(MarketContext::pricing));
94 } catch (...) {
95 }
96
97 if (!hasCreditRisk) {
98 dpts = Handle<DefaultProbabilityTermStructure>();
99 }
100
101 return QuantLib::ext::make_shared<QuantExt::BlackBondOptionEngine>(
102 discountCurve, yieldVola, yts, dpts, recovery, spread, parsePeriod(engineParameter("TimestepPeriod")));
103 };
104};
105} // namespace data
106} // namespace ore
Abstract template engine builder class.
Engine builder for bond option.
Definition: bondoption.hpp:49
virtual std::string keyImpl(const string &id, const Currency &ccy, const string &creditCurveId, const bool hasCreditRisk, const string &securityId, const string &referenceCurveId, const string &volatilityCurveId) override
Definition: bondoption.hpp:54
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const string &id, const Currency &ccy, const string &creditCurveId, const bool hasCreditRisk, const string &securityId, const string &referenceCurveId, const string &volatilityCurveId) override
Definition: bondoption.hpp:63
Abstract template EngineBuilder class that can cache engines and coupon pricers.
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)
Pricing Engine Factory.
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
@ data
Definition: log.hpp:77
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
market data related utilties
QuantLib::Handle< QuantExt::CreditCurve > securitySpecificCreditCurve(const QuantLib::ext::shared_ptr< Market > &market, const std::string &securityId, const std::string &creditCurveId, const std::string &configuration)
Definition: marketdata.cpp:98
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Structured Trade Error class.