Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
deltagammaengines.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 20 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/deltagammaengines.hpp
20 \brief Additional builders for engines that return deltas, vegas, gammas, cross-gammas
21 \ingroup portfolio
22*/
23
24#pragma once
25
26#include <qle/pricingengines/analyticeuropeanenginedeltagamma.hpp>
27#include <qle/pricingengines/discountingcurrencyswapenginedeltagamma.hpp>
28#include <qle/pricingengines/discountingfxforwardenginedeltagamma.hpp>
29#include <qle/pricingengines/discountingswapenginedeltagamma.hpp>
30
31#include <boost/make_shared.hpp>
39#include <ql/pricingengines/swap/discountingswapengine.hpp>
40
41namespace ore {
42namespace data {
43
44using namespace QuantLib;
45using namespace QuantExt;
46using namespace ore::data;
47
48//! Engine Builder for Single Currency Swaps
49/*! This builder uses DiscountingSwapEngineDeltaGamma
50 \ingroup portfolio
51*/
53public:
54 SwapEngineBuilderDeltaGamma() : SwapEngineBuilderBase("DiscountedCashflows", "DiscountingSwapEngineDeltaGamma") {}
55
56protected:
57 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const Currency& ccy, const std::string& discountCurve,
58 const std::string& securitySpread) override {
59
60 std::vector<Time> bucketTimes = parseListOfValues<Time>(engineParameter("BucketTimes"), &parseReal);
61 bool computeDelta = parseBool(engineParameter("ComputeDelta"));
62 bool computeGamma = parseBool(engineParameter("ComputeGamma"));
63 bool computeBPS = false; // parseBool(engineParameter("ComputeBPS"));
64
65 Handle<YieldTermStructure> yts = discountCurve.empty()
66 ? market_->discountCurve(ccy.code(), configuration(MarketContext::pricing))
68 if (!securitySpread.empty())
69 yts = Handle<YieldTermStructure>(QuantLib::ext::make_shared<ZeroSpreadedTermStructure>(
70 yts, market_->securitySpread(securitySpread, configuration(MarketContext::pricing))));
71 return QuantLib::ext::make_shared<DiscountingSwapEngineDeltaGamma>(yts, bucketTimes, computeDelta,
72 computeGamma, computeBPS);
73 }
74};
75
76//! Engine Builder for Cross Currency Swaps
77/*! This builder uses DiscountingCurrencySwapEngineDeltaGamma
78 */
80public:
82 : CrossCurrencySwapEngineBuilderBase("DiscountedCashflows", "DiscountingCrossCurrencySwapEngineDeltaGamma") {}
83
84protected:
85 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const std::vector<Currency>& ccys,
86 const Currency& base) override {
87
88 std::vector<Time> bucketTimes = parseListOfValues<Time>(engineParameter("BucketTimes"), &parseReal);
89 bool computeDelta = parseBool(engineParameter("ComputeDelta"));
90 bool computeGamma = parseBool(engineParameter("ComputeGamma"));
91 bool applySimmExemptions = parseBool(engineParameter("ApplySimmExemptions", {}, false, "false"));
92 bool linearInZero = parseBool(engineParameter("LinearInZero", {}, false, "true"));
93 std::vector<Handle<YieldTermStructure>> discountCurves;
94 std::vector<Handle<Quote>> fxQuotes;
95 for (Size i = 0; i < ccys.size(); ++i) {
96 discountCurves.push_back(xccyYieldCurve(market_, ccys[i].code(), configuration(MarketContext::pricing)));
97 string pair = ccys[i].code() + base.code();
98 fxQuotes.push_back(market_->fxRate(pair, configuration(MarketContext::pricing)));
99 }
100 return QuantLib::ext::make_shared<DiscountingCurrencySwapEngineDeltaGamma>(
101 discountCurves, fxQuotes, ccys, base, bucketTimes, computeDelta, computeGamma, linearInZero,
102 applySimmExemptions);
103 }
104};
105
106//! Engine Builder for European Options with delta/gamma extension
107/*!
108 \ingroup builders
109 */
111public:
112 EuropeanOptionEngineBuilderDeltaGamma(const string& model, const set<string>& tradeTypes,
113 const AssetClass& assetClass)
114 : VanillaOptionEngineBuilder(model, "AnalyticEuropeanEngineDeltaGamma", tradeTypes, assetClass, Date()) {}
115
116protected:
117 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
118 const AssetClass& assetClassUnderlying,
119 const Date& expiryDate, const bool useFxSpot) override {
120 std::vector<Time> bucketTimesDeltaGamma =
121 parseListOfValues<Time>(engineParameter("BucketTimesDeltaGamma"), &parseReal);
122 std::vector<Time> bucketTimesVega = parseListOfValues<Time>(engineParameter("BucketTimesVega"), &parseReal);
123 bool computeDeltaVega = parseBool(engineParameter("ComputeDeltaVega"));
124 bool computeGamma = parseBool(engineParameter("ComputeGamma"));
125
126 string pair = assetName + ccy.code();
127 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
128 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
129
130 return QuantLib::ext::make_shared<AnalyticEuropeanEngineDeltaGamma>(
131 gbsp, bucketTimesDeltaGamma, bucketTimesVega, computeDeltaVega, computeGamma);
132 }
133};
134
135//! Engine Builder for European FX Options with analytical sensitivities
136/*!
137 \ingroup builders
138 */
140public:
142 : EuropeanOptionEngineBuilderDeltaGamma("GarmanKohlhagen", {"FxOption"}, AssetClass::FX) {}
143};
144
145//! Engine Builder for European Equity Options with analytical sensitivities
146/*! Pricing engines are cached by asset/currency
147 \ingroup builders
148 */
150public:
152 : EuropeanOptionEngineBuilderDeltaGamma("BlackScholesMerton", {"EquityOption"}, AssetClass::EQ) {}
153};
154
155//! Engine Builder for FX Forwards
156/*! This builder uses DiscountingFxForwardEngineDeltaGamma
157 */
159public:
161 : FxForwardEngineBuilderBase("DiscountedCashflows", "DiscountingFxForwardEngineDeltaGamma") {}
162
163protected:
164 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const Currency& forCcy, const Currency& domCcy) override {
165
166 std::vector<Time> bucketTimes = parseListOfValues<Time>(engineParameter("BucketTimes"), &parseReal);
167 bool computeDelta = parseBool(engineParameter("ComputeDelta"));
168 bool computeGamma = parseBool(engineParameter("ComputeGamma"));
169 bool linearInZero = parseBool(engineParameter("LinearInZero", {}, false, "True")); // FIXME: Add to pricing engine parameters?
170 bool applySimmExemptions = parseBool(engineParameter("ApplySimmExemptions", {}, false, "false"));
171
172 string pair = keyImpl(forCcy, domCcy);
173 Handle<YieldTermStructure> domCcyCurve =
174 market_->discountCurve(domCcy.code(), configuration(MarketContext::pricing));
175 Handle<YieldTermStructure> forCcyCurve =
176 market_->discountCurve(forCcy.code(), configuration(MarketContext::pricing));
177 Handle<Quote> fx = market_->fxRate(pair, configuration(MarketContext::pricing));
178
179 return QuantLib::ext::make_shared<DiscountingFxForwardEngineDeltaGamma>(
180 domCcy, domCcyCurve, forCcy, forCcyCurve, fx, bucketTimes, computeDelta, computeGamma, linearInZero,
181 boost::none, Date(), Date(), applySimmExemptions);
182 }
183};
184
185} // namespace data
186} // namespace ore
Engine builder for FX Forwards.
Engine builder for FX Options.
Engine builder for Swaps.
Abstract engine builders for European and American Options.
QuantLib::ext::shared_ptr< QuantLib::GeneralizedBlackScholesProcess > getBlackScholesProcess(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const std::vector< Time > &timePoints={}, const bool useFxSpot=true)
Engine Builder base class for Cross Currency Swaps.
Definition: swap.hpp:110
Engine Builder for Cross Currency Swaps.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const std::vector< Currency > &ccys, const Currency &base) override
QuantLib::ext::shared_ptr< Market > market_
const set< string > & tradeTypes() const
Return the possible trade types.
const string & model() const
Return the model name.
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)
Engine Builder for European Equity Options with analytical sensitivities.
Engine Builder for European Options with delta/gamma extension.
EuropeanOptionEngineBuilderDeltaGamma(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate, const bool useFxSpot) override
Engine Builder for European FX Options with analytical sensitivities.
Engine Builder base class for FX Forwards.
Definition: fxforward.hpp:39
virtual string keyImpl(const Currency &forCcy, const Currency &domCcy) override
Definition: fxforward.hpp:45
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &forCcy, const Currency &domCcy) override
Engine Builder base class for Single Currency Swaps.
Definition: swap.hpp:49
Engine Builder for Single Currency Swaps.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const Currency &ccy, const std::string &discountCurve, const std::string &securitySpread) override
Abstract Engine Builder for Vanilla Options.
Pricing Engine Factory.
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Base Market class.
Handle< YieldTermStructure > xccyYieldCurve(const QuantLib::ext::shared_ptr< Market > &market, const string &ccyCode, const string &configuration)
Definition: marketdata.cpp:41
Handle< YieldTermStructure > indexOrYieldCurve(const QuantLib::ext::shared_ptr< Market > &market, const std::string &name, const std::string &configuration)
Definition: marketdata.cpp:65
Serializable Credit Default Swap.
Definition: namespaces.docs:23