Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
asianoption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Skandinaviska Enskilda Banken AB (publ)
3 Copyright (C) 2022 Quaternion Risk Management Ltd
4 All rights reserved.
5
6 This file is part of ORE, a free-software/open-source library
7 for transparent pricing and risk analysis - http://opensourcerisk.org
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 This program is distributed on the basis that it will form a useful
13 contribution to risk analytics and model standardisation, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
16 */
17
18 /*! \file portfolio/builders/asianoption.hpp
19 \brief Abstract engine builders for European Asian Options
20 \ingroup builders
21 */
22
23 #pragma once
24
26 #include <boost/make_shared.hpp>
28 #include <ored/utilities/log.hpp>
32 #include <ql/pricingengines/asian/analytic_cont_geom_av_price.hpp>
33 #include <ql/pricingengines/asian/analytic_discr_geom_av_price.hpp>
34 #include <ql/pricingengines/asian/analytic_discr_geom_av_strike.hpp>
35 #include <ql/pricingengines/asian/mc_discr_arith_av_price.hpp>
36 #include <ql/pricingengines/asian/mc_discr_arith_av_strike.hpp>
37 #include <ql/pricingengines/asian/turnbullwakemanasianengine.hpp>
38 #include <ql/utilities/null.hpp>
41
42 namespace ore {
43 namespace data {
44
45 //! Abstract Engine Builder for Asian Options
46 /*! Pricing engines are cached by asset/currency/expiry, where
47 expiry is null (Date()) if irrelevant.
48 \ingroup builders
49 */
51 : public CachingOptionEngineBuilder<string, const string&, const Currency&, const AssetClass&, const Date&> {
52 public:
53 AsianOptionEngineBuilder(const string& model, const string& engine, const set<string>& tradeTypes,
54 const AssetClass& assetClass, const Date& expiryDate)
55 : CachingOptionEngineBuilder(model, engine, tradeTypes, assetClass), expiryDate_(expiryDate) {}
56
57 QuantLib::ext::shared_ptr<PricingEngine> engine(const string& assetName, const Currency& ccy, const Date& expiryDate) {
58 return CachingPricingEngineBuilder<string, const string&, const Currency&, const AssetClass&,
59 const Date&>::engine(assetName, ccy, assetClass_, expiryDate);
60 }
61
62 QuantLib::ext::shared_ptr<PricingEngine> engine(const Currency& ccy1, const Currency& ccy2, const Date& expiryDate) {
63 return CachingPricingEngineBuilder<string, const string&, const Currency&, const AssetClass&,
64 const Date&>::engine(ccy1.code(), ccy2, assetClass_, expiryDate);
65 }
66
67 //! This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption
68 virtual std::string processType() { return ""; }
69
70 protected:
71 virtual string keyImpl(const string& assetName, const Currency& ccy, const AssetClass& assetClassUnderlying,
72 const Date& expiryDate) override {
73 return assetName + "/" + ccy.code() + "/" + to_string(expiryDate);
74 }
75
77 };
78
79 //! Discrete Monte Carlo Engine Builder for European Asian Arithmetic Average Price Options
80 /*! Pricing engines are cached by asset/currency/expiry, where
81 expiry is null (Date()) if irrelevant.
82 \ingroup builders
83 */
85 public:
86 EuropeanAsianOptionMCDAAPEngineBuilder(const string& model, const set<string>& tradeTypes,
87 const AssetClass& assetClass, const Date& expiryDate)
88 : AsianOptionEngineBuilder(model, "MCDiscreteArithmeticAPEngine", tradeTypes, assetClass, expiryDate) {}
89
90 std::string processType() override { return "Discrete"; }
91
92 protected:
93 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
94 const AssetClass& assetClassUnderlying,
95 const Date& expiryDate) override {
96 bool brownianBridge = ore::data::parseBool(engineParameter("BrownianBridge", {}, false, "true"));
97 bool antitheticVariate = ore::data::parseBool(engineParameter("AntitheticVariate", {}, false, "true"));
98 bool controlVariate = ore::data::parseBool(engineParameter("ControlVariate", {}, false, "true"));
99 Size requiredSamples = ore::data::parseInteger(engineParameter("RequiredSamples", {}, false, "0"));
100 Real requiredTolerance = ore::data::parseReal(engineParameter("RequiredTolerance", {}, false, "0"));
101 Size maxSamples = ore::data::parseInteger(engineParameter("MaxSamples", {}, false, "0"));
102 BigNatural seed = ore::data::parseInteger(engineParameter("Seed", {}, false, "123456"));
103
104 // Check if values defaulted to 0, if so replace by Null<T>().
105 if (requiredSamples == 0)
106 requiredSamples = Null<Size>();
107 if (requiredTolerance == 0)
108 requiredTolerance = Null<Real>();
109 if (maxSamples == 0)
110 maxSamples = Null<Size>();
111 QL_REQUIRE(requiredSamples != QuantLib::Null<Size>() || requiredTolerance != QuantLib::Null<Real>(),
112 "RequiredSamples or RequiredTolerance must be set for engine MCDiscreteArithmeticAPEngine.");
113
114 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
115 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
116 return QuantLib::ext::make_shared<MCDiscreteArithmeticAPEngine<LowDiscrepancy>>(gbsp, brownianBridge, antitheticVariate,
117 controlVariate, requiredSamples,
118 requiredTolerance, maxSamples, seed);
119 }
120 };
121
122 //! Discrete Monte Carlo Engine Builder for European Asian Arithmetic Average Strike Options
123 /*! Pricing engines are cached by asset/currency/expiry, where
124 expiry is null (Date()) if irrelevant.
125 \ingroup builders
126 */
128 public:
129 EuropeanAsianOptionMCDAASEngineBuilder(const string& model, const set<string>& tradeTypes,
130 const AssetClass& assetClass, const Date& expiryDate)
131 : AsianOptionEngineBuilder(model, "MCDiscreteArithmeticASEngine", tradeTypes, assetClass, expiryDate) {}
132
133 std::string processType() override { return "Discrete"; }
134
135 protected:
136 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
137 const AssetClass& assetClassUnderlying,
138 const Date& expiryDate) override {
139 bool brownianBridge = ore::data::parseBool(engineParameter("BrownianBridge", {}, false, "true"));
140 bool antitheticVariate = ore::data::parseBool(engineParameter("AntitheticVariate", {}, false, "true"));
141 Size requiredSamples = ore::data::parseInteger(engineParameter("RequiredSamples", {}, false, "0"));
142 Real requiredTolerance = ore::data::parseReal(engineParameter("RequiredTolerance", {}, false, "0"));
143 Size maxSamples = ore::data::parseInteger(engineParameter("MaxSamples", {}, false, "0"));
144 BigNatural seed = ore::data::parseInteger(engineParameter("Seed", {}, false, "123456"));
145
146 // Check if values defaulted to 0, if so replace by Null<T>().
147 if (requiredSamples == 0)
148 requiredSamples = Null<Size>();
149 if (requiredTolerance == 0)
150 requiredTolerance = Null<Real>();
151 if (maxSamples == 0)
152 maxSamples = Null<Size>();
153 QL_REQUIRE(requiredSamples != QuantLib::Null<Size>() || requiredTolerance != QuantLib::Null<Real>(),
154 "RequiredSamples or RequiredTolerance must be set for engine MCDiscreteArithmeticASEngine.");
155
156 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
157 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
158 return QuantLib::ext::make_shared<MCDiscreteArithmeticASEngine<LowDiscrepancy>>(
159 gbsp, brownianBridge, antitheticVariate, requiredSamples, requiredTolerance, maxSamples, seed);
160 }
161 };
162
163 //! Discrete Monte Carlo Engine Builder for European Asian Geometric Average Price Options
164 /*! Pricing engines are cached by asset/currency/expiry, where
165 expiry is null (Date()) if irrelevant.
166 \ingroup builders
167 */
169 public:
170 EuropeanAsianOptionMCDGAPEngineBuilder(const string& model, const set<string>& tradeTypes,
171 const AssetClass& assetClass, const Date& expiryDate)
172 : AsianOptionEngineBuilder(model, "MCDiscreteGeometricAPEngine", tradeTypes, assetClass, expiryDate) {}
173
174 std::string processType() override { return "Discrete"; }
175
176 protected:
177 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
178 const AssetClass& assetClassUnderlying,
179 const Date& expiryDate) override {
180 bool brownianBridge = ore::data::parseBool(engineParameter("BrownianBridge", {}, false, "true"));
181 bool antitheticVariate = ore::data::parseBool(engineParameter("AntitheticVariate", {}, false, "true"));
182 Size requiredSamples = ore::data::parseInteger(engineParameter("RequiredSamples", {}, false, "0"));
183 Real requiredTolerance = ore::data::parseReal(engineParameter("RequiredTolerance", {}, false, "0"));
184 Size maxSamples = ore::data::parseInteger(engineParameter("MaxSamples", {}, false, "0"));
185 BigNatural seed = ore::data::parseInteger(engineParameter("Seed", {}, false, "123456"));
186
187 // Check if values defaulted to 0, if so replace by Null<T>().
188 if (requiredSamples == 0)
189 requiredSamples = Null<Size>();
190 if (requiredTolerance == 0)
191 requiredTolerance = Null<Real>();
192 if (maxSamples == 0)
193 maxSamples = Null<Size>();
194 QL_REQUIRE(requiredSamples != QuantLib::Null<Size>() || requiredTolerance != QuantLib::Null<Real>(),
195 "RequiredSamples or RequiredTolerance must be set for engine MCDiscreteGeometricAPEngine.");
196
197 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
198 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
199 return QuantLib::ext::make_shared<MCDiscreteGeometricAPEngine<LowDiscrepancy>>(
200 gbsp, brownianBridge, antitheticVariate, requiredSamples, requiredTolerance, maxSamples, seed);
201 }
202 };
203
204 //! Discrete Analytic Engine Builder for European Asian Geometric Average Price Options
205 /*! Pricing engines are cached by asset/currency
206 \ingroup builders
207 */
209 public:
210 EuropeanAsianOptionADGAPEngineBuilder(const string& model, const set<string>& tradeTypes,
211 const AssetClass& assetClass)
212 : AsianOptionEngineBuilder(model, "AnalyticDiscreteGeometricAPEngine", tradeTypes, assetClass, Date()) {}
213
214 std::string processType() override { return "Discrete"; }
215
216 protected:
217 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
218 const AssetClass& assetClassUnderlying,
219 const Date& expiryDate) override {
220 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
221 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
222 return QuantLib::ext::make_shared<AnalyticDiscreteGeometricAveragePriceAsianEngine>(gbsp);
223 }
224 };
225
226 //! Discrete Analytic Engine Builder for European Asian Geometric Average Strike Options
227 /*! Pricing engines are cached by asset/currency
228 \ingroup builders
229 */
231 public:
232 EuropeanAsianOptionADGASEngineBuilder(const string& model, const set<string>& tradeTypes,
233 const AssetClass& assetClass)
234 : AsianOptionEngineBuilder(model, "AnalyticDiscreteGeometricASEngine", tradeTypes, assetClass, Date()) {}
235
236 std::string processType() override { return "Discrete"; }
237
238 protected:
239 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
240 const AssetClass& assetClassUnderlying,
241 const Date& expiryDate) override {
242 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
243 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
244 return QuantLib::ext::make_shared<AnalyticDiscreteGeometricAverageStrikeAsianEngine>(gbsp);
245 }
246 };
247
248 //! Continuous Analytic Engine Builder for European Asian Geometric Average Price Options
249 /*! Pricing engines are cached by asset/currency
250 Note that this engine disregards fixing dates, i.e. it utilizes continuous averaging and is mainly for testing.
251 \ingroup builders
252 */
254 public:
255 EuropeanAsianOptionACGAPEngineBuilder(const string& model, const set<string>& tradeTypes,
256 const AssetClass& assetClass)
257 : AsianOptionEngineBuilder(model, "AnalyticContinuousGeometricAPEngine", tradeTypes, assetClass, Date()) {}
258
259 std::string processType() override { return "Continuous"; }
260
261 protected:
262 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
263 const AssetClass& assetClassUnderlying,
264 const Date& expiryDate) override {
265 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
266 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
267 return QuantLib::ext::make_shared<AnalyticContinuousGeometricAveragePriceAsianEngine>(gbsp);
268 }
269 };
270
271 //! Discrete Analytic TW Engine Builder for European Asian Arithmetic Average Price Options
272 /*! Pricing engines are cached by asset/currency
273 \ingroup builders
274 */
276 public:
277 EuropeanAsianOptionTWEngineBuilder(const string& model, const set<string>& tradeTypes,
278 const AssetClass& assetClass)
279 : AsianOptionEngineBuilder(model, "TurnbullWakemanAsianEngine", tradeTypes, assetClass, Date()) {}
280
281 std::string processType() override { return "Discrete"; }
282
283 protected:
284 virtual QuantLib::ext::shared_ptr<PricingEngine> engineImpl(const string& assetName, const Currency& ccy,
285 const AssetClass& assetClassUnderlying,
286 const Date& expiryDate) override {
287 QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> gbsp =
288 getBlackScholesProcess(assetName, ccy, assetClassUnderlying);
289 return QuantLib::ext::make_shared<TurnbullWakemanAsianEngine>(gbsp);
290 }
291 };
292
294public:
296 : DelegatingEngineBuilder("ScriptedTrade", "ScriptedTrade",
297 {"EquityAsianOptionArithmeticPrice", "EquityAsianOptionArithmeticStrike",
298 "EquityAsianOptionGeometricPrice", "EquityAsianOptionGeometricStrike",
299 "FxAsianOptionArithmeticPrice", "FxAsianOptionArithmeticStrike",
300 "FxAsianOptionGeometricPrice", "FxAsianOptionGeometricStrike",
301 "CommodityAsianOptionArithmeticPrice", "CommodityAsianOptionArithmeticStrike",
302 "CommodityAsianOptionGeometricPrice", "CommodityAsianOptionGeometricStrike"}) {}
303 QuantLib::ext::shared_ptr<ore::data::Trade> build(const Trade* trade,
304 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) override;
305 std::string effectiveTradeType() const override { return "ScriptedTrade"; }
306};
307
308 } // namespace data
309 } // namespace ore
basket option wrapper for scripted trade
Abstract engine builders for European and American Options.
Abstract template engine builder class.
Abstract Engine Builder for Asian Options.
Definition: asianoption.hpp:51
QuantLib::ext::shared_ptr< PricingEngine > engine(const Currency &ccy1, const Currency &ccy2, const Date &expiryDate)
Definition: asianoption.hpp:62
AsianOptionEngineBuilder(const string &model, const string &engine, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
Definition: asianoption.hpp:53
virtual string keyImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Definition: asianoption.hpp:71
QuantLib::ext::shared_ptr< PricingEngine > engine(const string &assetName, const Currency &ccy, const Date &expiryDate)
Definition: asianoption.hpp:57
virtual std::string processType()
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
Definition: asianoption.hpp:68
QuantLib::ext::shared_ptr< ore::data::Trade > build(const Trade *trade, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
Definition: asianoption.cpp:24
std::string effectiveTradeType() const override
Abstract template EngineBuilder class that can cache engines and coupon pricers.
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)
Delegating Engine Builder.
const string & engine() const
Return the engine name.
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
Continuous Analytic Engine Builder for European Asian Geometric Average Price Options.
EuropeanAsianOptionACGAPEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Discrete Analytic Engine Builder for European Asian Geometric Average Price Options.
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
EuropeanAsianOptionADGAPEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
Discrete Analytic Engine Builder for European Asian Geometric Average Strike Options.
EuropeanAsianOptionADGASEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Discrete Monte Carlo Engine Builder for European Asian Arithmetic Average Price Options.
Definition: asianoption.hpp:84
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
Definition: asianoption.hpp:90
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Definition: asianoption.hpp:93
EuropeanAsianOptionMCDAAPEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
Definition: asianoption.hpp:86
Discrete Monte Carlo Engine Builder for European Asian Arithmetic Average Strike Options.
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
EuropeanAsianOptionMCDAASEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Discrete Monte Carlo Engine Builder for European Asian Geometric Average Price Options.
EuropeanAsianOptionMCDGAPEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass, const Date &expiryDate)
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Discrete Analytic TW Engine Builder for European Asian Arithmetic Average Price Options.
EuropeanAsianOptionTWEngineBuilder(const string &model, const set< string > &tradeTypes, const AssetClass &assetClass)
std::string processType() override
This is used in building the option to select between Discrete- and ContinuousAveragingAsianOption.
virtual QuantLib::ext::shared_ptr< PricingEngine > engineImpl(const string &assetName, const Currency &ccy, const AssetClass &assetClassUnderlying, const Date &expiryDate) override
Trade base class.
Definition: trade.hpp:55
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
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
string conversion utilities